Expand paths from a channel

Not sure how you’d like to provide your input batch names, but you could create your list of glob patterns using a simple closure then use them to create your input channel:

params.root_dir = '/path/to/dir'
params.batch_names = /path/to/batch_names.txt'

batch_names = file(params.batch_names)
sample_dirs = batch_names.readLines().collect { "${params.root_dir}/${it}/sample_*" }

samples = Channel.fromPath( sample_dirs, type: 'dir' )

process my_process{

    input:
    path(sample) from samples

    """
    ls -l "${sample}"
    """
}

I would be inclined to just leave the input glob pattern as a param, though. This approach offers the most flexibility, but may not suit your use case:

params.samples = '/path/to/dir/batch_{2,322}/sample_*'

samples = Channel.fromPath( params.samples, type: 'dir' )

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top