The clustergrammer_widget
class is now being loaded into the Network
class. The class and widget instance are saved in th Network
instance, net
. This allows us to load data, cluster, and finally produce a new widget instance using the widget
method. The instance of the widget is saved in net
and can be used to grab the data from the clustergram as a Pandas DataFrame using the widget_df
method. The exported DataFrame will reflect any filtering or imported categories that were added on the front end.
In these examples, we will filter the matrix using the brush crop tool, export the filtered matrix as a DataFrame, and finally visualize this as a new clustergram widget.
In [1]:
import numpy as np
import pandas as pd
from clustergrammer_widget import *
net = Network(clustergrammer_widget)
In [2]:
net.load_file('rc_two_cats.txt')
net.cluster()
net.widget()
Above, we have filtered the matrix to a region of interest using the brush cropping tool. Below we will get export this region of interest, defined on the front end, to a DataFrame, df_genes
. This demonstrates the two-way communication capabilities of widgets.
In [3]:
df_genes = net.widget_df()
df_genes.shape
Out[3]:
In [4]:
net.load_df(df_genes)
net.cluster()
net.widget()
Above, we made a new widget visualizing this region of interest.
In [5]:
# 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)
In [6]:
net.load_df(df)
net.cluster()
net.widget()
Above, we selected a region of interest using the front-end brush crop tool and export to DataFrame, df_random. Below we will visualize it using a new widget.
In [7]:
df_random = net.widget_df()
df_random.shape
Out[7]:
In [8]:
net.load_df(df_random)
net.cluster()
net.widget()
In [ ]: