Skip to content

Commit

Permalink
fix: allow case insensitive search for OMIM terms (#160) (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe authored Jul 11, 2024
1 parent 5c19d95 commit 0d0e5af
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 6 deletions.
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
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ query:
omim_id: ~
name: tel-Manzke syndro
match_: contains
ignore_case: ~
max_results: 100
hpo_terms: false
result:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ query:
omim_id: ~
name: tel-Manzke syndro
match_: contains
ignore_case: ~
max_results: 100
hpo_terms: true
result:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ query:
omim_id: ~
name: Catel-Manzke syndrome
match_: ~
ignore_case: ~
max_results: 100
hpo_terms: false
result:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ query:
omim_id: ~
name: Catel-Manzke syndrome
match_: ~
ignore_case: ~
max_results: 100
hpo_terms: true
result:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ query:
omim_id: ~
name: Catel-Manzke syndro
match_: prefix
ignore_case: ~
max_results: 100
hpo_terms: false
result:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ query:
omim_id: ~
name: Catel-Manzke syndro
match_: prefix
ignore_case: ~
max_results: 100
hpo_terms: true
result:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ query:
omim_id: ~
name: tel-Manzke syndrome
match_: suffix
ignore_case: ~
max_results: 100
hpo_terms: false
result:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ query:
omim_id: ~
name: tel-Manzke syndrome
match_: suffix
ignore_case: ~
max_results: 100
hpo_terms: true
result:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ query:
omim_id: "616145"
name: ~
match_: ~
ignore_case: ~
max_results: 100
hpo_terms: false
result:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ query:
omim_id: "616145"
name: ~
match_: ~
ignore_case: ~
max_results: 100
hpo_terms: true
result:
Expand Down

0 comments on commit 0d0e5af

Please sign in to comment.