[R] Can't use attributes from gml file in Cytoscape

Gábor Csárdi csardi at rmki.kfki.hu
Fri Apr 15 17:00:03 CEST 2011


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)

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.


On Fri, Apr 15, 2011 at 9:25 AM, Sandeep Amberkar <ssamberkar at gmail.com> wrote:
> Hello,
> I am exporting a graph in "gml" format from igraph 0.5.5. When I open the
> file in Cytoscape v.2.7 I can't map the color attribute that I assign to the
> graph when I export it from igraph. Could anyone help me in this?
> Thanks.
> --
> Warm Regards,
> Sandeep Amberkar
> BioQuant,BQ26,
> Im Neuenheimer Feld 267,
> D-69120,Heidelberg
> Tel: +49-6221-5451354
>        [[alternative HTML version deleted]]
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

Gabor Csardi <csardi at rmki.kfki.hu>     MTA KFKI RMKI

More information about the R-help mailing list