def out_net_commudet(dbname, colname, name): # transform the largest component to undirect for community detection # G = nt.load_beh_network(dbname, colname) G = nt.load_beh_network(dbname, colname) nx.write_edgelist(G, "data/net.data") # G = nx.read_edgelist("data/net.data") GC = nt.get_gaint_comp(G) # nt.net_statis(GC) # GCG = GC.to_undirected() # nt.net_statis(GCG) nx.write_edgelist(GC, "data/comp.data") print GC.number_of_selfloops() out_net(GC, name)
def plot_communty(dbname, colname, name, commline): G = nt.load_network(dbname, colname) GC = nt.get_gaint_comp(G) id_map = pickle.load(open("data/" + name + "-id.pick", "r")) nodelist = list() fr = open("data/" + name + "-fc_best.groups", "r") line = "" while commline not in line: line = fr.readline() print line print "----------------------------" for line in fr.readlines(): if "GROUP" in line: break else: nodelist.append(id_map[int(line.strip())]) print "node size:", str(len(nodelist)) # plot.network_top(GC.subgraph(nodelist)) pickle.dump(nodelist, open("data/" + name + "uid.pick", "w")) return GC.subgraph(nodelist)