Possible Bug with 'reduce' Operator in Nextflow – Minimal Reproducible Example Provided

When using the reduce operator within a subworkflow, the subworkflow is being triggered to run even when there are no inputs to initiate it.

I’ve created a GitHub repo with a minimal, reproducible example of the issue. It’s possible I missed something, but it might also point to a potential bug.
Looking forward to thoughts and suggestions:
:link: GitHub - vinegang/debug_reduce_nf

Hi @vinegang , sorry you never got a response. I thought someone else answered but guess you fell through the cracks.

This is an (understandable) misunderstanding of how workflows work. In the RNAseq_only workflow you are creating a channel via channel factory and passing it to the reduce operator. This will run independently of the workflow input rnaseq_samplesheet.

Workflows are used to build the workflow DAG, not to actually run anything, so the workflow logic will run even if the input channels are empty, as if the logic were in the entry workflow.

Because the reduce operator is controlled solely by this channel factory and not the subworklfow input, it is essentially independent from the rest of the subworkflow.

Hope that makes sense. As a best practice, I recommend using channel factories only in the entry workflow as much as possible (except e.g. using channel.value() to wrap a value in a channel). This should make surprises like this one less likely.

1 Like