Loading the optional definition attribute

  1. Load the ontology file while also loading the optional definition attribute (“def” or “defn”) for each GO term

from os.path import exists
from goatools.obo_parser import GODag

if not exists('go-basic.obo'):
    !wget http://geneontology.org/ontology/go-basic.obo
dag = GODag('go-basic.obo', optional_attrs=['def'])
go-basic.obo: fmt(1.2) rel(2021-02-01) 47,291 Terms; optional_attrs(def)

Get one GOTerm object

The DAG is a dictionary where:

  • a key is an ID field (Example: GO:NNNNNNN)

  • a value is a GOTerm object

term = next(iter(dag.values()))

The optional ‘def’ obo field becomes a ‘defn’ data member in a GOTerm object

Because “def” is a keyword in Python, the optional obo attribute “def” gets renamed as “defn”, meaning “definition”

print(dir(term))
['__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_parents', 'alt_ids', 'children', 'defn', 'depth', 'get_all_child_edges', 'get_all_children', 'get_all_lower', 'get_all_parent_edges', 'get_all_parents', 'get_all_upper', 'get_goterms_lower', 'get_goterms_lower_rels', 'get_goterms_upper', 'get_goterms_upper_rels', 'has_child', 'has_parent', 'id', 'is_obsolete', 'item_id', 'level', 'name', 'namespace', 'parents']