Entering edit mode
Bill Gibb
▴
20
@bill-gibb-5755
Last seen 10.2 years ago
Hello,
I noticed that when applying set operations to GRanges objects, the
returned range is reduced (by default), e.g.
r1 <- GRanges(seqnames=c(1,1,1),
ranges=IRanges(start=c(1,3,5), end=c(1,3,5)), strand='*')
length(r1)
r2 <- GRanges(seqnames=c(1,1,1),
ranges=IRanges(start=c(1,3,4), end=c(1,3,4)), strand='*')
length(r2)
r3 <- union(r1,r2)
length(r3)
sum(width(ranges(r3)))
Both r1 and r2 have length 3, whereas r3 has length 2, due to the
implicit reduce applied to the result of union(). I can see that
reducing the ranges would normally be desired when applying set
operations, however there are occasions when one might want to keep a
list of singleton ranges (e.g. when sub-sampling at the genomic
coordinate level). Is there a way to suppress the reduce() operation
when applying set operations to GRanges? Something like union(r1, r2,
reduce.ranges=FALSE) would be nice.
I also tried:
resize(r3,width=1)
however it appears to simply truncate multi-base sequences.
Thank you.
Bill Gibb
Genomic Health, Inc.
Redwood City, CA
______________________________________________________________________
The contents of this electronic message, including any attachments,
are intended only for the use of the individual or entity to which
they are addressed and may contain confidential information. If you
are not the intended recipient, you are hereby notified that any use,
dissemination, distribution, or copying of this message or any
attachment is strictly prohibited. If you have received this
transmission in error, please send an e-mail to postmaster at
genomichealth.com and delete this message, along with any attachments,
from your computer.
Dear Herve,
I have a similar problem, but this time with setdiff: I have two GRanges objects, of which one is the genome in 100k bins (bin.grange):
The other GRange is a GRanges object (called peak.grange) that I would like to remove from bin.grange:
Similar to the above example, a setdiff() between the two GRanges will automatically evoke the reduce method on the result:
I would, however, like to maintain the 100k binned nature of the result. Is there a way to avoid evoking the reduce method?
Thank you very much,
Thomas Kuilman
--------------------------------------------------
Thomas Kuilman, PhD
Department of Molecular Oncology
Netherlands Cancer Institute
1066 CX Amsterdam
The Netherlands
Just after writing this post I found out how to get around this problem and I thought I should share this piece of code (see below). The trick I used is to use split() to split odd and even indices over two separate GRanges objects in a GRangesList. The example code below does setdiff(bin.grange, peak.grange) without reducing the result:
Regards,
Thomas