How can I perform a try catch in nextflow?
I am currently writing a pipeline where it is possible that the bash command I am executing exits with an exitcode 1 under certain conditions. This brings my pipeline to a grinding halt. I would now like to use a try catch clause to define some alternative behavior in case this happens.
I have tried doing this in groovy fashion which does not seem to work:
process align_kallisto {
publishDir "${params.outdir}/kallisto", mode: 'copy', saveAs:{ filename -> "${name}_abundance.tsv" }
input:
tuple val(name), file(fastq) from fq_kallisto.dump(tag: 'kallisto fq')
file(index) from kallisto_index.collect().dump(tag: 'kallisto index')
output:
file("output/abundance.tsv") into kallisto_quant
// this can throw an exit 1 status
try {
"""
kallisto quant -i ${index} --bias --single --fr-stranded -o output --plaintext \
--fragment-length ${params.frag_length} --sd ${params.frag_deviation} ${fastq}
"""
}
// if this happens catch and do something else
catch (Exception e) {
println("Exception: ${e} for $name")
"""
// execute some alternative command
"""
}
}
Any advise?
I could tell nextflow to just ignore this error and still continue, but I would rather learn how to do a proper try catch.