Pure, 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
)

Arguments

err_rows

data.frame with at least chr, label. Optional source, message (carried into note CSVs when present).

resolve_regions

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).

null_model

The run's fitted null-model list (must include $sample_id).

filter

A glow_variant_filter (from variant_filter()).

gds_dir

Character. Directory holding the per-chr GDS files.

gds_pattern

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)).

pi_features

Character vector of annotation feature names passed to extract_variant_set().

err_dir

Output directory for the per-error CSVs (created if missing).

file_basename_fn

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".

verbose

Logical. If TRUE (default), cats one timestamped line per error processed.

Value

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)).

Details

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).