4

Is it possible to pass custom command line arguments to snakemake scripts? I have tried, but executing Snakefile with argparse results in error snakemake: error: unrecognized arguments: -zz. Below is an example script.

import argparse

def get_args():
    parser = argparse.ArgumentParser(description='Compares Illumina and 10x VCFs using RTG vcfeval')

    # required main arguments
    parser.add_argument('-zz', metavar='--filename', dest='fn', help='Filename', required=True)

    # parse arguments
    args = parser.parse_args()

    fn = args.fn
    return fn

fn = get_args()

rule test_1:
    input:
        fn + "/example.txt"
    shell:
        "echo Using file {input}"
Manavalan Gajapathy
  • 3,900
  • 2
  • 20
  • 43
  • How are you invoking this script? Normally I'd expect to see: `python your_script.py -zz afilename`. – hpaulj Aug 31 '17 at 00:05
  • 1
    Found the solution. Allows it via `--config`. [Source](http://snakemake.readthedocs.io/en/stable/project_info/faq.html#is-it-possible-to-pass-variable-values-to-the-workflow-via-the-command-line) – Manavalan Gajapathy Aug 31 '17 at 00:17

1 Answers1

8

Passing arguments from command line is possible using --config. For example:

snakemake --config zz="filename"

In snakefile script, this can be used in this way:

rule test_1:
    input:
        fn + config['zz']
    shell:
        "echo Using file {input}"

See the doc for more info.

Manavalan Gajapathy
  • 3,900
  • 2
  • 20
  • 43