{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "h:pato g:\n"
     ]
    }
   ],
   "source": [
    "from ontobio.ontol_factory import OntologyFactory\n",
    "\n",
    "ofactory = OntologyFactory()\n",
    "ont = ofactory.create(\"pato\")  ## Connect remotely to PATO over SPARQL\n",
    "##\n",
    "## Note: Jupyter may show '*' to indicate kernel busy while this is being\n",
    "## fetched - should only take a few seconds. Wait before proceeding"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'label': 'ploidy'}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cls = ont.node('PATO:0001374')\n",
    "cls"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'PATO:0001375',\n",
       " 'PATO:0001376',\n",
       " 'PATO:0001377',\n",
       " 'PATO:0001378',\n",
       " 'PATO:0001379',\n",
       " 'PATO:0001380',\n",
       " 'PATO:0001381',\n",
       " 'PATO:0001382',\n",
       " 'PATO:0001383',\n",
       " 'PATO:0001384',\n",
       " 'PATO:0001385',\n",
       " 'PATO:0001386',\n",
       " 'PATO:0001387',\n",
       " 'PATO:0001388',\n",
       " 'PATO:0001389',\n",
       " 'PATO:0001390',\n",
       " 'PATO:0001391',\n",
       " 'PATO:0001392',\n",
       " 'PATO:0001393',\n",
       " 'PATO:0001394',\n",
       " 'PATO:0001395'}"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ancs = ont.descendants('PATO:0001374')\n",
    "ancs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[\"PATO:0001376 'monoploid'\",\n",
       " \"PATO:0001380 'paleopolyploid'\",\n",
       " \"PATO:0001379 'allopolyploidy'\",\n",
       " \"PATO:0001377 'polyploid'\",\n",
       " \"PATO:0001390 'partial trisomy'\",\n",
       " \"PATO:0001375 'haploid'\",\n",
       " \"PATO:0001392 'endopolyploid'\",\n",
       " \"PATO:0001385 'aneuploid'\",\n",
       " \"PATO:0001395 'haplodiploid'\",\n",
       " \"PATO:0001382 'tetraploid'\",\n",
       " \"PATO:0001378 'autopolyploid'\",\n",
       " \"PATO:0001394 'diploid'\",\n",
       " \"PATO:0001383 'pentaploid'\",\n",
       " \"PATO:0001393 'euploid'\",\n",
       " \"PATO:0001391 'mosaic trisomy'\",\n",
       " \"PATO:0001386 'monosomy'\",\n",
       " \"PATO:0001389 'trisomy'\",\n",
       " \"PATO:0001387 'disomy'\",\n",
       " \"PATO:0001388 'uniparental disomy'\",\n",
       " \"PATO:0001381 'triploid'\",\n",
       " \"PATO:0001384 'hexaploid'\"]"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[\"{} '{}'\".format(x, ont.label(x)) for x in ont.descendants('PATO:0001374')]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['http://purl.obolibrary.org/obo/pato#abnormal_slim',\n",
       " 'http://purl.obolibrary.org/obo/pato#absent_slim',\n",
       " 'http://purl.obolibrary.org/obo/pato#attribute_slim',\n",
       " 'http://purl.obolibrary.org/obo/pato#cell_quality',\n",
       " 'http://purl.obolibrary.org/obo/pato#disposition_slim',\n",
       " 'http://purl.obolibrary.org/obo/pato#hpo_slim',\n",
       " 'http://purl.obolibrary.org/obo/pato#mpath_slim',\n",
       " 'http://purl.obolibrary.org/obo/pato#relational_slim',\n",
       " 'http://purl.obolibrary.org/obo/pato#scalar_slim',\n",
       " 'http://purl.obolibrary.org/obo/pato#value_slim']"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ont.subsets() ## Issues remote call; Jupyter may show '*' for ~1s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "slim = ont.extract_subset('absent_slim') ## Issues remote call; Jupyter may show '*' for ~1s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[\"PATO:0000462 'absent'\",\n",
       " \"PATO:0000467 'present'\",\n",
       " \"PATO:0015001 'absence due to degeneration'\"]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "[\"{} '{}'\".format(x, ont.label(x)) for x in slim]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "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.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}