nextflow-io / patterns

A curated collection of Nextflow implementation patterns
http://nextflow-io.github.io/patterns/
MIT License
329 stars 72 forks source link

Example of conditional execution based on channel output #43

Closed nick-youngblut closed 1 year ago

nick-youngblut commented 1 year ago

The conditional process example is a great example, but it only covers a conditional based on a pre-set param value (params.flag in the example), and does not cover dynamic conditionals based on process/workflow output. For example, one may want to run Sub-workflow1 if Process1 generates non-empty files, while Sub-workflow2 is run if the files are all empty.

Code like the following does not work:

  if( MY_PROCESS.out.map{ it.size() }.sum() == 0 ){
    ch_out = WORKFLOW1()
  } else {
    ch_out = WORKFLOW2()
  }

...since MY_PROCESS.out.map{ it.size() }.sum() is not considered an integer that can be compared to 0. So how can one handle dynamic flow control in Nextflow, based on process/workflow output?