在Snakemake脚本中使用argparse [英] Use of argparse in Snakemake script
本文介绍了在Snakemake脚本中使用argparse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以将自定义命令行参数传递给 snakemake
脚本?我已经尝试过,但是用 argparse
执行Snakefile会导致错误 snakemake:错误:无法识别的参数:-zz
.下面是一个示例脚本.
import argparsedef get_args():parser = argparse.ArgumentParser(description ='使用RTG vcfeval比较Illumina和10x VCF')#必需的主要参数parser.add_argument('-zz',metavar ='-filename',dest ='fn',help ='Filename',required = True)#解析参数args = parser.parse_args()fn = args.fn返回fnfn = get_args()规则test_1:输入:fn +"/example.txt"壳:使用文件{input}回显"
解决方案
在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.
这篇关于在Snakemake脚本中使用argparse的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文