本文整理汇总了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
示例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
示例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
示例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')
示例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')
示例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)
示例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)
示例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')
示例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')
示例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')
示例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')
示例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)
示例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()
示例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')
示例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()