Skip to content

Commit

Permalink
fix: make /hpo/genes endpoint return HGNC ID (#16) (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe authored Jun 11, 2023
1 parent f38a1bb commit 77bd9af
Show file tree
Hide file tree
Showing 41 changed files with 127 additions and 47 deletions.
6 changes: 0 additions & 6 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,6 @@ jobs:
version: 0.21.0
args: "--all-features -- --test-threads 1"

- name: Build all examples
uses: actions-rs/cargo@v1
with:
command: build
args: --examples

- name: Codecov
uses: codecov/codecov-action@v3
with:
Expand Down
15 changes: 13 additions & 2 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,18 @@ impl FromStr for ScoreCombiner {
}

/// The version of `viguno` package.
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
#[cfg(not(test))]
const VERSION: &str = env!("CARGO_PKG_VERSION");

/// Returns the current version of `viguno`.
///
/// This allows us to override the version to `0.0.0` in tests.
pub fn version() -> &'static str {
#[cfg(test)]
return "0.0.0";
#[cfg(not(test))]
return VERSION;
}

/// Version information that is returned by the HTTP server.
#[derive(serde::Serialize, serde::Deserialize, Default, Debug, Clone)]
Expand All @@ -260,7 +271,7 @@ impl Version {
pub fn new(hpo: &str) -> Self {
Self {
hpo: hpo.to_string(),
viguno: VERSION.to_string(),
viguno: version().to_string(),
}
}
}
Expand Down
15 changes: 14 additions & 1 deletion src/server/actix_server/hpo_genes.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Implementation of `/hpo/genes`.

use std::collections::HashMap;

use actix_web::{
get,
web::{self, Data, Json, Path},
Expand Down Expand Up @@ -56,18 +58,26 @@ fn _default_hpo_terms() -> bool {

/// Result entry for `handle`.
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
#[serde_with::skip_serializing_none]
struct ResultEntry {
/// The gene's NCBI ID.
pub gene_ncbi_id: u32,
/// The gene's HGNC symbol.
pub gene_symbol: String,
/// The gene's HGNC ID.
pub hgnc_id: Option<String>,
/// The gene's associated HPO terms.
#[serde(default = "Option::default", skip_serializing_if = "Option::is_none")]
pub hpo_terms: Option<Vec<ResultHpoTerm>>,
}

impl ResultEntry {
pub fn from_gene_with_ontology(gene: &Gene, ontology: &Ontology, hpo_terms: bool) -> Self {
pub fn from_gene_with_ontology(
gene: &Gene,
ontology: &Ontology,
hpo_terms: bool,
ncbi_to_hgnc: &HashMap<u32, String>,
) -> Self {
let hpo_terms = if hpo_terms {
let mut terms = gene
.to_hpo_set(ontology)
Expand All @@ -86,6 +96,7 @@ impl ResultEntry {
ResultEntry {
gene_ncbi_id: gene.id().as_u32(),
gene_symbol: gene.name().to_string(),
hgnc_id: ncbi_to_hgnc.get(&gene.id().as_u32()).cloned(),
hpo_terms,
}
}
Expand Down Expand Up @@ -134,6 +145,7 @@ async fn handle(
gene,
ontology,
query.hpo_terms,
&data.ncbi_to_hgnc,
));
}
} else if let Some(gene_symbol) = &query.gene_symbol {
Expand All @@ -152,6 +164,7 @@ async fn handle(
gene.expect("checked above"),
ontology,
query.hpo_terms,
&data.ncbi_to_hgnc,
));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ expression: "&run_query(\"/hpo/sim/term-gene?terms=HP:0010442,HP:0000347&gene_id
---
version:
hpo: 2023-04-05
viguno: 0.1.0
viguno: 0.0.0
query:
terms:
- term_id: "HP:0000347"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ expression: "&run_query(\"/hpo/sim/term-gene?terms=HP:0010442,HP:0000347&gene_id
---
version:
hpo: 2023-04-05
viguno: 0.1.0
viguno: 0.0.0
query:
terms:
- term_id: "HP:0000347"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ expression: "&run_query(\"/hpo/sim/term-gene?terms=HP:0010442,HP:0000347&gene_sy
---
version:
hpo: 2023-04-05
viguno: 0.1.0
viguno: 0.0.0
query:
terms:
- term_id: "HP:0000347"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ expression: "&run_query(\"/hpo/sim/term-term?lhs=HP:0010442&rhs=HP:0001780\").aw
---
version:
hpo: 2023-04-05
viguno: 0.1.0
viguno: 0.0.0
query:
lhs:
- "HP:0010442"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ expression: "&run_query(\"/hpo/sim/term-term?lhs=HP:0010442,HP:0000347&rhs=HP:00
---
version:
hpo: 2023-04-05
viguno: 0.1.0
viguno: 0.0.0
query:
lhs:
- "HP:0010442"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ expression: "&run_query(\"/hpo/genes?gene_symbol=GD&match=contains\").await?"
---
version:
hpo: 2023-04-05
viguno: 0.1.0
viguno: 0.0.0
query:
gene_id: ~
gene_symbol: GD
Expand All @@ -14,54 +14,80 @@ query:
result:
- gene_ncbi_id: 396
gene_symbol: ARHGDIA
hgnc_id: "HGNC:678"
- gene_ncbi_id: 1421
gene_symbol: CRYGD
hgnc_id: "HGNC:2411"
- gene_ncbi_id: 2245
gene_symbol: FGD1
hgnc_id: "HGNC:3663"
- gene_ncbi_id: 2657
gene_symbol: GDF1
hgnc_id: "HGNC:4214"
- gene_ncbi_id: 2658
gene_symbol: GDF2
hgnc_id: "HGNC:4217"
- gene_ncbi_id: 2661
gene_symbol: GDF9
hgnc_id: "HGNC:4224"
- gene_ncbi_id: 2664
gene_symbol: GDI1
hgnc_id: "HGNC:4226"
- gene_ncbi_id: 2668
gene_symbol: GDNF
hgnc_id: "HGNC:4232"
- gene_ncbi_id: 3081
gene_symbol: HGD
hgnc_id: "HGNC:4892"
- gene_ncbi_id: 3248
gene_symbol: HPGD
hgnc_id: "HGNC:5154"
- gene_ncbi_id: 4967
gene_symbol: OGDH
hgnc_id: "HGNC:8124"
- gene_ncbi_id: 7358
gene_symbol: UGDH
hgnc_id: "HGNC:12525"
- gene_ncbi_id: 8200
gene_symbol: GDF5
hgnc_id: "HGNC:4220"
- gene_ncbi_id: 9573
gene_symbol: GDF3
hgnc_id: "HGNC:4218"
- gene_ncbi_id: 10220
gene_symbol: GDF11
hgnc_id: "HGNC:4216"
- gene_ncbi_id: 23483
gene_symbol: TGDS
hgnc_id: "HGNC:20324"
- gene_ncbi_id: 26227
gene_symbol: PHGDH
hgnc_id: "HGNC:8923"
- gene_ncbi_id: 29958
gene_symbol: DMGDH
hgnc_id: "HGNC:24475"
- gene_ncbi_id: 54332
gene_symbol: GDAP1
hgnc_id: "HGNC:15968"
- gene_ncbi_id: 54834
gene_symbol: GDAP2
hgnc_id: "HGNC:18010"
- gene_ncbi_id: 55753
gene_symbol: OGDHL
hgnc_id: "HGNC:25590"
- gene_ncbi_id: 79641
gene_symbol: ROGDI
hgnc_id: "HGNC:29478"
- gene_ncbi_id: 79944
gene_symbol: L2HGDH
hgnc_id: "HGNC:20499"
- gene_ncbi_id: 121512
gene_symbol: FGD4
hgnc_id: "HGNC:19125"
- gene_ncbi_id: 392255
gene_symbol: GDF6
hgnc_id: "HGNC:4221"
- gene_ncbi_id: 728294
gene_symbol: D2HGDH
hgnc_id: "HGNC:28358"

Loading

0 comments on commit 77bd9af

Please sign in to comment.