Width of the overlapped segment in GenomicRanges package

為{幸葍}努か 提交于 2020-01-04 01:54:04

问题


I'm using GenomicRanges to find which transcripts from one experiment overlap with those coming from other one.

head(to_ranges1)
   knowngene  chr strand Start    Gene
1 uc001aaa.3  chr1    +  9873 16409   DDX11L1
2 uc001aac.4  chr1    - 12361 31370  WASH7P
3 uc001aae.4  chr1    - 12361 21759  WASH7P
library(GenomicRanges)
object_one<-with(to_ranges, GRanges(chr, IRanges(Start,End), 
                                     strand,names=knowngene,Gene=Gene)
object_two<-with(to_ranges, GRanges(chr, IRanges(Start,End), 
                                     strand,names=knowngene, Gene=Gene))
mm<-findOverlaps(object_one,object_two)
solution <- data.frame(as.data.frame(object_one[as.matrix(mm)[,1],]),
                       as.data.frame(object_two[as.matrix(mm)[,2],]))

What I am trying to find is the WIDTH of the overlapped segment between the hits in the solution data frame, however the only width I could get is the related to the original transcripts before the overlapping procedure.

Could you help me pleas?


回答1:


You can apply the ranges function over hits class( results of findOverlaps) . ranges returns a Ranges holding the intersection of the ranges in the Ranges objects query and subject.

You don't supply a reproducible example , so here an example :

query <- IRanges(c(1, 4, 9), c(5, 7, 10))
subject <- IRanges(c(2, 2, 10), c(2, 3, 12))
mm <- findOverlaps(query,subject)
ranges(mm,query,subject)
Ranges of length 3
    start end width
[1]     2   2     1
[2]     2   3     2
[3]    10  10     1


来源:https://stackoverflow.com/questions/14685802/width-of-the-overlapped-segment-in-genomicranges-package

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!