Search code examples
nextflow

Get array from 1 to number of columns of csv in nextflow


One of my process gives output of one csv file. I want to create an array channel from 1 to number of columns. For example: My output

my_out_ch.view() -> test.csv

Assume, test.csv has 11 columns. Now I want to create a channel which gives me:

1,2,3,4,5,6,7,8,910,11

How could I get this? I have tried with splitText operator as below without luck:

my_out_ch.splitText(by:1,limit:1)

But it only gives me the columns names. There is a parameter elem, I am not sure if elem could give me the array and also not sure how to use it. Any help?


Solution

  • You could use the splitCsv operator to parse the CSV file. Then create an intRange using the map operator. Either call collect() to emit a java.util.ArrayList or call join() to emit a string. For example:

    params.input_tsv = 'test.tsv'
    
    Channel.fromPath( params.input_tsv )
        | splitCsv( sep: '\t', limit: 1 )
        | map { (1..it.size()).join(',') }
        | view()
    

    Results:

    1,2,3,4,5,6,7,8,9,10,11