def mcl_cluster(vs, es):
    g = nx.Graph()
    for i in range(len(vs)):
        g.add_node(i)
    for n0, n1 in es:
        g.add_edge(n0, n1)

    M, clusters = networkx_mcl(g)
    locations = []
    for _, cluster in clusters.items():
        locations.append(set(cluster))
    return locations
Example #2
0
def mcl_cluster(G):
    t0 = time.time()
    M, cluster = networkx_mcl(G,
                              expand_factor=2,
                              inflate_factor=2,
                              max_loop=10,
                              mult_factor=1)
    t1 = time.time() - t
    print t1
    print type(M), type(cluster)
    f1 = open('mcl_m.txt', 'w')
    f1.write(M)
    f1.close()
    f2 = open('mcl_cluster.txt', 'w')
    f2.write(json.dumps(cluster))
    f2.close()
Example #3
0
File: main.py Project: 1j4k7/mcl
begin = time.time()
# graph = readDataToGraph("interactions.tsv")
originalGraph = sampleData("interactions.tsv", 1000)
graph = originalGraph
print "ORIGINAL GRAPH:"
# print "finished extracting interactions"
displayGraphStats(graph)
# print "displayed graph stats"
end = time.time()
print "Graph Creation Time:", end - begin

print ""

begin = time.time()
# nodes in cluster are identified by the same number as they were given
M, clusters = networkx_mcl(graph, inflate_factor=1.8, max_loop=60)
# print "finished clustering algorithm"
clusters = convertClustersOfNodeIDsToClustersOfGeneIdentifiers(graph, clusters)
clusters = removeDuplicateClusters(clusters)
displayClusterStats(clusters)
# print "displayed cluster stats"
end = time.time()
print "Clustering Time:", end - begin

print ""

begin = time.time()
pathways = readPathwayData("pathways.tsv")
# print "finished extracting pathways"
displayPathwayStats(pathways)
# print "displayed pathway stats"
Example #4
0
File: t.py Project: 1j4k7/mcl
G.add_edge(1,2)
G.add_edge(1,3)
G.add_edge(1,4)
G.add_edge(3,4)
G.add_edge(2,3)
G.add_edge(2,0)
G.add_edge(2,5)
G.add_edge(0,8)
G.add_edge(0,6)
G.add_edge(5,8)
G.add_edge(4,5)
G.add_edge(5,6)
G.add_edge(8,6)
G.add_edge(5,9)
G.add_edge(6,7)
G.add_edge(5,7)
G.add_edge(6,9)
G.add_edge(7,9)

M, clusters = networkx_mcl(G, inflate_factor = 1.8,
                   max_loop = 100)

print clusters
print nx.get_node_attributes(G, "num")

#nx.draw_networkx(G)
#plt.show()

#    M = output matrix
#    clusters = dict with keys = [<cluster id>] values = [<vertex id>]
Example #5
0
    M.append(l)




G = nx.from_numpy_matrix(np.matrix(M))
M = np.array(M)


from mcl_clustering import get_graph, networkx_mcl, draw
#M, G = get_graph("example.csv")

print(" number of nodes: %s\n" % M.shape[0])

M, clusters = networkx_mcl(G)
draw(G, M, clusters)













Example #6
0
                if not marked[e[0]]:
                    location.add(e[0])
                    marked[e[0]] = True
        locations.append(location)

    return locations



if __name__ == '__main__':
    user = '******'
    records = load_loc_records(user)
    print('Loaded %d records' % len(records))

    raw_g = create_raw_graph(user, records, False)
    loc_g = create_loc_graph(user, records, False)

    raw_M, raw_clusters = networkx_mcl(
            raw_g,
        )
    print("Raw clusters", len(raw_clusters))
    print("Clusters:")
    t = 0 
    for k, v in raw_clusters.items():
        t += len(v)
        print(k, len(v))
    print(t)



def get_mcl_communities(G):
    M, clusters = networkx_mcl(G, max_loop=100)
    node_map = convert_to_node_comm_map(clusters)
    return node_map