我想使用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:
...
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句