From 6f24758d17e075470534f11cbeaaac66bfef47a0 Mon Sep 17 00:00:00 2001 From: Jonathan Griffiths <7976085+jonathangriffiths@users.noreply.github.com> Date: Wed, 23 Aug 2023 10:57:48 +0100 Subject: [PATCH] Fix bug for no indels --- R/check_on_ref_genome.R | 46 +++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/R/check_on_ref_genome.R b/R/check_on_ref_genome.R index d4d205b..f11158a 100644 --- a/R/check_on_ref_genome.R +++ b/R/check_on_ref_genome.R @@ -51,26 +51,26 @@ check_on_ref_genome <-function(sumstats_dt, #if indels in dataset, don't check they are present on the ref # genome as they won't be there if(indels){ - data.table::setkey(sumstats_dt, SNP) - #make copy, check if not pres in ref first - indel_dt <- - data.table::copy(sumstats_dt[!unique(rsids$SNP),]) - #also check >1 character in A1 A2, use this to define indel - indel_dt <- indel_dt[(nchar(A1)>1 | nchar(A2)>1),] - if(nrow(indel_dt)>0){ - #remove indels from sumstats for now - sumstats_dt <- sumstats_dt[!indel_dt$SNP, ] - msg <- paste0("Found ", - formatC(nrow(indel_dt),big.mark = ","), - " Indels. These won't", - " be checked against the reference ", - "genome as it does not contain ", - "Indels.\nWARNING If your sumstat ", - "doesn't contain Indels, set the ", - "indel param to FALSE & rerun ", - "MungeSumstats::format_sumstats()") - message(msg) - } + data.table::setkey(sumstats_dt, SNP) + #make copy, check if not pres in ref first + indel_dt <- + data.table::copy(sumstats_dt[!unique(rsids$SNP),]) + #also check >1 character in A1 A2, use this to define indel + indel_dt <- indel_dt[(nchar(A1)>1 | nchar(A2)>1),] + if(nrow(indel_dt)>0){ + #remove indels from sumstats for now + sumstats_dt <- sumstats_dt[!indel_dt$SNP, ] + msg <- paste0("Found ", + formatC(nrow(indel_dt),big.mark = ","), + " Indels. These won't", + " be checked against the reference ", + "genome as it does not contain ", + "Indels.\nWARNING If your sumstat ", + "doesn't contain Indels, set the ", + "indel param to FALSE & rerun ", + "MungeSumstats::format_sumstats()") + message(msg) + } }else{ # join using SNP data.table::setkey(sumstats_dt, SNP) @@ -115,8 +115,10 @@ check_on_ref_genome <-function(sumstats_dt, if (imputation_ind && !"IMPUTATION_SNP" %in% names(sumstats_dt)) { sumstats_dt[, IMPUTATION_SNP := NA] - #update for indels so can rbind later - indel_dt[, IMPUTATION_SNP := NA] + # update for indels so can rbind later + if(indels){ + indel_dt[, IMPUTATION_SNP := NA] + } } sumstats_dt <- data.table::rbindlist(