我想使用snakemake运行第一个规则的一个实例,该规则接受一个输入文件并创建多个输出文件。然后,我想将每个输出文件作为第二条规则的输入。我只想运行第一个规则的一个实例,以避免不必要地重复此规则,因为创建输出只需要一个。
这里是一个过于简化的示例:
说我有一个包含以下内容的输入文件samplenames.txt:
sample1
sample2
我想从该文件中获取文件名,并为每个文件创建一个相同的名称。然后,我想使用以下最终输出文件制作每个副本:
sample1_copy
sample2_copy
我的Snakefile包含以下内容:
SAMPLES = [1,2]
rule all:
input:
expand(
"sample{sample}_copy",
sample=SAMPLES
)
rule fetch_filenames:
input:
"samplenames.txt"
output:
"sample{sample}"
shell:
"while IFS= read -r line; do touch $line; done < {input}"
rule copy_files:
input:
expand(
"sample{sample}",
sample=SAMPLES
)
output:
expand(
"sample{sample}_copy",
sample=SAMPLES
)
shell:
"touch {output}"
这可以完成工作,但是当仅需要一个规则时,将完成第一个规则的两个实例。当我在更复杂的工作流程中将其应用于更多文件时,会导致许多不必要的实例。是否有一种仅运行第一个规则的实例的运行方式?
我已经尝试了以下第一条规则:
rule fetch_filenames:
input:
"samplenames.txt"
output:
"sample1"
shell:
"while IFS= read -r line; do touch $line; done < {input}"
但是这会导致以下错误:“缺少规则copy_files的输入文件:sample2“
我很伤心。任何帮助都会让我很高兴。
如果要fetch_filenames
在一次执行中生成所有输出文件,则应在output
指令中列出所有必需的输出文件。例如:
rule fetch_filenames:
input:
"samplenames.txt"
output:
expand("sample{sample}", sample= SAMPLES),
shell:
...
相反,如果您希望对每个输入/输出对执行一次copy_files
,则删除扩展功能:
rule copy_files:
input:
"sample{sample}",
output:
"sample{sample}_copy",
shell:
...