Skip to content

Commit

Permalink
dbsnp
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe committed Nov 18, 2024
1 parent 49896a9 commit 355c365
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 15 deletions.
50 changes: 43 additions & 7 deletions openapi.schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4398,6 +4398,33 @@ components:
properties:
err:
type: string
DbsnpRecord:
type: object
description: A record corresponding to dbSNP VCF.
required:
- chrom
- pos
- ref_allele
- alt_allele
- rs_id
properties:
chrom:
type: string
description: Chromosome name.
pos:
type: integer
format: int32
description: 1-based start position.
ref_allele:
type: string
description: Reference allele.
alt_allele:
type: string
description: Alternate allele.
rs_id:
type: integer
format: int32
description: The rs ID.
ExtractedVcvRecordList:
type: object
description: List of `ClinvarExtractedVcvRecord`s.
Expand Down Expand Up @@ -6827,24 +6854,33 @@ components:
properties:
cadd:
type:
- boolean
- object
- 'null'
description: Annotations from CADD (TSV annotation file).
additionalProperties: {}
propertyNames:
type: string
dbsnp:
type:
- boolean
- 'null'
description: Annotations from dbSNP.
oneOf:
- type: 'null'
- $ref: '#/components/schemas/DbsnpRecord'
description: Annotations from dbSNP.
dbnsfp:
type:
- boolean
- object
- 'null'
description: Annotations from dbNSFP (TSV annotation file).
additionalProperties: {}
propertyNames:
type: string
dbscsnv:
type:
- boolean
- object
- 'null'
description: Annotations from dbscSNV.
additionalProperties: {}
propertyNames:
type: string
gnomad_mtdna:
type:
- boolean
Expand Down
103 changes: 95 additions & 8 deletions src/server/run/annos_variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,33 @@ async fn handle(
pub mod response {
use crate::server::run::clinvar_data::ClinvarExtractedVcvRecord;

/// A record corresponding to dbSNP VCF.
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
pub struct DbsnpRecord {
/// Chromosome name.
pub chrom: String,
/// 1-based start position.
pub pos: i32,
/// Reference allele.
pub ref_allele: String,
/// Alternate allele.
pub alt_allele: String,
/// The rs ID.
pub rs_id: i32,
}

impl From<crate::pbs::dbsnp::Record> for DbsnpRecord {
fn from(value: crate::pbs::dbsnp::Record) -> Self {
DbsnpRecord {
chrom: value.chrom,
pos: value.pos,
ref_allele: value.ref_allele,
alt_allele: value.alt_allele,
rs_id: value.rs_id,
}
}
}

/// A HelixMtDb record.
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
pub struct HelixMtDbRecord {
Expand Down Expand Up @@ -382,13 +409,13 @@ pub mod response {
#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize, utoipa::ToSchema)]
pub struct SeqvarsAnnoResponseRecord {
/// Annotations from CADD (TSV annotation file).
pub cadd: Option<bool>,
pub cadd: Option<indexmap::IndexMap<String, serde_json::Value>>,
/// Annotations from dbSNP.
pub dbsnp: Option<bool>,
pub dbsnp: Option<DbsnpRecord>,
/// Annotations from dbNSFP (TSV annotation file).
pub dbnsfp: Option<bool>,
pub dbnsfp: Option<indexmap::IndexMap<String, serde_json::Value>>,
/// Annotations from dbscSNV.
pub dbscsnv: Option<bool>,
pub dbscsnv: Option<indexmap::IndexMap<String, serde_json::Value>>,
/// Annotations from gnomAD-mtDNA.
pub gnomad_mtdna: Option<bool>,
/// Annotations from gnomAD-exomes.
Expand Down Expand Up @@ -444,11 +471,71 @@ pub async fn handle_with_openapi(
CustomError::new(anyhow::anyhow!("problem getting genome release: {}", e))
})?;

fn json_value_to_indexmap(
value: serde_json::Value,
) -> Result<indexmap::IndexMap<String, serde_json::Value>, CustomError> {
value
.as_object()
.map(|v| {
Ok(v.iter()
.map(|(k, v)| (k.clone(), v.clone()))
.collect::<indexmap::IndexMap<_, _>>())
})
.unwrap_or_else(|| Err(CustomError::new(anyhow::anyhow!("expected object"))))
}

let result = SeqvarsAnnoResponseRecord {
// cadd: Option<bool>,
// dbsnp: Option<bool>,
// dbnsfp: Option<bool>,
// dbscsnv: Option<bool>,
cadd: data.annos[genome_release][AnnoDb::Cadd]
.as_ref()
.map(|db| {
fetch_var_tsv_json(
&db.data,
AnnoDb::Cadd.cf_name(),
query.clone().into_inner().into(),
)
})
.transpose()?
.flatten()
.map(json_value_to_indexmap)
.transpose()?,
dbsnp: data.annos[genome_release][AnnoDb::Dbsnp]
.as_ref()
.map(|db| {
fetch_var_protobuf::<crate::dbsnp::pbs::Record>(
&db.data,
AnnoDb::Dbsnp.cf_name(),
query.clone().into_inner().into(),
)
})
.transpose()?
.flatten()
.map(Into::into),
dbnsfp: data.annos[genome_release][AnnoDb::Dbnsfp]
.as_ref()
.map(|db| {
fetch_var_tsv_json(
&db.data,
AnnoDb::Cadd.cf_name(),
query.clone().into_inner().into(),
)
})
.transpose()?
.flatten()
.map(json_value_to_indexmap)
.transpose()?,
dbscsnv: data.annos[genome_release][AnnoDb::Dbscsnv]
.as_ref()
.map(|db| {
fetch_var_tsv_json(
&db.data,
AnnoDb::Cadd.cf_name(),
query.clone().into_inner().into(),
)
})
.transpose()?
.flatten()
.map(json_value_to_indexmap)
.transpose()?,
// gnomad_mtdna: Option<bool>,
// gnomad_exomes: Option<bool>,
// gnomad_genomes: Option<bool>,
Expand Down

0 comments on commit 355c365

Please sign in to comment.