1.0 Running Clustergrammer2

This notebook demonstrates how Clustergrammer2 can be used to visualize two simple datasets.

In [1]:
import numpy as np
import pandas as pd
from clustergrammer2 import net, Network, CGM2
import warnings
warnings.filterwarnings('ignore')
>> clustergrammer2 backend version 0.16.0

Load Dataset

Try replacing this dataset with your own, by uploading data through Jupyter Lab.

In [2]:
df = {}
df['clean'] = pd.read_csv('../data/rc_two_cat_clean.csv', index_col=0)
df['meta_col'] = pd.read_csv('../data/meta_col.csv', index_col=0)
df['meta_cat'] = pd.read_csv('../data/meta_cat_col.csv', index_col=0)

View Toy Dataset

In [3]:
net.load_df(df['clean'], meta_col=df['meta_col'])
net.set_manual_category(col='Category', preferred_cats=df['meta_cat'])
net.widget()

Generate Random Matrix

In [4]:
# generate random matrix
num_cols = 1000
num_rows = 50

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['rand'] = pd.DataFrame(data=mat, columns=cols, index=rows)
df['rand'].shape
Out[4]:
(50, 1000)
In [5]:
n2 = Network(CGM2)
n2.load_df(df['rand'])
n2.cluster()
n2.widget()
In [ ]:
 
In [ ]:
 
In [ ]: