From 18894baaa899710aa04944a07e175034c5f376e8 Mon Sep 17 00:00:00 2001 From: Manuel Holtgrewe Date: Fri, 1 Mar 2024 13:47:42 +0100 Subject: [PATCH] fix: don't require queried for HGNC IDs to be present (#418) --- src/server/actix_server/genes_clinvar.rs | 20 +++++++++++--------- src/server/actix_server/genes_info.rs | 19 +++++++++++-------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/server/actix_server/genes_clinvar.rs b/src/server/actix_server/genes_clinvar.rs index a6de034f..495fd834 100644 --- a/src/server/actix_server/genes_clinvar.rs +++ b/src/server/actix_server/genes_clinvar.rs @@ -55,15 +55,17 @@ async fn handle( let mut genes = indexmap::IndexMap::new(); if let Some(hgnc_id) = query.hgnc_id.as_ref() { for hgnc_id in hgnc_id { - let raw_buf = db_clinvar - .get_cf(&cf_genes, hgnc_id) - .map_err(|e| CustomError::new(anyhow::anyhow!("problem querying database: {}", e)))? - .ok_or_else(|| CustomError::new(anyhow::anyhow!("no such gene: {}", hgnc_id)))?; - let record = crate::pbs::clinvar::per_gene::ClinvarPerGeneRecord::decode( - std::io::Cursor::new(raw_buf), - ) - .map_err(|e| CustomError::new(anyhow::anyhow!("problem decoding value: {}", e)))?; - genes.insert(hgnc_id.to_string(), record); + if let Some(raw_buf) = db_clinvar.get_cf(&cf_genes, hgnc_id).map_err(|e| { + CustomError::new(anyhow::anyhow!("problem querying database: {}", e)) + })? { + let record = crate::pbs::clinvar::per_gene::ClinvarPerGeneRecord::decode( + std::io::Cursor::new(raw_buf), + ) + .map_err(|e| CustomError::new(anyhow::anyhow!("problem decoding value: {}", e)))?; + genes.insert(hgnc_id.to_string(), record); + } else { + tracing::debug!("no such gene: {}", hgnc_id); + } } } diff --git a/src/server/actix_server/genes_info.rs b/src/server/actix_server/genes_info.rs index 80abf00c..61a7f956 100644 --- a/src/server/actix_server/genes_info.rs +++ b/src/server/actix_server/genes_info.rs @@ -50,14 +50,17 @@ async fn handle( let mut genes = indexmap::IndexMap::new(); if let Some(hgnc_id) = query.hgnc_id.as_ref() { for hgnc_id in hgnc_id { - let raw_buf = genes_db - .db - .get_cf(&cf_genes, hgnc_id) - .map_err(|e| CustomError::new(anyhow::anyhow!("problem querying database: {}", e)))? - .ok_or_else(|| CustomError::new(anyhow::anyhow!("no such gene: {}", hgnc_id)))?; - let record = genes::base::Record::decode(std::io::Cursor::new(raw_buf)) - .map_err(|e| CustomError::new(anyhow::anyhow!("problem decoding value: {}", e)))?; - genes.insert(hgnc_id.to_string(), record); + if let Some(raw_buf) = genes_db.db.get_cf(&cf_genes, hgnc_id).map_err(|e| { + CustomError::new(anyhow::anyhow!("problem querying database: {}", e)) + })? { + let record = + genes::base::Record::decode(std::io::Cursor::new(raw_buf)).map_err(|e| { + CustomError::new(anyhow::anyhow!("problem decoding value: {}", e)) + })?; + genes.insert(hgnc_id.to_string(), record); + } else { + tracing::debug!("no such gene: {}", hgnc_id); + } } }