In [2]:
from ontobio.ontol_factory import OntologyFactory

# Create ontology object, for mammalian phenotype ontology
# Transparently uses remote SPARQL service.
# (May take a few seconds to run first time, Jupyter will show '*'. BE PATIENT, do
# not re-execute cell)
ofactory = OntologyFactory()
ont = ofactory.create('mp')

In [3]:
from ontobio.assoc_factory import AssociationSetFactory

MOUSE = 'NCBITaxon:10090'

# Create association set
# Transparently uses remote Monarch service.
# (May take a few seconds to run first time, Jupyter will show '*'. BE PATIENT, do
# not re-execute cell)
afactory = AssociationSetFactory()
aset = afactory.create(ontology=ont,
                       subject_category='gene',
                       object_category='phenotype',
                       taxon=MOUSE)

In [9]:
[p1] = ont.search("abnormal hippocampus morphology")
[p2] = ont.search("abnormal glucose homeostasis")

In [10]:
genes = aset.query([p1, p2])

In [11]:
len(genes)


Out[11]:
12

In [12]:
genes


Out[12]:
['MGI:88227',
 'MGI:107164',
 'MGI:102548',
 'MGI:1926884',
 'MGI:88145',
 'MGI:97362',
 'MGI:98331',
 'MGI:102709',
 'MGI:109583',
 'MGI:103555',
 'MGI:2145264',
 'MGI:1929213']

In [14]:
["{} '{}'".format(g, aset.label(g)) for g in genes]


Out[14]:
["MGI:88227 'C3'",
 "MGI:107164 'Ppp3ca'",
 "MGI:102548 'Tsc2'",
 "MGI:1926884 'Huwe1'",
 "MGI:88145 'Bdnf'",
 "MGI:97362 'Nos3'",
 "MGI:98331 'Snap25'",
 "MGI:102709 'Cav1'",
 "MGI:109583 'Pten'",
 "MGI:103555 'Clcn3'",
 "MGI:2145264 'Nhlrc1'",
 "MGI:1929213 'Zbtb20'"]

In [28]:
z, xlabels, ylabels = aset.similarity_matrix(genes, genes)

In [29]:
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np

In [35]:
trace = go.Heatmap(z=-np.array(z),
                       x=xlabels,
                       y=ylabels)

In [36]:
py.iplot([trace], filename='labelled-heatmap')


Out[36]:

In [ ]: