Skip to content

Process outputs into groups


You need to process in the same batch all files that have a matching key in the file name.


Use the map operator to associate each file with a key extracted from the file name. Then chain the resulting channel with the groupTuple operator to group together all files that have a matching key. Finally, use the resulting channel as input for the process.


params.reads = "$baseDir/data/reads/*"

process foo {
  debug true
  tuple val(key), file(samples)

  echo your_command --batch $key --input $samples 

workflow {
  Channel.fromPath(params.reads, checkIfExists:true) \
    | map { file -> 
      def key ='_').get(0)
      return tuple(key, file)
    } \
    | groupTuple() \
    | foo

Run it

nextflow run nextflow-io/patterns/