Skip to content

Instantly share code, notes, and snippets.

@pditommaso
Last active July 28, 2021 09:06
Show Gist options
  • Save pditommaso/a7fb853e2528158b885c to your computer and use it in GitHub Desktop.
Save pditommaso/a7fb853e2528158b885c to your computer and use it in GitHub Desktop.
Nextflow script showing how to repeat the execution of a process
#!/bin/env nextflow
Channel
.from('abc')
.map { tuple(0,it) }
.set { foo }
Channel.create().set { feedback }
index = 0
loop = feedback.take(3).map { tuple(index++,it) }
process bar {
input:
set val(index), file(x) from foo .mix(loop)
output:
file q
script:
if( index == 0 )
"""
rev $x > q
"""
else if( index >1 )
"""
rev $x > q
"""
}
process baz {
input:
file q from q
output:
file z into feedback
file z into result
"""
cat $q > z
echo 'hello' >> z
"""
}
result.last().println { it.text }
@pditommaso
Copy link
Author

The tricky part is line 11. The input for process bar is given by a channel that emits both the content of foo and feedback channels. The first provides the initial input while the second brings the output produced by the baz process. The take operator takes the first 3 items thus stopping the iteration after that.

@tlamadon
Copy link

tlamadon commented Apr 1, 2021

This is a very useful example! Would this look similar in DSL2? I guess it could be used as a work around the fact that each process can only be called once?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment