From eb096b6b2894f9abd678b28424a3b86d330c6696 Mon Sep 17 00:00:00 2001 From: teng-gao Date: Sun, 17 Mar 2024 19:16:41 -0400 Subject: [PATCH] improve error handling in pileup step; save log to pileup.log; #179 --- inst/bin/pileup_and_phase.R | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/inst/bin/pileup_and_phase.R b/inst/bin/pileup_and_phase.R index 8bcceb0..47f5ea1 100644 --- a/inst/bin/pileup_and_phase.R +++ b/inst/bin/pileup_and_phase.R @@ -187,12 +187,7 @@ list(cmds) %>% fwrite(script, sep = '\n') system(glue('chmod +x {script}')) -tryCatch({ - system(glue('sh {script}'), intern = TRUE) -}, -warning = function(w){ - stop('Pileup failed') -}) +system(glue('sh {script} 2>&1 | tee {outdir}/pileup.log'), intern = FALSE) ## VCF creation cat('Creating VCFs\n') @@ -203,6 +198,9 @@ vcfs = lapply(samples, function(sample) { if (file.exists(vcf_file)) { if (file.size(vcf_file) != 0) { vcf = vcfR::read.vcfR(vcf_file, verbose = F) + if (nrow(vcf@fix) == 0) { + stop(glue('Pileup VCF for sample {sample} has 0 variants')) + } return(vcf) } else { stop('Pileup VCF is empty') @@ -309,3 +307,5 @@ for (sample in samples) { fwrite(df, glue('{outdir}/{sample}_allele_counts.tsv.gz'), sep = '\t') } + +cat('All done!\n') \ No newline at end of file