如何使 Snakemake 包装器与 {threads} 变量一起工作

How to make Snakemake wrappers work with the {threads} variable

编辑 27-07-2018:包装器不考虑线程。此外,我在这里尝试的语法将不起作用,而且据我所知,不支持类似的语法。答案来自 Snakemake Google 组上的 cross-post 和下面的 meono。

我正在使用 Snakemake,我对它很满意。但是,对于某些过程,我使用包装器(即 FastQC 和 Trimmomatic)。但是,我注意到这些包装器没有考虑 {threads} 变量。有人可以解释一下使这项工作有效的正确语法是什么吗?

我试过设置 threads: 4,然后在代码的适当位置指定 {threads}(例如,对于 FastQC:params: "--threads {threads}")。同样,我测试了设置 {wildcards.threads}{snakemake.threads}。看起来包装器代码块无法 "see" threads 变量的值。

请看下面的例子。

注意:我查看了 Bitbucket snakemake-wrapper 存储库和 readthedocs 自述文件,但找不到答案。

rule FastQC_preTrim:
input:
    join(RAW_DATA, PATTERN_ANY)
output:
    html="FastQC_pretrim/{sample}.html",
    zip="FastQC_pretrim/{sample}_fastqc.zip"
threads: 4
params:
    "--threads {wildcards.threads}"   # Also tried {threads}
wrapper:
    "0.20.1/bio/fastqc"

(会把它放在评论中但没有代表)

fastqc wrapper 不考虑规则中的 threads。我觉得

params:
    "--threads 4"

适合你。

我 运行 在尝试使用 snakemake 包装器时遇到了同样的问题,但在将 {threads} 或任何其他通配符指定到参数时失败了。

解决方法是在 config.yaml 中显式定义一个“线程”参数并从那里调用它。例如:

# In config.yaml
thread_use: 32

# In rule
rule some_rule_with_wrapper:
    input:
        "path/to/input"
    output:
        "path/to/output"
    params:
        extra="-t "+str(config["thread_use"])  # Remember to coerce int to string
    threads: 32
    wrapper:
        "some/wrapper"