当前位置: 首页>>代码示例>>Python>>正文


Python Network.dat['mat_dn']方法代码示例

本文整理汇总了Python中clustergrammer.Network.dat['mat_dn']方法的典型用法代码示例。如果您正苦于以下问题:Python Network.dat['mat_dn']方法的具体用法?Python Network.dat['mat_dn']怎么用?Python Network.dat['mat_dn']使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在clustergrammer.Network的用法示例。


在下文中一共展示了Network.dat['mat_dn']方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from clustergrammer import Network [as 别名]
# 或者: from clustergrammer.Network import dat['mat_dn'] [as 别名]
def main(mongo_address, viz_id, vect_post):
  from bson.objectid import ObjectId
  from pymongo import MongoClient
  from clustergrammer import Network

  # set up database connection 
  client = MongoClient(mongo_address)
  db = client.clustergrammer 
  viz_id = ObjectId(viz_id)
  # get placeholder viz data 
  found_viz = db.networks.find_one({'_id': viz_id })

  # initialize export_dat 
  export_dat = {}
  export_viz = {}

  # try to make clustegram using vect_post 
  try:

    # ini network obj 
    net = Network()
    
    # vector endpoint 
    net.load_vect_post_to_net(vect_post)

    # swap nans for zeros
    net.swap_nan_for_zero()

    # deprecated clustering modules 
    ####################################
    # cluster g2e using pandas
    # net.fast_mult_views()

    # # calculate top views rather than percentage views
    # net.N_top_views()
    ####################################

    net.make_filtered_views(dist_type='cosine', dendro=True, \
      views=['N_row_sum'], linkage_type='average')

    # export dat 
    try:

      # convert data to list 
      net.dat['mat'] = net.dat['mat'].tolist()
      net.dat['mat_up'] = net.dat['mat_up'].tolist()
      net.dat['mat_dn'] = net.dat['mat_dn'].tolist()

      export_dat['dat'] = net.export_net_json('dat')
      export_dat['source'] = 'g2e_enr_vect'
      dat_id = db.network_data.insert( export_dat )
      print('G2E: network data successfully uploaded')
    
    except:
      export_dat['dat'] = 'data-too-large'
      export_dat['source'] = 'g2e_enr_vect'
      dat_id = db.network_data.insert( export_dat )
      print('G2E: network data too large to be uploaded')

    update_viz = net.viz 
    update_dat = dat_id

  # if there is an error update json with error 
  except:

    print('\n--------------------------------')
    print('G2E clustering error')
    print('----------------------------------\n')
    update_viz = 'error'
    update_dat = 'error'


  # export vix to database 

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

   # update the viz data 
  try:
    db.networks.update_one( {"_id":viz_id}, {"$set": found_viz} )
    print('\n\n---------------------------------------------------')
    print( 'G2E Successfully made and uploaded clustergram')
    print('---------------------------------------------------\n\n')
  except:
    print('\n--------------------------------')
    print('G2E error in loading viz into database')
    print('----------------------------------\n')

  # close database connection 
  client.close() 
开发者ID:aeron15,项目名称:clustergrammer,代码行数:92,代码来源:run_g2e_background.py


注:本文中的clustergrammer.Network.dat['mat_dn']方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。