如何在关键字wildcard_constraints中使用通配符

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

例如,我有以下通配符。

dataset = ['A1', 'A2', 'A3', 'B1', 'B2', 'B3']
group = ['A', 'B']

我正在尝试将我的数据集与我的小组禁止使用。例如,我想创建

A1 / file.A.txt A2 / file.A.txt A3 / file.A.txt B1 / file.B.txt ...

我写了以下规则,希望可以做到这一点

rule complex_conversion:
    input:
        "{dataset}/inputfile"
    output:
        "{dataset}/file.{group}.txt"
    wildcard_constraints:
        dataset = {group} + '\d+'
        #dataset = {wildcards.group} + '\d+'
    shell:
        "somecommand --group {wildcards.group}  < {input}  > {output}"

糟糕,我收到了错误

TypeError:unhashable type: 'list'
#NameError: name 'wildcards' is not defined

似乎{group}被视为传递关键字wildcard_constraints的列表。

[在wildcards_constrain中是否有使用通配符的方法或将数据集映射到组的替代方法。

wildcard snakemake
1个回答
0
投票

这不能回答您的问题,但可能会有所帮助...如果您的输出文件列表是datasetgroup的组合,我将首先创建该列表,然后将其用作输出文件列表:

dataset = ['A1', 'A2', 'A3', 'B1', 'B2', 'B3']
group = ['A', 'B']

# Use a for-loop or whatever to create this list:
datagrp = ['A1/file.A.txt','A2/file.A.txt', 'A3/file.A.txt', 'B1/file.B.txt']

wildcard_constraints:
    # This prevents wildcards to be interpreted as regexes
    dataset = '|'.join([x for x in dataset]),
    group = '|'.join([x for x in group])

rule all:
    input:
        datagrp,

rule complex_conversion:
    input:
        "{dataset}/inputfile"
    output:
        "{dataset}/file.{group}.txt"
    shell:
        "somecommand --group {wildcards.group}  < {input}  > {output}"
© www.soinside.com 2019 - 2024. All rights reserved.