Loading the optional definition attribute¶
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']
Print one GO term and its optional definition (defn) data member value¶
pattern = '{ID} {NAME}\n{DEF}'
print(pattern.format(ID=term.item_id, NAME=term.name, DEF=term.defn))
GO:0000001 mitochondrion inheritance
"The distribution of mitochondria, including the mitochondrial genome, into daughter cells after mitosis or meiosis, mediated by interactions between mitochondria and the cytoskeleton." [GOC:mcc, PMID:10873824, PMID:11389764]
Print the first term in biological process¶
term1 = dag['GO:0000001']
print(pattern.format(ID=term1.item_id, NAME=term1.name, DEF=term1.defn))
GO:0000001 mitochondrion inheritance
"The distribution of mitochondria, including the mitochondrial genome, into daughter cells after mitosis or meiosis, mediated by interactions between mitochondria and the cytoskeleton." [GOC:mcc, PMID:10873824, PMID:11389764]
Copyright (C) 2021-present, DV Klopfenstein and Haibao Tang. All rights reserved.