Snakemake appears to traverse the DAG in a breadth-first manner. Is it possible (e.g. through an option / flag / etc.) to force snakemake to traverse the DAG depth-first?
Asked
Active
Viewed 343 times
4
-
How would that be possible to generate a file when the dependences are not generated yet? Overall, what problem are you trying to solve? – Dmitry Kuzminov Oct 02 '20 at 22:38
-
1@DmitryKuzminov Say I have input files _A_, _B_ and _C_. **Rule 1** generates corresponding files _A_preproc_, _B_preproc_ and _C_preproc_. **Rule 2** generates _A_final_, _B_final_ and _C_final_ using each of the *_preproc files. There are now two option to traverse the resulting DAG: (1) First generate all *_preproc files and then all *_final files OR (2) generate A_preproc, followed by A_final, THEN generate B_preproc and B_final, etc. The first traverse order I would call breadth-first, while the second is rather depth-first. I hope this clears things up :) – Scholar Oct 03 '20 at 09:16
1 Answers
5
One way I can come up with is by setting priorities for each rule:
rule all:
input:
["third_a.txt", "third_b.txt", "third_c.txt"]
rule first:
output:
touch("first_{sample}.txt")
priority: 1
rule second:
input:
rules.first.output
output:
touch("second_{sample}.txt")
priority: 2
rule third:
input:
rules.second.output
output:
touch("third_{sample}.txt")
priority: 3
and if you now run it with snakemake -j 1
it is executed depth-first!

Maarten-vd-Sande
- 3,413
- 10
- 27