{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Loading the optional definition attribute\n", "\n", "1) Load the ontology file while also loading the optional definition attribute (\"def\" or \"defn\") for each GO term" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "go-basic.obo: fmt(1.2) rel(2021-02-01) 47,291 Terms; optional_attrs(def)\n" ] } ], "source": [ "from os.path import exists\n", "from goatools.obo_parser import GODag\n", "\n", "if not exists('go-basic.obo'):\n", " !wget http://geneontology.org/ontology/go-basic.obo\n", "dag = GODag('go-basic.obo', optional_attrs=['def'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Get one GOTerm object\n", "\n", "The DAG is a dictionary where:\n", " * a key is an ID field (Example: GO:NNNNNNN)\n", " * a value is a GOTerm object" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "term = next(iter(dag.values()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The optional 'def' obo field becomes a 'defn' data member in a GOTerm object\n", "Because \"def\" is a keyword in Python, the optional obo attribute \"def\" gets renamed as \"defn\", meaning \"definition\"" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "['__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']\n" ] } ], "source": [ "print(dir(term))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Print one GO term and its optional definition (defn) data member value" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "GO:0000001 mitochondrion inheritance\n", "\"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]\n" ] } ], "source": [ "pattern = '{ID} {NAME}\\n{DEF}'\n", "print(pattern.format(ID=term.item_id, NAME=term.name, DEF=term.defn))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Print the first term in biological process" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "GO:0000001 mitochondrion inheritance\n", "\"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]\n" ] } ], "source": [ "term1 = dag['GO:0000001']\n", "print(pattern.format(ID=term1.item_id, NAME=term1.name, DEF=term1.defn))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Copyright (C) 2021-present, DV Klopfenstein and Haibao Tang. All rights reserved." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.7" } }, "nbformat": 4, "nbformat_minor": 2 }