如何在 nextflow 中执行 try catch?
我目前正在编写一个管道,在某些条件下,我正在执行的 bash 命令可能会以 exitcode 1 退出。这使我的管道陷入停顿。我现在想使用 try catch 子句来定义一些替代行为,以防发生这种情况。
我尝试过以 groovy 方式执行此操作,但似乎不起作用:
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
"""
}
}
有什么建议吗?
我可以告诉 nextflow 忽略这个错误并继续,但我宁愿学习如何做一个正确的 try catch。