使用`name`指令时,有没有办法在Sankemake中获取`rules`中的规则名称?

问题描述 投票:0回答:1

桑克马克版本:

❯ snakemake --version
8.20.6

意外行为

rule all:
    input:
        "test2"

rule:
    name: "test",
    output:
        "test",
    shell:
        "touch {output} "

rule:
    name: "test2",
    input: rules.test.output,
    # input: rules._rules["2"].output,
    output:
        "test2",
    shell:
        "touch {output} "

上面的代码会引发错误:

❯ snakemake -n
WorkflowError in file /bioproj/analysis/11.metagenomics/11.genek/Snakefile, line 14:
Rule test is not defined in this workflow. Available rules: all, 2

虽然我可以使用

rules._rules["2"].output
访问输出,但这种方法似乎不合适,因为
"2"
是可变的。

问题

有没有办法获得

rules.test.output
或达到类似的目标?

python snakemake
1个回答
0
投票

我发现我可以像下面这样写,它有效!但我不确定这样做是否有危险,有人可以给我一些建议吗?

rule all:
    input:
        "test2"

rule a:
    name: "test",
    output:
        "test",
    shell:
        "touch {output} "

rule b:
    name: "test2",
    input: rules.a.output,
    output:
        "test2",
    shell:
        "touch {output} "

日志:

Building DAG of jobs...
Using shell: /usr/bin/bash
Provided cores: 16
Rules claiming more threads will be scaled down.
Job stats:
job      count
-----  -------
all          1
test         1
test2        1
total        3

Select jobs to execute...
Execute 1 jobs...

[Sat Oct 12 14:33:20 2024]
localrule test:
    output: test
    jobid: 2
    reason: Missing output files: test
    resources: tmpdir=/tmp

touch test
[Sat Oct 12 14:33:20 2024]
Finished job 2.
1 of 3 steps (33%) done
Select jobs to execute...
Execute 1 jobs...

[Sat Oct 12 14:33:20 2024]
localrule test2:
    input: test
    output: test2
    jobid: 1
    reason: Missing output files: test2; Input files updated by another job: test
    resources: tmpdir=/tmp

touch test2
[Sat Oct 12 14:33:20 2024]
Finished job 1.
2 of 3 steps (67%) done
Select jobs to execute...
Execute 1 jobs...

[Sat Oct 12 14:33:20 2024]
localrule all:
    input: test2
    jobid: 0
    reason: Input files updated by another job: test2
    resources: tmpdir=/tmp

[Sat Oct 12 14:33:20 2024]
Finished job 0.
3 of 3 steps (100%) done
Complete log: .snakemake/log/2024-10-12T143320.208718.snakemake.log

© www.soinside.com 2019 - 2024. All rights reserved.