def build_layout(): df = load_data.load_gsva_compare_cluster('hallmark') # TODO THIS NEEDS TO BE CLEANED UP!!!!!! cat_to_true = defaultdict(lambda: []) for clust in df.index: if 'PJ030' in clust: cat_to_true['LGG'].append(clust) elif 'PJ' in clust: cat_to_true['GBM'].append(clust) elif 'LX' in clust: cat_to_true['LUAD'].append(clust) elif 'GSE146026' in clust: cat_to_true['OV'].append(clust) elif 'GSE72056' in clust: cat_to_true['SKCM'].append(clust) elif 'GSE103322' in clust: cat_to_true['HNSC'].append(clust) elif 'GSE111672' in clust: cat_to_true['PAAD'].append(clust) cats = [{ 'title': 'Cancer Type', 'cats': {k: v for k, v in cat_to_true.items()} }] net = Network() net.load_df(df) net.add_cats('row', cats) net.make_clust() layout = dcc.Tab(label='Cluster Comparison', children=[ dbc.Container( fluid=True, children=[ html.Link(rel='stylesheet', href='./static/custom.css'), dash_clustergrammer.DashClustergrammer( id='cgram-component', label='', network_data=net.viz) ]) ]) return layout
def prepare_heatmap(matrix_input, html_file, html_dir, tools_dir, categories, distance, linkage): # prepare directory and html os.mkdir(html_dir) env = Environment(loader=FileSystemLoader(tools_dir + "/templates")) template = env.get_template("clustergrammer.template") overview = template.render() with open(html_file, "w") as outf: outf.write(overview) json_output = html_dir + "/mult_view.json" net = Network() net.load_file(matrix_input) if (categories['row']): net.add_cats('row', categories['row']) if (categories['col']): net.add_cats('col', categories['col']) net.cluster(dist_type=distance, linkage_type=linkage) net.write_json_to_file('viz', json_output)
def get_clustergrammer_json(self, outfile): # Create network net = Network() # Load file net.load_df(self.expression_dataframe) # Add categories try: net.add_cats('col', self.sample_cats) except: pass try: # calculate clustering using default parameters net.cluster() # save visualization JSON to file for use by front end net.write_json_to_file('viz', outfile) except: os.system('touch {outfile}'.format(**locals()))