2
$\begingroup$

Below is the code from nextflow site (https://www.nextflow.io/docs/edge/operator.html#grouptuple).

For the output, the first is A B C, and the second is C, A.

Is there a way to make the output like this

[1, [A, B, C]] [2, [A, C]]

That is, the stuff inside [] is in some order.

Channel
    .of(
        [1, 'A'],
        [1, 'B'],
        [2, 'C'],
        [3, 'B'],
        [1, 'C'],
        [2, 'A'],
        [3, 'D']
    )
    .groupTuple()
    .view()

[1, [A, B, C]]
[2, [C, A]]
[3, [B, D]]

$\endgroup$

1 Answer 1

2
$\begingroup$

You can change the sorting criteria for the grouped items using the sort keyword. To perform a natural sort, just use sort: true. For example:

Channel.of(
    [1, 'A'],
    [1, 'B'],
    [2, 'C'],
    [3, 'B'],
    [1, 'C'],
    [2, 'A'],
    [3, 'D']
)
.groupTuple(sort: true)
.view()

Results:

$ nextflow run main.nf 
N E X T F L O W  ~  version 22.04.0
Launching `main.nf` [special_darwin] DSL2 - revision: 2e641ccfd9
[1, [A, B, C]]
[2, [A, C]]
[3, [B, D]]

Otherwise, a custom sorting criteria can be specified using a closure.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.