Clustergrammer Widget

Gene Expression Example

This example shows how to visualize a matrix of gene expression data saved as a tab-separated-file (e.g. rc_two_cats.txt) using the Clustergrammer interactive widget (see the Clustergrammer Jupyter Widget Documentation for more information).


In [1]:
# import widget classes and instantiate Network instance
from clustergrammer_widget import *
net = Network(clustergrammer_widget)

In [2]:
# load matrix file
net.load_file('rc_two_cats.txt')

# cluster using default parameters
net.cluster(enrichrgram=True)

# make interactive widget
net.widget()


Widget Javascript not detected.  It may not be installed or enabled properly.

Interactive Features

  • zoom/pan
  • reorder rows and columns using buttons or by double-clicking row/column/category names
  • interactively perform dimensionality reduction (and re-clustering) using row-filter sliders (e.g. filter rows based on variance)
  • identify clusters of varying sizes using the interactive row and column dendrograms
  • export cluster names or crop matrix to clusters using the dendrogram and dendrogram crop buttons
  • search for rows using the search box
  • crop the matrix using the brush cropping tool in the sidebar
  • take a PNG/SVG snapshot or download a TSV file snapshot of the matrix using the sidebar icons

Biollogy-specific Features

Clustergrammer widget has biology-specific features that are activated when rows are given as official gene symbols:

  • mouseover gene (row) name to show full name and description (information provided by Harmonizome)
  • find biological information specific to your gene list with enrichment analysis from Enrichr

General Purpose Pandas DataFrame Viewer

Clustergrammer can also be used as a general purpose Pandas dataframe viewer. This example generates a dataframe with random data and visualizes it with Clustergrammer widget:


In [3]:
import numpy as np
import pandas as pd

# generate random matrix
num_rows = 500
num_cols = 10
np.random.seed(seed=100)
mat = np.random.rand(num_rows, num_cols)

# make row and col labels
rows = range(num_rows)
cols = range(num_cols)
rows = [str(i) for i in rows]
cols = [str(i) for i in cols]

# make dataframe 
df = pd.DataFrame(data=mat, columns=cols, index=rows)

Initialize the network object, load the dataframe, hierarchically cluster the rows and columns using default parameters, and finally visualize using clustergrammer_widget.


In [4]:
net.load_df(df)
net.cluster(enrichrgram=False)
net.widget()


Widget Javascript not detected.  It may not be installed or enabled properly.

Installation

Clustergrammer widget is built using the ipywidgets framework (using the cookie cutter template) and can be installed (with pip) and enabled using the following commands:

pip install clustergrammer_widget
jupyter nbextension enable --py --sys-prefix widgetsnbextension
jupyter nbextension enable --py --sys-prefix clustergrammer_widget

See the documentation and clustergrammer_widget GitHub for more information.

nbviewer

Interactive widgets can also be rendered using Jupyter's nbviewer by using the 'Save Notebook with Widgets' action from the Widgets menu in the notebook (see ipywidgets documents). This notebook is being rendered by nbviewer using the Github repo.

Clustergrammer Web-app and Libraries

The Clustergrammer project can also be used through: