Skip to content

Commit

Permalink
Merge pull request #5 from opentargets/ag_xref2efo
Browse files Browse the repository at this point in the history
Ag xref2efo
  • Loading branch information
Daniel Suveges authored Jul 17, 2020
2 parents 4bdcb40 + cf974c4 commit 0a76f30
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Version 0.0.15:
- New function get_efo_from_xref() to map disease ids from other ontologies to EFO using xrefs
Version 0.0.14:
- Query strings are searched as they are, splitting at commas and semicolons and using the largest substring has been removed.
- Use latest EFO OBO file instead of hard-coded v2018-01-15
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.14
0.0.15
33 changes: 33 additions & 0 deletions ontoma/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ def name_to_label_mapping(obonetwork):
name_to_id[synonim.split('\"')[1]] = nodeid
return id_to_name, name_to_id

def xref_to_name_and_label_mapping(obonetwork):
'''
builds xref to list of name and label lookup dictionary starting from an OBO file
'''
xref_to_name_and_label = {}
for nodeid, data in obonetwork.nodes(data=True):
if 'xref' in data:
for xref in data['xref']:
name_and_label = {'id': nodeid, 'name': data['name']}
if xref in xref_to_name_and_label:
xref_to_name_and_label[xref].append(name_and_label)
else:
xref_to_name_and_label[xref] = [name_and_label]
return xref_to_name_and_label

def make_uri(ontology_short_form):
'''
Expand Down Expand Up @@ -231,6 +245,13 @@ def name_to_efo(self):
logger.info("Parsed %s Name to EFO mapping " % len(name_to_efo))
return name_to_efo

@lazy_property
def xref_to_efo(self):
'''Create xref => EFO id and label mappings'''
xref_to_efo = xref_to_name_and_label_mapping(self._efo)
return xref_to_efo


@lazy_property
def mondo_to_name(self):
'''Create name <=> label mappings'''
Expand Down Expand Up @@ -271,6 +292,18 @@ def get_efo_label(self, efocode):
logger.error('EFO ID %s not found', efocode)
return None

def get_efo_from_xref(self, efocode):
'''Given an short disease id, returns the id and label of equivalent term(s) in EFO as defined by xrefs
'''
if '/' in efocode:
#extract short form from IRI
efocode = efocode.split('/')[-1]
try:
return self.xref_to_efo[efocode.replace('_', ':')]
except KeyError:
logger.error('There are no EFO ID that have xrefs to %s', efocode)
return None

def zooma_lookup(self, name):
'''Searches against the EBI Zooma service for an high confidence mapping
'''
Expand Down

0 comments on commit 0a76f30

Please sign in to comment.