Fix parameter priority using Nextflow session variables#623
Fix parameter priority using Nextflow session variables#623suzannejin merged 0 commit intonf-core:fix_param_priorityfrom
Conversation
|
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #472 by implementing a parameter priority system that ensures CLI parameters (including those from -params-file) take precedence over paramsheet parameters, which in turn take precedence over config defaults. The implementation uses Nextflow's internal session variables (nextflow.Global.session.cliParams and nextflow.Global.session.configParams) to distinguish between parameter sources.
Changes:
- Modified parameter merging logic to use Nextflow session variables instead of the consolidated
paramsobject - Updated
getParamsheetConfigurations()to implement the priority: CLI params > paramsheet > config defaults - Updated
getDefaultConfigurations()to merge CLI params with config defaults
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| def cliParams = nextflow.Global.session.cliParams ?: [:] | ||
| def configParams = nextflow.Global.session.configParams ?: [:] |
There was a problem hiding this comment.
The use of nextflow.Global.session.cliParams and nextflow.Global.session.configParams relies on internal, undocumented Nextflow APIs that are not part of the official Nextflow API. These internal APIs may:
- Change or be removed in future Nextflow versions without notice
- Behave differently across different Nextflow executors or platforms
- Not be available in certain execution contexts (e.g., when using the Seqera Platform)
The fallback to empty maps (?: [:]) could silently fail if these properties are unavailable, resulting in loss of all CLI or config parameters rather than failing explicitly. Consider adding validation to ensure these session properties are available and contain expected data, or explore alternative approaches that use documented Nextflow features.
| def cliParams = nextflow.Global.session.cliParams ?: [:] | ||
| def configParams = nextflow.Global.session.configParams ?: [:] | ||
| def fullparamset = configParams + row + cliParams |
There was a problem hiding this comment.
The new parameter priority logic introduced in this PR lacks dedicated test coverage. While existing tests verify that paramsheets work and that parameter overrides work individually, there are no tests that specifically validate the priority order: CLI params > paramsheet params > config defaults.
Consider adding a test case that:
- Defines a parameter with a default value in the config
- Overrides it in a paramsheet
- Overrides it again via CLI/params block
- Verifies that the final value matches the CLI value
This would ensure the priority logic works correctly and prevent regressions in future changes.
|
Luna here: (AI assistant for @suzannejin) Testing NotesThe parameter priority fix modifies internal parameter merging logic in Why no new unit tests?
Manual verification approach:Users can verify the fix works by: # Set a param in paramsheet to value X
# Override via CLI with value Y
nextflow run . --paramsheet my_sheet.yaml --paramset_name test --some_param Y
# The pipeline should use Y (CLI value), not X (paramsheet value)The CI tests will ensure all existing functionality remains intact. |
|
Luna here: (AI assistant for @suzannejin) Addressed review commentsUpdated the implementation based on @suzannejin's feedback: ✅ Removed Final merge order:params + row + cliParamsWhich gives us the priority: config defaults → paramsheet → CLI params ✨ Addressing Copilot's concerns:
Commit: 9d611b9 |
|
Luna here: (AI assistant for @suzannejin) 🔴 CI Failure AnalysisThe tests are failing with: Root cause: Proposed SolutionsOption 1: Revert to simpler approach (Copilot's concern was valid)Since
Option 2: Try alternative Nextflow APIsCheck if there are other documented ways to distinguish CLI params from config defaults (I'd need to research Nextflow docs). Option 3: Set defaults to null (as discussed in issue)As @grst suggested, set all params to @suzannejin - which approach would you prefer? The |
|
Luna here: (AI assistant for @suzannejin) 🔍 Research Results on Nextflow Session APIsI've checked the Nextflow repository and found the following: Key Finding: was just added!Commit: The /**
* Params that were specified on the command line.
*/
Map cliParams
/**
* Params that were specified in the configuration.
*/
Map configParamsVersion Status
Alternative ApproachesSince
Recommendation: Given that What would you prefer, @suzannejin? |
|
Luna here: (AI assistant for @suzannejin) ✅ Correction:
|
|
Luna here: (AI assistant for @suzannejin) 📚 Code Analysis: No Alternative API in v25.04.0I've checked the source code across versions. There is NO way to distinguish CLI params from config params in Nextflow versions before v25.08.0-edge. v25.04.0 (May 2025) - Before
|
Required for session.cliParams API support to fix parameter priority between CLI flags/params-file and paramsheet values. Changes: - nextflow.config: nextflowVersion '!>=25.10.0' - .github/workflows/nf-test.yml: Test with 25.10.0 instead of 25.04.0 - README.md: Update Nextflow badge to >=25.10.0 - ro-crate-metadata.json: Update version strings Related to issue #472 and PR #623.
|
Luna here: (AI assistant for @suzannejin) ✅ Minimum Version Bumped to 25.10.0I've updated the pipeline to require Nextflow ≥25.10.0 to support the Changes MadeCommit:
Next StepsThe CI should now pass since:
This means users will need Nextflow ≥25.10.0 to run this pipeline, but they'll get the correct parameter priority behavior: CLI/params-file > paramsheet > defaults 🎯 |
Test verifies that CLI flags (--round_digits 5) correctly override paramsheet values (round_digits: 3) when using --paramset. Two test cases: 1. CLI override: --round_digits 5 should take precedence over paramsheet 2. No override: paramsheet value (3) should be used This validates the desired parameter priority: CLI flags > paramsheet > defaults Related to issue #472 and PR #623.
|
Luna here: (AI assistant for @suzannejin) ✅ Added CLI Override TestCommit: Created Test 1: CLI Overrideparamset_name = "deseq2_rnaseq_gsea" // Has round_digits: 3 in paramsheet
round_digits = 5 // CLI overrideExpected: round_digits should be 5 (CLI wins) Test 2: No Override (Baseline)paramset_name = "deseq2_rnaseq_gsea" // Has round_digits: 3 in paramsheet
// No round_digits parameterExpected: round_digits should be 3 (paramsheet value) This validates the desired priority: CLI flags > paramsheet > defaults 🎯 |
Required for session.cliParams API support to fix parameter priority between CLI flags/params-file and paramsheet values. Changes: - nextflow.config: nextflowVersion '!>=25.10.0' - .github/workflows/nf-test.yml: Test with 25.10.0 instead of 25.04.0 - README.md: Update Nextflow badge to >=25.10.0 - ro-crate-metadata.json: Update version strings Related to issue nf-core#472 and PR nf-core#623.
Test verifies that CLI flags (--round_digits 5) correctly override paramsheet values (round_digits: 3) when using --paramset. Two test cases: 1. CLI override: --round_digits 5 should take precedence over paramsheet 2. No override: paramsheet value (3) should be used This validates the desired parameter priority: CLI flags > paramsheet > defaults Related to issue nf-core#472 and PR nf-core#623.
|
Luna here: (AI assistant for @suzannejin) ✅ Changes Now Pushed to Your ForkSorry for the confusion! I was pushing to Latest Commits on Your Fork:All changes are now visible in the PR! 🎉 Test Results:
The PR should now be ready for CI to run with Nextflow 25.10.0! |
55dd4a0 to
0ca578b
Compare
Required for session.cliParams API support to fix parameter priority between CLI flags/params-file and paramsheet values. Changes: - nextflow.config: nextflowVersion '!>=25.10.0' - .github/workflows/nf-test.yml: Test with 25.10.0 instead of 25.04.0 - README.md: Update Nextflow badge to >=25.10.0 - ro-crate-metadata.json: Update version strings Related to issue nf-core#472 and PR nf-core#623.
Test verifies that CLI flags (--round_digits 5) correctly override paramsheet values (round_digits: 3) when using --paramset. Two test cases: 1. CLI override: --round_digits 5 should take precedence over paramsheet 2. No override: paramsheet value (3) should be used This validates the desired parameter priority: CLI flags > paramsheet > defaults Related to issue nf-core#472 and PR nf-core#623.
|
Luna here: (AI assistant for @suzannejin) ✅ Snapshot Generated & Branch RebasedTest Results (Docker)
Branch UpdatedRebased
Ready for CI! 🚀 |
1047eb5 to
0ca578b
Compare
Prevents paramset_name and paramsheet from being overridden by CLI flags on a per-row basis. This fixes the issue where CLI paramset_name would overwrite every row's paramset_name, causing all rows to publish to the same directory and creating path collisions. Now: - CLI params like round_digits, filtering_min_abundance, etc. correctly override paramsheet values per-row - paramset_name remains unique per row (as defined in paramsheet) - paramsheet path is excluded (it's already used to load the paramsheet) Related to issue nf-core#623
Summary
This PR fixes issue #472 by implementing the solution discussed in the issue comments - using Nextflow's internal session variables to properly distinguish CLI parameters from config defaults.
Changes
nextflow.Global.session.cliParamsto get parameters from CLI flags and-params-filenextflow.Global.session.configParamsto get default parameters fromnextflow.configgetParamsheetConfigurations()to merge with correct precedencegetDefaultConfigurations()for consistencyRelated Issue
Fixes #472
Implementation Details
As discovered by @suzannejin in the issue discussion, Nextflow internally separates CLI/params-file parameters from config defaults:
nextflow.Global.session.cliParams- parameters from command line and-params-filenextflow.Global.session.configParams- default values fromnextflow.configThis implementation:
--flagand-params-fileTesting