snakemake 中的 ambiguousruleexception,两个分支的 parms 崩溃

ambiguousruleexception in snakemake, parms crash of two branches

我的第一个 运行 中有两个 类 样本要由不同的参数处理,然后在第二个 运行 中将它们合并在一起。像下面的例子:

SAMPLES = ['1', '2', '3']
CLASS1 = ['1', '2']
CLASS2 = ['3']

rule all:
    input:
        expand('{class1}.first.txt', class1 = CLASS1),
        expand('{class2}.first.txt', class2 = CLASS2),
        expand('{sample}.second.tx', sample = SAMPLES)

rule first_CLASS1:
    input:
        '{class1}.txt'
    output:
        '{class1}.first.txt'
    shell:
        'touch {wildcards.class1}.first.txt'

rule first_CLASS2:
    input:
        '{class2}.txt'
    output:
        '{class2}.first.txt'
    shell:
        'touch {wildcards.class2}.first.txt'

rule second:
    input:
        '{sample}.first.txt'
    output:
        '{sample}.second.txt'
    shell:
        'touch {wildcards.sample}.second.txt'

但我得到了这样的 AmbiguousRuleException:

AmbiguousRuleException:
Rules first_CLASS2 and first_CLASS1 are ambiguous for the file 1.first.txt.
Consider starting rule output with a unique prefix, constrain your wildcards, or use the ruleorder directive.
Wildcards:
    first_CLASS2: class2=1
    first_CLASS1: class1=1
Expected input files:
    first_CLASS2: 1.txt
    first_CLASS1: 1.txtExpected output files:
    first_CLASS2: 1.first.txt
    first_CLASS1: 1.first.txt

我声明了

expand('{class2}.first.txt', class2 = CLASS2)

在 运行 全部,以及 CLASS2 = ['3']。 然而它报告class2 = 1,这让我很困惑。

我认为这是因为 {class1}.first.txt{class2}.first.txt 共享相同的常数部分,即 .first.txt 并且正如错误消息所暗示的那样,它们不是唯一的。您可以通过在规则 all:

之前放置通配符来解决它
wildcard_constraints:
    class1= '|'.join([re.escape(x) for x in CLASS1]),
    class2= '|'.join([re.escape(x) for x in CLASS2]),

另见我在 https://groups.google.com/forum/#!msg/snakemake/wVlJW9X-9EU/gSZh4U0_CQAJ 提出的这个问题。就我个人而言,如果约束是默认行为,我更愿意...