Question: nested loop to overlap two genomic ranges lists?
0
gravatar for cpc5
2.2 years ago by
cpc550
chicaho
cpc550 wrote:

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

granges R • 627 views
ADD COMMENTlink modified 2.2 years ago • written 2.2 years ago by cpc550
1

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

ADD REPLYlink written 2.2 years ago by abascalfederico1.1k

yes! I forgot to add the 1 in

ADD REPLYlink written 2.2 years ago by cpc550
1
gravatar for cpc5
2.2 years ago by
cpc550
chicaho
cpc550 wrote:

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 COMMENTlink written 2.2 years ago by cpc550
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1947 users visited in the last hour