Consider the following simple snakefile, which is an attempt to write a file in a run
instruction:
rule all:
input:
"test.txt"
rule make_test:
output:
filename = "test.txt"
run:
with open(output.filename) as f:
f.write("test")
Running it results in the following:
Provided cores: 1
Rules claiming more threads will be scaled down.
Job counts:
count jobs
1 all
1 make_test
2
rule make_test:
output: test.txt
Error in job make_test while creating output file test.txt.
RuleException:
FileNotFoundError in line 10 of /tmp/Snakefile:
[Errno 2] No such file or directory: 'test.txt'
File "/tmp/Snakefile", line 10, in __rule_make_test
Will exit after finishing currently running jobs.
Exiting because a job execution failed. Look above for error message
I'm surprised of this FileNotFoundError
. Obviously, I didn't find the correct way to tell snakemake that this is the file I want the rule make_test
to create.
I also tried the following modification of the output syntax:
rule all:
input:
"test.txt"
rule make_test:
output:
"test.txt"
run:
with open(output[0]) as f:
f.write("test")
The error is the same.
What's happening?
I found the reason for the bug: I had simply forgotten to open the file in write mode:
rule all: input: "test.txt"
The following works:
rule make_test:
output:
"test.txt"
run:
with open(output[0], "w") as f:
f.write("test")