<commit_before>{
 "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**](#Parents-and-Ancestors)\n",
    "  * [**Code to get Parents and Ancestors**](#Code-to-get-Parents-and-Ancestors)\n",
    "    * [**Get parents through *is_a* relationship**](#Get-parents-through-is_a-relationship)\n",
    "    * [**Get parents through *is_a* relationship and optional relationship, *regulates*.**](#Get-parents-through-is_a-relationship-and-optional-relationship,-regulates)\n",
    "    * [**Get ancestors through *is_a* relationship**](#Get-ancestors-through-is_a-relationship)\n",
    "    * [**Get ancestors through *is_a* relationship and optional relationship, *regulates*.**](#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](images/parents_and_ancestors.png)\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": {},<commit_msg>make image smaller so code below and image can be seen in the same screen<commit_after>{
 "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**](#Parents-and-Ancestors)\n",
    "  * [**Code to get Parents and Ancestors**](#Code-to-get-Parents-and-Ancestors)\n",
    "    * [**Get parents through *is_a* relationship**](#Get-parents-through-is_a-relationship)\n",
    "    * [**Get parents through *is_a* relationship and optional relationship, *regulates*.**](#Get-parents-through-is_a-relationship-and-optional-relationship,-regulates)\n",
    "    * [**Get ancestors through *is_a* relationship**](#Get-ancestors-through-is_a-relationship)\n",
    "    * [**Get ancestors through *is_a* relationship and optional relationship, *regulates*.**](#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",
    "<img src=\"images/parents_and_ancestors.png\" alt=\"parents_and_ancestors\" width=\"550\">\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": {},
{'fraction_non_alphanumeric': 0.17484276729559747, 'fraction_numerical': 0.007389937106918239, 'mean_word_length': 3.061941251596424, 'pattern_counts': {'":': 34, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3613963', 'n_tokens_mistral': 2178, 'n_tokens_neox': 2045, 'n_words': 537}