{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Adding optional relationships changes the *dcnt* value\n", "**SYNOPSIS**: For GO:0019012, *virion*, the descendants count *dcnt*, is:\n", " * 0 when using *is_a* relationships (the default) and \n", " * 48 when adding the optional relationship, *part_of*.\n", "\n", "**Table of Contents:** \n", " 1. Download Ontologies, if necessary\n", " 2. Depth-01 term, virion, has dcnt=0 through ***is_a*** relationships (default)\n", " 3. Depth-01 term, virion, dcnt value is higher using **all** relationships\n", " 4. Depth-01 term, virion, dcnt value is higher using ***part_of*** relationships\n", " 5. Descendants under virion\n", " 6. Plot some descendants of virion" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1) Download Ontologies, if necessary" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " EXISTS: go-basic.obo\n", "go-basic.obo: fmt(1.2) rel(2019-06-10) 47,442 GO Terms; optional_attrs(relationship)\n" ] } ], "source": [ "from goatools.base import get_godag\n", "godag = get_godag(\"go-basic.obo\", optional_attrs={'relationship'})\n", "go_leafs = set(o.item_id for o in godag.values() if not o.children)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2) Depth-01 term, GO:0019012 (*virion*) has *dcnt=0* through *is_a* relationships (default)\n", "GO:0019012, *virion*, has no GO terms below it through the *is_a* relationship, so the default value of dcnt will be zero, even though it is very high in the DAG at depth=01." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "virion = 'GO:0019012'" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "INITIALIZING GoSubDag: 27482 sources in 44990 GOs rcnt(True). 0 alt GO IDs\n", " GoSubDag: namedtuple fields: NS level depth GO alt GO_name dcnt D1 id\n", " GoSubDag: relationships: set()\n" ] } ], "source": [ "from goatools.gosubdag.gosubdag import GoSubDag\n", "gosubdag_r0 = GoSubDag(go_leafs, godag)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Notice that ***dcnt=0*** for GO:0019012, *virion*, even though it is very high in the DAG hierarchy (depth=1). This is because there are no GO IDs under GO:0019012 (*virion*) using the *is_a* relationship." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "NtGo(NS='CC', level=1, depth=1, GO='GO:0019012', alt='', GO_name='virion', dcnt=0, D1='T', id='GO:0019012')\n", "THE VALUE OF dcnt IS: 0\n" ] } ], "source": [ "nt_virion = gosubdag_r0.go2nt[virion]\n", "print(nt_virion)\n", "print('THE VALUE OF dcnt IS: {dcnt}'.format(dcnt=nt_virion.dcnt))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3) Depth-01 term, GO:0019012 (*virion*) *dcnt* value is higher using all relationships\n", "Load all relationships into GoSubDag using *relationships=True*" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "INITIALIZING GoSubDag: 27482 sources in 44990 GOs rcnt(True). 0 alt GO IDs\n", " GoSubDag: namedtuple fields: NS level depth reldepth GO alt GO_name dcnt D1 childcnt REL REL_short rel id\n", " GoSubDag: relationships: {'part_of', 'negatively_regulates', 'positively_regulates', 'regulates'}\n" ] } ], "source": [ "gosubdag_r1 = GoSubDag(go_leafs, godag, relationships=True)" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "NtGo(NS='CC', level=1, depth=1, reldepth=1, GO='GO:0019012', alt='', GO_name='virion', dcnt=48, D1='Q', childcnt=0, REL='....', REL_short='', rel='p...', id='GO:0019012')\n", "THE VALUE OF dcnt IS: 48\n" ] } ], "source": [ "nt_virion = gosubdag_r1.go2nt[virion]\n", "print(nt_virion)\n", "print('THE VALUE OF dcnt IS: {dcnt}'.format(dcnt=nt_virion.dcnt))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 4) Depth-01 term, GO:0019012 (*virion*) *dcnt* value is higher using part_of relationships\n", "Load all relationships into GoSubDag using *relationships={'part_of'}*" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "INITIALIZING GoSubDag: 27482 sources in 44990 GOs rcnt(True). 0 alt GO IDs\n", " GoSubDag: namedtuple fields: NS level depth reldepth GO alt GO_name dcnt D1 childcnt REL REL_short rel id\n", " GoSubDag: relationships: {'part_of'}\n" ] } ], "source": [ "gosubdag_partof = GoSubDag(go_leafs, godag, relationships={'part_of'})" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "NtGo(NS='CC', level=1, depth=1, reldepth=1, GO='GO:0019012', alt='', GO_name='virion', dcnt=48, D1='Q', childcnt=0, REL='.', REL_short='', rel='p', id='GO:0019012')\n", "THE VALUE OF dcnt IS: 48\n" ] } ], "source": [ "nt_virion = gosubdag_partof.go2nt[virion]\n", "print(nt_virion)\n", "print('THE VALUE OF dcnt IS: {dcnt}'.format(dcnt=nt_virion.dcnt))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 5) Descendants under GO:0019012 (*virion*)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "48 descendants of virion were found\n" ] } ], "source": [ "virion_descendants = gosubdag_partof.rcntobj.go2descendants[virion]\n", "print('{N} descendants of virion were found'.format(N=len(virion_descendants)))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 6) Plot descendants of *virion*" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "CC GO:0098032 dcnt(0) D-04 icosahedral viral capsid, collar fiber\n", "CC GO:0098033 dcnt(0) D-04 icosahedral viral capsid, neck fiber\n" ] } ], "source": [ "from goatools.gosubdag.plot.gosubdag_plot import GoSubDagPlot\n", "\n", "# Limit plot of descendants to get a smaller plot\n", "virion_capsid_fiber = {'GO:0098033', 'GO:0098032'}\n", "nts = gosubdag_partof.prt_goids(virion_capsid_fiber, \n", " '{NS} {GO} dcnt({dcnt}) D-{depth:02} {GO_name}')" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "INITIALIZING GoSubDag: 2 sources in 11 GOs rcnt(True). 0 alt GO IDs\n", " GoSubDag: namedtuple fields: NS level depth reldepth GO alt GO_name dcnt D1 childcnt REL REL_short rel id\n", " GoSubDag: relationships: {'part_of'}\n", " 2 usr 11 GOs WROTE: virion_capsid_fiber.png\n" ] } ], "source": [ "# Limit plot size by choosing just two virion descendants\n", "# Get a subset containing only a couple virion descendants and their ancestors\n", "pltdag = GoSubDag(virion_capsid_fiber, godag, relationships={'part_of'})\n", "pltobj = GoSubDagPlot(pltdag)\n", "pltobj.plt_dag('virion_capsid_fiber.png')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The descendant count is the number next to the **d** in the GO term boxes. \n", "\n", "The **c0** seen in some boxes, like GO:0019012 *virion*, indicates that this term has no children through the default *is_a* relationship, but does have children when viewed using additional optional relationships. \n", "\n", "" ] } ], "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 }