[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[igraph] Re: Igraph and SONIA

From: Lorenzo Isella
Subject: [igraph] Re: Igraph and SONIA
Date: Thu, 21 Oct 2010 20:40:43 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv: Gecko/20100623 Spicebird/0.8

Hi Gabor,
I myself know very little about SONIA, but according to some collaborators of mine (to whom I'll drop a line soon) the SONIA format is a de facto standard for evolving networks. While this may be a bit an exaggeration, I am more than interested in finding out more about this format.
I'll check your scripts in the next few days (a bit hectic these days).
Many thanks!


Date: Wed, 20 Oct 2010 17:40:03 +0200
From: G?bor Cs?rdi <address@hidden>
Subject: Re: [igraph] Igraph and SONIA
To: Help for igraph users <address@hidden>
Content-Type: text/plain; charset=ISO-8859-1

Lorenzo, Simone,

here is a function that seems to work on two of the three examples at
the sonia website:

sonia2igraph <- function(filename, directed=TRUE) {
  lines <- readLines(filename)
  lines <- grep("^//", lines, value=TRUE, invert=TRUE)
  fromid <- grep("^FromId", lines)[1]
  nodes <- lines[1:(fromid-1)]
  edges <- lines[fromid:length(lines)]

  nodes <- strsplit(split="\t", nodes)
  nodesnames <- nodes[[1]]
  nodes <- data.frame(do.call(rbind, nodes[-1]))
  colnames(nodes) <- nodesnames
  colnames(nodes)[1] <- "name"

  edges <- strsplit(split="\t", edges)
  edgesnames <- edges[[1]]
  edges <- data.frame(do.call(rbind, edges[-1]))
  colnames(edges) <- edgesnames

  graph.data.frame(edges, directed=directed, vertices=nodes)

All attributes are added as strings, modify the function if you want
to convert them to numeric and/or use the igraph attribute names:
'color', etc. Clusters are not supported.

The third example file does not work, because it contains multiple
lines for the same vertex, and I don't know what this means. They do
not say anything about this on the website, unfortunately.

I have added a bug report for putting (and extended version of) this
into igraph:


reply via email to

[Prev in Thread] Current Thread [Next in Thread]