簡體   English   中英

如何在snakemake包裝器中訪問snakefile中定義的變量?

[英]How to access variables defined in the snakefile in a snakemake wrapper?

我想編寫一個snakemake 包裝器,能夠根據主snakefile中定義的變量值調整其行為。

這似乎不起作用,當我嘗試在包裝器中使用這樣的變量時,我得到一個NameError

特別是,我希望在使用這種機制將一些程序放入PATH的集群上運行時,根據配置中定義的信息,使用包裝器添加module load ...module unload ...命令來執行shell命令文件:

在主要的snakefile中:

load_modules = False
# By default, cluster nodes are expected
# to have names starting with "tars"
cluster_prefix = config.get("cluster_prefix", "tars")
if cluster_prefix:
    from socket import gethostname
    if gethostname().startswith(cluster_prefix):
        load_modules = True

# ...

rule ...:
    # ...
    wrapper:
        "file://path/to/the/wrapper/folder"

然后,在相應的wrapper.py文件中:

if load_modules:
    # ...

這導致:

NameError: name 'load_modules' is not defined

是否有可能使包裝器知道一些變量而不通過規則中的額外params段?

一種不需要在規則的params部分添加內容的可能性是將變量存儲在config ,可以在snakemake包裝器中以snakemake.config

例如,在snakefile中:

# By default, cluster nodes are expected
# to have names starting with "tars"
cluster_prefix = config.get("cluster_prefix", "tars")
if cluster_prefix:
    from socket import gethostname
    if gethostname().startswith(cluster_prefix):
        config["load_modules"] = True

# ...

rule ...:
    # ...
    wrapper:
        "file://path/to/the/wrapper/folder"

wrapper.py

load_modules = snakemake.config.get("load_modules", False)
if load_modules:
    # ...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM