3
$\begingroup$

How should I do:

...
if ($(params.aligner) == "bowtie") {
    align_bowtie2(get_fq_info.out.fq_info)
}
else {
    align_bwa(get_fq_info.out.fq_info)
}
...
$\endgroup$

2 Answers 2

2
$\begingroup$

You can move that into your workflow definition. There's an example in the docs of how best to use workflow parameters:

A workflow component can access any variable and parameter defined in the outer scope:

params.data = '/some/data/file'

workflow my_pipeline {
    if( params.data )
        bar(params.data)
    else
        bar(foo()) }

Your example workflow would look like:

workflow {

    fq_info = get_fq_info.out.fq_info

    if( params.aligner == "bowtie" ) {
        align_bowtie2( fq_info )
    }
    else {
        align_bwa( fq_info )
    }

    ...
}
```
$\endgroup$
2
$\begingroup$

Is this inside the main.nf file or inside the process.nf file? Anyway, the param.anything variable should already be available in the nextflow context when executed, thus, you could simply do:

if (params.aligner == "bowtie") {
    align_bowtie2(get_fq_info.out.fq_info)
} else {
    align_bwa(get_fq_info.out.fq_info)
}

Check out this main.nf of a nextflow pipeline of mine, it contains some working if/else snippets.

Here it is another StackOverflow question on conditional nextflow pipelines that might help.

Hope it helps.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.