5.6 Processes

Let’s add a process to the previous script test0.nf and let’s call it test1.nf

#!/usr/bin/env nextflow

nextflow.enable.dsl=2

str = Channel.from('hello', 'hola', 'bonjour')

/*
 * Creates a process which receives an input channel containing values
 * Each value emitted by the channel triggers the execution
 * of the process. The process stdout is captured and sent over
 * the another channel.
 */

process printHello {

   tag { "${str_in}" } // this is for displaying the content of `str_in` in the log file

   input:        
   val str_in

   output:        
   stdout

   script:        
   """
   echo ${str_in} in Italian is ciao
   """
}

The process can be seen as a function that is composed of:

  • An input part where the input channels are defined.
  • An output part where we specify what to store as a result, that will be sent to other processes or published as final result.
  • A script part where we have the block of code to be executed using data from the input channel, and that will produce the output for the ouput channel.
    Any kind of code / command line can be run there, as it is language agnostic.
    NOTE: You can have some trouble with escaping some characters: in that case, it is better to save the code into a file and call that file as a program.

Before the input, you can indicate a tag that will be reported in the log. This is quite useful for logging / debugging.