From 0c7b4fbc27b66765587c7bc15e83aa1ab92d31e5 Mon Sep 17 00:00:00 2001 From: gw Date: Sat, 18 Apr 2026 15:33:32 -0400 Subject: [PATCH] Use pecotmr::build_twas_score_row in quantile_twas_pipeline Lazy-bind via zzz.R so the per-(context, study) twas result row shape is produced by a single shared helper in pecotmr. Eliminates a 6-line data.frame() duplicate. Co-Authored-By: Claude Opus 4.6 --- R/quantile_twas_pipeline.R | 8 +------- R/zzz.R | 4 +++- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/R/quantile_twas_pipeline.R b/R/quantile_twas_pipeline.R index 2b2cfe6..5def8f7 100644 --- a/R/quantile_twas_pipeline.R +++ b/R/quantile_twas_pipeline.R @@ -210,13 +210,7 @@ quantile_twas_pipeline <- function(twas_weights_data, if (is.null(twas_rs)) { return(list(twas_rs_df = data.frame())) } - twas_rs_df <- data.frame( - gwas_study = study, method = sub("_[^_]+$", "", names(twas_rs)), - twas_z = find_data(twas_rs, c(2, "z")), - twas_pval = find_data(twas_rs, c(2, "pval")), - context = context, molecular_id = weight_db - ) - return(list(twas_rs_df = twas_rs_df)) + return(list(twas_rs_df = build_twas_score_row(twas_rs, weight_db, context, study))) }) twas_context_table <- do.call(rbind, lapply(study_results, function(x) x$twas_rs_df)) return(list(twas_context_table = twas_context_table)) diff --git a/R/zzz.R b/R/zzz.R index 32d4097..b4c869b 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -6,10 +6,12 @@ compute_qvalues <- NULL pval_cauchy <- NULL drop_collinear_columns <- NULL +build_twas_score_row <- NULL .onLoad <- function(libname, pkgname) { ns_self <- asNamespace(pkgname) - for (sym in c("compute_qvalues", "pval_cauchy", "drop_collinear_columns")) { + for (sym in c("compute_qvalues", "pval_cauchy", + "drop_collinear_columns", "build_twas_score_row")) { assign(sym, utils::getFromNamespace(sym, "pecotmr"), envir = ns_self) } }