{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Relationships in the GO\n",
"_Alex Warwick Vesztrocy, March 2016_"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For some analyses, it is possible to only use the is_a definitions given in the Gene Ontology. \n",
"\n",
"However, it is important to remember that this isn't always the case. As such, GOATOOLS includes the option to load the relationship definitions also."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Loading GO graph with the relationship tags\n",
"This is possible by using the optional_attrs argument, upon instantiating a GODag."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"go-basic.obo: fmt(1.2) rel(2019-04-17) 47,398 GO Terms; optional_attrs(relationship)\n"
]
}
],
"source": [
"import os\n",
"from goatools.obo_parser import GODag\n",
"\n",
"if not os.path.exists('go-basic.obo'):\n",
" !wget http://geneontology.org/ontology/go-basic.obo\n",
"go = GODag('go-basic.obo', optional_attrs=['relationship'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Viewing relationships in the GO graph"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"So now, when looking at an individual term (which has a relationship defined in the GO) these are listed in a nested manner. As an example, look at GO:1901990 which has a single regulates relationship."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"eg_term = go['GO:1901990']"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"GOTerm('GO:1901990'):\n",
" id:GO:1901990\n",
" item_id:GO:1901990\n",
" name:regulation of mitotic cell cycle phase transition\n",
" namespace:biological_process\n",
" _parents: 2 items\n",
" GO:1901987\n",
" GO:0007346\n",
" parents: 2 items\n",
" GO:1901987\tlevel-06\tdepth-06\tregulation of cell cycle phase transition [biological_process]\n",
" GO:0007346\tlevel-05\tdepth-05\tregulation of mitotic cell cycle [biological_process]\n",
" children: 6 items\n",
" GO:1901991\tlevel-07\tdepth-08\tnegative regulation of mitotic cell cycle phase transition [biological_process]\n",
" GO:0010389\tlevel-07\tdepth-08\tregulation of G2/M transition of mitotic cell cycle [biological_process]\n",
" GO:1901992\tlevel-07\tdepth-08\tpositive regulation of mitotic cell cycle phase transition [biological_process]\n",
" GO:0007096\tlevel-07\tdepth-08\tregulation of exit from mitosis [biological_process]\n",
" GO:2000045\tlevel-07\tdepth-08\tregulation of G1/S transition of mitotic cell cycle [biological_process]\n",
" GO:0030071\tlevel-07\tdepth-10\tregulation of mitotic metaphase/anaphase transition [biological_process]\n",
" level:6\n",
" depth:7\n",
" is_obsolete:False\n",
" alt_ids: 0 items\n",
" relationship: 1 items\n",
" regulates: 1 items\n",
" GO:0044772\tlevel-04\tdepth-04\tmitotic cell cycle phase transition [biological_process]\n",
" relationship_rev: 0 items\n",
" reldepth:7"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"eg_term"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"These different relationship types are stored as a dictionary within the relationship attribute on a GO term."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"dict_keys(['regulates'])\n"
]
}
],
"source": [
"print(eg_term.relationship.keys())"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{GOTerm('GO:0044772'):\n",
" id:GO:0044772\n",
" item_id:GO:0044772\n",
" name:mitotic cell cycle phase transition\n",
" namespace:biological_process\n",
" _parents: 2 items\n",
" GO:0044770\n",
" GO:1903047\n",
" parents: 2 items\n",
" GO:0044770\tlevel-03\tdepth-03\tcell cycle phase transition [biological_process]\n",
" GO:1903047\tlevel-03\tdepth-03\tmitotic cell cycle process [biological_process]\n",
" children: 4 items\n",
" GO:0007091\tlevel-05\tdepth-10\tmetaphase/anaphase transition of mitotic cell cycle [biological_process]\n",
" GO:0010458\tlevel-05\tdepth-05\texit from mitosis [biological_process]\n",
" GO:0000082\tlevel-05\tdepth-05\tG1/S transition of mitotic cell cycle [biological_process]\n",
" GO:0000086\tlevel-05\tdepth-05\tG2/M transition of mitotic cell cycle [biological_process]\n",
" level:4\n",
" depth:4\n",
" is_obsolete:False\n",
" alt_ids: 0 items\n",
" relationship: 0 items\n",
" relationship_rev: 3 items\n",
" regulates: 1 items\n",
" GO:1901990\tlevel-06\tdepth-07\tregulation of mitotic cell cycle phase transition [biological_process]\n",
" negatively_regulates: 1 items\n",
" GO:1901991\tlevel-07\tdepth-08\tnegative regulation of mitotic cell cycle phase transition [biological_process]\n",
" positively_regulates: 1 items\n",
" GO:1901992\tlevel-07\tdepth-08\tpositive regulation of mitotic cell cycle phase transition [biological_process]\n",
" reldepth:5}\n"
]
}
],
"source": [
"print(eg_term.relationship['regulates'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Example use case\n",
"One example use case for the relationship terms, would be to look for all functions which regulate pseudohyphal growth (GO:0007124). That is:\n",
"\n",
"> A pattern of cell growth that occurs in conditions of nitrogen limitation and abundant fermentable carbon source. Cells become elongated, switch to a unipolar budding pattern, remain physically attached to each other, and invade the growth substrate. \n",
">\n",
"> _Source: https://www.ebi.ac.uk/QuickGO/GTerm?id=GO:0007124#term=info&info=1_"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"term_of_interest = go['GO:0007124']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"First, find the relationship types which contain \"regulates\":"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"frozenset({'positively_regulates', 'regulates', 'negatively_regulates'})\n"
]
}
],
"source": [
"regulates = frozenset([typedef \n",
" for typedef in go.typedefs.keys() \n",
" if 'regulates' in typedef])\n",
"print(regulates)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, search through the terms in the tree for those with a relationship in this list and add them to a dictionary dependent on the type of regulation."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"from collections import defaultdict\n",
"\n",
"regulating_terms = defaultdict(list)\n",
"\n",
"for t in go.values():\n",
" if hasattr(t, 'relationship'):\n",
" for typedef in regulates.intersection(t.relationship.keys()):\n",
" if term_of_interest in t.relationship[typedef]:\n",
" regulating_terms['{:s}d_by'.format(typedef[:-1])].append(t)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now regulating_terms contains the GO terms which relate to regulating protein localisation to the nucleolus."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"pseudohyphal growth (GO:0007124) is:\n",
"\n",
" - regulated_by:\n",
" -- GO:2000220 regulation of pseudohyphal growth\n",
" -- GO:2000222 positive regulation of pseudohyphal growth\n",
" -- GO:2000221 negative regulation of pseudohyphal growth\n",
"\n",
" - negatively_regulated_by:\n",
" -- GO:2000221 negative regulation of pseudohyphal growth\n",
" -- GO:1900462 negative regulation of pseudohyphal growth by negative regulation of transcription from RNA polymerase II promoter\n",
" -- GO:0100042 negative regulation of pseudohyphal growth by transcription from RNA polymerase II promoter\n",
"\n",
" - positively_regulated_by:\n",
" -- GO:2000222 positive regulation of pseudohyphal growth\n",
" -- GO:0100041 positive regulation of pseudohyphal growth by transcription from RNA polymerase II promoter\n",
" -- GO:1900461 positive regulation of pseudohyphal growth by positive regulation of transcription from RNA polymerase II promoter\n"
]
}
],
"source": [
"print('{:s} ({:s}) is:'.format(term_of_interest.name, term_of_interest.id))\n",
"for regulate_desc, goterms in regulating_terms.items():\n",
" print('\\n - {:s}:'.format(regulate_desc))\n",
" for goterm in goterms:\n",
" print(' -- {:s} {:s}'.format(goterm.id, goterm.name))\n",
" for gochild in goterm.children:\n",
" print(' -- {:s} {:s}'.format(gochild.id, gochild.name))"
]
}
],
"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": 1
}