module documentation

Undocumented

Function _construct_graph_from_adjacency_file Constructs a graph based on an adjacency matrix from the given file.
Function _construct_graph_from_dimacs_file Reads a graph from a file conforming to the DIMACS minimum-cost flow file format.
Function _construct_graph_from_file Unified reading function for graphs.
Function _construct_graph_from_graphmlz_file Reads a graph from a zipped GraphML file.
Function _construct_graph_from_pickle_file Reads a graph from Python pickled format
Function _construct_graph_from_picklez_file Reads a graph from compressed Python pickled format, uncompressing it on-the-fly.
Function _identify_format _identify_format(filename)
Function _write_graph_to_adjacency_file Writes the adjacency matrix of the graph to the given file
Function _write_graph_to_dimacs_file Writes the graph in DIMACS format to the given file.
Function _write_graph_to_file Unified writing function for graphs.
Function _write_graph_to_graphmlz_file Writes the graph to a zipped GraphML file.
Function _write_graph_to_pickle_file Saves the graph in Python pickled format
Function _write_graph_to_picklez_file Saves the graph in Python pickled format, compressed with gzip.
def _construct_graph_from_adjacency_file(cls, f, sep=None, comment_char='#', attribute=None, *args, **kwds): (source)

Constructs a graph based on an adjacency matrix from the given file.

Additional positional and keyword arguments not mentioned here are passed intact to Graph.Adjacency.

Parameters
clsUndocumented
fthe name of the file to be read or a file object
septhe string that separates the matrix elements in a row. None means an arbitrary sequence of whitespace characters.
comment_charlines starting with this string are treated as comments.
attributean edge attribute name where the edge weights are stored in the case of a weighted adjacency matrix. If None, no weights are stored, values larger than 1 are considered as edge multiplicities.
*argsUndocumented
**kwdsUndocumented
Returns
the created graph
def _construct_graph_from_dimacs_file(cls, f, directed=False): (source)

Reads a graph from a file conforming to the DIMACS minimum-cost flow file format.

For the exact definition of the format, see http://lpsolve.sourceforge.net/5.5/DIMACS.htm.

Restrictions compared to the official description of the format are as follows:

  • igraph's DIMACS reader requires only three fields in an arc definition, describing the edge's source and target node and its capacity.
  • Source vertices are identified by 's' in the FLOW field, target vertices are identified by 't'.
  • Node indices start from 1. Only a single source and target node is allowed.
Parameters
clsUndocumented
fthe name of the file or a Python file handle
directedwhether the generated graph should be directed.
Returns
the generated graph. The indices of the source and target vertices are attached as graph attributes source and target, the edge capacities are stored in the capacity edge attribute.
def _construct_graph_from_file(cls, f, format=None, *args, **kwds): (source)

Unified reading function for graphs.

This method tries to identify the format of the graph given in the first parameter and calls the corresponding reader method.

The remaining arguments are passed to the reader method without any changes.

Parameters
clsUndocumented
fthe file containing the graph to be loaded
formatthe format of the file (if known in advance). None means auto-detection. Possible values are: "ncol" (NCOL format), "lgl" (LGL format), "graphdb" (GraphDB format), "graphml", "graphmlz" (GraphML and gzipped GraphML format), "gml" (GML format), "net", "pajek" (Pajek format), "dimacs" (DIMACS format), "edgelist", "edges" or "edge" (edge list), "adjacency" (adjacency matrix), "dl" (DL format used by UCINET), "pickle" (Python pickled format), "picklez" (gzipped Python pickled format)
*argsUndocumented
**kwdsUndocumented
Raises
IOErrorif the file format can't be identified and none was given.
def _construct_graph_from_graphmlz_file(cls, f, index=0): (source)

Reads a graph from a zipped GraphML file.

Parameters
clsUndocumented
fthe name of the file
indexif the GraphML file contains multiple graphs, specified the one that should be loaded. Graph indices start from zero, so if you want to load the first graph, specify 0 here.
Returns
the loaded graph object
def _construct_graph_from_pickle_file(cls, fname=None): (source)

Reads a graph from Python pickled format

Parameters
clsUndocumented
fnamethe name of the file, a stream to read from, or a string containing the pickled data.
Returns
the created graph object.
def _construct_graph_from_picklez_file(cls, fname): (source)

Reads a graph from compressed Python pickled format, uncompressing it on-the-fly.

Parameters
clsUndocumented
fnamethe name of the file or a stream to read from.
Returns
the created graph object.
def _identify_format(filename): (source)

_identify_format(filename)

Tries to identify the format of the graph stored in the file with the given filename. It identifies most file formats based on the extension of the file (and not on syntactic evaluation). The only exception is the adjacency matrix format and the edge list format: the first few lines of the file are evaluated to decide between the two.

Parameters
filenamethe name of the file or a file object whose name attribute is set.
Returns
the format of the file as a string.
Note
Internal function, should not be called directly.
def _write_graph_to_adjacency_file(graph, f, sep=' ', eol='\n', *args, **kwds): (source)

Writes the adjacency matrix of the graph to the given file

All the remaining arguments not mentioned here are passed intact to Graph.get_adjacency.

Parameters
graphUndocumented
fthe name of the file to be written.
septhe string that separates the matrix elements in a row
eolthe string that separates the rows of the matrix. Please note that igraph is able to read back the written adjacency matrix if and only if this is a single newline character
*argsUndocumented
**kwdsUndocumented
def _write_graph_to_dimacs_file(graph, f, source=None, target=None, capacity='capacity'): (source)

Writes the graph in DIMACS format to the given file.

Parameters
graphUndocumented
fthe name of the file to be written or a Python file handle.
sourcethe source vertex ID. If None, igraph will try to infer it from the source graph attribute.
targetthe target vertex ID. If None, igraph will try to infer it from the target graph attribute.
capacitythe capacities of the edges in a list or the name of an edge attribute that holds the capacities. If there is no such edge attribute, every edge will have a capacity of 1.
def _write_graph_to_file(graph, f, format=None, *args, **kwds): (source)

Unified writing function for graphs.

This method tries to identify the format of the graph given in the first parameter (based on extension) and calls the corresponding writer method.

The remaining arguments are passed to the writer method without any changes.

Parameters
graphUndocumented
fthe file containing the graph to be saved
format

the format of the file (if one wants to override the format determined from the filename extension, or the filename itself is a stream). None means auto-detection. Possible values are:

  • "adjacency": adjacency matrix format
  • "dimacs": DIMACS format
  • "dot", "graphviz": GraphViz DOT format
  • "edgelist", "edges" or "edge": numeric edge list format
  • "gml": GML format
  • "graphml" and "graphmlz": standard and gzipped GraphML format
  • "gw", "leda", "lgr": LEDA native format
  • "lgl": LGL format
  • "ncol": NCOL format
  • "net", "pajek": Pajek format
  • "pickle", "picklez": standard and gzipped Python pickled format
  • "svg": SVG format
*argsUndocumented
**kwdsUndocumented
Raises
IOErrorif the file format can't be identified and none was given.
def _write_graph_to_graphmlz_file(graph, f, compresslevel=9): (source)

Writes the graph to a zipped GraphML file.

The library uses the gzip compression algorithm, so the resulting file can be unzipped with regular gzip uncompression (like gunzip or zcat from Unix command line) or the Python gzip module.

Uses a temporary file to store intermediate GraphML data, so make sure you have enough free space to store the unzipped GraphML file as well.

Parameters
graphUndocumented
fthe name of the file to be written.
compresslevelthe level of compression. 1 is fastest and produces the least compression, and 9 is slowest and produces the most compression.
def _write_graph_to_pickle_file(graph, fname=None, version=-1): (source)

Saves the graph in Python pickled format

Parameters
graphUndocumented
fnamethe name of the file or a stream to save to. If None, saves the graph to a string and returns the string.
versionpickle protocol version to be used. If -1, uses the highest protocol available
Returns
None if the graph was saved successfully to the given file, or a string if fname was None.
def _write_graph_to_picklez_file(graph, fname=None, version=-1): (source)

Saves the graph in Python pickled format, compressed with gzip.

Saving in this format is a bit slower than saving in a Python pickle without compression, but the final file takes up much less space on the hard drive.

Parameters
graphUndocumented
fnamethe name of the file or a stream to save to.
versionpickle protocol version to be used. If -1, uses the highest protocol available
Returns
None if the graph was saved successfully to the given file.