當前位置: 首頁>>代碼示例>>Python>>正文


Python clustergrammer.Network類代碼示例

本文整理匯總了Python中clustergrammer.Network的典型用法代碼示例。如果您正苦於以下問題:Python Network類的具體用法?Python Network怎麽用?Python Network使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Network類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: add_mutations

def add_mutations(cl_info):
  print('add mutations\n')

  from clustergrammer import Network
  net = Network()
  old_cl_info = net.load_json_to_dict('cell_line_muts.json')

  cl_muts = old_cl_info['muts']

  for inst_cl in cl_info:

    # remove plex name if necessary
    if '_plex_' in inst_cl:
      simple_cl = inst_cl.split('_')[0]
    else:
      simple_cl = inst_cl

    for inst_mut in cl_muts:
      mutated_cls = cl_muts[inst_mut]

      if simple_cl in mutated_cls:
        has_mut = 'true'
      else:
        has_mut = 'false'

      mutation_title = 'mut-'+inst_mut

      # use the original long cell line name (with possible plex)
      cl_info[inst_cl][mutation_title] = has_mut

  return cl_info
開發者ID:MaayanLab,項目名稱:cst_drug_treatment,代碼行數:31,代碼來源:make_cell_line_info_dict.py

示例2: df_filter_row

  def df_filter_row(df, threshold, take_abs=True):
    ''' filter rows in matrix at some threshold
    and remove columns that have a sum below this threshold '''

    from copy import deepcopy
    from clustergrammer import Network
    net = Network()

    if take_abs is True:
      df_copy = deepcopy(df['mat'].abs())
    else:
      df_copy = deepcopy(df['mat'])

    ini_rows = df_copy.index.values.tolist()
    df_copy = df_copy.transpose()
    tmp_sum = df_copy.sum(axis=0)
    tmp_sum = tmp_sum.abs()
    tmp_sum.sort_values(inplace=True, ascending=False)

    tmp_sum = tmp_sum[tmp_sum > threshold]
    keep_rows = sorted(tmp_sum.index.values.tolist())

    if len(keep_rows) < len(ini_rows):
      df['mat'] = net.grab_df_subset(df['mat'], keep_rows=keep_rows)

      if 'mat_up' in df:
        df['mat_up'] = net.grab_df_subset(df['mat_up'], keep_rows=keep_rows)
        df['mat_dn'] = net.grab_df_subset(df['mat_dn'], keep_rows=keep_rows)

    return df
開發者ID:abdohlman,項目名稱:clustergrammer,代碼行數:30,代碼來源:deleting_clustergrammer.py

示例3: df_filter_col

  def df_filter_col(df, threshold, take_abs=True):
    ''' filter columns in matrix at some threshold
    and remove rows that have all zero values '''

    from copy import deepcopy
    from clustergrammer import Network
    net = Network()

    if take_abs is True:
      df_copy = deepcopy(df['mat'].abs())
    else:
      df_copy = deepcopy(df['mat'])

    df_copy = df_copy.transpose()
    df_copy = df_copy[df_copy.sum(axis=1) > threshold]
    df_copy = df_copy.transpose()
    df_copy = df_copy[df_copy.sum(axis=1) > 0]

    if take_abs is True:
      inst_rows = df_copy.index.tolist()
      inst_cols = df_copy.columns.tolist()
      df['mat'] = net.grab_df_subset(df['mat'], inst_rows, inst_cols)

    else:
      df['mat'] = df_copy

    return df
開發者ID:abdohlman,項目名稱:clustergrammer,代碼行數:27,代碼來源:deleting_clustergrammer.py

示例4: calc_treatment_ratios

def calc_treatment_ratios():

  from clustergrammer import Network

  net = Network()

  net.load_tsv_to_net('treated_cell_12_1_2015/treated_cl_phospho.tsv')
開發者ID:MaayanLab,項目名稱:cst_drug_treatment,代碼行數:7,代碼來源:load_latest_cst.py

示例5: make_enr_vect_clust

def make_enr_vect_clust():
  import enrichr_functions as enr_fun 
  from clustergrammer import Network

  net = Network()

  g2e_post = net.load_json_to_dict('json/g2e_enr_vect.json')

  net = enr_fun.make_enr_vect_clust(g2e_post, 0.001, 1)

  net.write_json_to_file('viz','json/enr_vect_example.json')
開發者ID:ErwanDavid,項目名稱:clustergrammer.js,代碼行數:11,代碼來源:make_enr_vect_clust.py

示例6: main

def main():
  from clustergrammer import Network

  net = Network()

  net.load_file('txt/rc_two_cats.txt')

  tmp_size = 50

  inst_dm = make_distance_matrix(net, tmp_size)

  randomly_sample_rows(net, inst_dm, tmp_size)
開發者ID:ErwanDavid,項目名稱:clustergrammer.js,代碼行數:12,代碼來源:cat_arrangement_pval.py

示例7: main

def main():
  from clustergrammer import Network

  net = Network()

  gene_list = ['EGFR', 'TP53', 'SMARCA4', 'CLASP1']
  list_id = net.enrichr('post', gene_list)

  print(list_id)

  enr, response_list = net.enrichr('get', lib='ChEA_2015', list_id=list_id,
    max_terms=10)

  print(response_list)
開發者ID:ErwanDavid,項目名稱:clustergrammer.js,代碼行數:14,代碼來源:clustergrammer_enrichr.py

示例8: make_viz_json

def make_viz_json(inst_df, name):
  from clustergrammer import Network
  net = Network()

  filename = 'json/'+name
  load_df = {}
  load_df['mat'] = inst_df
  net.df_to_dat(load_df)
  net.swap_nan_for_zero()
  net.make_clust(views=[])
  net.write_json_to_file('viz', filename, 'no-indent')
開發者ID:MaayanLab,項目名稱:IDG_poster_2016,代碼行數:11,代碼來源:make_hgram_poster_image.py

示例9: cluster

def cluster():
  from clustergrammer import Network

  net = Network()

  vect_post = net.load_json_to_dict('fake_vect_post.json')  

  net.load_vect_post_to_net(vect_post)

  net.swap_nan_for_zero()
  
  # net.N_top_views()
  net.make_clust(dist_type='cos',views=['N_row_sum','N_row_var'], dendro=True)

  net.write_json_to_file('viz','json/large_vect_post_example.json','indent')  
開發者ID:ErwanDavid,項目名稱:clustergrammer.js,代碼行數:15,代碼來源:fake_vect_post.py

示例10: make_plex_matrix

def make_plex_matrix():
  '''
  Make a cell line matrix with plex rows and cell line columns.
  This will be used as a negative control that should show worsening correlation
  as data is normalized/filtered.
  '''
  import numpy as np
  import pandas as pd
  from clustergrammer import Network

  # load cl_info
  net = Network()
  cl_info = net.load_json_to_dict('../cell_line_info/cell_line_info_dict.json')

  # load cell line expression
  net.load_file('../CCLE_gene_expression/CCLE_NSCLC_all_genes.txt')
  tmp_df = net.dat_to_df()
  df = tmp_df['mat']

  cols = df.columns.tolist()

  rows = range(9)
  rows = [i+1 for i in rows]
  print(rows)

  mat = np.zeros((len(rows), len(cols)))

  for inst_col in cols:

    for inst_cl in cl_info:

      if inst_col in inst_cl:
        inst_plex = int(cl_info[inst_cl]['Plex'])

        if inst_plex != -1:
          # print(inst_col + ' in ' + inst_cl + ': ' + str(inst_plex))

          row_index = rows.index(inst_plex)
          col_index = cols.index(inst_col)

          mat[row_index, col_index] = 1


  df_plex = pd.DataFrame(data=mat, columns=cols, index=rows)

  filename = '../lung_cellline_3_1_16/lung_cl_all_ptm/precalc_processed/' + \
            'exp-plex.txt'
  df_plex.to_csv(filename, sep='\t')
開發者ID:MaayanLab,項目名稱:cst_drug_treatment,代碼行數:48,代碼來源:precalc_PTM_norm.py

示例11: main

def main():
  import numpy as np
  import pandas as pd
  from clustergrammer import Network

  rtk_list = load_rtks()

  net = Network()
  net.load_file('txt/tmp_cst_drug_treat_cl.txt')
  df_dict = net.dat_to_df()

  inst_df = df_dict['mat']

  inst_df = inst_df.ix[rtk_list]

  inst_df.to_csv('txt/RTK_exp_in_drug_treat_cl.txt', sep='\t')
開發者ID:MaayanLab,項目名稱:cst_drug_treatment,代碼行數:16,代碼來源:get_RTK_CCLE.py

示例12: post_to_clustergrammer

def post_to_clustergrammer():

  from clustergrammer import Network
  import requests 
  import json

  upload_url = 'http://localhost:9000/clustergrammer/vector_upload/'
  # upload_url = 'http://amp.pharm.mssm.edu/clustergrammer/vector_upload/'

  net = Network()
  vect_post = net.load_json_to_dict('test_vector_upload.json')
  # vect_post = net.load_json_to_dict('fake_vect_post.json')

  r = requests.post(upload_url, data=json.dumps(vect_post) )

  link = r.text

  print(link)
開發者ID:jjdblast,項目名稱:clustergrammer.js,代碼行數:18,代碼來源:test_vect_post.py

示例13: main

def main( buff, inst_filename, mongo_address, viz_id):
  import numpy as np
  import flask
  from bson.objectid import ObjectId
  from pymongo import MongoClient
  from flask import request
  from clustergrammer import Network
  import StringIO

  client = MongoClient(mongo_address)
  db = client.clustergrammer

  viz_id = ObjectId(viz_id)
  found_viz = db.networks.find_one({'_id':viz_id})

  try:

    net = Network()
    net.load_tsv_to_net(buff)

    net.swap_nan_for_zero()

    views = ['N_row_sum', 'N_row_var']

    net.make_clust(dist_type='cosine', dendro=True, views=views, \
                   linkage_type='average')

    export_dat = {}
    export_dat['name'] = inst_filename
    export_dat['dat'] = net.export_net_json('dat')
    export_dat['source'] = 'user_upload'

    dat_id = db.network_data.insert(export_dat)

    update_viz = net.viz 
    update_dat = dat_id

  except:
    print('\n-----------------------')
    print('error in clustering')
    print('-----------------------\n')
    update_viz = 'error'
    update_dat = 'error'

  found_viz['viz'] = update_viz
  found_viz['dat'] = update_dat

  db.networks.update_one( {'_id':viz_id}, {'$set': found_viz} )

  client.close()


  
開發者ID:abdohlman,項目名稱:clustergrammer,代碼行數:50,代碼來源:load_tsv_file.py

示例14: mock_g2e_json

def mock_g2e_json(gl):
  import enrichr_functions as enr_fun
  from clustergrammer import Network

  ''' 
  A json of signatures from g2e, for enrichment vectoring, should look like this

  {
    "signature_ids":[
      {"col_title":"title 1", "enr_id_up":###, "enr_id_dn":###},
      {"col_title":"title 2", "enr_id_up":###, "enr_id_dn":###}
    ],
    "background_type":"ChEA_2015"
  }
  '''

  net = Network()

  g2e_post = {}
  sig_ids = []

  # I have to get user_list_ids from Enrichr 
  tmp = 1
  for inst_gl in gl:

    inst_sig = {}
    inst_sig['col_title'] = 'Sig-'+str(tmp)
    tmp = tmp+1

    # submit to enrichr and get user_list_ids
    for inst_updn in inst_gl:
      inst_list = inst_gl[inst_updn]
      inst_id = enr_fun.enrichr_post_request(inst_list)
      inst_sig['enr_id_'+inst_updn] = inst_id

    sig_ids.append(inst_sig)

  g2e_post['signature_ids'] = sig_ids

  g2e_post['background_type'] = 'ChEA_2015'

  net.save_dict_to_json(g2e_post,'json/g2e_enr_vect.json','indent')
開發者ID:ErwanDavid,項目名稱:clustergrammer.js,代碼行數:42,代碼來源:make_enr_vect_clust.py

示例15: main

def main():
  '''
  This will add cell line category information (including plexes and
  gene-expression groups to the gene expression data from CCLE)
  '''
  from clustergrammer import Network
  net = Network()

  # load original CCLE gene expression data for CST lung cancer cell lines
  filename = 'CCLE_gene_expression/CCLE_NSCLC_all_genes.txt'
  f = open(filename, 'r')
  lines = f.readlines()
  f.close()

  # load cell line info
  cl_info = net.load_json_to_dict('cell_line_info/cell_line_muts.json')

  # write to new file
  new_file = 'CCLE_gene_expression/CCLE_NSCLC_cats_all_genes.txt'
  fw = open(new_file, 'w')

  fw.close()
開發者ID:MaayanLab,項目名稱:cst_drug_treatment,代碼行數:22,代碼來源:add_cl_categories_to_CCLE_gene_expression.py


注:本文中的clustergrammer.Network類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。