Hi ALL,

I want to reduce a GRanges data by fixed window size and keep scores after reduce. My code is

.dat <- GRanges("chr1", Iranges(start=1:50, width=2), strand="+", score=Sample(1:50, 50))
windowSize <- 10
Grwin <- GRanges("chr1", IRanges(start=(0:5)*windowSize+scale[1]-1,
                                          width=windowSize), strand="+")
ol <- findOverlaps(.dat, GRwin)
ol <- as.data.frame(ol)
ol <- ol[!duplicated(ol[,1]),]
.dat <- split(.dat, ol[,2])
reduceValue <- function(.datReduce){
                .datReduceM <- reduce(.datReduce, with.mapping=TRUE)
                wid <- width(.datReduce)
                .datReduceScore <- .datReduce$value
                .datReduceM$score <- sapply(.datReduceM$mapping, function(.idx){
                    round(sum(.datReduceScore[.idx]*wid[.idx])/sum(wid[.idx]))
                })
                .datReduceM$mapping <- NULL
                .datReduceM
            }
.dat <- lapply(.dat, reduceValue)
.dat <- unlist(GRangesList(.dat))

But the efficiency is very low. What is the best way to keep scores when reduce GRanges data by fixed window size? Thanks for your help.

Yours sincerely,

Jianhong Ou

LRB 670A
Program in Gene Function and Expression
364 Plantation Street Worcester,
MA 01605

	[[alternative HTML version deleted]]

