gli*_*ihm 5 python-3.x snakemake
有没有办法在snakemake中重用规则,仅更改params?
例如:
rule job1:
...
params:
reference = "path/to/ref1"
...
rule job2:
input: rules.job1.output
...
params:
reference = "path/to/ref2"
Run Code Online (Sandbox Code Playgroud)
job1和job2规则正在做同样的事情,但我需要连续调用它们并且reference必须修改参数。它为非常相似的任务生成大量代码。
我尝试为这一步制作一个子工作流程,并且主 Snakefile 更具可读性。然而,子工作流程代码仍然重复。
有什么想法或建议吗?我错过了什么?
编辑
更具体地说,job2 必须在 job1 之后执行,使用后者的输出。
如果规则相同,您可以在输出文件的命名中使用通配符。这样,相同的规则将被执行两次:
references = ["ref1", "ref2"]
rule all:
input: expand("my_output_{ref}", ref=references)
rule job:
input: "my_input"
output: "my_output_{ref}"
params: ref = "path/to/{ref}"
shell: "... {params.ref} {output}"
Run Code Online (Sandbox Code Playgroud)
希望这会有所帮助,如果没有,您能否让您的问题更具体一些?
编辑
好的,可以使用 python 函数为规则定义自定义输入。也许你可以朝这个方向发展。请参阅此工作示例:
references = ["ref1", "ref2"]
rule all:
input: expand("my_output_{ref}", ref=references)
def rule_input(wildcards):
if (wildcards.ref == "ref1"):
input = "my_first_input"
elif (wildcards.ref == "ref2"):
input = "my_output_ref1"
return(input)
rule job:
input: rule_input
output: "my_output_{ref}"
params: ref = "path/to/{ref}"
shell: "echo input: {input} ; echo output: {output} ; touch {output}"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1892 次 |
| 最近记录: |