且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Snakemake脚本中使用argparse

更新时间:2023-12-05 21:14:58

从命令行传递参数为

在snakefile脚本中,可以通过以下方式使用:

 规则test_1:输入:fn + config ['zz']壳:使用文件{input}回显" 

有关详细信息,请参阅文档.>

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.