Hi all! Me and my team have been working on adapti...
# nostupidquestions
c
Hi all! Me and my team have been working on adapting a pipeline to the NF framework, and we are curious about some of the conditional flow best practices. We have a setup/pre-flight script that generates a run configuration file that very simply assigns a true/false value as to whether or not a particular step needs to run. For example, if the file is zipped, we would have a parameter like "run_unzip_process" set to true and force that process to run on the input. From the workflow scope, we thought maybe we could create some helper command to read the config, extract that param for a particular process, and then use a basic if else statement to run that process or forward the original input to the next process (pseudocode in the comments). We think this might become cumbersome and repetitive since we will need this for a lot of our processes. Has anyone done something similar for their own pipelines or have any insight into a more robust way to implement this?
Pseudocode:
Copy code
def shouldWeRunThisProcess(config, process) {[true|false]}

workflow {
   ...
   if shouldWeRunThisProcess(run_channel.config,"unzip_input") {
       next_step_ch=UNZIP_INPUT(run_channel)
   } else {
       next_step_ch=run_channel
   }
}
n
This seems unusual to me, are you setting this per sample?
The "classic" approach is essentially using
params
Copy code
if params.someparam { SOMEPROCESS(channel) }
Which controls at the pipelinelevel
Of course, this does not make a ton of sense for a potentially zipped input. You can solve this bei either making your process smart enough:
Copy code
input:
tuple meta, file
output: meta, "${meta.id}.fa"
...

def cmd = file.endsWith(".gz") ? "gunzip $file > ${meta.id}.fa" : "mv $file ${meta.id}.fa"
script:
"""
$cmd
"""
Or by checking your channel:
Copy code
inputs = run_channel.branch{it -> 
   unzip: it[fileidx].endsWith('gz')
   nozip: true }
UNZIP(inputs.unzip)
prepared_inputs = inputs.nozip.mix(UNZIP.out) // depends if those are compatible or need some transformation
m
There's a subworkflow to extract archive, that directly branch depending on extension. I would go on a similar path and branch out things you don't want extracted. filter is my new favorite operator
n
filter and branch are pretty exchangable in this situation I think, yeah
💯 1
c
Okay this is great help, thank you!