Last active
July 28, 2021 09:06
-
-
Save pditommaso/a7fb853e2528158b885c to your computer and use it in GitHub Desktop.
Nextflow script showing how to repeat the execution of a process
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 } |
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
The tricky part is line 11. The input for process
bar
is given by a channel that emits both the content offoo
andfeedback
channels. The first provides the initial input while the second brings the output produced by thebaz
process. Thetake
operator takes the first 3 items thus stopping the iteration after that.