Make windows with the size of window_size along genome. Must provide genome so that intervals are restricted by chromosome sizes.

make_windows(window_size, genome, chrom = NULL)

Arguments

window_size

An integer value. Size of the windows in base pairs.

genome

Provide the genome identifier, e.g. GRCh37, hs37-1kg, or path/URL to the chromosome size file. Refer to GenomeInfoDb::Seqinfo() and read_bed().

chrom

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

Value

A GRanges object containing the generated windows.

Examples

# Generate 500kbp intervals for chr20 and chr22, GRCh38
result <- make_windows(window_size = 500e3L, genome = "GRCh38", chrom = c("20", "22"))
head(result)
#> GRanges object with 6 ranges and 0 metadata columns:
#>       seqnames          ranges strand
#>          <Rle>       <IRanges>  <Rle>
#>   [1]       20        1-500000      *
#>   [2]       20  500001-1000000      *
#>   [3]       20 1000001-1500000      *
#>   [4]       20 1500001-2000000      *
#>   [5]       20 2000001-2500000      *
#>   [6]       20 2500001-3000000      *
#>   -------
#>   seqinfo: 455 sequences (1 circular) from GRCh38 genome

# Generate 5Mbp intervals for all chromosomes of GRCh37 (default reference genome)
result <- make_windows(window_size = 5e6L, genome = "GRCh37")
head(result)
#> GRanges object with 6 ranges and 0 metadata columns:
#>       seqnames            ranges strand
#>          <Rle>         <IRanges>  <Rle>
#>   [1]        1         1-5000000      *
#>   [2]        1  5000001-10000000      *
#>   [3]        1 10000001-15000000      *
#>   [4]        1 15000001-20000000      *
#>   [5]        1 20000001-25000000      *
#>   [6]        1 25000001-30000000      *
#>   -------
#>   seqinfo: 92 sequences from GRCh37 genome