Assign value() output to a Groovy variable

Hi Everybody,

Sorry if I’ve missed something obvious, as this question seems quite basic.

The code below writes 5 to standard out. How do I capture that value and assign to a Groovy variable?

x = Channel
    .from(1, 2, 3, 4, 5)  

x.count().view()

(As an aside: the reason I want to do this is that I’ve written a pipeline that maps FASTQ files and quantifies the results. The pipeline then needs to combine the results from each replicate. However, if there is only 1 replicate then the pipeline should not run the combining script.

Therefore, I’ve tried to add logic to my pipeline which assesses the number of samples in a channel and runs the combining script accordingly.)

There must be an easy answer to this, but I just can’t see it. Any help would be much appreciated.

Thanks very much!

Steven

The reason it’s not easily findable is because this isn’t the way you should approach the problem.

What you want to do is use either branch, or probably better, filter, to do conditional process execution.

Using either collect or more likely groupTuple, you can then filter inputs.

ch_analysed = ANALYSE_REPLICATE.out.report
    .groupTuple() // Group together replicates or samples based on key
MERGE_REPORT( ch_analysed.filter{ meta, reports -> reports.size() > 1 } )
ch_reports = ch_analysed.filter{ meta, reports -> reports.size() == 1 }
    .map { meta, reports -> tuple( meta, reports.head() ) } // Unlist singleton report
    .mix( MERGE_REPLICATES.out.report )

Thanks very much for your reply. I shall try this.