#!/usr/bin/env python # coding: utf-8 # # 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](https://github.com/MaayanLab/clustergrammer-widget/blob/master/rc_two_cats.txt)) using the Clustergrammer interactive widget (see the Clustergrammer Jupyter Widget [Documentation](http://clustergrammer.readthedocs.io/clustergrammer_widget.html) 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() # ## 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](http://amp.pharm.mssm.edu/Harmonizome/)) # * find biological information specific to your gene list with enrichment analysis from [Enrichr](http://amp.pharm.mssm.edu/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() # # Installation # Clustergrammer widget is built using the [ipywidgets](https://github.com/ipython/ipywidgets) framework (using the [cookie cutter](https://github.com/jupyter/widget-cookiecutter) 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](http://clustergrammer.readthedocs.io/clustergrammer_widget.html) and clustergrammer_widget [GitHub](https://github.com/MaayanLab/clustergrammer-widget) for more information. # # # nbviewer # Interactive widgets can also be rendered using Jupyter's [nbviewer](http://nbviewer.jupyter.org/) by using the 'Save Notebook with Widgets' action from the Widgets menu in the notebook (see ipywidgets [documents](http://ipywidgets.readthedocs.io/en/latest/embedding.html#rendering-interactive-widgets-on-nbviewer)). This notebook is being rendered by nbviewer using the Github [repo](https://github.com/MaayanLab/clustergrammer-widget). # # # Clustergrammer Web-app and Libraries # The Clustergrammer project can also be used through: # * a web application: http://amp.pharm.mssm.edu/clustergrammer/ # * and as JavaScript (front-end) and Python (back-end) libraries by developers: [clustergrammer.js](https://github.com/MaayanLab/clustergrammer) and [clustergrammer.py](https://github.com/MaayanLab/clustergrammer-py)