gpt4 book ai didi

parameters - Snakemake:扩展参数

转载 作者:行者123 更新时间:2023-12-03 22:00:11 26 4
gpt4 key购买 nike

我正在尝试构建一个简单的工作流程来将参数列表提供给脚本。为了显示:

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在同一条线上。

我是否遗漏了扩展与参数一起工作的方式?理想情况下,我想添加 -j标志以并行运行它们(目前 -j 仅与 A 一起执行)。

最佳答案

这就是预期的输出。在这种情况下,扩展只是一个包装器

[str(sample) for sample in SAMPLES]

当输入到 shell 或脚本时,它变成了用空格连接的项目 A B .

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

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 .

接下来,您必须询问您想要的输出。这通常是蛇文件中的第一条规则,并称为全部:

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

同样, expand 会给你一个样本列表,在你的情况下,规则全部变成:
rule all:
input: 'A.out', 'B.out'

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

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

关于parameters - Snakemake:扩展参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60173518/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com