Skip to content

Allow conditional process execution from configuration#1393

Merged
mahesh-panchal merged 2 commits intonf-core:devfrom
mahesh-panchal:add_when
Feb 4, 2022
Merged

Allow conditional process execution from configuration#1393
mahesh-panchal merged 2 commits intonf-core:devfrom
mahesh-panchal:add_when

Conversation

@mahesh-panchal
Copy link
Member

@mahesh-panchal mahesh-panchal commented Feb 3, 2022

Addition:
Allow modules to use when: block by moving it to configuration.

when:
task.ext.when == null || task.ext.when

Allows modules to flexibly use the when: from the configuration file.
Allows conditional process execution on settings not available in the workflow block.

Configuration is set using process.ext.when allowing one to use process selectors and other configuration benefits to
apply a when condition to a group of processes or test process specific values.

Execution conditions

process {
    withName: 'FOO' {
        ext.args = 'module1,module2'
        // Example settings
        ext.when = null                           // Process executes - no conditional defined. 
        ext.when = true                          // Process executes - e.g. override for existing configuration
        ext.when = !params.skip_module // Process executes if set, or if null 
        ext.when = ext.args.tokenize(',').contains('module1')  // Process does not execute - evaluated in configuration context.
        ext.when = { task.ext.args.tokenize(',').contains('module1') }  // Process does not execute - evaluated in task context.
    }
}

PR checklist

  • This comment contains a description of changes (with reason)
  • CHANGELOG.md is updated
  • If you've fixed a bug or added code that should be tested, add tests!
  • Documentation in docs is updated

@mahesh-panchal
Copy link
Member Author

Bonus insight from @drpatelh: Allows one to skip mirroring conditional logic in the configuration file.

Copy link
Member

@JoseEspinosa JoseEspinosa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice @mahesh-panchal , if with this we don't need to use all these ifs in the modules.config to avoid the warning regarding the process config selectors, we really owe you something 🙏

@mahesh-panchal
Copy link
Member Author

I already began a trial. It's not so simple.
https://github.com/mahesh-panchal/rnaseq/tree/when_trial
It requires rewriting logic in the rnaseq workflow here to get it to work.
Just updating modules.config and all the modules brings back the WARN's. One needs to remove all the if's and change some channel assignments to mixes and so on.

@mahesh-panchal mahesh-panchal merged commit ff5286e into nf-core:dev Feb 4, 2022
@mahesh-panchal mahesh-panchal deleted the add_when branch February 4, 2022 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants