[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 20:40:14 CEST 2009
Hi,
On Sep 9, 2009, at 2:12 PM, Martin Morgan wrote:
> Hi Steve -- I suspect the developer will get to this shortly, and that
> this has to do with internal issues in R. So your best bet is to
> give it
> a break for a couple of hours.
>
> In the mean time, you can find out what's going on with
>
>> selectMethod("[", "IntervalTree")
Hah ... wow, need to learn S4 ... I (dumbly) thought it was using the
'[' defined for IRanges classes, even though inherits(myIntervalTree,
'IRanges') is FALSE ...
> Method Definition:
>
> function (x, i, j, ..., drop = TRUE)
> {
> cl <- class(x)
> mc <- match.call()
> mc$x <- as(x, "IRanges")
> as(eval(mc), cl)
> }
> <environment: namespace:IRanges>
>
> Signatures:
> x i j
> target "IntervalTree" "ANY" "ANY"
> defined "Ranges" "ANY" "ANY"
>> trace("[", signature="IntervalTree", tracer=browser)
> Tracing specified method for function "[" in package "base"
> [1] "["
>> query <- IRanges(c(1, 4, 9), c(5, 7, 10))
>> subject <- IRanges(c(2, 2, 10), c(2, 3, 12))
>> tree <- IntervalTree(subject)
>> tree[1:2]
> Tracing tree[1:2] on entry
> Called from: eval(expr, envir, enclos)
> Browse[1]> n
>
> my guess is that 'eval' is in the wrong frame, probably because of the
> way the methods package manipulates things. I'm not sure why
> "[",IntervalTree was implemented this way.
Indeed!
Anyway, from your hint I found the appropriate function (notice the
fixme note :-) in Ranges-class.R:
### FIXME: hopefully temporary
setMethod("[", "Ranges",
function(x, i, j, ..., drop)
{
cl <- class(x)
mc <- match.call()
mc$x <- as(x, "IRanges")
as(eval(mc), cl)
}
)
in Ranges-class.R
I tweaked it to capture the parent.frame and now it works:
setMethod("[", "Ranges",
function(x, i, j, ..., drop)
{
cl <- class(x)
mc <- match.call()
pf <- parent.frame()
mc$x <- as(x, "IRanges")
as(eval(mc, pf), cl)
}
)
It seems that the match.call is taking the name of my the variable I'm
passing into the argument as i, instead of using ``i`` itself, for
instance, using your example.
R> idx <- 1:2
R> tree[idx]
Looking at the value of mc, we see:
debug: mc$x <- as(x, "IRanges")
Browse[2]> mc
the.tree[i = idx]
So ... sending the parent.frame allows the eval to see the appropriate
idx var.
I'm not sure if that's the fix you should use, but it seems to be
working atm.
Thanks for the heads up,
-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