Skip to content

Fix GWAS fine-mapping postprocessing export - #1401

Merged
gaow merged 1 commit into
StatFunGen:mainfrom
Yining97:gwas-postproc-fixes
Aug 11, 2026
Merged

Fix GWAS fine-mapping postprocessing export#1401
gaow merged 1 commit into
StatFunGen:mainfrom
Yining97:gwas-postproc-fixes

Conversation

@Yining97

Copy link
Copy Markdown
Contributor

The GWAS path through mnm_postprocessing had three defects that only show up on a real GWAS region with signal, so the toy/empty-region tests never hit them.

1. pip_sum crash on GWAS results

fine_mapping_cis_db_export.R builds the pip_sum table by reading db$context and db$trait. A GwasFineMappingResult has neither column (it's study, method, region_id, entry), so db$context is NULL and as.character(db$context[i]) is character(0) — length 0. On a region with signal getPip returns a real vector and the row hits data.frame(pip_sum = <len 1>, condition = character(0)), which errors with "arguments imply differing number of rows: 1, 0". Empty regions return early (getPip NULL), which is why it stayed hidden. The db and meta are written before this point, so only pip_sum is lost — and the step fails at the very end.

Fix: read each identity field NULL-safely, substituting NA when the column is absent. getPip already accepts context = NA.

2. export_top_loci silently empty under --gwas

Step 1 writes *.block_results_db.rds in GWAS mode, but export_top_loci_2 hardcoded export_suffix = 'cis_results_db.rds'. Under --gwas the glob matches nothing, stop_if skips gracefully, and step 3 combines over nothing and writes a 0-row .top_loci.bed.gz with exit 0 — a silent empty result unless you knew to pass --export_suffix block_results_db.rds by hand.

Fix: default export_suffix to empty and derive it from the gwas flag (block_results_db.rds under --gwas, else cis_results_db.rds); an explicit --export_suffix still overrides.

3. export_top_loci_3 combine aborts on macOS

The combine ran zcat "$f" without -f on its two emit lines; BSD zcat fails on .gz without -f, and set -euo pipefail aborts the step once fix #2 finally produces a non-empty bed to combine. Added -f, matching the zcat -f the same block already uses in its guard. No-op on GNU/Linux.

Validation

Real chr21 AD_Bellenguez FMRs, pecotmr 0.6.11 + susieR 0.16.6, full sos run.

No pecotmr change; no change to fine-mapping numbers — this is the export layer only.

🤖 Generated with Claude Code

- pip_sum crashed on a GwasFineMappingResult (no context/trait column) for any
  region with signal; read identity fields NULL-safely so absent columns are NA.
- export_top_loci produced a silent empty bed under --gwas: export_suffix stayed
  cis_results_db while step 1 writes block_results_db. Derive it from the gwas flag.
- export_top_loci_3 combine now uses zcat -f so it doesn't abort on macOS once a
  non-empty bed exists to concatenate (no-op on Linux).
@gaow
gaow merged commit 7869168 into StatFunGen:main Aug 11, 2026
3 checks passed
@Yining97
Yining97 deleted the gwas-postproc-fixes branch August 11, 2026 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants