<p>You can change the sorting criteria for the grouped items using the <code>sort</code> keyword. To perform a <em>natural</em> sort, just use <code>sort: true</code>. For example:</p>
<pre><code>Channel.of(
    [1, 'A'],
    [1, 'B'],
    [2, 'C'],
    [3, 'B'],
    [1, 'C'],
    [2, 'A'],
    [3, 'D']
)
.groupTuple(sort: true)
.view()
</code></pre>
<p>Results:</p>
<pre><code>$ 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]]
</code></pre>
<p>Otherwise, a custom sorting criteria can be specified using a closure.</p>

CC BY-SA 4.0
2023-03-15T04:08:24.417Z
2023-03-15T04:08:24.417Z
Steve
<p>Below is the code from nextflow site (<a href="https://www.nextflow.io/docs/edge/operator.html#grouptuple" rel="nofollow noreferrer">https://www.nextflow.io/docs/edge/operator.html#grouptuple</a>).</p>
<p>For the output, the first is A B C, and the second is C, A.</p>
<p>Is there a way to make the output like this</p>
<p>[1, [A, B, C]]
[2, [A, C]]</p>
<p>That is, the stuff inside [] is in some order.</p>
<pre><code>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]]

</code></pre>

<nextflow>
file order after nextflow groupTuple
# file order after nextflow groupTuple

(Asked by: username_0 on 2023-03-15)

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]]

**Tags:** nextflow

---

## 1 answers

### Answer by username_1 on 2023-03-15. Score: 2 | Accepted answer

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.


---

