Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe committed Jul 11, 2024
1 parent 722195b commit cf2180d
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 9 deletions.
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{env, path::PathBuf};

fn main() -> Result<(), anyhow::Error> {
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("protos");
let proto_files = vec!["viguno/v1/simulation.proto"]
let proto_files = ["viguno/v1/simulation.proto"]
.iter()
.map(|f| root.join(f))
.collect::<Vec<_>>();
Expand Down
9 changes: 8 additions & 1 deletion openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,19 @@ paths:
nullable: true
- name: match_
in: query
description: The match mode.
description: The match mode, default is `Match::Exact`.
required: false
schema:
allOf:
- $ref: '#/components/schemas/Match'
nullable: true
- name: ignore_case
in: query
description: Whether case is insentivie, default is `false`.
required: false
schema:
type: boolean
nullable: true
- name: max_results
in: query
description: Maximal number of results to return.
Expand Down
2 changes: 1 addition & 1 deletion src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ pub fn run(args_common: &crate::common::Args, args: &Args) -> Result<(), anyhow:
tracing::info!("Loading HGNC xlink...");
let before_load_xlink = Instant::now();
let path_hgnc_xlink = format!("{}/hgnc_xlink.tsv", args.path_hpo_dir);
let ncbi_to_hgnc = crate::common::hgnc_xlink::load_ncbi_to_hgnc(&path_hgnc_xlink)?;
let ncbi_to_hgnc = crate::common::hgnc_xlink::load_ncbi_to_hgnc(path_hgnc_xlink)?;
tracing::info!(
"... done loading HGNC xlink in {:?}",
before_load_xlink.elapsed()
Expand Down
34 changes: 29 additions & 5 deletions src/server/run/hpo_omims.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ pub struct Query {
pub omim_id: Option<String>,
/// The disease name to search for.
pub name: Option<String>,
/// The match mode.
/// The match mode, default is `Match::Exact`.
#[serde(alias = "match")]
pub match_: Option<Match>,
/// Whether case is insentivie, default is `false`.
pub ignore_case: Option<bool>,
/// Maximal number of results to return.
#[serde(default = "_default_max_results")]
pub max_results: usize,
Expand Down Expand Up @@ -144,6 +146,7 @@ pub struct Result {

/// Query for OMIM diseases in the HPO database.
#[allow(clippy::unused_async)]
#[allow(clippy::too_many_lines)]
#[utoipa::path(
operation_id = "hpo_omims",
params(Query),
Expand All @@ -167,11 +170,22 @@ async fn handle(
.map_err(|e| CustomError::new(anyhow::anyhow!(e)))?;
ontology.omim_disease(&omim_id)
} else if let Some(name) = &query.name {
let name = if query.ignore_case.unwrap_or_default() {
name.to_lowercase()
} else {
name.clone()
};
let mut omim_disease = None;
let mut it = ontology.omim_diseases();
let mut tmp = it.next();
while tmp.is_some() && omim_disease.is_none() {
if tmp.expect("checked above").name() == name {
let tmp_name = tmp.expect("checked above").name();
let tmp_name = if query.ignore_case.unwrap_or_default() {
tmp_name.to_lowercase()
} else {
tmp_name.to_string()
};
if tmp_name == name {
omim_disease = tmp;
}
tmp = it.next();
Expand All @@ -191,11 +205,21 @@ async fn handle(
let mut it = ontology.omim_diseases();
let mut omim_disease = it.next();
while omim_disease.is_some() && result.len() < query.max_results {
let name = if query.ignore_case.unwrap_or_default() {
name.to_lowercase()
} else {
name.clone()
};
let omim_name = omim_disease.as_ref().expect("checked above").name();
let omim_name = if query.ignore_case.unwrap_or_default() {
omim_name.to_lowercase()
} else {
omim_name.to_string()
};
let is_match = match query.match_.unwrap_or_default() {
Match::Prefix => omim_name.starts_with(name),
Match::Suffix => omim_name.ends_with(name),
Match::Contains => omim_name.contains(name),
Match::Prefix => omim_name.starts_with(&name),
Match::Suffix => omim_name.ends_with(&name),
Match::Contains => omim_name.contains(&name),
Match::Exact => panic!("cannot happen here"),
};
if is_match {
Expand Down
2 changes: 1 addition & 1 deletion src/server/run/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ pub fn run(args_common: &crate::common::Args, args: &Args) -> Result<(), anyhow:
tracing::info!("Loading HGNC xlink...");
let before_load_xlink = std::time::Instant::now();
let path_hgnc_xlink = format!("{}/hgnc_xlink.tsv", args.path_hpo_dir);
let ncbi_to_hgnc = crate::common::hgnc_xlink::load_ncbi_to_hgnc(&path_hgnc_xlink)?;
let ncbi_to_hgnc = crate::common::hgnc_xlink::load_ncbi_to_hgnc(path_hgnc_xlink)?;
let hgnc_to_ncbi = crate::common::hgnc_xlink::inverse_hashmap(&ncbi_to_hgnc);
tracing::info!(
"... done loading HGNC xlink in {:?}",
Expand Down

0 comments on commit cf2180d

Please sign in to comment.