Question: aggregate bins in large SummarizedExperiment efficiently
0
alessandro.pastore20 wrote:

I have a SummarizedExperiment (but we can consider it a GRanges). What I want is to reduce the number of intervals, keeping only one row for every identical adjacent mcol(gr), important is to also keep track of the new extend interval.

if a state pair is present also in non adjacent intervals (this second e.g. 1,1 pair has to be report independely from the first)

Thanks a lot!

gr <- GRanges(
seqnames = Rle(c("chr1"), c(12)),
ranges = IRanges(1:12*10, end = 1:12*10+5),
state1 = c(1,1,1,1,2,3,4,5,5,5,1,1),
state2 = c(1,1,1,2,2,2,5,5,6,6,1,1))

must became:

gr2 <- GRanges(
seqnames = Rle(c("chr1"), c(8)),
ranges = IRanges(start = c(10,40,50,60,70,80,90,110), end = c(35,45,55,65,75,85,105,125)),
state1 = c(1,1,2,3,4,5,5,1),
state2 = c(1,2,2,2,5,5,6,1))​

Answer: aggregate bins in large SummarizedExperiment efficiently
3
Michael Lawrence11k wrote:

It can be done like this:

r <- disjoin(c(ranges(Rle(gr$state1)), ranges(Rle(gr$state2))))
grl <- relist(gr, PartitioningByEnd(r))
grr <- unlist(range(grl), use.names=FALSE)
mcols(grr) <- mcols(unlist(phead(grl, 1L), use.names=FALSE))

That is admittedly pretty ugly. Sorry about that.

ADD COMMENTlink modified 3.1 years ago • written 3.1 years ago by Michael Lawrence11k

Thanks this is nice, but it only list the first and last occurrence of a state pair, not if a state pair occur more than one time.

the pair 1,1 occurs at the begin and at the end of the GRanges but in you case is listed as occurring in a interval that span the whole GRanges. I need both interval one for each occurrence of adjacent values

Sorry, I edited my answer to do what you wanted.