Multi-outputs from a Process

Overview

  • Tutorial: 15 min

    Objectives:
    • Learn how to manage multiple outputs from a process.

Most processes will have multiple inputs. This section demonstrates how to handle them.

 1process collectGreetings {
 2
 3    publishDir 'results', mode: 'copy'
 4
 5    input:
 6        path input_files
 7        val batch_name
 8
 9    output:
10        path "COLLECTED-${batch_name}-output.txt", emit: outfile
11        val count_greetings , emit: count
12
13    script:
14        count_greetings = input_files.size()
15
16        """
17        cat ${input_files} > 'COLLECTED-${batch_name}-output.txt'
18        """
19}
20
21
22workflow {
23
24    .....
25
26    collectGreetings(convertToUpper.out.collect(), params.batch)
27
28    collectGreetings.out.count.view { "There were $it greetings in this batch" }
29
30    .....
31}

Explanation

In Nextflow, the emit keyword is used inside a process to explicitly define and name output channels.

Run the following workflow:

1nextflow run 14_multi_output.nf

Key Points

  1. Processes can have have multiple inputs.

  2. The emit keyword allows naming specific output channels, making it easier to reference them in the workflow.