Take the 2-minute tour ×

I went through the manual but couldnt completely figure it out.

I have a massive file of 3 columns, node1 hits node 2 with a certain strength. From this many clusters are generated by NetworkX and this works perfectly. However I cannot load these files into for example cytoscape so I need to write every cluster to a separate file.

I tried:

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

Or looked into G.number_of_nodes / edges, G.graph.keys(), dir(G) but this doesnt result in what I want.

Is there a way to store every cluster separately with the strength?

With Clusters = nx.connected_components(G) I can obtain the clusters yet I loose all the connection information.

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

When using that upon an empty line I think that those are separate clusters.

    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:
share|improve this question

1 Answer 1

Try using graphs = nx.connected_component_subgraphs(). That will return a list of graphs which you could write individually in whatever format works for cytoscape.

share|improve this answer
Last night I managed to fixed according to the new edit above. I will look in your example as well thanks! –  Jasper Oct 26 '12 at 5:59

Your Answer


