Reputation: 2782
The following works with strings:
Channel
.of('test1.fastq', 'test2.fastq', 'test1.bam', 'test2.bam')
.filter( ~/.*bam|.*1.fastq/ )
.view()
BUT not with paths. Is there a way to make this work with path
?
E.g.
Channel
.fromPath( params.inputs )
.filter( ~/.*bam|.*1.fastq/ )
.view()
Thankn you!
Upvotes: 3
Views: 691
Reputation: 54502
The filter
operator also lets you specify a closure, which would let you use Groovy's find operator, for example:
params.inputs = '*.{bam,fastq}'
workflow {
Channel
.fromPath( params.inputs )
.filter { it.name =~ /(\.bam|1\.fastq)$/ }
.view()
}
Another way to do what you want, I think, would be to use the find() method, which returns the first value in a list or null if no such element exists. Note that, according to the Groovy Truth, non-empty strings are coerced to true:
params.inputs = '*.{bam,fastq}'
workflow {
Channel
.fromPath( params.inputs )
.filter { file ->
['.bam', '1.fastq'].find { file.name.endsWith(it) }
}
.view()
}
Upvotes: 3