diff --git a/R/allele_qc.R b/R/allele_qc.R index 85c3e32b..7b32d0a8 100644 --- a/R/allele_qc.R +++ b/R/allele_qc.R @@ -83,10 +83,13 @@ allele_qc <- function(target_data, ref_variants, col_to_flip = NULL, if (any(columns_to_remove %in% colnames(target_data))) { target_data <- select(target_data, -any_of(columns_to_remove)) } - - match_result <- merge(target_data, ref_variants, by = c("chrom", "pos"), all = FALSE, suffixes = c(".target", ".ref")) %>% + match_result <- merge(target_data, ref_variants, by = c("chrom", "pos"), all = FALSE, suffixes = c(".target", ".ref")) %>% as.data.frame() + if (nrow(match_result) == 0) { + warning("No matching variants found between target data and reference variants.") + return(list(target_data_qced = match_result, qc_summary = match_result)) + } # match target & ref by chrom and position - as.data.frame() %>% + match_result = match_result %>% mutate(variants_id_original = paste(chrom, pos, A2.target, A1.target, sep = ":")) %>% mutate(variants_id_qced = paste(chrom, pos, A2.ref, A1.ref, sep = ":")) %>% # filter out totally same rows. diff --git a/R/univariate_pipeline.R b/R/univariate_pipeline.R index 6826ad1a..7a577c0d 100644 --- a/R/univariate_pipeline.R +++ b/R/univariate_pipeline.R @@ -200,11 +200,16 @@ rss_analysis_pipeline <- function( 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) sumstats <- preprocess_results$sumstats LD_mat <- preprocess_results$LD_mat - + # Check if no variants in preprocess_results + if (nrow(sumstats)==0){ + message("No variants left after preprocessing. Returning empty results.") + return(list(rss_data_analyzed = sumstats)) + } if (pip_cutoff_to_skip != 0) { if (pip_cutoff_to_skip < 0) { # automatically determine the cutoff to use