You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This example uses shell **conditional statement** (if/then/elif/else) in the Snakefile to select one of several commands to run, which is specified in the **config file**.
456
+
457
+
#### config.yaml
458
+
459
+
```
460
+
# parameters
461
+
option: a # choose from: a, b, c
462
+
```
463
+
464
+
The parameter `option` is a string that will be used in a string comparison in the Snakefile.
465
+
466
+
#### Snakefile
467
+
468
+
```
469
+
configfile: "config.yaml"
470
+
471
+
rule choose_from_options:
472
+
params:
473
+
option=config["option"]
474
+
shell:
475
+
"if [ {params.option} == 'a' ]; then "
476
+
" echo 'Doing option a...'; "
477
+
"elif [ {params.option} == 'b' ]; then "
478
+
" echo 'Doing option b...'; "
479
+
"elif [ {params.option} == 'c' ]; then "
480
+
" echo 'Doing option c...'; "
481
+
"else "
482
+
" echo 'Doing default option'; "
483
+
"fi"
484
+
```
485
+
486
+
At the top of the Snakefile, we define the config file.
487
+
488
+
The rule `choose_from_options` gets the `option` parameter from the config file. The shell command then uses a conditional statement (if/then/elif/else) to execute different code for each of the accepted options, or the default code if an unaccepted option is provided.
0 commit comments