How to use clustergrammer2 - 10 common examples

To help you get started, we’ve selected a few clustergrammer2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ismms-himc / clustergrammer2 / clustergrammer2 / clustergrammer_fun / load_data.py View on Github external
def load_tsv_to_net(net, file_buffer, filename=None):
  lines = file_buffer.getvalue().split('\n')
  num_labels = categories.check_categories(lines)

  row_arr = list(range(num_labels['row']))
  col_arr = list(range(num_labels['col']))

  # use header if there are col categories
  if len(col_arr) > 1:
    df = pd.read_table(file_buffer, index_col=row_arr,
                                  header=col_arr)
  else:
    df = pd.read_table(file_buffer, index_col=row_arr)

  df = proc_df_labels.main(df)

  net.df_to_dat(df, True)
  net.dat['filename'] = filename
github ismms-himc / clustergrammer2 / clustergrammer2 / clustergrammer_fun / load_data.py View on Github external
def load_tsv_to_net(net, file_buffer, filename=None):
  lines = file_buffer.getvalue().split('\n')
  num_labels = categories.check_categories(lines)

  row_arr = list(range(num_labels['row']))
  col_arr = list(range(num_labels['col']))

  # use header if there are col categories
  if len(col_arr) > 1:
    df = pd.read_table(file_buffer, index_col=row_arr,
                                  header=col_arr)
  else:
    df = pd.read_table(file_buffer, index_col=row_arr)

  df = proc_df_labels.main(df)

  net.df_to_dat(df, True)
  net.dat['filename'] = filename
github ismms-himc / clustergrammer2 / clustergrammer2 / clustergrammer_fun / __init__.py View on Github external
def export_df(self):
    '''
    Export Pandas DataFrame/
    '''
    df = data_formats.dat_to_df(self)

    # drop tuple categories if downsampling
    if self.is_downsampled:
      df.columns = self.dat['nodes']['col']
      df.index = self.dat['nodes']['row']

    return df
github ismms-himc / clustergrammer2 / clustergrammer2 / clustergrammer_fun / __init__.py View on Github external
def dat_to_df(self):
    '''
    Export Pandas DataFrams (will be deprecated).
    '''
    return data_formats.dat_to_df(self)
github ismms-himc / clustergrammer2 / clustergrammer2 / clustergrammer_fun / __init__.py View on Github external
else:
        self.col_cats = col_cats

      self.meta_cat = True

    if isinstance(meta_row, pd.DataFrame):
      self.meta_row = meta_row

      if row_cats is None:
        self.row_cats = meta_row.columns.tolist()
      else:
        self.row_cats = row_cats

      self.meta_cat = True

    data_formats.df_to_dat(self, df, define_cat_colors=True)
github ismms-himc / clustergrammer2 / clustergrammer2 / clustergrammer_fun / __init__.py View on Github external
def df_to_dat(self, df, define_cat_colors=False):
    '''
    Load Pandas DataFrame (will be deprecated).
    '''
    data_formats.df_to_dat(self, df, define_cat_colors)
github ismms-himc / clustergrammer2 / clustergrammer2 / clustergrammer_fun / load_vect_post.py View on Github external
def main(real_net, vect_post):
  import numpy as np
  from copy import deepcopy
  from .__init__ import Network
  from . import proc_df_labels

  net = deepcopy(Network())

  sigs = vect_post['columns']

  all_rows = []
  all_sigs = []
  for inst_sig in sigs:
    all_sigs.append(inst_sig['col_name'])

    col_data = inst_sig['data']

    for inst_row_data in col_data:
      all_rows.append(inst_row_data['row_name'])

  all_rows = sorted(list(set(all_rows)))
  all_sigs = sorted(list(set(all_sigs)))
github ismms-himc / clustergrammer2 / clustergrammer2 / clustergrammer_fun / make_views.py View on Github external
all_filt = list(range(10))
  all_filt = [i / float(10) for i in all_filt]

  mat = deepcopy(df['mat'])
  sum_row = np.sum(mat, axis=1)
  max_sum = max(sum_row)

  for inst_filt in all_filt:

    cutoff = inst_filt * max_sum
    copy_net = deepcopy(net)
    inst_df = deepcopy(df)
    inst_df = run_filter.df_filter_row_sum(inst_df, cutoff, take_abs=False)

    tmp_net = deepcopy(Network())
    tmp_net.df_to_dat(inst_df)

    try:
      try:
        calc_clust.cluster_row_and_col(tmp_net, dist_type=dist_type,
                                       run_clustering=True)

      except:
        calc_clust.cluster_row_and_col(tmp_net, dist_type=dist_type,
                                       run_clustering=False)

      inst_view = {}
      inst_view['pct_row_' + rank_type] = inst_filt
      inst_view['dist'] = 'cos'
      inst_view['nodes'] = {}
      inst_view['nodes']['row_nodes'] = tmp_net.viz['row_nodes']
github ismms-himc / clustergrammer2 / clustergrammer2 / clustergrammer_fun / make_sim_mat.py View on Github external
from .__init__ import Network
  from copy import deepcopy
  from . import calc_clust

  sim_dict = {}

  for inst_rc in which_sim:

    sim_dict[inst_rc] = dm_to_sim(inst_dm[inst_rc], make_squareform=True,
                             filter_sim=filter_sim)

  sim_net = {}

  for inst_rc in which_sim:

    sim_net[inst_rc] = deepcopy(Network())

    sim_net[inst_rc].dat['mat'] = sim_dict[inst_rc]

    sim_net[inst_rc].dat['nodes']['row'] = net.dat['nodes'][inst_rc]
    sim_net[inst_rc].dat['nodes']['col'] = net.dat['nodes'][inst_rc]

    sim_net[inst_rc].dat['node_info']['row'] = net.dat['node_info'][inst_rc]
    sim_net[inst_rc].dat['node_info']['col'] = net.dat['node_info'][inst_rc]

    calc_clust.cluster_row_and_col(sim_net[inst_rc])

    all_views = []
    df = sim_net[inst_rc].dat_to_df()
    send_df = deepcopy(df)

    sim_net[inst_rc].viz['views'] = all_views
github ismms-himc / clustergrammer2 / clustergrammer2 / clustergrammer_fun / make_views.py View on Github external
rows_sorted = run_filter.get_sorted_rows(df['mat'], rank_type)

  for inst_keep in keep_top:

    tmp_df = deepcopy(df)

    check_keep_num = inst_keep

    # convert 'all' to -1 to clean up checking mechanism
    if check_keep_num == 'all':
      check_keep_num = -1

    if check_keep_num < len(rows_sorted):

      tmp_net = deepcopy(Network())

      if inst_keep != 'all':

        keep_rows = rows_sorted[0:inst_keep]

        tmp_df['mat'] = tmp_df['mat'].loc[keep_rows]

        if 'mat_orig' in tmp_df:
          tmp_df['mat_orig'] = tmp_df['mat_orig'].loc[keep_rows]

        tmp_df = run_filter.df_filter_col_sum(tmp_df, 0.001)
        tmp_net.df_to_dat(tmp_df)

      else:
        tmp_net.df_to_dat(tmp_df)