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>
Message-ID:
<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:
https://bugs.launchpad.net/igraph/+bug/663959
Best,
Gabor