运行 仅当另一个规则失败时才在 Snakemake 中规则,对于它失败的特定样本?

Run rule in Snakemake only if another rule fails, for the specific samples that it failed for?

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

例如:

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

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

我不熟悉你提到的程序,但我认为你不需要单独的规则来满足你的需要。您可以编写一个规则,首先尝试 运行 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、stdout 和 return 代码。您可以分析 stderr and/or return 代码来决定下一步做什么。您可能需要的不仅仅是上述内容,但希望这个想法是正确的。