Skip to content

Commit

Permalink
fix: use correct source priority in normalize resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
jsstevenson committed Sep 27, 2023
1 parent 58e3832 commit 669e6e6
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 26 deletions.
3 changes: 1 addition & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ repos:
hooks:
- id: black
args: ["--check"]
language_version: python3.10
- repo: https://github.com/pycqa/isort
rev: 5.6.4
rev: 5.11.5
hooks:
- id: isort
args: ["--profile", "black", "--check"]
28 changes: 4 additions & 24 deletions disease/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
RefType,
SearchService,
ServiceMeta,
SourceName,
SourcePriority,
)

from .version import __version__
Expand Down Expand Up @@ -356,28 +356,6 @@ def _add_vod(
response = self._add_merged_meta(response)
return NormalizationService(**response)

def _record_order(self, record: Dict) -> Tuple[int, str]:
"""Construct priority order for matching. Only called by sort().
:param Dict record: individual record item in iterable to sort
:return: tuple with rank value and concept ID
"""
src = record["src_name"]
if src == SourceName.NCIT.value:
source_rank = 1
elif src == SourceName.MONDO.value:
source_rank = 2
elif src == SourceName.ONCOTREE.value:
source_rank = 3
elif src == SourceName.OMIM.value:
source_rank = 4
elif src == SourceName.DO.value:
source_rank = 5
else:
logger.warning(f"query.record_order: Invalid source name for " f"{record}")
source_rank = 4
return source_rank, record["concept_id"]

def _handle_failed_merge_ref(self, record, response, query) -> NormalizationService:
"""Log + fill out response for a failed merge reference lookup.
Expand Down Expand Up @@ -440,7 +418,9 @@ def normalize(self, query: str) -> NormalizationService:
matching_records = [
self.db.get_record_by_id(ref, False) for ref in matching_refs
]
matching_records.sort(key=self._record_order) # type: ignore
matching_records.sort(
key=lambda i: SourcePriority[i["src_name"]] # type: ignore
)

# attempt merge ref resolution until successful
for match in matching_records:
Expand Down

0 comments on commit 669e6e6

Please sign in to comment.