R/write_error_drilldowns.R
write_error_drilldowns.RdPure, resolver-agnostic per-error CSV drill-down writer. For each row of
err_rows it asks resolve_regions(err_row) where the analyzed
region(s) are; on status = "ok" it re-opens the chr GDS, runs
extract_variant_set, and writes
<err_dir>/<label>-variants.csv with per-variant cohort genotype
summaries (n_g0, n_g1, n_g2, n_missing,
variance, is_constant); on any non-"ok" status it writes a note-only
CSV carrying a status code plus a plain reason (so an empty CSV
explains itself).
write_error_drilldowns(
err_rows,
resolve_regions,
null_model,
filter,
gds_dir,
gds_pattern,
pi_features,
err_dir,
file_basename_fn = NULL,
link_path_prefix = "error_diagnostics",
verbose = TRUE
)data.frame with at least chr, label. Optional
source, message (carried into note CSVs when present).
function(err_row) -> list. Required key
$status; "ok" proceeds to GDS re-extraction, any other value
writes a note CSV with that status code. On "ok", also required:
$regions, a list of lists {chr, start, end, label}. On non-ok
statuses, optional $note (note text) and $location (copied
into the returned location column).
The run's fitted null-model list (must include $sample_id).
A glow_variant_filter (from variant_filter()).
Character. Directory holding the per-chr GDS files.
Character. Per-chr GDS filename pattern with a literal
{chr} placeholder; the path is
file.path(gds_dir, gsub("\{chr\}", err_row$chr, gds_pattern)).
Character vector of annotation feature names passed to
extract_variant_set().
Output directory for the per-error CSVs (created if missing).
Optional function(err_row) -> CSV basename.
Default sprintf("%s-variants.csv", err_row$label).
Character. Prefix for the markdown links written into
err_rows$error_diagnostics. Default "error_diagnostics".
Logical. If TRUE (default), cats one timestamped line
per error processed.
err_rows with two appended columns: location
("chr:start-end" of the analyzed region(s), semicolon-separated when
multiple) and error_diagnostics (markdown link(s) to the written
CSV(s)).
Two scripts call this helper with different resolvers: the gene-based
diagnostics resolves by matching the error's label/chr against the aggregated
results; the window-based diagnostics parses the analyzed region directly out
of the window label "chrN:start-end". Multiple regions for the same
error are emitted as <label>-<chr>_<start>_<end>-variants.csv (no
silent overwrite).