Indeed, it would be nice if snakemake had a flag which looked for missing intermediate results and regenerates them if missing (an all it's dependencies).
I'm not aware of such an option, but there are some workarounds.
Note, the -R
option suggested by m00am and Jon Chung will regenerate all other files reagardless of wheather intermediate files are missing or not. So this is not ideal at all.
Workaround 1: Force recreation of file
Force recreation of the intermediate file using -R
or -f
flag (help copied below). The key here to be explicit targetting the file rather than the rule.
snakemake -s test.sf testA1.txt # only works if testA1.txt was deleted
# or
snakemake -s test.sf -R testA1.txt # testA1.txt can be present or absent
# or
snakemake -s test.sf -f testA1.txt
# or
snakemake -s test.sf -F testA1.txt
Note, the later for the latter two, the pipeline need to be run again to update dependencies:
snakemake -s test.sf
prevent update of dependent files (by touching files)
If you don't want the dependent files (i.e. testB1.txt, testC1.txt) to be updated there are also options.
You could regenerate testA1.txt and then "reset" it's modification time, e.g. to the source file which will prevent the pipeline to update anything:
snakemake -s test.sf -f testA1.txt
touch testA1.txt -r test1.txt
snakemake -s test.sf
now won't to anything since testB1.txt
is newer than testA1.txt
Or you could mark the dependent files (i.e. testB1.txt, testC1.txt) as "newer" using --touch
:
snakemake -s test.sf -f testA1.txt
snakemake -s test.sf --touch
Workaround 2: Creating a new rule
The snakefile could be extended by a new rule:
rule A_all:
input: "testA1.txt", "testA2.txt"
Which could then be called like so:
snakemake A_all -s test.sf
This will only generate testA1.txt
, similar to -f
in the workflow above, so the the pipline needs to be rerun or the modification time can to be changed.
A trick might to "update" a intermediate file using --touch
snakemake -s test.sf --touch testA1.txt -n
This will "update" testA1.txt
. To recreate the dependent files snakemake needs to be run as normal afterwards:
snakemake -s test.sf
Note this will not work if testA1.txt
was deleted, this needs to be done instead of deletion.
Relevant help on used parameters:
--touch, -t Touch output files (mark them up to date without
really changing them) instead of running their
commands. This is used to pretend that the rules were
executed, in order to fool future invocations of
snakemake. Fails if a file does not yet exist.
--force, -f Force the execution of the selected target or the
first rule regardless of already created output.
--forceall, -F Force the execution of the selected (or the first)
rule and all rules it is dependent on regardless of
already created output.
--forcerun [TARGET [TARGET ...]], -R [TARGET [TARGET ...]]
Force the re-execution or creation of the given rules
or files. Use this option if you changed a rule and
want to have all its output in your workflow updated.