如何在Snakemake中进行部分扩展? [英] How to do a partial expand in Snakemake?
问题描述
我尝试先为LETTERS x NUMS组合生成4个文件,然后对NUMS进行汇总,以在LETTERS中为每个元素获取一个文件:
I'm trying to first generate 4 files, for the LETTERS x NUMS combinations, then summarize over the NUMS to obtain one file per element in LETTERS:
LETTERS = ["A", "B"]
NUMS = ["1", "2"]
rule all:
input:
expand("combined_{letter}.txt", letter=LETTERS)
rule generate_text:
output:
"text_{letter}_{num}.txt"
shell:
"""
echo "test" > {output}
"""
rule combine text:
input:
expand("text_{letter}_{num}.txt", num=NUMS)
output:
"combined_{letter}.txt"
shell:
"""
cat {input} > {output}
"""
执行此蛇文件会导致以下错误:
Executing this snakefile results in the following error:
WildcardError in line 19 of /tmp/Snakefile:
No values given for wildcard 'letter'.
File "/tmp/Snakefile", line 19, in <module>
似乎不可能部分expand
.是expand
的限制吗?如果是这样,我应该如何规避呢?
It seems that partial expand
is not possible. Is it a limitation of expand
? If so, how should I circumvent it ?
推荐答案
似乎这不是expand
的限制,而是我对python字符串格式工作方式的熟悉程度的限制.对于非扩展的通配符,我需要使用双括号:
It seems that this is not a limitation of expand
, but a limitation of my familiarity with the way string-formatting works in python. I need to use double brackets for the non-expanded wildcard:
LETTERS = ["A", "B"]
NUMS = ["1", "2"]
rule all:
input:
expand("combined_{letter}.txt", letter=LETTERS)
rule generate_text:
output:
"text_{letter}_{num}.txt"
shell:
"""
echo "test" > {output}
"""
rule combine text:
input:
expand("text_{{letter}}_{num}.txt", num=NUMS)
output:
"combined_{letter}.txt"
shell:
"""
cat {input} > {output}
"""
现在执行此蛇文件会生成预期的以下文件:
Executing this snakefile now generates the expected following files:
text_A_2.txt
text_A_1.txt
text_B_2.txt
text_B_1.txt
combined_A.txt
combined_B.txt
这篇关于如何在Snakemake中进行部分扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!