Plotting is important and its features are currently under development and are experimental. Below is a demonstration of some current features.
Plotting currently depends on the excellent pygal package which is a python plotting that produces SVG plots. I have noticed that large SVGs tend to be heavy and choke the browser (I use Firefox, and perhaps moreso when in the context of a Jupyter notebook; I think Chrome could fare better from a few experiments), so proceed with your plotting experimentation with this warning in mind.
The plotting API is experimental.
In [1]:
%load_ext autoreload
%autoreload 2
#Load our data
from omicexperiment.experiment.microbiome import MicrobiomeExperiment
mapping = "example_map.tsv"
biom = "example_fungal.biom"
tax = "blast_tax_assignments.txt"
exp = MicrobiomeExperiment(biom, mapping,tax)
exp.data_df
Out[1]:
In [2]:
#you can load your plot in the notebook directly,
#but note that large graphics for large datasets tend to consume quite
#CPU power
from lxml import etree
plot = exp.plot() #this returns an lxml ElementTree
#you can also pass an outputfile
#plot = exp.plot('~/test_plot.html') #this saves the SVG figure to an html file
plot_string = etree.tostring(plot) #convert to string
from IPython.display import SVG
SVG(plot_string) #Hover over the bars and look at the tooltip
Out[2]:
In [3]:
plot_grp = exp.plot_groups("group") #this returns an lxml ElementTree
plot_string = etree.tostring(plot_grp) #convert to string
from IPython.display import SVG
SVG(plot_string) #Note the groupings below the bars
Out[3]:
In [4]:
#Try converting the otus to 'genus' level assignments before plotting
exp_genus = exp.apply(exp.Taxonomy.groupby('genus'))
plot_string = etree.tostring(exp_genus.plot()) #convert to string
from IPython.display import SVG
SVG(plot_string)
Out[4]:
In [5]:
#Grouping by some sample metadata to get average relative abundances for sample groups
exp_disease_group = exp_genus.apply(exp.Sample.groupby('group'))
plot_string = etree.tostring(exp_disease_group.plot()) #convert to string
from IPython.display import SVG
SVG(plot_string)
Out[5]: