Skip to content

Collect outputs into a file

Problem

You need to concatenate into a single file all output files produced by an upstream process.

Solution

Use the collectFile operator to merge all the output files into a single file.

Code

process foo {
  input:
  path x
  output:
  path 'file.fq'
  script:
  """
  < $x zcat > file.fq
  """
}

workflow {
  Channel.fromPath("$baseDir/data/reads/*_1.fq.gz", checkIfExists: true) \
    | foo \
    | collectFile \
    | view
}

Run it

Use the the following command to execute the example:

nextflow run nextflow-io/patterns/collect-into-file.nf