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
input:
tuple val(key), file(samples)
script:
"""
echo your_command --batch $key --input $samples
"""
}
workflow {
Channel.fromPath(params.reads, checkIfExists:true) \
| map { file ->
def key = file.name.toString().tokenize('_').get(0)
return tuple(key, file)
} \
| groupTuple() \
| foo
}
nextflow run nextflow-io/patterns/process-into-groups.nf