biolink / ontobio

python library for working with ontologies and ontology associations
https://ontobio.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
119 stars 30 forks source link

Mouse_Gene_Phenotypes error #211

Open pnrobinson opened 6 years ago

pnrobinson commented 6 years ago

When I run this code in my own notebook, http://nbviewer.jupyter.org/github/biolink/ontobio/blob/master/notebooks/Mouse_Gene_Phenotypes.ipynb

z, xlabels, ylabels = aset.similarity_matrix(diseases, diseases)
import plotly.plotly as py
import plotly.graph_objs as go
import numpy as np
trace = go.Heatmap(z=-np.array(z),
                       x=xlabels,
                       y=ylabels)
py.iplot([trace], filename='labelled-heatmap')

leads to the following error message

Aw, snap! We didn't get a username with your request.
Don't have an account? https://plot.ly/api_signup
Questions? accounts@plot.ly
---------------------------------------------------------------------------
PlotlyError                               Traceback (most recent call last)
<ipython-input-17-ba5d83e243b8> in <module>()
      6                        x=xlabels,
      7                        y=ylabels)
----> 8 py.iplot([trace], filename='labelled-heatmap')

~/bin/anaconda3/lib/python3.6/site-packages/plotly/plotly/plotly.py in iplot(figure_or_data, **plot_options)
    171         embed_options['height'] = str(embed_options['height']) + 'px'
    172 
--> 173     return tools.embed(url, **embed_options)
    174 
    175 

~/bin/anaconda3/lib/python3.6/site-packages/plotly/tools.py in embed(file_owner_or_url, file_id, width, height)
    393         else:
    394             url = file_owner_or_url
--> 395         return PlotlyDisplay(url, width, height)
    396     else:
    397         if (get_config_defaults()['plotly_domain']

~/bin/anaconda3/lib/python3.6/site-packages/plotly/tools.py in __init__(self, url, width, height)
   1440         def __init__(self, url, width, height):
   1441             self.resource = url
-> 1442             self.embed_code = get_embed(url, width=width, height=height)
   1443             super(PlotlyDisplay, self).__init__(data=self.embed_code)
   1444 

~/bin/anaconda3/lib/python3.6/site-packages/plotly/tools.py in get_embed(file_owner_or_url, file_id, width, height)
    298                 "'{1}'."
    299                 "\nRun help on this function for more information."
--> 300                 "".format(url, plotly_rest_url))
    301         urlsplit = six.moves.urllib.parse.urlparse(url)
    302         file_owner = urlsplit.path.split('/')[1].split('~')[1]

PlotlyError: Because you didn't supply a 'file_id' in the call, we're assuming you're trying to snag a figure from a url. You supplied the url, '', we expected it to start with 'https://plot.ly'.
Run help on this function for more information.

The notebook should explain how to set this up correctly

cmungall commented 6 years ago

This doesn't help you much right now, but I'm thinking we should use seaborn rather than plotly. Seems to be the most popular choice for data science in python - and doesn't require use of a server. Thoughts @kltm @kshefchek?

pnrobinson commented 6 years ago

@cmungall @kltm @kshefchek Here is an alternative that works with Seaborn thanks to my colleague @adeslatt https://github.com/TheJacksonLaboratory/robinson-lab-notebooks/blob/master/Linked_Data_Biolink.ipynb

from ontobio.assoc_factory import AssociationSetFactory
afactory = AssociationSetFactory()
HUMAN='NCBITaxon:9606'
aset=afactory.create(ontology=ont, subject_category='disease',object_category='phenotype',taxon=HUMAN)
[t]=ont.search('Nephroblastoma')
diseases=aset.query([t])
dlabels = ["{} '{}'".format(d, aset.label(d)) for d in diseases]
z, xlabels, ylabels = aset.similarity_matrix(diseases, diseases)
import seaborn as sns
import numpy as np 
import pandas as pd

sns.set(color_codes=True)
zarray = np.array(z)
zarray_df = pd.DataFrame(zarray, columns=dlabels, index=dlabels)

cm = sns.clustermap(zarray_df, method="average",metric="Euclid")