Dear Experts,
I have a "GRangesList" object and I am trying to overlap each row of this List to a GRanges object.
My goal is to get a data frame containing a count for the overlap of the GRanges object repeated for each of the GRangesList like. I have it working with a double loop but this is extremely slow and I am hoping there is a quicker and better solution using some kind of apply functions... I have tried apply
, mapply
, lapply
, but I get the overlap of the two obj1 and objList
only and not the repeated obj1 over objList
.
Please help.
Here are examples of the objList
and obj1
in R:
TYPE1 <- GRanges(seqnames = c("chr1", "chr1", "chr1"), ranges=IRanges(start=c(0,9600,24000),
end=c(10000, 20000, 30000)), id=c("Factor1", "Factor2", "Factor3"))
TYPE2 <- GRanges(seqnames = c("chr2", "chr2", "chr2"), ranges=IRanges(start=c(0,9000,14000),
end=c(13000, 20500, 30100)), id=c("Factor1", "Factor2", "Factor3"))
objList <- GRangesList("TYPE1" = TYPE1, "TYPE2" = TYPE2)
obj1 <- GRanges(seqnames = c("chr1", "chr1"), ranges=IRanges(start=c(0,9700), end=c(1, 9701)), id=c("rs1", "rs2"))
And this is what I have working now with loops (to find the overlap of obj1
with each row of objList
):
nameList=names(objList)
output=data.frame(row.names=c("rs1","rs2"))
for (name in nameList) {
id= objList[[name]]$id
for (i in 1:length(id)) {
dftemp=as.data.frame(countOverlaps(obj1, objList[[name]][i,], type=c("within")))
output=cbind.data.frame(output,dftemp)
}
}
Yes I am sorry! Answer was kindly provided by dpryan in http://seqanswers.com/forums/showthread.php?p=181564&posted=1#post181564