我有一个点文件,其中包含具有不同聚类的图形,例如:
subgraph cluster_bb_5020 {
style=filled fillcolor=white
label="label [5020]"
NODE230 [label="668"]
....
我想知道如何通过networkx或pydot或pygraphviz获取图中的节点簇数(例如,此处的NODE230簇为cluster_bb_5020)吗?还是一般来说,我如何获得群集信息?
谢谢!
答案 0 :(得分:0)
我找到了答案:
import pydot
graph = pydot.graph_from_dot_file('graph.dot')
nodes_bb = {}
for cluster in graph[0].get_subgraphs():
if cluster.obj_dict['name'].startswith('cluster_bb_'):
basic_block_id = cluster.obj_dict['name'].split('_')[-1]
for node in cluster.obj_dict['nodes'].keys():
nodes_bb[node] = str(basic_block_id)
print nodes_bb
但是,pydot真的很慢!