简体   繁体   中英

Use of argparse in Snakemake script

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM