cliques_analysis.py 818 Bytes
Newer Older
Yoann Dufresne's avatar
Yoann Dufresne committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3

import networkx as nx
import argparse

def parse_arguments():
    parser = argparse.ArgumentParser(description='Analysis graph cliques complexity')
    parser.add_argument('graph', help='The input graph to analyse')

    args = parser.parse_args()
    return args

def analyse_neighbors_cliques(graph):
    clique_sizes = []
    for node in graph.nodes():
        neighbors = list(graph.neighbors(node))
        subgraph = graph.subgraph(neighbors)
        cliques = list(nx.find_cliques(subgraph))
        print(node, " \t", len(neighbors), "  \t", len(cliques))
        clique_sizes.append(len(cliques))

    print(max(clique_sizes))


def main():
    args = parse_arguments()
    graph = nx.read_gexf(args.graph)

    analyse_neighbors_cliques(graph)


if __name__ == "__main__":
    main()