write.graph {igraph}R Documentation

Writing the graph to a file in some format

Description

write.graph is a general function for exporting graphs to foreign file formats, however not many formats are implemented right now.

Usage

write.graph(graph, file, format=c("edgelist", "pajek", "ncol",
       "lgl", "graphml", "dimacs", "gml", "dot"), ...)

Arguments

graph

The graph to export.

file

A connection or a string giving the file name to write the graph to.

format

Character string giving the file format. Right now pajek, graphml, dot, gml, edgelist, lgl, ncol and dimacs are implemented. As of igraph 0.4 this argument is case insensitive.

...

Other, format specific arguments, see below.

Details

The edgelist format is a simple text file, with one edge in a line, the two vertex ids separated by a space character. The file is sorted by the first and the second column. This format has no additional arguments.

The Pajek format is a text file, see read.graph for details. Appropriate vertex and edge attributes are also written to the file. This format has no additional arguments.

The GraphML format is a flexible XML based format. See read.graph for GraphML details. Vertex and edge attributes are also written to the file. This format has no additional arguments.

The dot format is used by the popular GraphViz program. Vertex and edge attributes are written to the file. There are no additional arguments for this format.

The lgl format is also a simple text file, this is the format expected by the 'Large Graph Layout' layout generator software. See read.graph for details. Additional arguments:

The ncol format is also used by LGL, it is a text file, see read.graph for details. Additional arguments:

The dimacs file format, more specifically the version for network flow problems, see the files at ftp://dimacs.rutgers.edu/pub/netflow/general-info/

This is a line-oriented text file (ASCII) format. The first character of each line defines the type of the line. If the first character is c the line is a comment line and it is ignored. There is one problem line (p in the file, it must appear before any node and arc descriptor lines. The problem line has three fields separated by spaces: the problem type (min, max or asn), the number of vertices and number of edges in the graph. Exactly two node identification lines are expected (n), one for the source, one for the target vertex. These have two fields: the id of the vertex and the type of the vertex, either s (=source) or t (=target). Arc lines start with a and have three fields: the source vertex, the target vertex and the edge capacity.

Vertex ids are numbered from 1.

Additional arguments:

GML is a quite general textual format, see http://www.infosun.fim.uni-passau.de/Graphlet/GML/ for details.

The graph, vertex and edges attributes are written to the file as well, if they are numeric of string.

As igraph is more forgiving about attribute names, it might be neccessary to simplify the them before writing to the GML file. This way we'll have a syntactically correct GML file. The following simple procedure is performed on each attribute name: first the alphanumeric characters are extracted, the others are ignored. Then if the first character is not a letter then the attribute name is prefixed with <quote>igraph</quote>. Note that this might result identical names for two attributes, igraph does not check this.

The “id” vertex attribute is treated specially. If the id argument is not NULL then it should be a numeric vector with the vertex ids and the “id” vertex attribute is ignored (if there is one). If id is 0 and there is a numeric id vertex attribute that is used instead. If ids are not specified in either way then the regular igraph vertex ids are used.

Note that whichever way vertex ids are specified, their uniqueness is not checked.

If the graph has edge attributes named “source” or “target” they're silently ignored. GML uses these attributes to specify the edges, so we cannot write them to the file. Rename them before calling this function if you want to preserve them.

Additional arguments:

Value

A NULL, invisibly.

Author(s)

Gabor Csardi csardi@rmki.kfki.hu

References

Adai AT, Date SV, Wieland S, Marcotte EM. LGL: creating a map of protein function with an algorithm for visualizing very large biological networks. J Mol Biol. 2004 Jun 25;340(1):179-90.

See Also

read.graph

Examples

g <- graph.ring(10)
## Not run: write.graph(g, "/tmp/g.txt", "edgelist")

[Package igraph version 0.5.5-4 Index]