On Mon, Jul 12, 2010 at 11:05 AM, Steve Lianoglou <
mailinglist.honeypot@gmail.com> wrote:

> Hi all,
>
> I wanted to slice and dice some IRanges object [a] with another [b]:
>
> R> a <- new("IRanges"
>    , start = c(6407436L, 6407603L, 6410874L, 6422902L, 6423274L, 6423582L,
> 6427129L, 6428312L, 6431289L, 6434251L, 6434481L, 6439832L, 6440009L,
> 6442647L, 6442794L)
>    , width = c(167L, 294L, 193L, 186L, 182L, 131L, 201L, 271L, 450L, 145L,
> 263L, 79L, 11L, 147L, 798L)
>    , NAMES = NULL
>    , elementMetadata = new("DataFrame"
>    , rownames = NULL
>    , nrows = 15L
>    , elementMetadata = NULL
>    , elementType = "ANY"
>    , metadata = list()
>    , listData = structure(list(exon.anno = c("utr5", "cds", "cds",
> "cds", "cds",
> "cds", "cds", "cds", "cds", "cds", "cds", "cds", "cds", "cds",
> "utr3")), .Names = "exon.anno")
> )
>    , elementType = "integer"
>    , metadata = structure(list(tx.start = 6407435L, tx.end =
> 6443591L, cds.start = 6407603L,
>    cds.end = 6442793L), .Names = c("tx.start", "tx.end", "cds.start",
> "cds.end"))
> )
>
> R> b <- new("IRanges"
>    , start = c(6407548L, 6410954L, 6410986L, 6423030L, 6423326L, 6427196L,
> 6427324L, 6428348L, 6428354L, 6428528L, 6431431L, 6431561L, 6434266L,
> 6439860L, 6443045L, 6443067L, 6443338L)
>    , width = c(4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
> 4L, 4L)
>    , NAMES = NULL
>    , elementMetadata = NULL
>    , elementType = "integer"
>    , metadata = list()
> )
>
> R> setdiff(a, b)
> Error in .Method(..., deparse.level = deparse.level) :
>  no method for coercing this S4 class to a vector
> Error in reduce(c(x0, y), drop.empty.ranges = TRUE) :
>  error in evaluating the argument 'x' in selecting a method for
> function 'reduce'
> Error in gaps(union(gaps(x, start = start, end = end), y), start = start,
>  :
>  error in evaluating the argument 'x' in selecting a method for function
> 'gaps'
>
> R> intersect(a,b)
> Error in .Method(..., deparse.level = deparse.level) :
>  no method for coercing this S4 class to a vector
> Error in reduce(c(x0, y), drop.empty.ranges = TRUE) :
>  error in evaluating the argument 'x' in selecting a method for
> function 'reduce'
> Error in gaps(union(gaps(x, start = start, end = end), y), start = start,
>  :
>  error in evaluating the argument 'x' in selecting a method for function
> 'gaps'
>
> This had me puzzled for a while until I realized I had a DataFrame
> loaded into the elementMetadata of `a` and wondered what the
> appropriate behavior for the elementMetadata should be if `a` is split
> into more or less pieces (via setdiff or intersect) -- which I didn't
> have an answer to.
>
> Nuking the elementMetadata first works just fine:
>
> R> aa <- a
> R> elementMetadata(aa) <- NULL
> R> setdiff(aa, b)
> ## works
>
> I don't know what the answer *really* should be as to what the correct
> behavior in this situation would be, which I guess could be an
> interesting discussion ... perhaps the elementMetadata can be
> split/merged with its associated range, or just dropped all together
> (perhaps via some explicit parameter in the setdiff, etc. function
> call?).
>
> Anyway, in an effort to skirt that rabbit hole for now, could I ask
> for a feature request and have IRanges provide a more informative
> error message when an end user is gunning at their feet w/ this
> scenario? :-)
>
>
I think it would be reasonable to simply drop the metadata, since one is
creating an entirely new set of ranges. Might want a warning/message, but
I'm not sure if even that is necessary. Just need to document the behavior.

Michael

Thanks,
> -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<http://cbio.mskcc.org/%7Elianos/contact>
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor@stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives:
> http://news.gmane.org/gmane.science.biology.informatics.conductor
>

	[[alternative HTML version deleted]]

