Genewise Scatter and Distributions

Plotting Guide Setup

In [1]:
import os
import numpy as np

import holoviews as hv
hv.extension('bokeh')

import GSForge as gsf

Declare used paths

In [2]:
# OS-independent path management.
from os import fspath, environ
from pathlib import Path
In [3]:
OSF_PATH = Path(environ.get("GSFORGE_DEMO_DATA", default="~/GSForge_demo_data")).expanduser()
AGEM_PATH = OSF_PATH.joinpath("osfstorage", "rice.nc")
BOR_COLL_PATH = OSF_PATH.joinpath("osfstorage", "boruta_gene_sets")
assert AGEM_PATH.exists()

Load an AnnotatedGEM

In [4]:
agem = gsf.AnnotatedGEM(AGEM_PATH)
agem
Out[4]:
<GSForge.AnnotatedGEM>
Name: Rice
Selected GEM Variable: 'counts'
    Gene   55986
    Sample 475
In [5]:
gsc = gsf.GeneSetCollection.from_folder(gem=agem, target_dir=BOR_COLL_PATH, 
                                        name="Boruta Results")
gsc
Out[5]:
<GSForge.GeneSetCollection>
Boruta Results
GeneSets (3 total): Support Count
    Boruta_Treatment: 681
    Boruta_Genotype: 661
    Boruta_Subspecies: 231

Creating a Gene-wise scatter plot

Default Styling Options

You should expect those for the backend not loaded to cause errors for now. You can comment out or delete those cells not in use.

In [6]:
bokeh_default = [
    hv.opts.Points(width=500, height=500, bgcolor="lightgrey", size=1.2, muted_alpha=0.05, 
                   show_grid=True),
    hv.opts.Area(bgcolor="lightgrey", show_grid=True, show_legend=False, alpha=0.25),
    hv.opts.Area("dist_x", width=150),
    hv.opts.Area("dist_y", height=150),
]

bokeh_datashaded = [
    hv.opts.Area(bgcolor="lightgrey", show_grid=True, show_legend=False, alpha=0.25),
    hv.opts.Area("dist_x", width=150),
    hv.opts.Area("dist_y", height=150),
    hv.opts.RGB(width=500, height=500, bgcolor="lightgrey", show_grid=True),
]
In [7]:
my_plot = gsf.plots.ScatterDistributionBase(agem, datashade_=True)
my_plot.opts(bokeh_datashaded)
Out[7]:
In [8]:
hv.save(my_plot.options(toolbar=None),  # This sometimes does not remove the toolbar.
        "datashaded_osativa_mean_vs_var.png")
---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
~/virtualenv/python3.7.1/lib/python3.7/site-packages/bokeh/util/dependencies.py in import_required(mod_name, error_msg)
     86     try:
---> 87         return import_module(mod_name)
     88     except ImportError:

~/virtualenv/python3.7.1/lib/python3.7/importlib/__init__.py in import_module(name, package)
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)
    128 

~/virtualenv/python3.7.1/lib/python3.7/importlib/_bootstrap.py in _gcd_import(name, package, level)

~/virtualenv/python3.7.1/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_)

~/virtualenv/python3.7.1/lib/python3.7/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

~/virtualenv/python3.7.1/lib/python3.7/importlib/_bootstrap.py in _call_with_frames_removed(f, *args, **kwds)

~/virtualenv/python3.7.1/lib/python3.7/importlib/_bootstrap.py in _gcd_import(name, package, level)

~/virtualenv/python3.7.1/lib/python3.7/importlib/_bootstrap.py in _find_and_load(name, import_)

~/virtualenv/python3.7.1/lib/python3.7/importlib/_bootstrap.py in _find_and_load_unlocked(name, import_)

ModuleNotFoundError: No module named 'selenium'

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
<ipython-input-8-d61111d310a1> in <module>
      1 hv.save(my_plot.options(toolbar=None),  # This sometimes does not remove the toolbar.
----> 2         "datashaded_osativa_mean_vs_var.png")

~/virtualenv/python3.7.1/lib/python3.7/site-packages/holoviews/util/__init__.py in save(obj, filename, fmt, backend, **kwargs)
    759         if formats[-1] in supported:
    760             filename = '.'.join(formats[:-1])
--> 761     return renderer_obj.save(obj, filename, fmt=fmt)
    762 
    763 

~/virtualenv/python3.7.1/lib/python3.7/site-packages/holoviews/plotting/renderer.py in save(self_or_cls, obj, basename, fmt, key, info, options, **kwargs)
    552             return
    553 
--> 554         rendered = self_or_cls(plot, fmt)
    555         if rendered is None: return
    556         (data, info) = rendered

~/virtualenv/python3.7.1/lib/python3.7/site-packages/holoviews/plotting/bokeh/renderer.py in __call__(self, obj, fmt, doc)
    103             return plot(), info
    104         elif fmt == 'png':
--> 105             png = self._figure_data(plot, fmt=fmt, doc=doc)
    106             return png, info
    107         elif fmt == 'html':

~/virtualenv/python3.7.1/lib/python3.7/site-packages/holoviews/plotting/bokeh/renderer.py in _figure_data(self, plot, fmt, doc, as_script, **kwargs)
    276         if fmt == 'png':
    277             from bokeh.io.export import get_screenshot_as_png
--> 278             img = get_screenshot_as_png(plot.state, None)
    279             imgByteArr = BytesIO()
    280             img.save(imgByteArr, format='PNG')

~/virtualenv/python3.7.1/lib/python3.7/site-packages/bokeh/io/export.py in get_screenshot_as_png(obj, driver, timeout, **kwargs)
    215             file.write(decode_utf8(html))
    216 
--> 217         web_driver = driver if driver is not None else webdriver_control.get()
    218 
    219         web_driver.get("file:///" + tmp.path)

~/virtualenv/python3.7.1/lib/python3.7/site-packages/bokeh/io/webdriver.py in get(self)
    114             if self.current is not None:
    115                 terminate_webdriver(self.current)
--> 116             self.current = self.create()
    117         return self.current
    118 

~/virtualenv/python3.7.1/lib/python3.7/site-packages/bokeh/io/webdriver.py in create(self)
    119     def create(self):
    120         if self.kind == "phantomjs":
--> 121             return create_phantomjs_webdriver()
    122         raise ValueError("Unknown webdriver kind %r" % self.kind)
    123 

~/virtualenv/python3.7.1/lib/python3.7/site-packages/bokeh/io/webdriver.py in create_phantomjs_webdriver()
     70 
     71         webdriver = import_required('selenium.webdriver',
---> 72                                     'To use bokeh.io image export functions you need selenium ' +
     73                                     '("conda install -c bokeh selenium" or "pip install selenium")')
     74 

~/virtualenv/python3.7.1/lib/python3.7/site-packages/bokeh/util/dependencies.py in import_required(mod_name, error_msg)
     87         return import_module(mod_name)
     88     except ImportError:
---> 89         raise RuntimeError(error_msg)
     90 
     91 def detect_phantomjs(version='2.1'):

RuntimeError: To use bokeh.io image export functions you need selenium ("conda install -c bokeh selenium" or "pip install selenium")


Right click to download this notebook from GitHub.