Skip to contents

This function takes a region and splits it into bins of a specified size.

Usage

bin_splitter(
  these_regions = NULL,
  qchrom = NULL,
  qstart = NULL,
  qend = NULL,
  bin_size = 1000
)

Arguments

these_regions

The region(s) to be queried. Can be a data frame with regions with the following columns; chrom, start, end. Or in a string in the following format chr:start-end.

qchrom

Query chromosome (prefixed or un-prefixed), Required if `these_regions` is not provided.

qstart

Query start position. Required if `these_regions` is not provided.

qend

Query end position. Required if `these_regions` is not provided.

bin_size

The size of the bins to split the regions into, default is 1000.

Value

A data frame with input regions binned into the specified bin size.

Details

This function internally calls the purify_regions function to properly format the incoming regions.Thus, this function can accept either a data frame of regions or individual region coordinates.

Examples

#Example 1 - Call function with regions specified individually
my_bins = bin_splitter(qchrom = c("chr1", "chr2"), 
                       qstart = c(100, 200), 
                       qend = c(200, 300),
                       bin_size = 10)
head(my_bins, 5)
#>   bin_chr bin_start bin_end
#> 1    chr1       100     110
#> 2    chr1       110     120
#> 3    chr1       120     130
#> 4    chr1       130     140
#> 5    chr1       140     150

#Example 2 - Call the function with regions from a data frame
my_regions = purify_regions(these_regions = c("chr7:1000-500000", 
                                              "chr8:50000-7000000"))

these_bins = bin_splitter(these_regions = my_regions,
                          bin_size = 100000)
head(these_bins, 5)
#>   bin_chr bin_start bin_end
#> 1    chr7      1000  101000
#> 2    chr7    101000  201000
#> 3    chr7    201000  301000
#> 4    chr7    301000  401000
#> 5    chr8     50000  150000