Chapter 3 Channels
We start with channels
as they are more resemble the variable in a typical programming language. Nextflow is based on the Dataflow programming model in which processes communicate through channels. Using these channels we can connect different processes together.
There are two different types of channel in Nextflow:
- A queue channel is a non-blocking unidirectional FIFO queue which connects two processes or operators. The same queue channel cannot be used more than one time as
- A value channel a.k.a. singleton channel by definition is bound to a single value and it can be read unlimited times without consuming its content.
We are going to focus on queue channels here. A queue channel is usually created using a factory method such as a from, fromPath, etc.
3.1 of
The of
method allows you to create a channel emitting any sequence of values that are specified as the method argument
println "Channel.of( 1, 3, 5, 7 ):"
ch = Channel.of( 1, 3, 5, 7 ) // #1
ch.view()
println "Channel.of( [1, 3, 5, 7, 9]):"
ch = Channel.of( [1, 3, 5, 7, 9]) // #2
ch.view()
- Creates a channel from a sequence of values and set the name to ch
- Creates a channel from a list of values
Create a file called main_2.nf
Copy the above code to it. Save the file (Ctrl+o enter)
and exit (Ctrl+x)
Now run
3.2 fromPath
You can create a channel emitting one or more file paths by using the fromPath method and specifying a path string as an argument.
// single file
myFileChannel = Channel.fromPath( '/crex/proj/uppmax2024-2-11/metabolomics/mzMLData/Blank10.mzML' ) // #1
myFileChannel.view()
// multiple files
myFileChannel = Channel.fromPath( '/crex/proj/uppmax2024-2-11/metabolomics/mzMLData/*.*' ) // #2
myFileChannel.view()
// recursive multiple files
myFileChannel = Channel.fromPath( '/crex/proj/uppmax2024-2-11/metabolomics/**.*' ) // #3
myFileChannel.view()
- Creates a channel and binds to it a Path item referring the specified file.
- Whenever the
fromPath
argument contains a*
or?
wildcard character it is interpreted as aglob
path matcher. - Two asterisks, i.e.
**
, works like*
but crosses directory boundaries.
Create a file called main_3.nf
Copy the above code to it. Save the file (Ctrl+o enter)
and exit (Ctrl+x)
Now run
There are many parameters as well as channel types that can be used for different purposes. Please check the (documentation)[https://www.nextflow.io/docs/latest/channel.html].