此处给出的print()
示例
https://snakemake.readthedocs.io/en/stable/snakefiles/rules.html#local-rules
显示了如何显式列出应在主机节点上执行的规则。
是否可以在运行时添加规则,以工作流程的参数为条件?
例如看起来像下面的东西?
localrules:
我尝试了以下操作,并带有警告,指示my_local_rules = ['rule1', 'rule_2']
if condition:
my_local_rules.append('rule3')
localrules: my_local_rules
指令没有执行我想要的操作。
localrules
具体地说,它失败并显示以下错误:
local_rules_list = ['all']
if True:
local_rules_list.append('test')
localrules: local_rules_list
rule all:
input:
# The first rule should define the default target files
# Subsequent target rules can be specified below. They should start with all_*.
"results/test.out"
rule test:
input:
"workflow/Snakefile"
output:
"results/test.out"
shell:
"cp {input} {output}"
我的特定用例是同时具有本地模式和Cell Ranger的软件cluster mode。
在本地模式下,localrules directive specifies rules that are not present in the Snakefile:
local_rules_list
命令作为作业提交到计算节点上。
在群集模式下,cellranger
命令应在头节点上运行,因为cellranger
本身负责将作业提交给计算节点。
我希望我的工作流程让用户选择运行Cell Ranger的模式(例如cellranger
或local
),因此,如果sge
工作流程将添加以下规则:将mode: sge
运行到cellranger
。
这可能吗,还是只能在Snakefile中对本地规则进行硬编码?
最好, 凯文
答案 0 :(得分:0)
谢谢
@ Maarten-vd-Sande的post linked中建议的“ hack”对我来说很好。
在这个玩具示例中,我对建议的技巧进行了如下修改。 即:
all
是在localrules
指令中明确设置的test1
添加到使用hack的本地规则集中,表明使用了虚拟条件test2
是一个否定控件,任何时候都不会添加到本地规则列表中
# The main entry point of your workflow.
# After configuring, running snakemake -n in a clone of this repository should successfully execute a dry-run of the workflow.
report: "report/workflow.rst"
# Allow users to fix the underlying OS via singularity.
singularity: "docker://continuumio/miniconda3"
localrules: all
rule all:
input:
# The first rule should define the default target files
# Subsequent target rules can be specified below. They should start with all_*.
"results/test1.out",
"results/test2.out"
rule test1:
input:
"workflow/Snakefile"
output:
"results/test1.out"
shell:
"cp {input} {output}"
rule test2:
input:
"workflow/Snakefile"
output:
"results/test2.out"
shell:
"cp {input} {output}"
include: "rules/common.smk"
include: "rules/other.smk"
# Conditionally add rules to the directive 'localrules'
_localrules = list(workflow._localrules) # get the local rules so far
if True: # set condition here
_localrules.append('test1') # add rules as required
workflow._localrules = set(_localrules) # set the updated local rules
谢谢!