例如,我有python脚本snakemake.py
:
from snakemake import snakemake
cfg={'a':'aaaa', 'b':'bbbb', 'c': 'cccc'}
snakemake(
'Snakefile',
targets=['all'],
printshellcmds=True,
forceall=True,
config=cfg,
# configfile=config,
keep_target_files=True,
keep_logger=False)
Snakefile
看起来像这样:
print(config)
print('------------------------------------------------------------------------------------------')
rule a:
output:
'a.out'
shell:
"echo %s ; "
"touch {output[0]}" % config['a']
rule b:
output:
'b.out'
shell:
"echo %s ; touch {output[0]}" % config['b']
rule c:
output:
'c.out'
run:
print(config['c'])
import os
os.system('touch ' + output[0])
rule all:
input:
'a.out', 'b.out', 'c.out'
当我运行python snakemake.py
时,我遇到了错误:
{'a': 'aaaa', 'c': 'cccc', 'b': 'bbbb'}
------------------------------------------------------------------------------------------
Provided cores: 1
Rules claiming more threads will be scaled down.
Job counts:
count jobs
1 a
1 all
1 b
1 c
4
rule c:
output: c.out
jobid: 1
{}
------------------------------------------------------------------------------------------
KeyError in line 8 of /Users/zech/Desktop/snakemake/Snakefile:
'a'
File "/Users/zech/Desktop/snakemake/Snakefile", line 8, in <module>
Will exit after finishing currently running jobs.
Exiting because a job execution failed. Look above for error message
当我从c.out
删除rule all
时,它运行得非常好。看起来规则中的每个run
块重置config
传递给snakemake
函数为空?这不是一种奇怪的行为吗?有没有解决方法?
我在最新的OSX上使用了snakemake 3.11.2版(从anaconda的bioconda频道安装)。
注意:运行snakemake命令行snakemake -p --keep-target-files all --config a="aaaa" b="bbb" c="cccc"
时运行正常。所以这看起来像API的问题。
答案 0 :(得分:0)
您的当前版本的Snakemake 是什么?
我使用 snakemake / 3.11.2 ,我的脚本没问题。
但是你必须知道每个规则的 params部分是调用configuration parameters
的正确方法。
在你的脚本中它应该是这样的:
rule a:
params:
name = config['a']
output:
'a.out'
shell:
"echo {params.name} ; "
"touch {output}"
rule b:
params:
name = config['b']
output:
'b.out'
shell:
"echo {params.name} ;"
"touch {output}"
rule c:
params:
name = config['c']
output:
'c.out'
run:
print(params.name)
import os
os.system('touch ' + output[0])