【问题标题】:`errorStrategy` setting to stop current process but continue pipeline`errorStrategy` 设置停止当前进程但继续管道
【发布时间】:2021-11-25 22:14:11
【问题描述】:

我有很多样本经历了有时会失败(确定性地)的过程。在这种情况下,我希望失败的进程停止,但所有其他样本仍然独立提交和处理。

如果我理解正确,设置 errorStrategy 'ignore' 将在失败的进程中继续脚本,这不是我想要的。并且errorStrategy 'finish' 将停止提交新样本,即使其他样本也没有理由失败。虽然errorStrategy 'retry' 在技术上可以工作(通过重复失败的过程而好的过程通过),但这似乎不是一个好的解决方案。

我错过了什么吗?

【问题讨论】:

    标签: nextflow


    【解决方案1】:

    如果一个进程可以确定性地失败,那么以某种方式处理这种情况可能会更好。将errorStrategy 指令设置为“忽略”将意味着忽略任何流程执行错误并允许您的工作流程继续。例如,如果进程以非零退出状态退出,或者缺少一个或多个预期输出文件,您可能会收到进程执行错误。管道将继续,但不会尝试下游流程。

    test.nf的内容:

    nextflow.enable.dsl=2
    
    process foo {
    
        tag { sample }
    
        input:
        val sample
    
        output:
        path "${sample}.txt"
    
        """
        if [ "${sample}" == "s1" ] ; then
            (exit 1)
        fi
        if [ "${sample}" == "s2" ] ; then
            echo "Hello" > "${sample}.txt"
        fi
        """
    }
    
    process bar {
    
        tag { txt }
    
        input:
        path txt
    
        output:
        path "${txt}.gz"
    
        """
        gzip -c "${txt}" > "${txt}.gz"
        """
    }
    
    workflow {
    
        Channel.of('s1', 's2', 's3') | foo | bar
    }
    

    nextflow.config的内容:

    process {
    
      // this is the default task.shell:
      shell = [ '/bin/bash', '-ue' ]
    
      errorStrategy = 'ignore'
    }
    

    运行:

    nextflow run -ansi-log false test.nf
    

    结果:

    N E X T F L O W  ~  version 20.10.0
    Launching `test.nf` [drunk_bartik] - revision: e2103ea23b
    [9b/56ce2d] Submitted process > foo (s2)
    [43/0d5c9d] Submitted process > foo (s1)
    [51/7b6752] Submitted process > foo (s3)
    [43/0d5c9d] NOTE: Process `foo (s1)` terminated with an error exit status (1) -- Error is ignored
    [51/7b6752] NOTE: Missing output file(s) `s3.txt` expected by process `foo (s3)` -- Error is ignored
    [51/267685] Submitted process > bar (s2.txt)
    

    【讨论】:

    • 我明白了,谢谢!如果我没记错的话,由于自动set -e?如果失败不是exit 1,而是外部程序中的错误(所以如果没有set -efoo 可以继续运行)。
    • @Alexlok 正确:如果命令以非零状态退出,set -e 将立即退出。 IE。不会运行此之后的命令。请注意,如果您在脚本中一起使用管道命令,除非您使用shell = [ '/bin/bash', '-euo', 'pipefail' ],否则无法保证。另请注意,我将exit 1 放在子shell 中以模拟外部命令。如果没有set -efoo 将继续,进程 s1 将与 s3 一样失败(即缺少输出文件......)
    • 对不起,有一个方面我还不是很清楚:在你的例子中,你在配置文件中添加了set -ue; iirc Nextflow 会自动将其添加到每个运行的文件中。而且,(在我看来,通过实验)errorStrategy 'ignore' 不会改变这种行为?
    • @Alexlok 不用担心 - 我只是指出默认 shell 是什么。 nextflow.config 中process.shell 的值只是成为每个workdir .command.sh 脚本中使用的shebang。您的最后一点也是正确的:设置 errorStrategy 'ignore' 不会改变脚本的运行方式。如果 shebang 是#!/bin/bash -e,即set -e,如果命令以非零退出状态退出,则命令脚本仍将立即退出,而不管errorStrategy。请注意,您可以在有时失败的命令之前执行 set +e 来覆盖它。
    • 有道理,谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-22
    • 2021-11-25
    相关资源
    最近更新 更多