4

I have 3 rules and their names are somewhat long. When using ruleorder, the line goes over my desired 80 character limit. Is it possible break up the ruleorder into multiple lines in such a way that the behaviour is exactly the same as if I wrote it all in one line?

Example:

ruleorder: long_rule_1 > long_rule_2 > long_rule_3

I would like to reformat it into something like this:

ruleorder: (
    long_rule_1 
    > long_rule_2 
    > long_rule_3
)
SultanOrazbayev
  • 14,900
  • 3
  • 16
  • 46
yippingAppa
  • 331
  • 1
  • 11

3 Answers3

3

To break the long lines it's possible to use \ as line continuation:

# Snakefile
rule all:
    input: '1.txt'

for k in list("abcde"):
    rule:
        name: k
        output: '1.txt'

ruleorder: a > b > c > \
        d > e
SultanOrazbayev
  • 14,900
  • 3
  • 16
  • 46
2

In addition to the answer from @SultanOrazbayev I would add that the syntax below also works:

ruleorder: long_rule_1 > long_rule_2
ruleorder: long_rule_2 > long_rule_3

That will work in your simple case, but is not fully equivalent to the ruleorder with all three rules in one line. Snakemake creates a list of ruleorders, and applies them one by one. Strictly speaking, there is a difference in applying one ruleorder of three rules and two ruleorders two rules each. This way you can even introduce cycles which is impossible in one line, so I would prefer a single ruleorder whenever possible.

Dmitry Kuzminov
  • 6,180
  • 6
  • 18
  • 40
  • I don't think this works anymore (it used to work in older snakemake versions, but when I try this syntax now I get an error)... could also be a bug (I'm using 7.20.0). – SultanOrazbayev Feb 01 '23 at 15:57
  • @SultanOrazbayev, what kind of *syntax* error do you get? This syntax is fully valid, aren't you disputing the syntax from the response of yippingAppa? – Dmitry Kuzminov Feb 01 '23 at 22:02
1

After looking at ways to do this, I believe the best way is pretty simple:

ruleorder:
    long_rule_1
    > long_rule_2
    > long_rule_3

The other answers are good too, but this is the one that I'm using

yippingAppa
  • 331
  • 1
  • 11