In [1]:
## First fetch ontology
from ontobio.ontol_factory import OntologyFactory
ofactory = OntologyFactory()
ont = ofactory.create("uberon") ## Connect remotely to Uberon over SPARQL
##
## Note: Jupyter may show '*' to indicate kernel busy while this is being
## fetched - should only take a few seconds. Wait before proceeding
In [2]:
## select a class
[cls] = ont.search("buccal mucosa")
cls
Out[2]:
In [4]:
## Get xrefs for a class
ont.xrefs(cls)
Out[4]:
In [64]:
## Get a networkx graph object
xg = ont.xref_graph
len(xg.edges())
Out[64]:
In [16]:
## Hacky convenience function to deal with URL xrefs
## TODO: use prefixcommons
def contract_xref(x):
x = x.replace('http://linkedlifedata.com/resource/umls/id/','UMLS:')
x = x.replace('http://ncicb.nci.nih.gov/xml/owl/EVS/Thesaurus.owl#', 'NCIT:')
x = x.replace('http://www.snomedbrowser.com/Codes/Details/', 'SCTID:')
return x
[contract_xref(x) for x in ont.xrefs(cls)]
Out[16]:
In [54]:
## Prepare to make a DataFrame
## Each item is a class
## Each column is a database
import pandas as pd
items = []
for c in ont.nodes():
label = ont.label(c)
d = dict(id=c, label=label)
items.append(d)
for x in ont.xrefs(c):
toks = contract_xref(x).split(":")
if len(toks) == 2:
d[toks[0]] = toks[1]
In [55]:
## Make dataframe
df = pd.DataFrame.from_records(items, index=['id','label'])
df=df.fillna('')
df[0:20]
Out[55]:
In [60]:
## Fetch sample of NCIT mappings
df['NCIT'][0:20]
Out[60]:
In [ ]: