For example, I have the following wildcards.
JavaScript
x
3
1
dataset = ['A1', 'A2', 'A3', 'B1', 'B2', 'B3']
2
group = ['A', 'B']
3
I am trying to contrain my dataset with my group. for example, I want to create
A1/file.A.txt A2/file.A.txt A3/file.A.txt B1/file.B.txt …
I wrote a following rule hoping to make that possible
JavaScript
1
11
11
1
rule complex_conversion:
2
input:
3
"{dataset}/inputfile"
4
output:
5
"{dataset}/file.{group}.txt"
6
wildcard_constraints:
7
dataset = {group} + 'd+'
8
#dataset = {wildcards.group} + 'd+'
9
shell:
10
"somecommand --group {wildcards.group} < {input} > {output}"
11
oops, I got the error
JavaScript
1
3
1
TypeError:unhashable type: 'list'
2
#NameError: name 'wildcards' is not defined
3
It seems like that the {group} is regarded as a list to pass in the keywords wildcard_constraints.
Are there any methods to use wildcards in wildcards_constrain or alternative to mapped the dataset to group.
Advertisement
Answer
This doesn’t answer your question but maybe it helps… If your list of output files is a combination of dataset
and group
, I would create that list first and then use it as list of output files:
JavaScript
1
23
23
1
dataset = ['A1', 'A2', 'A3', 'B1', 'B2', 'B3']
2
group = ['A', 'B']
3
4
# Use a for-loop or whatever to create this list:
5
datagrp = ['A1/file.A.txt','A2/file.A.txt', 'A3/file.A.txt', 'B1/file.B.txt']
6
7
wildcard_constraints:
8
# This prevents wildcards to be interpreted as regexes
9
dataset = '|'.join([x for x in dataset]),
10
group = '|'.join([x for x in group])
11
12
rule all:
13
input:
14
datagrp,
15
16
rule complex_conversion:
17
input:
18
"{dataset}/inputfile"
19
output:
20
"{dataset}/file.{group}.txt"
21
shell:
22
"somecommand --group {wildcards.group} < {input} > {output}"
23