Skip to content
Prev 256984 / 398506 Next

Can't use attributes from gml file in Cytoscape

Hi,

the problem is that igraph puts node colors into the GML file as
simple vertex attributes, but this is not what Cytoscape expects.
Plus, it seems that Cytoscape does not read all the node/edge
attributes from the GML file, only the ones it interprets, so the
color information is lost.

Sadly, there is no real workaround here, because Cytoscape uses
composite node attributes for storing the node color information, but
igraph cannot currently write composite node attributes to GML files.

Luckily, however, the GML file format is quite simple, so you can just
write your own GML export function:

exportGML <- function(graph, filename) {
  file <- file(filename, "w")
  cat("Creator \"igraph exportGML\"\n", file=file)
  cat("Version 1.0\n", file=file)
  cat("graph\n[\n", file=file)
  cat("  directed", as.integer(is.directed(graph)), "\n", file=file)
  for (i in seq_len(vcount(graph))) {
    cat("  node\n  [\n", file=file)
    cat("    id", i-1, "\n", file=file)
    cat("    graphics\n    [\n", file=file)
    cat("      fill \"", V(graph)$color[i], "\"\n", sep="", file=file)
    cat("      type \"rectangle\"\n", file=file)
    cat("      outline \"#000000\"\n", file=file)
    cat("    ]\n", file=file)
    cat("  ]\n", file=file)
  }
  el <- get.edgelist(graph, names=FALSE)
  for (i in seq_len(nrow(el))) {
    cat("  edge\n  [\n", file=file)
    cat("    source", el[i,1], "\n", file=file)
    cat("    target", el[i,2], "\n", file=file)
    cat("  ]\n", file=file)
  }
  cat("]\n", file=file)
  close(file)
}

You can modify it according to your needs, e.g. add layout
coordinates, etc. Look into a GML file, as exported from Cytoscape, to
see what else you can add to the file.

Best,
Gabor
On Fri, Apr 15, 2011 at 9:25 AM, Sandeep Amberkar <ssamberkar at gmail.com> wrote: