Skip to contents

Extend genome ranges in a strand-aware fashion.

Usage

extend_ranges(
  ranges,
  upstream = 0,
  downstream = 0,
  metadata_cols = c("strand"),
  chromosome_sizes = NULL,
  zero_based_coords = !is(ranges, "GRanges")
)

Arguments

ranges

Genomic regions given as GRanges, data.frame, or list. See help("genomic-ranges-like") for details on format and coordinate systems. Required attributes:

  • chr, start, end: genomic position

upstream

Number of bases to extend each range upstream (negative to shrink width)

downstream

Number of bases to extend each range downstream (negative to shrink width)

metadata_cols

Optional list of metadata columns to require & extract

chromosome_sizes

(optional) Size of chromosomes as a genomic-ranges object

zero_based_coords

If true, coordinates start and 0 and the end coordinate is not included in the range. If false, coordinates start at 1 and the end coordinate is included in the range

Details

Note that ranges will be blocked from extending past the beginning of the chromosome (base 0), and if chromosome_sizes is given then they will also be blocked from extending past the end of the chromosome

Examples

## Prep data
ranges <- tibble::tibble(
 chr = "chr1",
 start = seq(50, 4050, 1000),
 end = start + 50,
 strand = "+"
)
ranges
#> # A tibble: 5 × 4
#>   chr   start   end strand
#>   <chr> <dbl> <dbl> <chr> 
#> 1 chr1     50   100 +     
#> 2 chr1   1050  1100 +     
#> 3 chr1   2050  2100 +     
#> 4 chr1   3050  3100 +     
#> 5 chr1   4050  4100 +     


## Extend ranges 1 bp upstream, 1 bp downstream
extend_ranges(ranges, upstream = 1, downstream = 1)
#> # A tibble: 5 × 4
#>   chr   start   end strand
#>   <fct> <dbl> <dbl> <lgl> 
#> 1 chr1     49   101 TRUE  
#> 2 chr1   1049  1101 TRUE  
#> 3 chr1   2049  2101 TRUE  
#> 4 chr1   3049  3101 TRUE  
#> 5 chr1   4049  4101 TRUE