Snakemake:扩展参数

Snakemake: expand params

我正在尝试构建一个简单的工作流来将参数列表提供给脚本。举例说明:

SAMPLES=['A','B']

rule test:
    params:
        sample=expand("{sample}", sample=SAMPLES)
    script:
        "test.py {params.sample}"

然而,snakemake 只执行样本 A 的脚本,而不是 B。换句话说,我相信它正在执行 python test.py A B,而不是 python test.py A 然后 python test.py B。同样,我认为这可以通过以下方式说明:

SAMPLES=['A','B']

rule print_samples:
    params:
        sample=expand("{sample}", sample=SAMPLES)
    script:
        "echo {params.sample} \n"

我希望看到 AB 打印在不同的行上,但它却在同一行上打印 A B

我是否遗漏了一些关于 expand 与参数一起工作的方式?理想情况下,我想将 -j 标志并行添加到 运行 它们(目前 -j 仅使用 A 单独执行)。

这是预期的输出。 Expand 在这种情况下只是

的包装器
[str(sample) for sample in SAMPLES]

当输入到 shell 或脚本时,将成为在 A B.

之间与 space 连接的项目

相反,您需要一个适用于任何样本的通用规则(您还需要一个输出文件):

rule test:
   output: "{sample}.out"
   shell:
      "test.py {wildcards.sample}"  # no need for params, assume this writes output {sample}.out

这里test.py是一个可执行文件。 因此,当您请求 A.out、test.py A 运行 时,对于 B.out,您会得到 test.py B.

接下来你必须询问你想要的输出。这通常是 snakefile 中的第一条规则,称为 all:

rule all:
   input: expand('{sample}.out', sample=SAMPLES)

同样,expand 会给你一个样本列表,在你的例子中,rule all 变成:

rule all:
   input: 'A.out', 'B.out'

指定输出文件后,snakemake 确定规则测试需要 运行 两次,一次用 A,一次用 B。

所以请记住,将您的规则写成对任何 一个 样本的概括。您可能只需要在规则 all 中进行一次扩展,以针对每个样本专门化您的规则。 Snakemake 负责确定需要什么运行,如果你给它额外的核心,它可以同时为单独的工作做这些。