library(GenomicRanges)
gr=GRanges(seqnames=c("chr1","chr2","chr2"),
ranges=IRanges(start=c(50,150,200),end=c(100,200,300)),
strand=c("+","-","-")
)
I want to get all intervals between 200-300 on chromosome 2, the minus strand. How do I do that?
gr[seqnames(gr) == "chr2" & start(gr) > 200 & end(gr) < 300 & strand(gr) == "-"]
does not work as it does not find the overlaps with 200-300, but rather the intervals strictly contained in that range.
Read about
findOverlaps
?Construct a second
GRanges
object with the target ranges and then use eitherfindOverlaps
as zx8754 suggests, orsubsetByOverlaps
.