Normalize intervals to fixed or variable sizes
Source:R/intervals-operations.R
gintervals.normalize.RdThis function normalizes intervals by computing their centers and then expanding them to fixed or variable sizes, while ensuring they don't cross chromosome boundaries.
Arguments
- intervals
intervals set
- size
target size(s) for normalized intervals, before the clipping at chromosome ends. Can be either:
A single positive integer: all intervals normalized to this size
A numeric vector: each interval normalized to its corresponding size. Vector length must exactly match the number of intervals, OR a single interval can be provided with multiple sizes to create multiple output intervals (one-to-many expansion).
- intervals.set.out
intervals set name where the function result is saved. If NULL, the result is returned to the user.
Value
Normalized intervals set with fixed or variable sizes, or NULL if result is saved to intervals.set.out
Details
A window that would cross a chromosome end is clipped at that end, so near
the start or the end of a chromosome the returned interval is shorter than
'size' (no warning is given). Filter on end - start if the windows must
all have the full size.
Examples
gdb.init_examples()
# Single size (all intervals normalized to 500bp)
intervs <- gintervals(1, c(1000, 5000), c(2000, 6000))
gintervals.normalize(intervs, 500)
#> chrom start end
#> 1 chr1 1250 1750
#> 2 chr1 5250 5750
# Vector of sizes (each interval gets its own size)
intervs <- gintervals(1, c(1000, 3000, 5000), c(2000, 4000, 6000))
gintervals.normalize(intervs, c(500, 1000, 750))
#> chrom start end
#> 1 chr1 1250 1750
#> 2 chr1 3000 4000
#> 3 chr1 5125 5875
# One-to-many: single interval with multiple sizes
interv <- gintervals(1, 1000, 2000)
gintervals.normalize(interv, c(500, 1000, 1500))
#> chrom start end
#> 1 chr1 1250 1750
#> 2 chr1 1000 2000
#> 3 chr1 750 2250