{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# How to traverse to GO parents and ancestors\n", "Traverse immediate parents or all ancestors with or without user-specified optional relationships\n", "\n", " * **Parents and Ancestors described**\n", " * **Code to get Parents and Ancestors**\n", " * **Get parents through *is_a* relationship**\n", " * **Get parents through *is_a* relationship and optional relationship, *regulates*.**\n", " * **Get ancestors through *is_a* relationship**\n", " * **Get ancestors through *is_a* relationship and optional relationship, *regulates*.**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Parents and Ancestors\n", "\n", "### Parents\n", "Parents are terms directly above a GO term\n", "\n", "#### The yellow term, *regulation of metabolic process*, has one or two parents.\n", "\n", "* 1) If using only the default ***is_a*** relationship, the only parent is circled in green:\n", " * *regulation of biological process*\n", "\n", "* 2) If adding the optional relationship, ***regulates***, the two parents are circled in purple:\n", " * *regulation of biological process* \n", " * *metabolic process* \n", " \n", "### Ancestors\n", "Ancestors are all terms above a GO term, traversing up all of the GO hierarchy.\n", "\n", "* 3) If adding the optional relationship, ***regulates***, there are four ancestors are circled in blue:\n", " * *biological_process*\n", " * *biological regulation*\n", " * *regulation of biological process* \n", " * *metabolic process*\n", "\n", "* If using only the default ***is_a*** relationship, there are three ancestors (not circled)\n", " * *biological_process*\n", " * *biological regulation*\n", " * *regulation of biological process* \n", " \n", "\"parents_and_ancestors\"\n", "\n", "## Code to get Parents and Ancestors" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "../tests/data/i126/viral_gene_silence.obo: fmt(1.2) rel(2019-04-17) 79 GO Terms; optional_attrs(relationship)\n" ] } ], "source": [ "import os\n", "from goatools.obo_parser import GODag\n", "\n", "# Load a small test GO DAG and all the optional relationships,\n", "# like 'regulates' and 'part_of'\n", "godag = GODag('../tests/data/i126/viral_gene_silence.obo',\n", " optional_attrs={'relationship'})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Get parents through *is_a* relationship\n", "Parent is circled in green" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "GO_ID = 'GO:0019222' # regulation of metabolic process" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "GO:0019222 parent: {'GO:0050789'}\n" ] } ], "source": [ "from goatools.godag.go_tasks import get_go2parents\n", "\n", "optional_relationships = set()\n", "go2parents_isa = get_go2parents(godag, optional_relationships)\n", "print('{GO} parent: {P}'.format(\n", " GO=GO_ID,\n", " P=go2parents_isa[GO_ID]))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Get parents through *is_a* relationship and optional relationship, *regulates*\n", "Parents are circled in purple" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "GO:0019222 parents: {'GO:0050789', 'GO:0008152'}\n" ] } ], "source": [ "optional_relationships = {'regulates', 'negatively_regulates', 'positively_regulates'}\n", "go2parents_reg = get_go2parents(godag, optional_relationships)\n", "print('{GO} parents: {P}'.format(\n", " GO=GO_ID,\n", " P=go2parents_reg[GO_ID]))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Get ancestors through *is_a* relationship\n", "Not circled, but can be seen in figure" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "GO:0019222 ancestors: {'GO:0050789', 'GO:0008150', 'GO:0065007'}\n" ] } ], "source": [ "from goatools.gosubdag.gosubdag import GoSubDag\n", "\n", "gosubdag_r0 = GoSubDag([GO_ID], godag, prt=None)\n", "print('{GO} ancestors: {P}'.format(\n", " GO=GO_ID,\n", " P=gosubdag_r0.rcntobj.go2ancestors[GO_ID]))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Get ancestors through *is_a* relationship and optional relationship, *regulates*\n", "Circles in blue" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "GO:0019222 ancestors: {'GO:0008150', 'GO:0065007', 'GO:0050789', 'GO:0008152'}\n" ] } ], "source": [ "gosubdag_r1 = GoSubDag([GO_ID], godag, relationships=optional_relationships, prt=None)\n", "print('{GO} ancestors: {P}'.format(\n", " GO=GO_ID,\n", " P=gosubdag_r1.rcntobj.go2ancestors[GO_ID]))" ] } ], "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 }