【发布时间】:2021-02-12 07:29:49
【问题描述】:
如何在 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。
【问题讨论】: