Chapter 5 Workflow

Workflow connects process and channels together. The dataflow logic is executed here. The workflow definition starts with the keyword workflow, followed by an optional name, and finally the workflow body delimited by curly braces. The logic is written inside the curly bracket. The order in which a task is executed is determined only by its dependencies, so a task will be executed as soon as all of its required inputs are available.

workflow workflowname{
output_channel1 = example_workflow()
output_channel2 = example_workflow2(output_channel1)
output_channel2.view()
}

Channels can be passed and received in the workflow using

workflow {
output_channel = example_workflow(input_channel)
}

Operators can be applied to the input or output channel. For example

workflow {
output_channel = example_workflow(input_channel).collect() // #1
}
  1. Operator collect() is applied to the data coming from the process example_workflow

Multiple channels can be provided as input and also received as

workflow {
(output_channel1,output_channel2) = example_workflow(input_channel1,input_channel2)
}

5.1 Subworkflows

A named workflow is a “subworkflow” that can be invoked from other workflows. For example:

workflow my_pipeline { // #1
    foo()
    bar( foo.out.collect() )
}

workflow {
    my_pipeline()
}
  1. Name of the subworkflow here is my_pipeline