Similar to bedtools slop, this function increases the size of each feature in a feature file by a user-defined number of bases. Will restrict the resizing to the size of the chromosome.

slop_bed(
  x,
  genome = NULL,
  slop = 1L,
  slop_type = c("bp", "frac"),
  mode = c("both", "left", "right")
)

Arguments

x

A GRanges object.

genome

Specify the reference genome for the BED file. genome can be a valid genome name in GenomeInfoDb::Seqinfo(), e.g. GRCh37, or hs37-1kg, which is a genome shipped with this package, or any custom chromosome size files (local or remote). If NULL, will try to obtain such information from input data. Refer to read_bed().

slop

The number of base pairs to slop, or the percentage of the interval's width (refer to bedtools slop's -pct argument).

slop_type

If bp, slop is an integer indicating the number of base pairs. If frac, slop is a float point number indicating the percentage.

mode

If both, the resizing takes place on both ends of the interval. Otherwise, the resizing is only for the left end or the right end.

Value

A slopped GRanges object.

References

Manual page of bedtools slop: https://bedtools.readthedocs.io/en/latest/content/tools/slop.html

Examples

# Load data
tbl <- read_bed(system.file("extdata", "example_merge.bed", package = "bedtorch"), 
                use_gr = FALSE, genome = "hs37-1kg")

# Slop by 10 on both ends
result <- slop_bed(tbl, slop = 10L, slop_type = "bp", mode = "both")

# Slop by 10 only on the right end
result <- slop_bed(tbl, slop = 10L, slop_type = "bp", mode = "right")
head(result)
#>    chrom start end score
#> 1:    21     3  16     8
#> 2:    21    10  26     5
#> 3:    21    12  27     4
#> 4:    21    15  32     5
#> 5:    21    22  35     7
#> 6:    21    26  40     7
#> -------
#> genome: hs37-1kg.

# Slop by 20% on the left end
result <- slop_bed(tbl, slop = 0.2, slop_type = "frac", mode = "left")
head(result)
#>    chrom start end score
#> 1:    21     3   6     8
#> 2:    21     9  16     5
#> 3:    21    11  17     4
#> 4:    21    14  22     5
#> 5:    21    22  25     7
#> 6:    21    26  30     7
#> -------
#> genome: hs37-1kg.