Skip to content

Replace ctwas_ld_loader with ld_loader LD_info mode#463

Merged
gaow merged 4 commits intomainfrom
unify-ld-loader
Apr 7, 2026
Merged

Replace ctwas_ld_loader with ld_loader LD_info mode#463
gaow merged 4 commits intomainfrom
unify-ld-loader

Conversation

@gaow
Copy link
Copy Markdown
Contributor

@gaow gaow commented Apr 7, 2026

Summary

  • Add LD_info mode to ld_loader(): accepts a data.frame with LD_file (and optionally SNP_file) columns, loading .cor.xz blocks on demand via process_LD_matrix()
  • Remove ctwas_ld_loader() entirely — its functionality is now covered by ld_loader(LD_info = get_ctwas_meta_data(...)$LD_info)
  • ld_loader() now has 4 unified modes: R_list, X_list, ld_meta_path+regions, LD_info

Usage

# Old way (removed):
# R <- ctwas_ld_loader(file_path)

# New way:
meta <- get_ctwas_meta_data("ld_meta.tsv")
loader <- ld_loader(LD_info = meta$LD_info)
R <- loader(1)  # loads block 1 on demand

Test plan

  • R CMD check passes
  • Existing cTWAS tests pass (they don't reference ctwas_ld_loader directly)

🤖 Generated with Claude Code

gaow and others added 4 commits April 7, 2026 09:52
Add LD_info mode to ld_loader(): accepts a data.frame with LD_file
(and optionally SNP_file) columns, loading .cor.xz blocks on demand
via process_LD_matrix(). This is the fourth mode alongside R_list,
X_list, and ld_meta_path.

Remove ctwas_ld_loader() entirely. Its functionality is now covered
by: loader <- ld_loader(LD_info = get_ctwas_meta_data(...)$LD_info)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
process_LD_matrix() now auto-detects variant file format:
- .bim (PLINK1): 6 or 9 column tab-separated, no header
- .pvar/.pvar.zst (PLINK2): header starting with #CHROM, read via
  existing read_pvar_text()

When snp_file_path is NULL, tries .bim, .pvar, .pvar.zst in order.
The ld_loader LD_info mode now passes NULL to let auto-detection work
instead of hardcoding .bim.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The LD_info mode now auto-detects and handles:
1. Pre-computed .cor.xz + .bim/.pvar (custom block format)
2. PLINK1 prefix (.bed/.bim/.fam) - LD computed via compute_LD()
3. PLINK2 prefix (.pgen/.pvar/.psam) - LD computed via compute_LD()

Format is detected by checking which files exist at the LD_file path
using has_plink2_files() and has_plink1_files(). Falls back to
process_LD_matrix() for .cor.xz blocks.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gaow gaow merged commit a3951fb into main Apr 7, 2026
4 of 5 checks passed
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.

1 participant