[英]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.