我一直在尝试创建可移植的snakemake包装器,该包装器在“ wrapper.py”脚本中执行预先创建的脚本。到目前为止,我发现的所有示例都从shell
调用snakemake.shell
来从命令行运行函数。因此,我认为等效的脚本是使用script
中的snakemake.script
来执行脚本。但是当我在规则中使用它时,它会引发如下错误:
Traceback (most recent call last):
File "/home/robertlink/stack_overflow_dummy_example/.snakemake/scripts/tmpqfzkhuv_.wrapper.py", line 7, in <module>
script("scripts/foo.py")
TypeError: script() missing 19 required positional arguments: 'basedir', 'input', 'output', 'params', 'wildcards', 'threads', 'resources', 'log', 'config', 'rulename', 'conda_env', 'container_img', 'singularity_args', 'env_modules', 'bench_record', 'jobid', 'bench_iteration', 'cleanup_scripts', and 'shadow_dir'
有没有一种方法可以轻松检索使用script
所需的信息?还是我误以为我应该以这种方式使用script
?这是复制消息的虚拟示例:
目录结构:
.
├── Snakefile
└── wrapper
└── path
├── scripts
│ ├── bar.py
│ └── foo.py
└── wrapper.py
Snakefile:
rule foobar:
output:
"foobar.txt"
wrapper:
"file:wrapper/path"
wrapper.py
from snakemake.script import script
script("scripts/foo.py")
script("scripts/bar.py")
foo.py
with open("foo_intermediate.txt", 'w') as handle:
handle.write("foo")
bar.py
with open("foo_intermediate.txt", 'w') as handle:
foo = handle.read()
foo += 'bar'
with open(snakemake.output) as handle:
handle.write(foo)
命令运行:
$ snakemake --cores 3
任何对此的见识都会很棒。谢谢!
答案 0 :(得分:0)
您无需编写包装即可调用脚本-脚本可以成为包装。也许看一看基于Rscript的包装器,就可以了:
https://snakemake-wrappers.readthedocs.io/en/latest/wrappers/tximport.html