Skip to content

Commit

Permalink
update handling ids
Browse files Browse the repository at this point in the history
  • Loading branch information
korikuzma committed Sep 13, 2023
1 parent 1a32958 commit 04b6dee
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Call the `normalize()` method with a gene term. If available, a rich description

```
>>> result = q.normalize("BRAF")
>>> result.gene.id
>>> result.normalized_id
"hgnc:1097"
>>> result.gene.aliases
['NS7', 'RAFB1', 'B-raf', 'BRAF-1', 'BRAF1', 'B-RAF1']
Expand Down
2 changes: 1 addition & 1 deletion docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ The Gene Normalizer provides tools for resolving ambiguous human gene references
>>> from gene.database import create_db
>>> q = QueryHandler(create_db())
>>> result = q.normalize("BRAF")
>>> result.gene.id
>>> result.normalized_id
"hgnc:1097"
>>> result.gene.aliases
['NS7', 'RAFB1', 'B-raf', 'BRAF-1', 'BRAF1', 'B-RAF1']
Expand Down
7 changes: 4 additions & 3 deletions gene/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def _add_merged_meta(self, response: NormalizeService) -> NormalizeService:
"""
sources_meta = {}
gene = response.gene
sources = [gene.id.split(":")[0]]
sources = [response.normalized_id.split(":")[0]]
if gene.mappings:
sources += [m.coding.system for m in gene.mappings]

Expand Down Expand Up @@ -427,7 +427,7 @@ def _add_gene(
:return: Response with core Gene
"""
gene_obj = core_models.Gene(
id=record["concept_id"],
id=f"normalize.gene.{record['concept_id']}",
label=record["symbol"],
)

Expand Down Expand Up @@ -520,6 +520,7 @@ def _add_gene(
response = self._add_alt_matches(response, record,
possible_concepts)

response.normalized_id = record["concept_id"]
response.gene = gene_obj
response = self._add_merged_meta(response)
response.match_type = match_type
Expand Down Expand Up @@ -574,7 +575,7 @@ def normalize(self, query: str) -> NormalizeService:
>>> from gene.database import create_db
>>> q = QueryHandler(create_db())
>>> result = q.normalize("BRAF")
>>> result.gene.id
>>> result.normalized_id
'hgnc:1097'
>>> result.aliases
['BRAF1', 'RAFB1', 'B-raf', 'NS7', 'B-RAF1']
Expand Down
4 changes: 3 additions & 1 deletion gene/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ class BaseNormalizationService(BaseModel):
class NormalizeService(BaseNormalizationService):
"""Define model for returning normalized concept."""

normalized_id: Optional[constr(pattern=r"^normalize.gene.\w[^:]*:.+$")] = None # noqa: F722, E501
gene: Optional[core_models.Gene] = None
source_meta_: Dict[SourceName, SourceMeta] = {}

Expand All @@ -428,9 +429,10 @@ class NormalizeService(BaseNormalizationService):
"query": "BRAF",
"warnings": [],
"match_type": 100,
"normalized_id": "hgnc:1037",
"gene": {
"type": "Gene",
"id": "hgnc:1097",
"id": "normalize.gene.hgnc:1097",
"label": "BRAF",
"mappings": [
{
Expand Down
13 changes: 7 additions & 6 deletions tests/unit/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def normalized_ache():
"""Return normalized core Gene object for ACHE."""
params = {
"type": "Gene",
"id": "hgnc:108",
"id": "normalize.gene.hgnc:108",
"label": "ACHE",
"mappings": [
{
Expand Down Expand Up @@ -198,7 +198,7 @@ def normalized_braf():
"""Return normalized core Gene object for BRAF."""
params = {
"type": "Gene",
"id": "hgnc:1097",
"id": "normalize.gene.hgnc:1097",
"label": "BRAF",
"mappings": [
{
Expand Down Expand Up @@ -373,7 +373,7 @@ def normalized_abl1():
"""Return normalized core Gene object for ABL1."""
params = {
"type": "Gene",
"id": "hgnc:76",
"id": "normalize.gene.hgnc:76",
"label": "ABL1",
"mappings": [
{
Expand Down Expand Up @@ -554,7 +554,7 @@ def normalized_p150():
"""Return normalized core Gene object for p150."""
params = {
"type": "Gene",
"id": "hgnc:1910",
"id": "normalize.gene.hgnc:1910",
"label": "CHAF1A",
"mappings": [
{
Expand Down Expand Up @@ -762,7 +762,7 @@ def normalized_loc_653303():
"value": "+"
}
],
"id": "ncbigene:653303"
"id": "normalize.gene.ncbigene:653303"
}
return core_models.Gene(**params)

Expand Down Expand Up @@ -1094,7 +1094,7 @@ def normalized_ifnr():
"""Return normalized core Gene object for IFNR."""
params = {
"type": "Gene",
"id": "hgnc:5447",
"id": "normalize.gene.hgnc:5447",
"label": "IFNR",
"mappings": [
{
Expand Down Expand Up @@ -1185,6 +1185,7 @@ def compare_normalize_resp(resp, expected_query, expected_match_type,
assert resp.query == expected_query
compare_warnings(resp.warnings, expected_warnings)
assert resp.match_type == expected_match_type
assert resp.normalized_id == expected_gene.id.split("normalize.gene.")[-1]
compare_gene(expected_gene, resp.gene)
if not expected_source_meta:
assert resp.source_meta_ == {}
Expand Down

0 comments on commit 04b6dee

Please sign in to comment.