From 13aa2951c14f63ed67d5ac4b66f0327c4efeae16 Mon Sep 17 00:00:00 2001 From: xuewei cao <36172337+xueweic@users.noreply.github.com> Date: Wed, 26 Mar 2025 18:16:56 -0400 Subject: [PATCH] minor fix minor fix if region does not have sumstats variants --- R/colocboost_pipeline.R | 1 + R/file_utils.R | 10 ++++++++++ R/univariate_pipeline.R | 7 ++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/R/colocboost_pipeline.R b/R/colocboost_pipeline.R index e5d8f8b1..65d2053d 100644 --- a/R/colocboost_pipeline.R +++ b/R/colocboost_pipeline.R @@ -680,6 +680,7 @@ qc_regional_data <- function(region_data, sumstats <- sumstat_data$sumstats[[i]] for (ii in 1:length(sumstats)) { sumstat <- sumstats[[ii]] + if (nrow(sumstat$sumstats) == 0) next n <- sumstat$n var_y <- sumstat$var_y conditions_sumstat <- names(sumstats)[ii] diff --git a/R/file_utils.R b/R/file_utils.R index 47b82ea5..f0c8ce1e 100644 --- a/R/file_utils.R +++ b/R/file_utils.R @@ -799,6 +799,16 @@ load_rss_data <- function(sumstat_path, column_file_path, n_sample = 0, n_case = sumstats <- NULL var_y <- NULL sumstats <- load_tsv_region(file_path = sumstat_path, region = region, extract_region_name = extract_region_name, region_name_col = region_name_col) + + # To keep a log message + n_variants <- nrow(sumstats) + if (n_variants == 0){ + message(paste0("No variants in region ", region, ".")) + return(list(sumstats = sumstats, n = NULL, var_y = NULL)) + } else { + message(paste0("Region ", region, " include ", n_variants, " in input sumstats.")) + } + # Standardize column names based on mapping for (name in colnames(sumstats)) { if (name %in% column_data$original) { diff --git a/R/univariate_pipeline.R b/R/univariate_pipeline.R index e07bb07b..a80ba03c 100644 --- a/R/univariate_pipeline.R +++ b/R/univariate_pipeline.R @@ -195,6 +195,11 @@ rss_analysis_pipeline <- function( sumstats <- rss_input$sumstats n <- rss_input$n var_y <- rss_input$var_y + + # Check if no variants in sumstats + if (nrow(sumstats)==0){ + return(list(rss_data_analyzed = sumstats)) + } # Preprocess the input data preprocess_results <- rss_basic_qc(sumstats, LD_data, skip_region = skip_region, remove_indels = remove_indels) @@ -204,7 +209,7 @@ rss_analysis_pipeline <- function( if (pip_cutoff_to_skip != 0) { if (pip_cutoff_to_skip < 0) { # automatically determine the cutoff to use - pip_cutoff_to_skip <- 3 * 1 / ncol(X) + pip_cutoff_to_skip <- 3 * 1 / nrow(sumstats) } top_model_pip <- susie_rss_wrapper(z = sumstats$z, R = LD_mat, L = 1, n = n, var_y = var_y)$pip if (!any(top_model_pip > pip_cutoff_to_skip)) {