igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Node attributes


From: Tamas Nepusz
Subject: Re: [igraph] Node attributes
Date: Fri, 9 Oct 2009 11:40:49 +0100

1). Whenever a graph in "ncol" format is read by igraph the vertex names are converted into numbers. So my question is how is the node numbering sequence determined i.e which node is numbered as 1 and so on ?
I think igraph processes the file top-down, and whenever it finds a node that was not seen before, igraph assigns the next available ID to the node. So, in your case, eco:b4069 will be node 0, eco:b1241 will be node 1, eco:b0115 will be node 2 and so on. But you shouldn't rely on that as the behaviour might change in future releases. Check the "name" vertex attribute of the loaded graph instead, it will contain the original node IDs. If you are using R, you will have to load your graph as follows:

> g <- read.graph("my_graph.ncol")
> V(g)$name

2). I want to get the node property (degree, betweenness etc.) against the node name as a list after various graph calculatons are done. How do I do it ?
E.g., for degree and betweenness:

> df <- data.frame(degree=degree(g), betweenness=betweenness(g), row.names=V(g)$name)

Then you get a data frame with columns "degree" and "betweenness", and the row names contain the names of the corresponding vertices.

In Python, you can achieve something similar by:

>>> df = zip(g.vs["name"], g.degree(), g.betweenness())

This will be a list of triplets.

--
Tamas





reply via email to

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