carpentries-incubator / workflows-nextflow

Workflow management with Nextflow and nf-core
https://carpentries-incubator.github.io/workflows-nextflow/
Other
18 stars 29 forks source link

Config priority confusion issue. #62

Closed mahesh-panchal closed 2 months ago

mahesh-panchal commented 2 years ago

Config priority is listed as:

  1. Parameters specified on the command line (--something value)
  2. Parameters provided using the -params-file option
  3. Config file specified using the -c my_config option
  4. The config file named nextflow.config in the current directory
  5. The config file named nextflow.config in the workflow project directory
  6. The config file $HOME/.nextflow/config
  7. Values defined within the pipeline script itself (e.g. main.nf)

Then code written such as this: main.nf:

nextflow.enable.dsl = 2

workflow {
    if ( params.foo ) {
        FOO ( params.message )
    } else {
        BAR ( params.message )
    }
}

nextflow.config:

params {
    message = 'Hello'
    foo = false
}
if ( params.foo ){
    process {
        withName: 'FOO' {
            echo = true
        }
    }
} else {
    process {
        withName: 'BAR' {
            echo = true
        }
    }
}

Then override params.foo with a custom config -c.

process.foo = true

The output of this, is that the process FOO runs, but it doesntecho. A confusing issue here is that thecustom.confighas a higher priority than thenextflow.config, so why does FOO execute but notecho`?

The logic appears to be that first the command-line parameters are read in. Then comes the -params-file, but not overriding anything that has a value. Then comes the nextflow.config, in which the code is evaluated before being stored. Then comes the custom config, which is again evaluated before, but then overrides anything set in nextflow.config.

This then means that when nextflow.config is read in, params.foo is false, setting the configuration for BAR. After which the custom config is read in, overriding params.foo, so FOO executes in the workflow. This leads to unexpected behaviour as -c is thought to have higher priority, and while this is true for the workflow execution, it's not true for the config "execution".