nested loop to overlap two genomic ranges lists?
1
0
Entering edit mode
7.8 years ago
cpc5 ▴ 50

Hi all,

I want to create a matrix that lists number of overlaps between two lists. So the rows would be one list and the columns would be the other.

this is what I have to far:

for (i in length(list.1)) { 
    for (j in length(list.2)) {
     table <- table(countOverlaps(list.1[[i]], list.2[[j]], type='any', maxgap=0)) }}

but I am only getting one overlap

I have tried:

x <- lapply(list.1, function(x,y) {table(countOverlaps(x,y,type="any", maxgap=0))}, list.2)

but the numbers do not match when I do an individual test

any clues?

thanks in advance

R GRanges • 1.8k views
ADD COMMENT
1
Entering edit mode

Shouldn't it be for(i in c(1:length(list.1)) {?

ADD REPLY
0
Entering edit mode

yes! I forgot to add the 1 in

ADD REPLY
1
Entering edit mode
7.8 years ago
cpc5 ▴ 50

if anyone is coming from google, i forgot to build a matrix and assign the rows and columns

mymatrix <- matrix(nrow=length(list.1), ncol=length(list.2))

for (i in 1:length(list1)) { 
    for (j in 1:length(list.2)) {
    tmp <- table(countOverlaps(query=list.1[[i]], subject=list.2[[j]], type='any', maxgap=0)) 
    if("0" %in% names(tmp)) {
        mymatrix[i,j] <- sum(tmp[2:length(tmp)])
        } else mamatrix[i,j] <- sum(tmp)
        rm(tmp)
    }}
ADD COMMENT

Login before adding your answer.

Traffic: 1906 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