Snakemake:通配符不会在规则的脚本行中扩展

发布于 2025-02-10 22:58:55 字数 555 浏览 2 评论 0原文

我正在运行管道,并试图通过在配置文件(config.yaml)中声明路径来对其进行优化。 config.yaml文件包含找到可以在管道内运行的脚本的路径,但是当我扩展路径的通配符时,管道不会运行脚本。脚本本身运行良好。 要解释我的问题:

rule with_script:
input: someinput
output: someoutput
script: expand("{script_path}/scriptfile", script_path = config[scriptpath])

输入,输出或规则都不包含脚本的路径通配符,因此这是我第一次宣布它。包含路径的config.yaml行看起来像:

scriptpath: /path/to/the/script

有没有一种方法可以维护通配符和配置文件路径(以使其他人更容易在需要时进行更改)并使脚本工作?就像这个snakemake甚至没有输入脚本文件。还是可以在规则之外宣布全球通配符?

感谢您的帮助!

PS:很抱歉,如果这个问题已经得到回答,但是我找不到任何帮助我的问题。

I am running a pipeline and was trying to optimize it by declaring the paths in a config file (config.yaml). The config.yaml file contains the path to find the scripts to run inside the pipeline, but when I expand the wildcard of the path, the pipeline does not run the script. The script itself runs fine.
To explain my problem:

rule with_script:
input: someinput
output: someoutput
script: expand("{script_path}/scriptfile", script_path = config[scriptpath])

input, output or rule all do not contain the script's path wildcard, so here is the first time I'm declaring it. The config.yaml line that contains the path looks like this:

scriptpath: /path/to/the/script

is there a way to maintain the wildcard and config file path (to make it easier for others to make changes if needed) and have the script work? Like this snakemake doesn't even enter the script file. Or maybe it is possible to declare global wildcards outside the rule all?

Thank you for your help!

P.S.: I'm sorry if this question has already been answered, but I couldn't find anything to help me with this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

想念有你 2025-02-17 22:58:55

您不能在脚本部分中定义expand()的函数。 Snakemake期望您的脚本有一条途径。
documentation>

脚本路径始终相对于包含指令的蛇依(与输入和输出文件路径相对于工作目录而言)。建议将所有脚本放入子文件夹“脚本”

如果您需要定义脚本的不同路径,则可以随时在规则之外的Python中进行操作。别忘了,在构建DAG之前,在规则之外执行了所有Python代码。因此,您可以定义所需的所有变量,并在规则中使用它们。

SCRIPTSPATH = config["scriptpath"]

rule with_script:
    input: someinput
    output: someoutput
    script: "{SCRIPTSPATH}/scriptfile"

注意:
请勿混合 wildcards 和“变量”。 在{script_path}的扩展函数中,

expand("{script_path}/scriptfile", script_path = config[scriptpath])

不是通配符,而只是占位符的占位符。

You cannot define a function like expand() in the script section. Snakemake expects a path to your script.
Like the documentation states:

The script path is always relative to the Snakefile containing the directive (in contrast to the input and output file paths, which are relative to the working directory). It is recommended to put all scripts into a subfolder "scripts"

If you need to define different paths to your scripts, you can always do it in python outside of your rules. Don't forget, all python code outside of rules is executed before building the DAG. Thus, you can define all variables you want and use them in your rules.

SCRIPTSPATH = config["scriptpath"]

rule with_script:
    input: someinput
    output: someoutput
    script: "{SCRIPTSPATH}/scriptfile"

Note:
Do not mix wildcards and "variables". In an expand function as

expand("{script_path}/scriptfile", script_path = config[scriptpath])

{script_path} is not a wildcard but just a placeholder for the values given in the second parameter of the function.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文