我想将Snakemake规则放在一个循环中以便规则可以将前一次迭代的输出作为输入。这个是否可能,如果是,如何实现?
下面是我的示例:
- 设置测试数据
mkdir -p test
echo "SampleA" > test/SampleA.txt
echo "SampleB" > test/SampleB.txt
- Snakemake
SAMPLES = ["SampleA", "SampleB"]
rule all:
input:
# Output of the final loop
expand("loop3/{sample}.txt", sample = SAMPLES)
#### LOOP ####
for i in list(range(1, 4)):
# Setup prefix for input
if i == 1:
prefix = "test"
else:
prefix = "loop%s" % str(i-1)
# Setup prefix for output
opref = "loop%s" % str(i)
# Rule
rule loop_rule:
input:
prefix+"/{sample}.txt"
output:
prefix+"/{sample}.txt"
#expand("loop{i}/{sample}.txt", i = i, sample = wildcards.sample)
params:
add=prefix
shell:
"awk '{{print $0, {params.add}}}' {input} > {output}"
尝试运行示例会出现错误:
/Users/fabiangrammes/Desktop/Projects/snake_loop/Snakefile
的第 26 行出现 CreateRuleException: 规则名 loop_rule 已被其他规则使用
。如果有人发现解决方法,请告诉我,谢谢!
wildcard_constraints
,我一直把它们编码在大括号里面。这真的很有帮助。 - Russ Hyde