Sameesh Kher
05/13/2025, 12:40 AMimage_based set to true & coordinate_based set to false by default. The pipeline should run the image-based analysis workflow by default, but if the user provides the --coordinate_based , image_based should be set to false and the pipeline should run the coordinate-based workflow. In this case I am trying to set params.image_based=false but this does not work and both the options are now set to true in turn breaking my pipeline run. I want to understand the scope of the params being read from the nextflow.config file. At what stage can I update a value of a param? Is it before the pipeline initialization subworkflow? In that case where should the below code snippet reside?
def validateInputParameters() {
// check if both `--image_based` & `--coordinate_based` are true
if ( params.image_based && params.coordinate_based ) {
error "ERROR: Use either `--image_based` or `--coordinate_based` not both."
} // this works
// set image_based to false if coordinate based is provided
if (params.coordinate_based ) {
params.image_based = false
} // params.image based is not updated to false
// check if --relabel_genes is true but --gene_panel is not provided
if ( params.relabel_genes && !params.gene_panel ) {
log.warn "Relabel genes is enabled, but gene panel is not provided with the `--gene_panel`. Using `gene_panel.json` in the xenium bundle"
}
}Arthur
05/13/2025, 12:57 AMparams are scoped such that workflows (or modules) have access to the params in the state they were at the point in the code that the workflow/module was included
Consider the following:
params.test = 'a'
include { SUBWF1 } from '../workflows/subworkflow1/main.nf'
params.test = 'b'
include { SUBWF2 } from '../workflows/subworkflow2/main.nf'
In this scenario if code in SUBWF1 attempts to access params.test it will have the value a. If code in SUBWF2 tries to use params.test it will instead see b.
This is one of the many reasons it is not recommended to access params directly outside of the entry workflow.
It is also why it’s not recommended to try and modify params values after their initialisation - it rarely works.
In your situation you should most likely do one of a few things:
• make the parameters truly mutually exclusive and don’t attempt to allow the user to have one as default=true (i.e. user must supply one of the two flags but cannot supply both. They both default to false)
• make the parameters mutually exclusive within your code logic by always testing them as a pair: if (params.coordinate_based && !params.image_based)
• use the parameters to set values within the pipeline which can then be passed between workflows/modules:
image_based = params.image_based
coordinate_based = params.coordinate_based && !params.image_based
MY_SUBWORKFLOW(some_channel, image_based)Thomas Danhorn
05/13/2025, 2:33 PM--coordinate_based) should hold that single bit of information. Whenever it is false, the workflow is image-based, and when it is true, it is coordinate-based. If you foresee adding more modes in the future, you could have a parameter for the mode, either --mode image or --mode coordinate, or maybe in the future you can add --mode xyz. If you do that, check the parameter at the beginning and make sure it only contains valid settings.Sameesh Kher
05/13/2025, 2:35 PMSameesh Kher
05/13/2025, 2:38 PMsegmentation-free analysis going forward (in later releases), image-based and coordinate-based are segmentation approaches