[BioC] GenomicRanges: removing contained ranges without merging overlapping ranges

Jonathan Ellis Jonathan.Ellis at qimrberghofer.edu.au
Fri Jun 6 09:18:10 CEST 2014


Dear list,

I have a GRanges object that contains some ranges that are completely
contained within larger ranges as well as ranges that overlap. I know I
can use reduce to merge overlapping ranges and remove the smaller,
completely contained, ranges.  However, I would like to only remove
ranges that are completely within a larger range and leave overlapping
ranges intact.  For example,

> g <- GRanges(seqnames = Rle('chr1', 3), 
   ranges = IRanges(start = c(1, 3, 8), end = c(10, 7, 15)))
> reduce(g)
GRanges with 1 range and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  [1]     chr1   [1, 15]      *
  ---
  seqlengths:
   chr1
     NA

I would like to to get the following GRanges:

GRanges with 1 range and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  [1]     chr1   [1, 10]      *
  [2]     chr1   [8, 15]      *
  ---
  seqlengths:
   chr1
     NA

Does anyone know if there's an easy way to do this with GRanges?

Thanks,
Jonathan



More information about the Bioconductor mailing list