How to use the igraph.Graph.Read_GML function in igraph

To help you get started, we’ve selected a few igraph examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DaylightingSociety / SocMap / tools / sortNodeDegrees.py View on Github external
"""
	This script reads a social map, and prints out users in order of degree.
	Outputs in format:
username,degree
"""

import sys
import igraph as ig

if __name__ == "__main__":
	if( len(sys.argv) != 2 ):
		print("USAGE: %s " % sys.argv[0])
		sys.exit(1)
	mapFilename = sys.argv[1]

	orig = ig.Graph.Read_GML(mapFilename)

	users = []

	for i,e in enumerate(orig.vs):
		users.append((e["name"], orig.degree(i, mode="in")))

	try:
		for username, degree in (sorted(users, key=lambda n: n[1], reverse=True)):
			print("%s,%d" % (username, degree))
	except (BrokenPipeError, IOError):
		pass # Behave yourself when piped to 'head'
github DaylightingSociety / SocMap / tools / getDensity.py View on Github external
import sys, os
import igraph as ig

"""
	This tools returns a density measurement for each map provided as an argument
	and prints the densities in order
"""

if __name__ == "__main__":
	if( len(sys.argv) < 2 ):
		print("USAGE: %s  [map2.gml...]" % sys.argv[0])
		sys.exit(1)

	for fname in sys.argv[1:]:
		net = ig.Graph.Read_GML(fname)
		print("%s,%f" % (fname,net.density()))
github Lab41 / Circulo / circulo / algorithms / radicchi.py View on Github external
def main():
    parser = argparse.ArgumentParser(description="""Run the Radicchi algorithm from the command line.""")
    parser.add_argument('-s', '--strength', choices=['strong', 'weak'], 
                        help="""Use strong or weak definition of community structure in the graph.""")
    parser.add_argument('file', nargs='?', help="""The path to the file in the GML file format.""")
    args = parser.parse_args()

    if not args.file:
        print("radicchi.py: error: no file specified.")
        print(parser.parse_args(['-h']))
        return

    g = ig.Graph.Read_GML(args.file).as_undirected()
    communities = radicchi(g, measure=args.strength)

    print(communities)
github DaylightingSociety / SocMap / analyze.py View on Github external
if( has_igraph ):
			net = ig.Graph(directed=True)
			net.add_vertices(len(baseUsers))
			for i in range(0, len(baseUsers)):
				username = baseUsers[i]
				net.vs[i]["name"] = username
				net.vs[i]["layer"] = 0
				net.vs[i]["retweeted"] = "false"
				net.vs[i]["mentioned"] = "false"
		else:
			net = nx.DiGraph()
			for username in baseUsers:
				net.add_node(username, name=username, layer=0, retweeted="false", mentioned="false")
	else:
		if( has_igraph ):
			net = ig.Graph.Read_GML(oldMapFilename)
		else:
			net = nx.read_gml(oldMapFilename)

	# Now let's add the new users
	# This is messy in networkx, because we have to add all of the users *and*
	# their attributes up front -- there's no clean way to update them later
	mentionedUsernames = set()
	retweetedUsernames = set()
	if( has_igraph ):
		nodeNames = set(net.vs.select()["name"])
	else:
		nodeNames = set(net.nodes())
	# Get a set of all the usernames we'll be working with
	for srcUser in retweeted.keys():
		rts = retweeted[srcUser]
		for dstUser in rts:
github CalabreseLab / seekr / seekr / graph.py View on Github external
def get_partition(self, gml_path=None):
        """Run community detection on igraph Graph from .gml file.

        Parameters
        ----------
        gml_path: str (default=None)
            Alternative location for loading in .gml file. Defaults to self.gml_path.
        """
        paths = (gml_path, self.gml_path, self.tempfile_path)
        gml_path = next(path for path in paths if path is not None)
        graph = igraph.Graph.Read_GML(str(gml_path))
        extra_args = {}
        if self.seed is not None:
            if self.detector is louvain:
                self.detector.set_rng_seed(self.seed)
            else:
                extra_args['seed'] = self.seed
        self.partition = self.detector.find_partition(graph,
                                                      self.detector.RBConfigurationVertexPartition,
                                                      weights='weight',
                                                      resolution_parameter=self.gamma,
                                                      **extra_args)
github DaylightingSociety / SocMap / tools / getDegreePercentile.py View on Github external
def igraphVersion(inFilename):
	g = ig.Graph.Read_GML(inFilename)
	numNodes = len(g.vs)
	degree = Counter(g.vs.degree())
	inDegree = Counter(g.vs.indegree())
	outDegree = Counter(g.vs.outdegree())
	return (numNodes, degree, inDegree, outDegree)