Channels

In Nextflow, channels are the key data structures that facilitate the dataflow dependencies between each step (i.e. process) in a pipeline.

There are two kinds of channels, queue channels and value channels. Channels are created using channel factories and transformed using channel operators.

Queue channels

A queue channel is a channel that emits an asynchronous sequence of values.

A queue channel can be created by channel factories (e.g., channel.of and channel.fromPath), operators (e.g., map and filter), and processes (see Process outputs).

The values in a queue channel cannot be accessed directly – they can only be accessed by passing the channel as input to an operator or process. For example:

channel.of(1, 2, 3).view { v -> "queue channel emits ${v}" }
queue channel emits 1
queue channel emits 2
queue channel emits 3

Value channels

A value channel is a channel that is bound to an asynchronous value.

A value channel can be created with the channel.value factory, certain operators (e.g., collect and reduce), and processes (under certain conditions).

The value in a value channel cannot be accessed directly – it can only be accessed by passing the channel as input to an operator or process. For example:

channel.value(1).view { v -> "value channel is ${v}" }
value channel is 1

Channel factories

Channel factories are functions that create channels from regular values.

The channel.fromPath() factory creates a channel from a file name or glob pattern, similar to the files() function:

channel.fromPath('input/*.txt').view()

See Channel factories for the full list of channel factories.

Operators

Channel operators, or operators for short, are functions that consume and produce channels. Because channels are asynchronous, operators are necessary to manipulate the values in a channel. Operators are particularly useful for implementing glue logic between processes.

Commonly used operators include:

  • combine: emit the combinations of two channels

  • collect: collect the values from a channel into a list

  • filter: select the values in a channel that satisfy a condition

  • flatMap: transform each value from a channel into a list and emit each list element separately

  • groupTuple: group the values from a channel based on a grouping key

  • join: join the values from two channels based on a matching key

  • map: transform each value from a channel with a mapping function

  • mix: emit the values from multiple channels

  • view: print each value in a channel to standard output

See Operators for the full list of operators.