How to sort tuples

Hello, I am grouping a set of samples by sample, which I do by the following:

.groupTuple(by: [0])
.map {
meta,result →
[meta, meta.sample, result[0], result[1], result[2] ]}
.groupTuple(by: [1])
.map {
result →
.set { ch_bamreadbed }

and I end up with this, which is what I want:

[[id:test1, sample:test1, single_end:false], [test1_signal.bam,test1_background.bam], [test1_signal.readnum.txt, test1_background.readnum.txt], [test1_signal.clip.peakClusters.bed, test1_background.clip.peakClusters.bed]]

However, I would like to ensure that a certain order is always preserved: signal always goes before background (or viceversa). What command could help me with that? I could not find a sort and I am not sure how I would apply it here.

Hi @ramirobarrantes. I have run into something similar before and think that maybe the sort argument of groupTuple() might help. Several sorting criteria are included by default, but you can also create custom sorting criteria if necessary.

Here’s a link to the documentation ( Operators — Nextflow documentation) if you scroll down a bit you should be able to see the sorting options.

Please let me know if this is helpful!
Carson Miller

1 Like

Adding to what @CarsonJM explained, this Nextflow snippet may help you achieve what you’re looking for :wink:

1 Like

@mribeirodantas I will definitely be saving this snipped for future reference :sweat_smile:

1 Like

THis is excellent, thank you!!!

1 Like