# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # 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'])
# -

# ## 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))

# ## 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))

# ## Print the first term in biological process

term1 = dag['GO:0000001']
print(pattern.format(ID=term1.item_id, NAME=term1.name, DEF=term1.defn))

# Copyright (C) 2021-present, <NAME> and <NAME>. All rights reserved.

StarcoderdataJupyterScriptsDedupFiltered