Search code examples
snakemake

Is it possible to enable/disable certain Snakemake rules using command line flags


Is it possible to have the snakemake file and/or the rules files configured to execute certain rules only in certain cases using command line switches.

To elaborate, lets say I have these rules in my rules folder:

  • rule 1
  • rule 2a
  • rule 2b
  • rule 2c
  • rule 3

Is it possible to configure/execute the workflow in this way:

  • call snakemake --user_option 2a will cause rule 1, rule 2a, rule 3 to be invoked
  • call snakemake --user_option 2b will cause rule 1, rule 2b, rule 3 to be invoked
  • and so on

Thanks in advance.


Solution

  • You could pass the user_option as a configuration key at the command line and then have an if-else that decides what intermediate rule to use. E.g.

    snakemake --config option='2a'
    

    The dummy Snakefile:

    rule all:
        input:
            'output.txt',
    
    rule one:
        output:
            'foo.txt'
    
    if config['option'] == '2a':
        rule two_a:
            input:
                'foo.txt',
            output:
                'bar.txt',
    elif config['option'] == '2b':
        rule two_b:
            input:
                'foo.txt',
            output:
                'bar.txt',
    else:
        sys.exit() ## handle this case
    
    rule three:
        input:
            'bar.txt',
        output:
            'output.txt',