[SOLVED] Trying to apply overlap to each row of a "GRangesList"
1
0
Entering edit mode
9.2 years ago
User 7754 ▴ 270

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)
    }
}
R loop apply • 3.8k views
ADD COMMENT
2
Entering edit mode
9.2 years ago

Hello User 7754!

It appears that your post has been cross-posted to another site: http://seqanswers.com/forums/showthread.php?t=63056

This is typically not recommended as it runs the risk of annoying people in both communities.

ADD COMMENT
0
Entering edit mode

Yes I am sorry! Answer was kindly provided by dpryan in http://seqanswers.com/forums/showthread.php?p=181564&posted=1#post181564

ADD REPLY

Login before adding your answer.

Traffic: 2737 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6