Skip to content

Commit

Permalink
Merge pull request #169 from cancervariants/issue-168
Browse files Browse the repository at this point in the history
feat: Add transformed regulatory_approval field from Therapy Normalizer
  • Loading branch information
korikuzma authored May 6, 2022
2 parents 0223fad + 9325757 commit bd1ae93
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 9 deletions.
9 changes: 9 additions & 0 deletions metakb/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,15 @@ def _add_descriptor(tx, descriptor: Dict, added_ids: Set[str]):
'description', 'xrefs',
'alternate_labels'))

if descr_type == 'TherapyDescriptor':
# capture regulatory_approval field in therapy descriptor extensions
extensions = descriptor.get('extensions', [])
for ext in extensions:
name = ext['name']
if name == 'regulatory_approval':
descriptor[name] = json.dumps(ext['value'])
descr_keys += f", {name}:${name}"

query = f'''
MERGE (descr:{descr_type} {{ {descr_keys} }})
MERGE (value:{value_type} {{ id:${value_id} }})
Expand Down
56 changes: 54 additions & 2 deletions metakb/normalizers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
from typing import Optional, Tuple

from ga4gh.vrsatile.pydantic.vrs_models import VRSTypes
from ga4gh.vrsatile.pydantic.vrsatile_models import VariationDescriptor
from ga4gh.vrsatile.pydantic.vrsatile_models import VariationDescriptor, Extension
from variation.query import QueryHandler as VariationQueryHandler
from therapy.query import QueryHandler as TherapyQueryHandler
from therapy.schemas import NormalizationService as NormalizedTherapy
from therapy.schemas import NormalizationService as NormalizedTherapy, ApprovalRating
from disease.query import QueryHandler as DiseaseQueryHandler
from disease.schemas import NormalizationService as NormalizedDisease
from gene.query import QueryHandler as GeneQueryHandler
Expand Down Expand Up @@ -133,3 +133,55 @@ def normalize_therapy(self, queries)\
if highest_match == 100:
break
return therapy_norm_resp, normalized_therapy_id

@staticmethod
def get_regulatory_approval_extension(
therapy_norm_resp: NormalizedTherapy
) -> Optional[Extension]:
"""Given therapy normalization service response, extract out the regulatory
approval extension
:param NormalizedTherapy therapy_norm_resp: Response from normalizing therapy
:return: Extension containing transformed regulatory approval and indication
data if it `regulatory_approval` extensions exists in therapy normalizer
"""
regulatory_approval_extension = None
tn_resp_exts = therapy_norm_resp.dict().get("therapy_descriptor", {}).get("extensions") or [] # noqa: E501
tn_ext = [v for v in tn_resp_exts if v["name"] == "regulatory_approval"]

if tn_ext:
ext_value = tn_ext[0]["value"]
approval_ratings = ext_value.get("approval_ratings", [])
matched_ext_value = None

if any(ar in {ApprovalRating.FDA_PRESCRIPTION, ApprovalRating.FDA_OTC}
for ar in approval_ratings):
if ApprovalRating.FDA_DISCONTINUED not in approval_ratings or \
ApprovalRating.CHEMBL_4 in approval_ratings: # noqa: E125
matched_ext_value = "FDA"
elif ApprovalRating.CHEMBL_4 in approval_ratings:
matched_ext_value = "chembl_phase_4"

if matched_ext_value:
has_indications = ext_value.get("has_indication", [])
matched_indications = list()

for indication in has_indications:
indication_exts = indication.get("extensions", [])
for indication_ext in indication_exts:
if indication_ext["value"] == matched_ext_value:
matched_indications.append({
"id": indication["id"],
"type": indication["type"],
"label": indication["label"],
"disease_id": indication["disease_id"]
})

regulatory_approval_extension = Extension(
name="regulatory_approval",
value={
"approval_rating": "FDA" if matched_ext_value == "FDA" else "ChEMBL", # noqa: E501
"has_indications": matched_indications
})

return regulatory_approval_extension
10 changes: 9 additions & 1 deletion metakb/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,9 +836,17 @@ def _get_therapy_descriptor(
"label": therapy_descriptor.get("label"),
"therapy_id": None,
"alternate_labels": therapy_descriptor.get("alternate_labels"),
"xrefs": therapy_descriptor.get("xrefs")
"xrefs": therapy_descriptor.get("xrefs"),
"extensions": []
}

key = "regulatory_approval"
val = therapy_descriptor.get(key)
if val:
td_params["extensions"].append(Extension(name=key, value=json.loads(val)))
else:
del td_params["extensions"]

with self.driver.session() as session:
value_object = session.read_transaction(
self._find_descriptor_value_object, td_params["id"]
Expand Down
8 changes: 6 additions & 2 deletions metakb/transform/civic.py
Original file line number Diff line number Diff line change
Expand Up @@ -679,21 +679,25 @@ def _get_therapy_descriptor(self, drug) \
ncit_id = f"ncit:{drug['ncit_id']}"
queries = [ncit_id, label]

_, normalized_therapy_id = \
therapy_norm_resp, normalized_therapy_id = \
self.vicc_normalizers.normalize_therapy(queries)

if not normalized_therapy_id:
logger.warning(f"Therapy Normalizer unable to normalize: "
f"using queries {ncit_id} and {label}")
return None

regulatory_approval_extension = \
self.vicc_normalizers.get_regulatory_approval_extension(therapy_norm_resp)

therapy_descriptor = ValueObjectDescriptor(
id=therapy_id,
type="TherapyDescriptor",
label=label,
therapy_id=normalized_therapy_id,
alternate_labels=drug['aliases'],
xrefs=[ncit_id]
xrefs=[ncit_id],
extensions=[regulatory_approval_extension] if regulatory_approval_extension else None # noqa: E501
).dict(exclude_none=True)
return therapy_descriptor

Expand Down
5 changes: 4 additions & 1 deletion metakb/transform/moa.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,12 +381,15 @@ def _get_therapy_descriptors(self, assertion):
return []

if normalized_therapy_id:
regulatory_approval_extension = \
self.vicc_normalizers.get_regulatory_approval_extension(therapy_norm_resp) # noqa: E501
therapy_descriptor = ValueObjectDescriptor(
id=f"{schemas.SourceName.MOA.value}."
f"{therapy_norm_resp.therapy_descriptor.id}",
type="TherapyDescriptor",
label=label,
therapy_id=normalized_therapy_id
therapy_id=normalized_therapy_id,
extensions=[regulatory_approval_extension] if regulatory_approval_extension else None # noqa: E501
).dict(exclude_none=True)
else:
return []
Expand Down
4 changes: 2 additions & 2 deletions metakb/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""MetaKB version"""
# REQ: EACH TIME VERSION IS UPDATED, MUST ALSO UPDATE LAST_UPDATED
__version__ = "1.1.0-alpha.6"
LAST_UPDATED = "2022-04-07"
__version__ = "1.1.0-alpha.7"
LAST_UPDATED = "2022-05-04"
76 changes: 75 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,29 @@ def civic_tid146():
],
"xrefs": [
"ncit:C66940"
],
"extensions": [
{
"type": "Extension",
"name": "regulatory_approval",
"value": {
"approval_rating": "FDA",
"has_indications": [
{
"id": "hemonc:25316",
"type": "DiseaseDescriptor",
"label": "Non-small cell lung cancer Squamous",
"disease_id": None
},
{
"id": "hemonc:642",
"type": "DiseaseDescriptor",
"label": "Non-small cell lung cancer",
"disease_id": "ncit:C2926"
}
]
}
}
]
}

Expand Down Expand Up @@ -1192,7 +1215,58 @@ def moa_imatinib():
"id": "moa.normalize.therapy:Imatinib",
"type": "TherapyDescriptor",
"label": "Imatinib",
"therapy_id": "rxcui:282388"
"therapy_id": "rxcui:282388",
"extensions": [{
"type": "Extension",
"name": "regulatory_approval",
"value": {
"approval_rating": "FDA",
"has_indications": [
{
"id": "hemonc:634",
"type": "DiseaseDescriptor",
"label": "Myelodysplastic syndrome",
"disease_id": "ncit:C3247"
},
{
"id": "hemonc:616",
"type": "DiseaseDescriptor",
"label": "Hypereosinophilic syndrome",
"disease_id": "ncit:C27038"
},
{
"id": "hemonc:582",
"type": "DiseaseDescriptor",
"label": "Chronic myelogenous leukemia",
"disease_id": "ncit:C3174"
},
{
"id": "hemonc:669",
"type": "DiseaseDescriptor",
"label": "Systemic mastocytosis",
"disease_id": "ncit:C9235"
},
{
"id": "hemonc:24309",
"type": "DiseaseDescriptor",
"label": "Acute lymphoblastic leukemia",
"disease_id": "ncit:C3167"
},
{
"id": "hemonc:667",
"type": "DiseaseDescriptor",
"label": "Soft tissue sarcoma",
"disease_id": "ncit:C9306"
},
{
"id": "hemonc:602",
"type": "DiseaseDescriptor",
"label": "Gastrointestinal stromal tumor",
"disease_id": "ncit:C3868"
}
]
}
}]
}


Expand Down

0 comments on commit bd1ae93

Please sign in to comment.