diff --git a/src/server/run/annos_variant.rs b/src/server/run/annos_variant.rs index fc56351..6a0e6f2 100644 --- a/src/server/run/annos_variant.rs +++ b/src/server/run/annos_variant.rs @@ -2924,8 +2924,103 @@ pub async fn handle_with_openapi( .transpose()? .flatten() .map(Into::into), - // gnomad_exomes: Option, - // gnomad_genomes: Option, + gnomad_exomes: data.annos[genome_release][AnnoDb::GnomadExomes] + .as_ref() + .map(|db| { + let db_version = data.db_infos[genome_release][AnnoDb::GnomadExomes] + .as_ref() + .expect("must have db info here") + .db_version + .as_ref() + .expect("gnomAD must have db version"); + if db_version.starts_with("2.") { + Ok(fetch_var_protobuf::( + &db.data, + AnnoDb::GnomadExomes.cf_name(), + query.clone().into_inner().into(), + )? + .map(|record| { + Ok(GnomadRecord::Gnomad2( + record.try_into().map_err(CustomError::new)?, + )) + }) + .transpose()?) + } else if db_version.starts_with("3.") { + Ok(fetch_var_protobuf::( + &db.data, + AnnoDb::GnomadExomes.cf_name(), + query.clone().into_inner().into(), + )? + .map(|record| { + Ok(GnomadRecord::Gnomad3( + record.try_into().map_err(CustomError::new)?, + )) + }) + .transpose()?) + } else if db_version.starts_with("4.") { + Ok(fetch_var_protobuf::( + &db.data, + AnnoDb::GnomadExomes.cf_name(), + query.clone().into_inner().into(), + )? + .map(|record| { + Ok(GnomadRecord::Gnomad4( + record.try_into().map_err(CustomError::new)?, + )) + }) + .transpose()?) + } else { + Err(CustomError::new(anyhow::anyhow!( + "don't know how to handle gnomAD version {}", + db_version + ))) + } + }) + .transpose()? + .flatten(), + gnomad_genomes: data.annos[genome_release][AnnoDb::GnomadGenomes] + .as_ref() + .map(|db| { + let db_version = data.db_infos[genome_release][AnnoDb::GnomadGenomes] + .as_ref() + .expect("must have db info here") + .db_version + .as_ref() + .expect("gnomAD must have db version"); + + if db_version.starts_with("2.") { + Ok(fetch_var_protobuf::( + &db.data, + AnnoDb::GnomadGenomes.cf_name(), + query.clone().into_inner().into(), + )? + .map(|record| { + Ok(GnomadRecord::Gnomad2( + record.try_into().map_err(CustomError::new)?, + )) + }) + .transpose()?) + } else if db_version.starts_with("4.") { + Ok(fetch_var_protobuf::( + &db.data, + AnnoDb::GnomadGenomes.cf_name(), + query.clone().into_inner().into(), + )? + .map(|record| { + Ok(GnomadRecord::Gnomad4( + record.try_into().map_err(CustomError::new)?, + )) + }) + .transpose()?) + } else { + Err(CustomError::new(anyhow::anyhow!( + "don't know how to handle gnomAD version {}", + db_version + ))) + } + }) + .transpose()? + .flatten(), helixmtdb: data.annos[genome_release][AnnoDb::Helixmtdb] .as_ref() .map(|db| { @@ -2973,7 +3068,6 @@ pub async fn handle_with_openapi( }) .transpose()? .flatten(), - ..Default::default() }; Ok(Json(SeqvarsAnnosResponse { result }))