如何解决在snakemake中使用通配符运行外部脚本
我正在尝试使用包含蛇形 reathedocs 中所述的通配符的外部脚本运行蛇形规则。但是我在运行 snakemake 时遇到了 KeyError。
例如,如果我们有以下规则:
SAMPLE = ['test']
rule all:
input:
expand("output/{sample}.txt",sample=SAMPLE)
rule NAME:
input: "workflow/scripts/{sample}.R"
output: "output/{sample}.txt",script: "workflow/scripts/{wildcards.sample}.R"
使用包含以下代码的脚本 workflow/scripts/test.R
out.path = snakemake@output[[1]]
out = "Hello World"
writeLines(out,out.path)
我在尝试执行 snakemake 时收到以下错误。
Building DAG of jobs...
Using shell: /usr/bin/bash
Provided cores: 1 (use --cores to define parallelism)
Rules claiming more threads will be scaled down.
Job counts:
count jobs
1 NAME
1 all
2
[Fri May 21 12:04:55 2021]
rule NAME:
input: workflow/scripts/test.R
output: output/test.txt
jobid: 1
wildcards: sample=test
[Fri May 21 12:04:55 2021]
Error in rule NAME:
jobid: 1
output: output/test.txt
RuleException:
KeyError in line 14 of /sc/arion/projects/LOAD/Projects/sandbox/Snakefile:
'wildcards'
File "/sc/arion/work/andres12/conda/envs/py38/lib/python3.8/site-packages/snakemake/executors/__init__.py",line 2231,in run_wrapper
File "/sc/arion/projects/LOAD/Projects/sandbox/Snakefile",line 14,in __rule_NAME
File "/sc/arion/work/andres12/conda/envs/py38/lib/python3.8/site-packages/snakemake/executors/__init__.py",line 560,in _callback
File "/sc/arion/work/andres12/conda/envs/py38/lib/python3.8/concurrent/futures/thread.py",line 57,in run
File "/sc/arion/work/andres12/conda/envs/py38/lib/python3.8/site-packages/snakemake/executors/__init__.py",line 546,in cached_or_run
File "/sc/arion/work/andres12/conda/envs/py38/lib/python3.8/site-packages/snakemake/executors/__init__.py",line 2262,in run_wrapper
Shutting down,this might take some time.
Exiting because a job execution failed. Look above for error message
Complete log: /sc/arion/projects/LOAD/Projects/sandbox/.snakemake/log/2021-05-21T120454.713963.snakemake.log
有人知道为什么这不能正常工作吗?
解决方法
我同意 Dmitry Kuzminov 的观点,即脚本依赖于通配符是很奇怪的。也许有更好的解决方案。
无论如何,下面的这个在snakemake 6.0.0上对我有用。请注意,在您的 R 脚本中,snakemake@output[1]
应该是 snakemake@output[[1]]
,但这并没有给出您报告的问题。
SAMPLE = ['test']
rule all:
input:
expand("output/{sample}.txt",sample=SAMPLE)
rule make_script:
output:
"workflow/scripts/{sample}.R",shell:
r"""
echo 'out.path = snakemake@output[[1]]' > {output}
echo 'out = "Hello World"' >> {output}
echo 'writeLines(out,out.path)' >> {output}
"""
rule NAME:
input:
"workflow/scripts/{sample}.R"
output:
"output/{sample}.txt",script:
"workflow/scripts/{wildcards.sample}.R"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。