0

我浏览了手册,但无法完全弄清楚。

我有一个 3 列的大文件,节点 1 以一定的强度命中节点 2。NetworkX 从中生成了许多集群,并且效果很好。但是,我无法将这些文件加载​​到例如 cytoscape 中,因此我需要将每个集群写入一个单独的文件。

我试过了:

for n in G: nx.write_weighted_edgelist(G[n], 'test'+str(count))

或者查看 G.number_of_nodes / edges, G.graph.keys(), dir(G) 但这并没有得到我想要的结果。

有没有办法将每个集群与强度分开存储?

使用 Clusters = nx.connected_components(G) 我可以获得集群,但我会丢失所有连接信息。

    for n,nbrs in G.adjacency_iter():
            for nbr,eattr in nbrs.items():
                    data=eattr['weight']
                    if data < 2:  
                            print('(%s, %s, %s)' % (n,nbr,data))

在空行上使用它时,我认为这些是单独的集群。

##########解决方案
    Clusters = nx.connected_components(G)
    for Cluster in Clusters:
            count = count + 1
            cfile = open("tmp/Cluster_"+str(count)+".clus","w")
            for C in Cluster:
                    hit = G[C]
                    for h in hit:
                            cfile.write('\t'.join([str(C),str(h),str(hit[h].values()[0]),"\n"]))
4

1 回答 1

2

尝试使用 graphs = nx.connected_component_subgraphs()。这将返回一个图表列表,您可以以任何适用于 cytoscape 的格式单独编写这些图表。

于 2012-10-25T16:39:06.720 回答