【发布时间】:2019-05-23 11:17:54
【问题描述】:
我正在尝试在循环中使用 Snakemake 规则,以便该规则将上一次迭代的输出作为输入。这可能吗?如果可以,我该怎么做?
这是我的例子
- 设置测试数据
mkdir -p test
echo "SampleA" > test/SampleA.txt
echo "SampleB" > test/SampleB.txt
- 蛇人
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}"
尝试运行该示例会产生错误CreateRuleException in line 26 of /Users/fabiangrammes/Desktop/Projects/snake_loop/Snakefile:
The name loop_rule is already used by another rule。如果有人发现可以让这件事发挥作用,那就太好了!
谢谢!
【问题讨论】: