From 0fe332bfcec90197126b22dbc1caebf94c183181 Mon Sep 17 00:00:00 2001 From: Nicholas Sunderland Date: Wed, 11 Sep 2024 13:31:20 +0100 Subject: [PATCH] v27 --- DESCRIPTION | 2 +- R/class_gwas.R | 6 ------ R/plink.R | 14 ++++++++------ 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index e8c6498..36ac295 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: genepi.utils Title: GenEpi Utility Functions -Version: 0.0.26 +Version: 0.0.27 Authors@R: c(person("Nicholas", "Sunderland", , "nicholas.sunderland@bristol.ac.uk", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-3625-630X"))) Description: The genepi.utils package is a collection of utility functions for working with genetic epidemiology data. License: MIT + file LICENSE diff --git a/R/class_gwas.R b/R/class_gwas.R index a1cb7c2..f9b43e9 100644 --- a/R/class_gwas.R +++ b/R/class_gwas.R @@ -892,7 +892,6 @@ method(get_proxies, GWAS) <- function(x, } else { message(paste0("[i] ", length(missing), "/", length(snps), " (", sprintf("%.2f", 100*(length(missing)/length(snps))), "%) missing variants")) - tryCatch({ # search for proxies for the missing SNPs proxies <- get_proxies(missing, @@ -954,11 +953,6 @@ method(get_proxies, GWAS) <- function(x, return(object) }) - }, - error = function(e) { - warning("Getting proxies failed, returning original GWAS object") - return(x) - }) } diff --git a/R/plink.R b/R/plink.R index d8586b4..642583e 100644 --- a/R/plink.R +++ b/R/plink.R @@ -181,6 +181,9 @@ method(get_proxies, class_character) <- function(x, # read the found SNPs snps_exist <- data.table::fread(paste0(exists_file,".pvar"), skip="#CHROM POS ID REF ALT", select=c("ID")) + # clean up + unlink(paste0(exists_file,".pvar")) + # report message(paste0("[i] ", nrow(snps_exist), "/", length(x), " (", sprintf("%.1f", 100*(nrow(snps_exist)/length(x))), "%) input SNPs found in plink reference file")) @@ -203,8 +206,7 @@ method(get_proxies, class_character) <- function(x, system(cmd) if (!file.exists(paste0(proxy_file,".vcor"))) { - warning("No variants found, or plink failed") - return(NULL) + stop(paste0("Plink `", paste0("--", stat), "` failed")) } # read in the extracted variants file @@ -224,6 +226,10 @@ method(get_proxies, class_character) <- function(x, proxy_freq_alt = as.numeric(NONMAJ_FREQ_B), rstat = as.numeric(get(names(which(stats == stat)))))] + # clean up + unlink(paste0(proxy_file,".vcor")) + unlink(snps_found) + # filter on eaf if (!is.null(proxy_eaf)) { nproxies <- nrow(proxies) @@ -233,10 +239,6 @@ method(get_proxies, class_character) <- function(x, } } - # clean up - unlink(paste0(exists_file,".pvar")) - unlink(paste0(proxy_file,".vcor")) - return(proxies) }