Question: How to get overlap count (in basepair) of two IRange objects?
0
gravatar for Tori
2.2 years ago by
Tori90
Finland
Tori90 wrote:

I have following two IRanges objects query and ref. I would like to get overlap in number of basepairs.

> ref
  chr start  end
1   1   120  190
2   1   910 1050
3   1  1100 1140
4   1  2550 2650
5   2    50  100
> query
  chr start  end
1   1   101  173
2   1   918 1000
3   1  1060 1115
4   1  2468 2508

I got only this far.

library(GenomicRanges)
query = structure(list(chr = c("1", "1", "1", "1"), 
    start = c(101L, 918L, 1060L, 2468L),
    end = c(173L, 1000L, 1115L, 2508L)
), .Names = c("chr", "start", "end"), 
row.names = c(1L, 2L, 3L, 4L), class = "data.frame")


ref = structure(list(chr = c("1", "1", "1", "1","2"), 
    start = c(120L, 910L, 1100L, 2550L, 50L),
    end = c(190L, 1050L, 1140L, 2650L, 100L)
), .Names = c("chr", "start", "end"), 
row.names = c(1L, 2L, 3L, 4L, 5L), class = "data.frame")


refIR <- IRanges(start= ref$start, end =ref$end, name=ref$chr)
testIR <- IRanges(start = query$start, end =query$end, name=query$chr)

result <- findOverlaps(refIR, testIR, type="any")

data.frame(refIR[queryHits(result),], testIR[subjectHits(result),])
R iranges • 610 views
ADD COMMENTlink written 2.2 years ago by Tori90
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: 824 users visited in the last hour