Search code examples
groovynextflow

Create reduced set of combinations with nextflow tuple channel


I have a question regarding nextflow and how to process the following channel of tuples and two single elements:

tuple_ch = Channel.of([['a','a','a','a'], 
                       ['B','B','B','B'], 
                       ['m','m','m','m'], 
                       1,2])

How could I transform tuple_ch to look like this (so its now a list of tuples):

[['a','B','m',1,2],
 ['a','B','m',1,2],
 ['a','B','m',1,2],
 ['a','B','m',1,2]]

I would need an input like this for my next process in the pipeline.


Solution

  • The first thing I should mention is that the first channel you created is not a 2-element channel. It's a single-element channel containing

    [[a, a, a, a], [B, B, B, B], [m, m, m, m], 1, 2]
    

    This is easy to verify. Just .view() your channel and you'll see it's a single-element channel as it has a single emission.

    Anyway, if you want to convert that original channel of yours to the version you showed at the end you can use the transpose operator:

    tuple_ch
      .transpose()
      .toList()
      .view()
    

    The output:

    [[a, B, m, 1, 2],
     [a, B, m, 1, 2],
     [a, B, m, 1, 2],
     [a, B, m, 1, 2]]