R/define_genome_chunks.R
define_genome_chunks.RdBuilds the chunk lookup table for the genomic-chunk SLURM array that drives a
sliding-window GLOW scan. Each chunk is one array task; the table maps
SLURM_ARRAY_TASK_ID to a chromosome and a contiguous run of window
start positions.
define_genome_chunks(
chrom_spans,
window_size,
step_size,
chunk_strategy = "fixed_mb",
chunk_size_mb = 5,
gds_paths = NULL
)A data.frame with columns chr, start,
end — one row per chromosome, giving its inclusive position extent
(typically the per-chr GDS min/max position, computed during preparation). Rows
are processed in genomic order regardless of input order.
Integer window width in bp (e.g. 100000L).
Integer step between consecutive window starts (e.g.
10000L). Governs the window count.
Character. Only "fixed_mb" is supported in v1;
any other value is an error.
Numeric chunk width in Mb (default 5, the
STAARpipeline-proven value). Must be large enough to hold at least one step
(chunk_size_mb * 1e6 >= step_size).
Reserved for a future variant-count-balancing strategy;
unused in v1 ("fixed_mb").
A data.frame, one row per chunk in genomic order, with columns:
Integer, 1-based global id; the scan selects its
chunk by SLURM_ARRAY_TASK_ID == chunk_id.
Chromosome label.
Integer, inclusive lower bound of owned window starts
(grid-aligned). Passed as define_regions_window's start.
Integer, inclusive upper bound of owned window starts; the
scan keeps windows with start <= chunk_end.
Integer, the chromosome's max position; passed as
define_regions_window's end so boundary-spanning windows are
generated and window ends are capped at the chromosome extent.
Integer, the number of window starts owned by the chunk (exact for fixed geometry; for SLURM load inspection).
Boundary rule. A window is owned by the chunk containing its
start. Chunks own contiguous runs of
windows_per_chunk = floor(chunk_size_mb * 1e6 / step_size) positions on
the per-chromosome step grid (anchored at the span start), so chunk_start
is always a grid-aligned window start and the union of all chunks' windows
equals one full-span slide — no duplicates, no gaps. The scan builds
a chunk's windows with
define_regions_window(chr, chunk_start, span_end, window_size, step_size)
and keeps rows with start <= chunk_end; generating to span_end
(not chunk_end) lets a window start in the chunk and spill past its end,
matching the full-span slide. span_end is returned for that one lookup.
For configs where step_size divides chunk_size_mb * 1e6 (the
usual case, e.g. 5 Mb / 10 kb), chunk_start/chunk_end equal the
naive fixed-Mb boundaries; otherwise chunks are rounded down to a whole number
of steps to keep the grid aligned.
spans <- data.frame(chr = c("21", "22"),
start = c(1L, 1L),
end = c(12000000L, 8000000L))
chunks <- define_genome_chunks(spans, window_size = 100000L,
step_size = 10000L, chunk_size_mb = 5)
chunks
#> chunk_id chr chunk_start chunk_end span_end est_n_windows
#> 1 1 21 1 5000000 12000000 500
#> 2 2 21 5000001 10000000 12000000 500
#> 3 3 21 10000001 12000000 12000000 191
#> 4 4 22 1 5000000 8000000 500
#> 5 5 22 5000001 8000000 8000000 291