In [1]:
from ontobio.ontol_factory import OntologyFactory
ofactory = OntologyFactory()
ont = ofactory.create("nucleus.json") ## interpreted as a json local handle
Now we can search the ontology by label; regexes can be used, but here we specify an exact match, so we expect one result:
In [2]:
[nucleus] = ont.search('nucleus')
In [3]:
ont.ancestors(nucleus)
Out[3]:
In [4]:
## Extract labels for results
["{} '{}'".format(x, ont.label(x)) for x in ont.ancestors(nucleus)]
Out[4]:
In [5]:
## Filter ancestors based on relationship type
ont.ancestors(nucleus, relations='subClassOf')
Out[5]:
In [42]:
## Fetch the nucleus node
ont.node(nucleus)
Out[42]:
Note that the ontol object provides special convenience methods for accessing information in a node (see Synonyms section below). However, it is always possible to access the dictionary object for a node and to probe this directly, for example:
In [44]:
ont.node(nucleus)['meta']['synonyms']
Out[44]:
In [34]:
ont.synonyms('GO:0005575')
Out[34]:
In [37]:
graph = ont.get_graph()
In [38]:
## number of nodes in this test ontology
len(graph)
Out[38]:
In [41]:
graph.node[nucleus]
Out[41]:
In [45]:
import networkx
import matplotlib.pyplot as plt
In [47]:
networkx.draw(graph)
In [ ]:
plt.savefig('foo.png')