subtract-methods: Subtract a set of genomic ranges from a GRanges object

subtract-methodsR Documentation

Subtract a set of genomic ranges from a GRanges object

Description

Similar to bedtools subtract.

Usage

subtract(x, y, minoverlap=1L, ...)

## S4 method for signature 'GenomicRanges,GenomicRanges'
subtract(x, y, minoverlap=1L, ignore.strand=FALSE)

Arguments

x, y

Two GRanges objects, typically, but any GenomicRanges derivative should be supported. Note that y gets immediately replaced with:

  reduce(y, ignore.strand=ignore.strand)
    

internally.

minoverlap

Minimum overlap (in number of genomic positions) between a range in x and a range in reduce(y, ignore.strand=ignore.strand) for the 2 ranges to be considered overlapping, and for their overlapping portion to be removed from the range in x.

ignore.strand

If set to TRUE, the strand information is ignored in the computation and the strand of x is propagated to the result.

...

Further arguments to be passed to specific methods.

Details

subtract() first replaces its second argument y with:

  reduce(y, ignore.strand=ignore.strand)
  

Then it searches for genomic ranges in y that overlap genomic ranges in x by at least the number of base pairs specified via the minoverlap argument. If an overlapping range is found in y, the overlapping portion is removed from any range in x involved in the overlap.

Note that by default subtract(x, y) is equivalent to:

  psetdiff(x, rep(GRangesList(y), length(x)))
  

but will typically be hundred times more efficient.

Value

A GRangesList object parallel to x, that is, with one list element per range in x. The names and metadata columns on x are propagated to the result.

Author(s)

H. Pagès

See Also

  • bedtools subtract at https://bedtools.readthedocs.io/en/latest/content/tools/subtract.html

  • setops-methods for set operations on GRanges objects.

  • findOverlaps-methods for finding/counting overlapping genomic ranges.

  • intra-range-methods and inter-range-methods for intra range and inter range transformations of a GRanges object.

  • GRanges and GRangesList objects.

Examples

x <- GRanges(c(A="chr1:1-50", B="chr1:40-110", C="chrX:1-500"))
y <- GRanges(c("chr1:21-25", "chr1:38-150"))
z <- subtract(x, y)
z

unlist(z)

Bioconductor/GenomicRanges documentation built on May 4, 2024, 4:45 p.m.