本文介绍了在 Snakemake 脚本中使用 argparse的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以将自定义命令行参数传递给 snakemake
脚本?我已经尝试过了,但是使用 argparse
执行 Snakefile 会导致错误 snakemake: error: unrecognized arguments: -zz
.下面是一个示例脚本.
导入 argparsedef get_args():parser = argparse.ArgumentParser(description='Compares Illumina and 10x VCFs using RTG vcfeval')# 必需的主要参数parser.add_argument('-zz', metavar='--filename', dest='fn', help='Filename', required=True)# 解析参数args = parser.parse_args()fn = args.fn返回 fnfn = get_args()规则测试_1:输入:fn + "/example.txt"贝壳:回声使用文件{输入}"
解决方案
从命令行传递参数是 可能使用 --config
.例如:
snakemake --config zz="文件名"
在snakefile脚本中,可以这样使用:
规则 test_1:输入:fn + 配置['zz']贝壳:回声使用文件{输入}"
查看文档了解更多信息.>
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!