Channels and Operators

Channels are asynchronous, which means that outputs from a set of processes will not necessarily be produced in the same order as the corresponding inputs went in. However, the first element into a channel queue is the first out of the queue (First in - First out). This allows processes to run as soon as they receive input from a channel. Channels only send data in one direction, from a producer (a process/operator), to a consumer (another process/operator).


Figure 2.


Channels types

Nextflow distinguishes between two different kinds of channels: queue and value channels.

1. Queue channel

Queue channels are a type of channel in which data is consumed (used up) to make input for a process/operator. Queue channels can be created in two ways:

  • As the outputs of a process.
  • Explicitly using channel factory methods such as Channel.of or Channel.fromPath.

2. Value channels

The second type of Nextflow channel is a value channel. A value channel is bound to a single value (singleton). A value channel can be used an unlimited number times since its content is not consumed. This is also useful for processes that need to reuse input from a channel, for example, a reference genome sequence file that is required by multiple steps within a process, or by more than one process.

In Nextflow DSL1 queue channels can only be used once in a workflow, either connecting workflow input to process input, or process output to input for another process. In DSL2 we can use a queue channel multiple times.

Queue channel factory

Queue (consumable) channels can be created using the following channel factory methods.

  • Channel.of
  • Channel.fromList
  • Channel.fromPath
  • Channel.fromFilePairs
  • Channel.fromSRA


ch1 = Channel.value('GRCh38')

Figure 8.



ch2 = Channel.value(['chr1','chr2','chr3','chr4','chr5'])

Figure 9.



chromosome_ch = Channel.of( 'chr1','chr3','chr5','chr7')

Figure 10.



ch1.mix(ch2).collect()

Figure 11.



Channel.fromPath(“/data/yeast/reads/*”)

Figure 12.



Channel.fromPath(“/data/yeast/reads/*_{1,2}.fq”)

Figure 13.1.



Channel.fromFilePairs(“/data/yeast/reads/*_{1,2}.fq”,size:2)

Figure 13.2.


Filtering


Figure 14.1.

filter(Number)

Figure 14.2.


Transforming


Figure 15.1.

map({it.replaceAll(“chr”,””)})

Figure 15.2.



Figure 16.1.

flatten()

Figure 16.2.



Figure 17.1.

collect()

Figure 17.2.



Figure 18.1.

collect()

Figure 18.2.


Milestones


Figure 19.

Nextflow milestones