snakemake:从数组写入文件
snakemake: write files from an array
我有一个数组 xx = [1,2,3]
,我想使用 Snakemake 创建一个(空)文件列表 1.txt, 2.txt, 3.txt
。
这是我使用的 Snakefile:
xx = [1,2,3]
rule makefiles:
output: expand("{f}.txt", f=xx)
run:
with open(output, 'w') as file:
file.write('blank')
然而,我的文件夹中并没有出现三个闪亮的新文本文件,而是出现了一条错误消息:
expected str, bytes or os.PathLike object, not OutputFiles
不确定我做错了什么。
迭代output
获取文件名,然后写入它们。参见 relevant documentation here。
rule makefiles:
output: expand("{f}.txt", f=xx)
run:
for f in output:
with open(f, 'w') as file:
file.write('blank')
重写上面的规则,通过 defining target files 在 rule all
中并行化:
rule all:
expand("{f}.txt", f=xx)
rule makefiles:
output:
"{f}.txt"
run:
with open(output[0], 'w') as file:
file.write('blank')
我有一个数组 xx = [1,2,3]
,我想使用 Snakemake 创建一个(空)文件列表 1.txt, 2.txt, 3.txt
。
这是我使用的 Snakefile:
xx = [1,2,3]
rule makefiles:
output: expand("{f}.txt", f=xx)
run:
with open(output, 'w') as file:
file.write('blank')
然而,我的文件夹中并没有出现三个闪亮的新文本文件,而是出现了一条错误消息:
expected str, bytes or os.PathLike object, not OutputFiles
不确定我做错了什么。
迭代output
获取文件名,然后写入它们。参见 relevant documentation here。
rule makefiles:
output: expand("{f}.txt", f=xx)
run:
for f in output:
with open(f, 'w') as file:
file.write('blank')
重写上面的规则,通过 defining target files 在 rule all
中并行化:
rule all:
expand("{f}.txt", f=xx)
rule makefiles:
output:
"{f}.txt"
run:
with open(output[0], 'w') as file:
file.write('blank')