如何指定glob_wildcards获得的文件
假设我的sample1.txt、sample2.txt、sample3.txt和sample4.txt位于同一个目录中。
以下代码只是一个示例:
FILES = glob_wildcards("data/{sample}.txt")
SAMPLES = FILES.sample
rule all:
input:
expand("{sample}txt", sample=SAMPLES),
"concat.txt"
rule concat:
input:
SAMPLES[0],
SAMPLES[1]
output:
"concat.txt"
shell:
"cat {input[0]} {input[1]} > {output}"当我想连接rule concat中所示的sample1.txt和sample2.txt时,我如何指定这些文件?写SAMPLES[0]和SAMPLES[1]是正确的吗
发布于 2022-06-07 15:41:08
您几乎是正确的,但请记住,glob_wildcards只返回通配符值,所以当在规则中引用文件时,需要将这些通配符值提供到特定的文件路径中。
为了保持一致性,可以继续使用expand()。
file_pattern = 'data/{sample}.txt'
SAMPLES, = glob_wildcards(file_pattern)
rule all:
input:
expand(file_pattern, sample=SAMPLES),
"concat.txt"
rule concat:
input:
expand(file_pattern, sample=SAMPLES[:2]),
output:
"concat.txt"
shell:
"cat {input} > {output}"https://stackoverflow.com/questions/72525694
复制相似问题