{ "cells": [ { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from ontobio.ontol_factory import OntologyFactory\n", "\n", "# Create ontology object, for mammalian phenotype ontology\n", "# Transparently uses remote SPARQL service.\n", "# (May take a few seconds to run first time, Jupyter will show '*'. BE PATIENT, do\n", "# not re-execute cell)\n", "ofactory = OntologyFactory()\n", "ont = ofactory.create('mp')" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "from ontobio.assoc_factory import AssociationSetFactory\n", "\n", "MOUSE = 'NCBITaxon:10090'\n", "\n", "# Create association set\n", "# Transparently uses remote Monarch service.\n", "# (May take a few seconds to run first time, Jupyter will show '*'. BE PATIENT, do\n", "# not re-execute cell)\n", "afactory = AssociationSetFactory()\n", "aset = afactory.create(ontology=ont,\n", " subject_category='gene',\n", " object_category='phenotype',\n", " taxon=MOUSE)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": true }, "outputs": [], "source": [ "[p1] = ont.search(\"abnormal hippocampus morphology\")\n", "[p2] = ont.search(\"abnormal glucose homeostasis\")" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": true }, "outputs": [], "source": [ "genes = aset.query([p1, p2])" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "12" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "len(genes)" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "['MGI:88227',\n", " 'MGI:107164',\n", " 'MGI:102548',\n", " 'MGI:1926884',\n", " 'MGI:88145',\n", " 'MGI:97362',\n", " 'MGI:98331',\n", " 'MGI:102709',\n", " 'MGI:109583',\n", " 'MGI:103555',\n", " 'MGI:2145264',\n", " 'MGI:1929213']" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "genes" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[\"MGI:88227 'C3'\",\n", " \"MGI:107164 'Ppp3ca'\",\n", " \"MGI:102548 'Tsc2'\",\n", " \"MGI:1926884 'Huwe1'\",\n", " \"MGI:88145 'Bdnf'\",\n", " \"MGI:97362 'Nos3'\",\n", " \"MGI:98331 'Snap25'\",\n", " \"MGI:102709 'Cav1'\",\n", " \"MGI:109583 'Pten'\",\n", " \"MGI:103555 'Clcn3'\",\n", " \"MGI:2145264 'Nhlrc1'\",\n", " \"MGI:1929213 'Zbtb20'\"]" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "[\"{} '{}'\".format(g, aset.label(g)) for g in genes]" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "collapsed": true }, "outputs": [], "source": [ "z, xlabels, ylabels = aset.similarity_matrix(genes, genes)" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import plotly.plotly as py\n", "import plotly.graph_objs as go\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "collapsed": true }, "outputs": [], "source": [ "trace = go.Heatmap(z=-np.array(z),\n", " x=xlabels,\n", " y=ylabels)\n" ] }, { "cell_type": "code", "execution_count": 36, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "py.iplot([trace], filename='labelled-heatmap')" ] }, { "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.6.2" } }, "nbformat": 4, "nbformat_minor": 2 }