【问题标题】:Snakemake: rename fastQC output in one ruleSnakemake:在一条规则中重命名 fastQC 输出
【发布时间】:2018-06-15 18:06:53
【问题描述】:

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

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 规则的输出消失了,它想要重建它们。因此,我试图将这两个规则合并为一个步骤。

【问题讨论】:

    标签: snakemake


    【解决方案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}
            """
    

    【讨论】:

    • 我不知道您可以将输出用作params 函数的参数。很高兴知道,谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多