Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
When this option is present with no parameters, defaults to 'label'. When the option is not
present, defaults to the index.""")
parser.add_argument('-n', '--num_clusters', type=int, help="""Specify the number of clusters to use.""")
parser.add_argument('-w', '--height', default=2, type=int, help="""The lengh of the longest shortest paths that CONGO considers.""")
parser.add_argument('file', nargs='?', help="""The path to the file in igraph readable format.""")
args = parser.parse_args()
if args.demo:
run_demo()
return
if not args.file:
print("CONGO.py: error: no file specified.\n")
print(parser.parse_args('-h'.split()))
return
# only works for undirected
G = ig.read(args.file).as_undirected()
result = congo(G, args.height)
if args.num_clusters:
result.pretty_print_cover(args.num_clusters, label=args.label)
else:
result.pretty_print_cover(result.optimal_count, label=args.label)
parser.add_argument("-g", "--gen_graph", action="store_true", help="Generate a new ER graph")
parser.add_argument("-n", "--num_nodes", action="store", type=int, help="The number of nodes in the ER graph")
parser.add_argument("-p", "--probability", action="store", type=float, help="The probability of connectivity of each node to another in the graph")
parser.add_argument("-s", "--save", action="store_true", help="Save conversion to disk")
parser.add_argument("-f", "--save_fn", action="store", default="csc_matlab", help="Save file name")
parser.add_argument("-t", "--test", action="store_true", help="Run test only!")
result = parser.parse_args()
if result.test:
test()
exit(1)
if os.path.exists(result.graph_fn):
g = igraph.read(result.graph_fn, format="gml")
elif result.gen_graph or result.num_nodes or result.probability:
assert (result.gen_graph and result.num_nodes and result.probability), "You must set all ER parameters i.e. n, p"
g = igraph.Graph.Erdos_Renyi(n=result.num_nodes, p=result.probability)
igraph.write(g, result.save_fn+".gml", format="gml")
else:
sys.stderr.writelines("Invalid path %s ... and all (i.e. n, p, g) ER parameters not set so no action taken. \n EXITING NOW! \n")
exit(-1)
igraph_to_csc(g, result.save, result.save_fn)
parser.add_argument('-l', '--label', default='CONGA_index', nargs='?', const='label', help="""Choose which attribute of the graph to print.
When this option is present with no parameters, defaults to 'label'. When the option is not
present, defaults to the index.""")
parser.add_argument('file', nargs='?', help="""The path to the file in igraph readable format.""")
args = parser.parse_args()
if args.demo:
run_demo()
return
if not args.file:
print("conga.py: error: no file specified.\n")
print(parser.parse_args('-h'.split()))
return
# only works for undirected
G = ig.read(args.file).as_undirected()
result = conga(G, calculate_modularities=args.modularity_measure, optimal_count=args.num_clusters)
result.pretty_print_cover(result.optimal_count, label=args.label)
def main():
G = ig.read("enron.gml")
run_all_hypotheses(G, 1000, None)
run_all_hypotheses(G, 1000, prune_enron_only(G))
run_all_hypotheses(G, 1000, prune_with_nonenron_collaborators_only(G))
def main():
G = ig.read("enron.gml")
#plot_degree_distrib(G)
plot_pruned_graph(G, 250)
def loadGraph(self, path):
G = igraph.read(path, format="gml")
return G
do_del = False
if os.path.splitext(fn)[1] == ".zip":
fn = unzip_file(fn)
do_del = True
elif os.path.splitext(fn)[1] == ".gz":
fn = untar_file(fn)
do_del = True
start = time()
try:
if (headers_only):
g = read_graphml_headers(fn)
print " Fast read took %.3f sec .." % ((time()-start))
else: assert 0
except:
g = igraph_read(fn, format=informat)
print " Read took %.3f sec ..." % ((time()-start))
finally:
if do_del:
print "Deleting temp %s" % fn
os.remove(fn)
return g
def convert_graph(gfn, informat, save_dir, *outformats):
"""
Convert between igraph supported formats. No conversion to MAT or NPY available.
Positional arguments:
====================
gfn - the graph file name
informat - the input format of the graph
save_dir - the directory where we save result to
outformat - a list of output formats
"""
try:
if informat in ["graphml", "ncol", "edgelist", "lgl", "pajek", "graphdb"]:
g = igraph.read(gfn, None)
elif informat == "mat":
g = csc_to_igraph(loadAnyMat(gfn))
elif informat == "npy":
g = csc_to_igraph(np.load(gfn).item())
elif informat == "attredge":
g = attredge_to_igraph(gfn)
else:
err_msg = "[ERROR]: Unknown format '%s'. Please check format and retry!" % informat
print err_msg
return (None, err_msg)
except Exception, err_msg:
print err_msg
return (None, "[ERROR]: "+str(err_msg))
out_err_msg = ""
fn = ""
def q7():
G = read_gdf("../../data/network_analysis/MiddleEastern.gdf")
nx.write_gml(G, "/tmp/MiddleEastern.gml")
G = ig.read("/tmp/MiddleEastern.gml")
bcs = G.betweenness()
labels = [v["label"] for v in G.vs()]
label_bcs = sorted(zip(labels, bcs), key=operator.itemgetter(1), reverse=True)
ingredient_set = set(["coriander", "garlic", "walnut", "dill"])
print [x for x in label_bcs if x[0] in ingredient_set]
def q4():
G = ig.read("../../data/network_analysis/dolphins.gml")
nodes = [int(v["id"]) for v in G.vs]
bcs = G.betweenness()
it = sorted(zip(nodes, bcs), key=operator.itemgetter(1), reverse=True)[0][0]
print "Dolphin with highest betweenness =", G.vs[it]["label"]