This function is aware of chromosome size differences and intervals are randomly generated in proportion to chromosome sizes. In another word, larger chromosomes will have more randomly generated intervals.

make_random_bed(
  n,
  interval_width,
  genome,
  chrom = NULL,
  seed = NULL,
  sort = TRUE
)

Arguments

n

Number of intervals to generate.

interval_width

An integer value of the width of the interval.

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().

chrom

A character vector. If provided, only generate random intervals for the specified chromosome(s).

seed

An integer seed for the random number generator. If NULL, the seed is randomly chosen.

sort

Logical value. Should the random BED data be sorted?

Value

A GRanges of generated intervals.

References

Manual page for bedtools random: https://bedtools.readthedocs.io/en/latest/content/tools/random.html

Examples

# Generate 100 500kbp-intervals for chr20 and chr22, GRCh38
result <- make_random_bed(100, 500e3L, genome = "GRCh38", chrom = c("20", "22"))
head(result)
#>    chrom    start      end
#> 1:    20   250273   750273
#> 2:    20  1851209  2351209
#> 3:    20  2736167  3236167
#> 4:    20  5175998  5675998
#> 5:    20  9298753  9798753
#> 6:    20 10628140 11128140
#> -------
#> genome: GRCh38.

# Generate 100 500bp unsorted intervals for all chromosomes of GRCh37 (default reference genome)
result <- make_random_bed(100, interval_width = 500, genome = "GRCh37", sort = FALSE)
#> Error: is_integer(x = x$end) is not TRUE
head(result)
#>    chrom    start      end
#> 1:    20   250273   750273
#> 2:    20  1851209  2351209
#> 3:    20  2736167  3236167
#> 4:    20  5175998  5675998
#> 5:    20  9298753  9798753
#> 6:    20 10628140 11128140
#> -------
#> genome: GRCh38.