Skip to content

Commit

Permalink
make uri_to_curie slightly more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
apriltuesday committed Apr 21, 2023
1 parent 1047f3d commit 9b4137b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
16 changes: 15 additions & 1 deletion eva_cttv_pipeline/clinvar_xml_io/clinvar_xml_io/ontology_uri.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import logging

logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)


class OntologyUri:
# ClinVar stores cross-references in very different formats. This provides their conversion to full IRIs, along with
# some examples of how this looks like in ClinVar data.
Expand Down Expand Up @@ -47,6 +54,13 @@ def uri_to_curie(uri):
db = "OMIM"
id_ = uri_list[-1]
else:
db, id_ = uri_list[-1].split("_")
last_component = uri_list[-1]
if ":" in last_component:
return last_component
elif "_" in last_component:
db, id_ = last_component.split("_")
else:
logger.warning(f"Could not convert URI to CURIE: {uri}")
return None
db = uri_db_to_curie_db[db.lower()]
return "{}:{}".format(db, id_)
11 changes: 11 additions & 0 deletions eva_cttv_pipeline/clinvar_xml_io/tests/test_ontology_uri.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from eva_cttv_pipeline.clinvar_xml_io.clinvar_xml_io.ontology_uri import OntologyUri


def test_uri_to_curie():
assert OntologyUri.uri_to_curie('http://www.orpha.net/ORDO/Orphanet_713') == 'Orphanet:713'
assert OntologyUri.uri_to_curie('http://purl.obolibrary.org/obo/HP_0002930') == 'HP:0002930'
assert OntologyUri.uri_to_curie('https://omim.org/entry/300377') == 'OMIM:300377'
# If for some reason we're already passed a CURIE (probably a mistake in OLS response), return it as-is
assert OntologyUri.uri_to_curie('HP:0002505') == 'HP:0002505'
# Not a supported db
assert OntologyUri.uri_to_curie('http://purl.obolibrary.org/obo/DOID_10652') == None

0 comments on commit 9b4137b

Please sign in to comment.