snakemake - 在snakemake中运行带有通配符的外部脚本
问题描述
我正在尝试使用包含通配符的外部脚本运行snakemake 规则,如snakemake rethedocs中所述。但是我在运行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"
推荐阅读
- azure-sql-database - Azure SQL 支持堆还是仍然需要聚集索引?
- c - 在 Linux 上使用 sigwaitinfo 无法同步捕获 SIGCHLD
- asp.net-mvc - C#剃须刀选择2禁用
- c# - 无法在 asp.net Core 3.0 Web 应用程序中访问命令 dotnet ef
- html - 修复与标题高度重叠的菜单项
- python - python bokeh保存问题和标签消失,并显示问题
- java - 谷歌地图片段滚动和拖动生涩
- matlab - 在 Matlab 中对 y 轴标签进行分组
- visual-studio - LuaRock Visual Studio 命令提示错误
- ajax - 即使使用 Ajax Listener 也提交了整个表单