igraph-help
[Top][All Lists]
Advanced

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

Re: [igraph] Subsetting graph by edges + building large graph troubles (


From: Steve Lianoglou
Subject: Re: [igraph] Subsetting graph by edges + building large graph troubles (R interface)
Date: Wed, 4 Mar 2009 17:24:02 -0500

Hi,

On Mar 4, 2009, at 4:18 PM, Gábor Csárdi wrote:

Hi Steve,

On Wed, Mar 4, 2009 at 9:51 PM, Steve Lianoglou
<address@hidden> wrote:
[...]
# threshold and directed are defined elsewhere
graf <- read.graph(filepath, format='ncol', directed=directed)
good.edges <- E(graf)[weight >= threshold]
good.graf <- graph(edges, directed=directed)

This is not good. 'good.edges' is just a list of edge IDs here, it is
actually a numeric vector, it is just printed otherwise. What you need
is

bad.edges <- E(graf[ weight < threshold]
good.graf <- delete.edges(graf, bad.edges)

Thanks for that.

# modifed head(E(g), 10) call (modifications in trailing []):
R> head(E(g), 10)              ## Top 10 lines from file
[1]  Q0045   -> Q0060  [433]   ## Q0032 YNL182C 433
[2]  Q0045   -> Q0085  [186]   ## Q0045 Q0060 186
[3]  Q0045   -> Q0105  [716]   ## Q0045 Q0085 716
[4]  Q0045   -> Q0110  [997]   ## Q0045 Q0105 997
[5]  Q0045   -> Q0115  [882]   ## Q0045 Q0110 882
[6]  Q0045   -> Q0120  [898]   ## Q0045 Q0115 898
[7]  Q0045   -> Q0130  [928]   ## Q0045 Q0120 928
[8]  Q0045   -> Q0140  [201]   ## Q0045 Q0130 201
[9]  Q0045   -> Q0250  [222]   ## Q0045 Q0140 222
[10] Q0045   -> Q0275  [999]   ## Q0045 Q0250 999

Actually, your graph is correct here. The problem is that E(g) has a
strange way of indexing and 'head' does not now about this. So 'head'
just omits the first (0th, really) edge. Print your first ten edges
with 'E(g)[0:9]' and you will see that it is all right.

Wow. I guess I should have asked sooner because there goes the past 6 hours of my day ...

I'm looking through the source code for the igraph package, and I have to say that your R-fu is strong ... some of the stuff going on in there seems like black magic to me atm, so it'll be good exercise to make sense of it.

It seems a bit strange to me that indexing an edgelist starts with 0 ... I guess it has to do with having to interface with C, which has 0-based indices? I'm sure as I get familiar w/ the API, it'll make more sense.

Anyway, I'm not sure if this issue has come up before, but in order to possibly avoid others from pulling their hair out for hours, perhaps it wouldn't hurt to add appropriate head/tail methods for the igraph.es and igraph.vs methods to deal with this, like:

head.igraph.es <- function (x, n = 6, ...)
{
    stopifnot(length(n) == 1)
    n <- if (n < 0)
        max(length(x) + n, 0)
    else min(n, length(x))
    x[seq_len(n)-1]
}


I tried my code on a smaller test file, and it works fine.

My guess is that you didn't use 'head' on the small file.

Yup, you're right.

Btw. there is a function called 'graph.data.frame' which does exactly
what you want, just call it after reading in the table from the file,
and naming your columns c("from", "to", "weight").

Thanks for that, too.

-steve

--
Steve Lianoglou
Graduate Student: Physiology, Biophysics and Systems Biology
Weill Medical College of Cornell University

http://cbio.mskcc.org/~lianos







reply via email to

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