Skip to content

Commit

Permalink
improve error handling in pileup step; save log to pileup.log; #179
Browse files Browse the repository at this point in the history
  • Loading branch information
teng-gao committed Mar 17, 2024
1 parent 4e4f541 commit eb096b6
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions inst/bin/pileup_and_phase.R
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -309,3 +307,5 @@ for (sample in samples) {
fwrite(df, glue('{outdir}/{sample}_allele_counts.tsv.gz'), sep = '\t')

}

cat('All done!\n')

0 comments on commit eb096b6

Please sign in to comment.