Use of argparse in Snakemake script

1.7k views Asked by At

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}"
1

There are 1 answers

0
Manavalan Gajapathy On BEST ANSWER

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.