Skip to content

Commit

Permalink
refactor: make versions infos endoint consistent with mehari
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe committed Nov 11, 2024
1 parent 73e4567 commit c9b00d0
Show file tree
Hide file tree
Showing 14 changed files with 305 additions and 118 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,38 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: lcov.info

Schema:
needs: Formatting
runs-on: ubuntu-24.04

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt-get update -y
sudo apt-get install -y librocksdb-dev libsnappy-dev libsqlite3-dev
- name: Install stable toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true

- name: Setup protoc
uses: arduino/[email protected]
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Write schema
run: cargo run -- server schema --output-file /tmp/openapi.schema.yaml-gen

- name: Copy repo schema and strip versions
run: |
cp openapi.schema.yaml /tmp/openapi.schema.yaml-repo
perl -p -i -e 's/^ version: .*/ version: 0.0.0/' /tmp/*.yaml-*
- name: Compare YAML in git to the one just generated
run: diff /tmp/openapi.schema.yaml-repo /tmp/openapi.schema.yaml-gen
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "annonars"
version = "0.41.3"
edition = "2021"
authors = ["Manuel Holtgrewe <[email protected]>"]
description = "Rust template repository"
description = "Genome annotation based on Rust and RocksDB"
license = "Apache-2.0"
repository = "https://github.com/varfish-org/annonars"
readme = "README.md"
Expand Down
1 change: 0 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ fn main() -> Result<(), anyhow::Error> {
"annonars/clinvar/minimal.proto",
"annonars/clinvar/per_gene.proto",
"annonars/clinvar/sv.proto",
"annonars/common/versions.proto",
"annonars/cons/base.proto",
"annonars/dbsnp/base.proto",
"annonars/functional/refseq.proto",
Expand Down
171 changes: 171 additions & 0 deletions openapi.schema.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
openapi: 3.0.3
info:
title: annonars
description: Genome annotation based on Rust and RocksDB
contact:
name: Manuel Holtgrewe
email: [email protected]
license:
name: Apache-2.0
version: 0.41.3
paths:
/api/v1/versionsInfo:
get:
tags:
- versions
summary: Query for annotations for one variant.
operationId: versionsInfo
parameters: []
responses:
'200':
description: Version information.
content:
application/json:
schema:
$ref: '#/components/schemas/VersionsResponse'
'500':
description: Internal server error.
content:
application/json:
schema:
$ref: '#/components/schemas/CustomError'
components:
schemas:
AnnoDb:
type: string
description: Encode annotation database.
enum:
- other
- cadd
- dbsnp
- dbnsfp
- dbscsnv
- gnomad_mtdna
- gnomad_exomes
- gnomad_genomes
- helixmtdb
- ucsc_conservation
- clinvar
CustomError:
type: object
description: Custom error type for the Actix server.
required:
- err
properties:
err:
type: string
GenomeRelease:
type: string
description: Local genome release for command line arguments.
enum:
- Grch37
- Grch38
VersionsAnnotationInfo:
type: object
description: Version information for one database.
required:
- database
properties:
database:
$ref: '#/components/schemas/AnnoDb'
version_spec:
allOf:
- $ref: '#/components/schemas/VersionsVersionSpec'
nullable: true
VersionsCreatedFrom:
type: object
description: Source name and version.
required:
- name
- version
properties:
name:
type: string
description: The name of the data source.
version:
type: string
description: The version of the data source.
VersionsInfoQuery:
type: object
description: Query parameters for `handle()`.
VersionsInfoResponse:
type: object
description: Response for `handle()`.
properties:
genes:
allOf:
- $ref: '#/components/schemas/VersionsVersionSpec'
nullable: true
seqvars:
type: array
items:
$ref: '#/components/schemas/VersionsPerRelease'
description: Version information of annotation databases per release.
VersionsPerRelease:
type: object
description: Version information for databases in a given release.
required:
- release
properties:
release:
$ref: '#/components/schemas/GenomeRelease'
version_infos:
type: array
items:
$ref: '#/components/schemas/VersionsAnnotationInfo'
description: Version information of annotation databases.
VersionsVersionSpec:
type: object
description: Version specification.
required:
- identifier
- title
- creator
- contributor
- format
- date
- version
- description
- source
- created_from
properties:
identifier:
type: string
description: Identifier of the data.
title:
type: string
description: Title of the data.
creator:
type: string
description: Creator of the data.
contributor:
type: array
items:
type: string
description: Contributors of the data.
format:
type: string
description: Format of the data.
date:
type: string
description: Date of the data.
version:
type: string
description: Version of the data.
genome_release:
type: string
description: Optional genome release.
nullable: true
description:
type: string
description: Data description.
source:
type: array
items:
type: string
description: Data source.
created_from:
type: array
items:
$ref: '#/components/schemas/VersionsCreatedFrom'
description: Created from information.
37 changes: 0 additions & 37 deletions protos/annonars/common/versions.proto

This file was deleted.

3 changes: 1 addition & 2 deletions src/common/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,15 @@ pub enum OutputFormat {
strum::EnumString,
enum_map::Enum,
serde::Serialize,
serde::Deserialize,
utoipa::ToSchema,
)]
#[strum(serialize_all = "lowercase")]
pub enum GenomeRelease {
/// GRCh37 genome release.
#[strum(serialize = "grch37")]
#[default]
Grch37,
/// GRCh38 genome release.
#[strum(serialize = "grch38")]
Grch38,
}

Expand Down
5 changes: 2 additions & 3 deletions src/genes/cli/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2796,9 +2796,8 @@ mod tests {
.lines()
.map(|s| {
serde_json::from_str::<panelapp::Record>(s)
.map_err(|e| {
println!("{}", &s);
e
.inspect_err(|e| {
println!("{} -- {:?}", &s, e);
})
.unwrap()
})
Expand Down
2 changes: 1 addition & 1 deletion src/genes/cli/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ fn write_rocksdb(
conditions: conditions_by_hgnc_id.get(&hgnc_id).cloned(),
});
tracing::debug!("writing {:?} -> {:?}", &hgnc, &record);
db.put_cf(&cf_genes, hgnc_id, &record.encode_to_vec())?;
db.put_cf(&cf_genes, hgnc_id, record.encode_to_vec())?;
}

// Finally, compact manually.
Expand Down
2 changes: 1 addition & 1 deletion src/gnomad_nuclear/cli/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ pub fn run(common: &common::cli::Args, args: &Args) -> Result<(), anyhow::Error>
for (header_field, val) in more_header_values {
db.put_cf(
&cf_meta,
&format!("gnomad-{}", header_field.replace('_', "-")),
format!("gnomad-{}", header_field.replace('_', "-")),
&val,
)?;
}
Expand Down
10 changes: 0 additions & 10 deletions src/pbs/common.rs

This file was deleted.

1 change: 0 additions & 1 deletion src/pbs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
pub mod clinvar;
pub mod clinvar_data;
pub mod common;
pub mod cons;
pub mod dbsnp;
pub mod functional;
Expand Down
8 changes: 5 additions & 3 deletions src/server/run/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
use actix_web::ResponseError;

/// Custom error type for the Actix server.
#[derive(Debug)]
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
pub struct CustomError {
err: anyhow::Error,
err: String,
}

impl std::fmt::Display for CustomError {
Expand All @@ -17,7 +17,9 @@ impl std::fmt::Display for CustomError {
impl CustomError {
/// Create from `anyhow::Error`.
pub fn new(err: anyhow::Error) -> Self {
CustomError { err }
CustomError {
err: err.to_string(),
}
}
}

Expand Down
Loading

0 comments on commit c9b00d0

Please sign in to comment.