The width of the overlapped segment in the GenomicRanges package
I use GenomicRanges to find which transcripts from one experiment are the same as those coming from another.
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'm trying to find is the WIDTH of the overlapped segment between the images in the decision dataframe, however the only width I could get is related to the original transcripts before the overlap procedure.
could you help me?
+3
source to share
1 answer
You can apply the function ranges
to the hit class (results findOverlaps
). ranges return Ranges that hold the intersection of ranges in the feature and feature query.
You are not giving a reproducible example, so here's 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
+5
source to share