【问题标题】:Run rule in Snakemake only if another rule fails, for the specific samples that it failed for?仅当另一个规则失败时才在 Snakemake 中运行规则,对于它失败的特定样本?
【发布时间】:2021-06-21 17:25:40
【问题描述】:

我正在 Snakemake 中运行宏基因组学管道。我正在为我的程序集运行 MetaSPAdes,但 MetaSPAdes 对于特定示例经常会失败的情况并不少见。如果 MetaSPAdes 失败,我只想在失败的样本上运行 MEGAHIT。有没有办法在 Snakemake 中创建这种规则依赖?

例如:

  1. 如果规则失败(在本例中为使用 MetaSPAdes 的程序集),则生成特定文件。我想这意味着 MetaSPAdes 规则的输出需要是重叠群或“失败的”输出文件。这将有助于 Snakemake 识别不重新运行此规则。
  2. 创建规则失败的样本列表,然后
  3. 仅对 MetaSPAdes 程序集失败的示例列表运行不同的规则(在这种情况下,对这些示例运行 MEGAHIT)。

有没有人想出一个优雅的方法来做这样的事情?

【问题讨论】:

    标签: bioinformatics snakemake


    【解决方案1】:

    我不熟悉您提到的程序,但我认为您不需要单独的规则来满足您的需求。您可以编写一条规则,首先尝试运行 metaspades,如果失败,请尝试 megahit。例如:

    rule assembly:
        input:
            '{sample}.in',
        output:
            '{sample}.out',
        run:
            import subprocess
    
            p = subprocess.Popen("MetaSPAdes {input} > {output}", shell= True, stderr= subprocess.PIPE, stdout= subprocess.PIPE)
            
            stdout, stderr= p.communicate()
            
            if p.returncode != 0:
                shell("megahit {input} > {output}")
    

    stdout, stderr= p.communicate() 捕获进程的标准错误、标准输出和返回码。您可以分析 stderr 和/或返回码来决定下一步该做什么。您可能需要比上述更多的东西,但希望这个想法是正确的。

    【讨论】:

    • 非常感谢!这非常有帮助,我已将其写入我的管道!真的很感激!
    猜你喜欢
    • 2020-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    相关资源
    最近更新 更多