{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Loading obsolete GO terms \n", "Obsolete GO terms are loaded upon request.\n", "\n", "Relevant GODag arguments include:\n", " * load_obsolete=True\n", " * optional_attrs={'consider', 'replaced_by'}\n", "\n", "## 1) Download GO DAG file, go-basic.obo" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "requests.get(http://purl.obolibrary.org/obo/go/go-basic.obo, stream=True)\n", " WROTE: go-basic.obo\n", "\n" ] } ], "source": [ "from goatools.base import download_go_basic_obo\n", "fin_dag = download_go_basic_obo(\"go-basic.obo\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 2) Read GO terms into a GODag instance: load_obsolete=True" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "go-basic.obo: fmt(1.2) rel(2020-09-10) 50,377 GO Terms\n" ] } ], "source": [ "from goatools.obo_parser import GODag\n", "\n", "godag = GODag(fin_dag, load_obsolete=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 3) Load the optional GODag attributes, *consider* and *replaced_by*" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "go-basic.obo: fmt(1.2) rel(2020-09-10) 50,377 GO Terms; optional_attrs(consider replaced_by)\n" ] } ], "source": [ "godag = GODag(fin_dag, optional_attrs={'consider', 'replaced_by'}, load_obsolete=True)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 3a) How to suppress the GODag output messages\n", "Set argument: `prt=None`." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "godag = GODag(fin_dag, optional_attrs={'consider', 'replaced_by'}, load_obsolete=True, prt=None)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 4) What GO term replaced the obsolete GO terms?" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2,971 GO terms are obsolete\n", "1 GO:0042142 was replaced by GO:0046911\n", "2 GO:0006502 was replaced by GO:0018342\n", "3 GO:0006503 was replaced by GO:0018343\n", "4 GO:0006504 was replaced by GO:0018344\n", "5 GO:0006510 was replaced by GO:0004176\n" ] } ], "source": [ "goterms_obsolete = set(o for o in godag.values() if o.is_obsolete)\n", "print('{N:,} GO terms are obsolete'.format(N=len(goterms_obsolete)))\n", "\n", "num = 1\n", "for goterm in goterms_obsolete:\n", " if goterm.replaced_by[:3] == 'GO:':\n", " print('{I} {OLD} was replaced by {NEW}'.format(\n", " I=num, OLD=goterm.item_id, NEW=goterm.replaced_by))\n", " if num == 5:\n", " break\n", " num += 1\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 5) What GO terms were considered?" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "1 Given GO:0006894, consider {'GO:0055107', 'GO:0055108'}\n", "2 Given GO:0045757, consider {'GO:0030837', 'GO:0030835'}\n", "3 Given GO:0052108, consider {'GO:0044117', 'GO:0044115'}\n", "4 Given GO:0006815, consider {'GO:0006814', 'GO:0006813'}\n", "5 Given GO:0006510, consider {'GO:0051603', 'GO:0016485', 'GO:0006508'}\n" ] } ], "source": [ "num = 1\n", "for goterm in goterms_obsolete:\n", " if goterm.consider:\n", " print('{I} Given {OLD}, consider {NEW}'.format(\n", " I=num, OLD=goterm.item_id, NEW=goterm.consider))\n", " if num == 5:\n", " break\n", " num += 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Copyright (C) 2019-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 }