Chapter 6 Operators
Nextflow operators are methods that allow you to connect channels to each other or to transform values emitted by a channel applying some user provided rules. There is a large number of operators that can be seen here. We go through some of them!
6.1 Collect
The collect
operator collects all the items emitted by a channel to a List and return the resulting object as a sole emission.
For example,
mzMLFiles = Channel.fromPath( '/crex/proj/uppmax2024-2-11/metabolomics/mzMLData/*.mzML' )
mzMLFiles.collect().view()
The above code, will get the files from the path and emit them all at once. You can try this and compare the results to when you don’t use collect.
Create a file called main_11.nf
Copy the above code to it. Save the file (Ctrl+o enter)
and exit (Ctrl+x)
Now run
This operator can also be used inside the process. For example,
mzMLFiles = Channel.fromPath( '/crex/proj/uppmax2024-2-11/metabolomics/mzMLData/*.mzML' )
process featureFinder {
debug true
input:
file x
"""
echo $x
"""
}
workflow {
featureFinder(mzMLFiles.collect()) // #1
}
- By using
collect()
, the process will gather all the files inmzMLFiles
channel and do the operation for this collection of files.
Run this example and compare the results to when you don’t use collect. What is the difference? How many times the process will be run if you use and don’t use collect?