Step 5 - Introduce an ID
If we can not guarantee the order of the different parallel branches, we should introduce a branch ID. This may be a label, a sample ID, a batch ID, etc. It’s the unit of parallelization.
// Step - 5
process addTuple {
input:
tuple val(id), val(input)
output:
tuple val("${id}"), val(output)
exec:
output = input + 1
}
workflow step5 {
Channel.from( [ 1, 2, 3 ] ) \
| map{ el -> [ el.toString(), el ]} \
| addTuple \
| view{ it }
}
We can run this code sample in the same way as the previous examples:
> nextflow -q run . -entry step5
WARN: DSL 2 IS AN EXPERIMENTAL FEATURE UNDER DEVELOPMENT -- SYNTAX MAY CHANGE IN FUTURE RELEASE
[3, 4]
[1, 2]
[2, 3]
Please note that the function to add 1 remains exactly the same, we only added the id
as the first element of the tuple in both input and output. As such we keep a handle on which sample is which, by means of the key in the tuple.
Note: Later, we will extend this tuple and add configuration parameters to it… but this was supposed to go step by step.