本文整理汇总了Python中clustergrammer.Network.pandas_load_tsv_to_net方法的典型用法代码示例。如果您正苦于以下问题:Python Network.pandas_load_tsv_to_net方法的具体用法?Python Network.pandas_load_tsv_to_net怎么用?Python Network.pandas_load_tsv_to_net使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类clustergrammer.Network
的用法示例。
在下文中一共展示了Network.pandas_load_tsv_to_net方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from clustergrammer import Network [as 别名]
# 或者: from clustergrammer.Network import pandas_load_tsv_to_net [as 别名]
def main():
import time
start_time = time.time()
import pandas as pd
import StringIO
# import network class from Network.py
from clustergrammer import Network
net = Network()
# load data to dataframe
# net.load_tsv_to_net('txt/example_tsv_network.txt')
# net.load_tsv_to_net('txt/mat_1mb.txt')
# choose file
################
# file_buffer = open('txt/col_categories.txt')
file_buffer = open('txt/example_tsv_network.txt' )
buff = StringIO.StringIO( file_buffer.read() )
net.pandas_load_tsv_to_net(buff)
# filter rows
views = ['filter_row_sum','N_row_sum']
# distance metric
dist_type = 'cosine'
# linkage type
linkage_type = 'average'
net.make_clust(dist_type=dist_type, views=views, calc_col_cats=True,\
linkage_type=linkage_type)
net.write_json_to_file('viz', 'json/mult_view.json', 'no-indent')
elapsed_time = time.time() - start_time
print('\n\n\nelapsed time: '+str(elapsed_time))
示例2: main
# 需要导入模块: from clustergrammer import Network [as 别名]
# 或者: from clustergrammer.Network import pandas_load_tsv_to_net [as 别名]
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
##############################
# set up database connection
##############################
# set up connection
client = MongoClient(mongo_address)
db = client.clustergrammer
# get placeholder viz data
viz_id = ObjectId(viz_id)
found_viz = db.networks.find_one({'_id':viz_id})
try:
########################
# load and cluster
########################
# initiate class network
net = Network()
# net.load_lines_from_tsv_to_net(file_lines)
net.pandas_load_tsv_to_net(buff)
# swap nans for zero
net.swap_nan_for_zero()
# deprecated clustering module
####################################
# # fast mult views takes care of pre-filtering
# net.fast_mult_views()
####################################
net.make_filtered_views(dist_type='cosine', dendro=True, \
views=['filter_row_sum'], linkage_type='average')
###############################
# save to database
###############################
export_dat = {}
export_dat['name'] = inst_filename
export_dat['dat'] = net.export_net_json('dat')
export_dat['source'] = 'user_upload'
# save dat to separate document
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'
# update found_viz
found_viz['viz'] = update_viz
found_viz['dat'] = update_dat
# update found_viz in database
db.networks.update_one( {'_id':viz_id}, {'$set': found_viz} )
############################
# end database connection
############################
client.close()