I want to skip intermediate rules if their output file already exists.
For example, I want to skip the second rule if it ran before in this basic Snakefile:
rule third:
input:
"b",
"c"
output: "d"
shell: "touch {output}"
rule second:
input: ancient("b")
output: "c"
shell: "touch {output}"
rule first:
input: "a"
output: "b"
shell: "touch {output}"
After touching a, this pipeline works fine.
When I touch a again, I would expect that the second rule will be skipped, as the input is
flagged as ancient.
This is not what happens, instead the while pipeline is run again.
Flagging c in the third rule instead of b in the second rule as ancient also has no effect.
Update: Using the suggestion, I updated the Snakefile to skip the second rule if it ran before (and is not forced):
ruleorder: cached_c > second
rule third:
input:
"b",
"c"
output: "d"
shell: "touch {output}"
rule second:
input: "b"
output:
c = "c"
shell: '''
touch {output.c}
cp {output.c} cache
'''
rule cached_c:
input: "cache"
output: "c"
shell: "cp {input} {output}"
rule first:
input: "a"
output: "b"
shell: "touch {output}"