Snakemake:在一个规则中重命名fastQC输出

时间:2018-06-15 18:06:54

标签: snakemake

我试图将这两个规则结合在一起

rule fastqc:
    input:
        fastq = "{sample}.fastq.gz",
    output:
        zip1 = "{sample}_fastqc.zip",
        html = "{sample}_fastqc.html",
    threads:8
    shell:
        "fastqc -t {threads} {input.fastq}"

rule renamefastqc:
    input:
        zip1 = "{sample}_fastqc.zip",
        html = "{sample}_fastqc.html",
    output:
        zip1 = "{sample}__fastqc.zip",
        html = "{sample}__fastqc.html",
    shell:
        "mv {input.zip} {output.zip} && "
        "mv {input.html} {output.html} "

看起来像这样。

rule fastqc:
    input:
        fastq = "{sample}.fastq.gz"
    output:
        zip1 = "{sample}__fastqc.zip",
        html = "{sample}__fastqc.html"
    threads:8
    shell:
        "fastqc -t {threads} {input.fastq} && "
        "mv {outfile.zip} {output.zip1} && "
        "mv {outfile.html} {output.html}"

FastQC无法指定文件输出,并且始终以fastq.gz结尾的文件创建两个以_fastqc.zip和_fastqc.html结尾的文件。通常我只写一个规则来接受那些输出并产生一个带有两个下划线的规则(renamefastqc规则)。但这意味着每次我运行管道时,snakemake都会看到fastqc规则的输出已经消失,并且想要重建它们。因此,我试图将两个规则合并为一步。

1 个答案:

答案 0 :(得分:1)

您可以使用params来定义要重命名的文件。

rule all:
    input:
        "a123__fastqc.zip",

rule fastqc:
    input:
        fastq = "{sample}.fastq.gz",
    output:
        zip1 = "{sample}__fastqc.zip",
        html = "{sample}__fastqc.html",
    threads:8
    params:
        zip1 = lambda wildcards, output: output.zip1.replace('__', '_'),
        html = lambda wildcards, output: output.html.replace('__', '_')
    shell:
        """
        fastqc -t {threads} {input.fastq}
        mv {params.zip1} {output.zip1} \\
            && mv  {params.html} {output.html}
        """