如何防止snakemake从失败的作业中删除输出文件夹?

jps*_*y19 5 snakemake

我有一个规则,它遍历文件会拉出 Fastq 文件路径并在 Fastq 文件上运行 trimGalore。但是,某些文件已损坏/被截断,因此 trimGalore 无法处理它们。它继续在剩余文件上运行,但整体规则失败并删除包含成功处理文件的输出文件夹。如何保留输出文件夹?

我尝试更改 shell 命令以忽略退出状态,但 snakemake 似乎set -euo pipefail在运行的 shell 元素中强制执行。

rule trimGalore:
    """
    This module takes in the temporary file created by parse sampleFile rule and determines if libraries are single end or paired end.
    The appropriate step for trimGalore is then ran and a summary of the runs is produced in summary_tg.txt
    """
    input:
        rules.parse_sampleFile.output[1]+"singleFile.txt", rules.parse_sampleFile.output[1]+"pairFile.txt"
    output:
        directory(projectDir+"/trimmed_reads/")
    log:
        projectDir+"/logs/"+stamp+"_trimGalore.log"
    params:
        p = trimGaloreParams
    shell:
        """
        (awk -F "," '{{print $2}}' {input[0]} |while read i; do echo $(date +"%Y-%m-%d %H:%M:%S") >>{log}; echo "$USER">>{log}; trim_galore {params.p} --gzip -o {output} $i; done
        awk -F "," '{{print $2" "$3}}' {input[1]} |while read i; do echo $(date +"%Y-%m-%d %H:%M:%S") >>{log}; echo "$USER">>{log}; trim_galore --paired {params.p} --gzip -o {output} $i; done) 2>>{log}
        """
Run Code Online (Sandbox Code Playgroud)

我很高兴它在失败时继续处理剩余的 Fastq 文件,但我希望在作业完成和失败时保留规则输出文件夹。我想继续处理未截断的文件

小智 2

目前,您的规则将整个目录视为输出,因此如果在此过程中出现任何错误,它将认为作业整体失败并丢弃输出(即您的整个文件夹)。

我能想到的解决方案与Snakemake 文档的这一部分以及它下面的Functions as input相关。

def myfunc(wildcards):
    return [... a list of input files depending on given wildcards ...]

rule:
    input: myfunc
    output: "someoutput.{somewildcard}.txt"
    shell: "..."
Run Code Online (Sandbox Code Playgroud)

有了这个,你可以尝试迭代你的文件,snakemake 将为每个 Fastq 创建一个作业,因此,如果单个作业失败,只有该输出文件将被删除。

免责声明:这是我刚刚学到的东西,还没有尝试过,但它对我也很有用!