How to merge back the processes by sample after splitting by chromosome in Nextflow?
Use the groupBy operator. If the content of channel xasxa is:
[&quot;/path/to/workdir/sample1_chr1.tsv&quot;, &quot;/path/to/workdir/sample1_chr2.tsv&quot;, &quot;/path/to/workdir/sample2_chr1.tsv&quot;, &quot;/path/to/workdir/sample2_chr2.tsv
You could probably do:
xasxa.groupBy{ it -&gt; it.fileName.toString().split(&quot;_&quot;)[0] }
The result would be a channel with:
[sample1:[/path/to/workdir/sample1_chr1.tsv, /path/to/workdir/sample1_chr2.tsv, sample2:[/path/to/workdir/sample2_chr1.tsv, /path/to/workdir/sample2_chr1.tsv]]
This breaks if you have an underscore in your samplename before _chr*. More robust would be to initialise all channels with a sample value, so that each channel is in the form of [samplename, chromosome]. Then all you need is a groupTuple on your channel.