UMAP Panels and views

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

View a Panel

Display an interacgive panel.

In [6]:
gsf.panels.UMAP_Panel(gsc).panel()
Out[6]:

Call Views

Specify options and directly view the output.

In [7]:
umap_panel = gsf.panels.UMAP_Panel(gsc, hue="Treatment", random_state=42)
plot_1 = umap_panel.hvplot_view()

umap_panel = gsf.panels.UMAP_Panel(gsc, hue="Treatment", random_state=42, interface_opts={"selected_gene_sets": ["Boruta_Treatment"]})
plot_2 = umap_panel.hvplot_view()

layout = (plot_1 + plot_2)
layout
Out[7]:
In [8]:
hv.save(layout.opts(toolbar=None), "umap_subsets.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-4f9511489f4f> in <module>
----> 1 hv.save(layout.opts(toolbar=None), "umap_subsets.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.