消除 snakemake 临时目录

Eliminating snakemake temporary directories

为了在 PC 上保存 space,我正在使用 snakemake 中的 temp() 函数。这将删除 dup 目录中的所有文件 {sample}.dup.bam,但不删除目录本身。如何改进?

rule all:
    input: 
        expand("dup/{sample}.dup.bam", sample=SAMPLES),
        "dup/bam_list"

rule samtools_markdup:
    input:
        sortbam ="rg/{sample}.rg.bam"
    output:
        dupbam = temp("dup/{sample}.dup.bam")
    threads: 5
    shell:
        """
        samtools markdup -@ {threads} {input.sortbam} {output.dupbam}
        """

rule bam_list:
    input: 
        expand("dup/{sample}.dup.bam", sample=SAMPLES)
    output:
        outlist = "dup/bam_list"
    shell:
         """
         ls dup/*.bam > {output.outlist}
         """

temp() 函数删除工作流程中不再需要的所有文件。
因为你在 rule all 中指定你需要创建文件 dup/bam_list,snakemake 不会删除这个文件,因此,dup 目录。我什至很惊讶所有的 bam 文件都被删除了,因为你在 rule all.

中要求它们

小贴士

您正在定义规则之间的依赖关系:
在 运行 rule bam_list 之前需要 rule samtools_markdup。因此,您不需要在rule all中请求expand("dup/{sample}.dup.bam", sample=SAMPLES)。将创建鞋楦(并删除标记为临时文件)以创建文件 dup/bam_list.

如果您需要删除目录,您也可以(可能)将其标记为 temp 以及 directory() 函数:

output: temp(directory("dup")) 

但是再一次,如果这个文件夹中的任何文件被提供给rule all,它不会被删除。使用目录总是有点棘手,因为 snakemake 使用文件(及其时间戳)来定义 DAG。