the nextflow language has depreciated the when cause in nextflow processes. The recommendation is to use an ‘if’ condition presumably in the workflow block. For this control flow I need to retrieve a boolean from a json file. See json, main.nf and output below.
% cat main.nf
#!/usr/bin/env nextflow
nextflow.enable.dsl=2
def runPost(fireflyConfig){
def jsonSlurper = new groovy.json.JsonSlurper()
def sampleParams = jsonSlurper.parse(fireflyConfig)
return sampleParams['RUN_POST_STAGE']
}
process replicate {
label "Replicate"
input:
path(configfile)
output:
path(configfile), emit: configoutput
script:
"""
echo "configfile: ${configfile}"
"""
}
workflow {
configfile = file('/Users/jkern/wip/whh-341/one.json')
replicate(configfile)
fireflyConfig = replicate.out.configoutput.flatten()
run_post_stage = fireflyConfig
.map { runPost(it) }
.dump{params -> "runPost: $params"}
.collect() // coverts from queue to variable channel
.map { it[0] } // Get the first (and only) element
run_post_stage.subscribe { runPost ->
if (runPost) {
println 'run_post_stage is true'
} else {
println 'run_post_stage is false'
}
}
}
it works. Here is output
% nextflow run main.nf
N E X T F L O W ~ version 24.10.2
Launching `main.nf` [evil_brenner] DSL2 - revision: 164e551660
executor > local (1)
[08/e0905b] replicate [100%] 1 of 1 ✔
run_post_stage is false
but it seems awkward. At this point, I’m inclined to stay with the ‘when’ clause in the process. Is there a straightforward way to write this? What about a compound decision in this control flow based on the RUN_VEP_ANNOTATION?
Thanks for taking the time to respond to my inquiry.
Things get interesting not simply retrieving the value but using it. Going back to the original. I had to call it like.
This works but seems awkward. How is one expected to use it in a principled way? What happens if there is a second boolean? I haven’t run this but are we expected to run it like…
run_vep_stage.subscribe { runVep ->
run_post_stage.subscribe { runPost ->
if (runPost && runVep) {
println 'run_post_stage is true'
} else {
println 'run_post_stage is false'
}
}
}
% nextflow run main.nf --configfilename="true.json"
N E X T F L O W ~ version 24.10.2
Launching `main.nf` [big_watson] DSL2 - revision: 57db1af215
executor > local (2)
[65/d8fb62] replicate [100%] 1 of 1 ✔
[8a/da0eb9] DOWNSTREAM_PROC (1) [100%] 1 of 1 ✔
% nextflow run main.nf --configfilename="false.json"
N E X T F L O W ~ version 24.10.2
Launching `main.nf` [desperate_shannon] DSL2 - revision: 57db1af215
executor > local (1)
[b2/f7221d] replicate [100%] 1 of 1 ✔
[- ] DOWNSTREAM_PROC -