[BioC] IRanges : Strange behavior subsetting an IntervalTree with an indexing variable from within a function

Steve Lianoglou mailinglist.honeypot at gmail.com
Wed Sep 9 18:57:42 CEST 2009


Hi all,

Sorry, I'm totally perplexed on what seems like something quite  
simple. I've tried to smoke this out in the debugger, but I still  
can't find an answer ... please bear with me as I explain what's going  
on.

I'm using IRanges and trying to subset an IntervalTree using a vector  
of indices found from an ``overlap`` query. R doesn't like this and  
behaves as if the variable I'm using to subset my IntervalTree  
essentially doesn't exist, but it does.

Here's the salient piece of code from WITHIN a function. I'll show you  
some results in a debugging session to illustrate what I mean.

   * ir is an IntervalTree
   * ranges.list is a SimpleRangesList
   * rl is therefore an IRanges object:

dist <- lapply(range.list, function(rl) {
   hits <- subjectHits(overlap(ir, rl))
   browser() # The debug calls below start from here
   if (length(hits) > 1) {
     diff(start(ir[hits]))
   } else {
     NA
   }
})

The problem is that R somehow thinks the ``hits`` vector is non- 
existent when I'm trying to use it to index the IntervalTree (ir),  
however the ``hits`` vector is, in fact, defined.

Browse[1]> hits
[1] 158 159 160 161

OK, so hits exists, but:

Browse[1]> ir[hits]
Error in eval(expr, envir, enclos) : object 'hits' not found

And if I just create a vector 158:161 "inline", indexing works fine:

Browse[1]> ir[158:161]
IntervalTree instance:
     start   end width
[1] 34576 34581     6
[2] 34608 34613     6
[3] 34635 34640     6
[4] 34888 34893     6

Using ANY variable to index doesn't work at all:

Browse[1]> b <- 158:161
Browse[1]> b
[1] 158 159 160 161
Browse[1]> ir[b]
Error in eval(expr, envir, enclos) : object 'b' not found

If I quite out of the browser() and, essentially, bail from the  
running function, these things now work against the same interval tree  
(it was passed in as one of the params to the function):

Browse[1]> Q
R> m <- 158:161
R> ir[m]
IntervalTree instance:
     start   end width
[1] 34576 34581     6
[2] 34608 34613     6
[3] 34635 34640     6
[4] 34888 34893     6

I'm at a loss, I tried looking for the definition of '[' in the  
IRanges::IntervalTree implementation (not defined), but IRanges::'['  
is ... dunno, it looks fine to me.

Does anyone have an idea of what I'm doing wrong?

-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
   |  Memorial Sloan-Kettering Cancer Center
   |  Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact



More information about the Bioconductor mailing list