如何在包装器中使用snakemake.script?

时间:2020-10-15 20:13:13

标签: snakemake

我一直在尝试创建可移植的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

任何对此的见识都会很棒。谢谢!

1 个答案:

答案 0 :(得分:0)

您无需编写包装即可调用脚本-脚本可以成为包装。也许看一看基于Rscript的包装器,就可以了:

https://snakemake-wrappers.readthedocs.io/en/latest/wrappers/tximport.html