Modify an input parameter based on another input parameter

Hi!

Is it possible to modify an input parameter based on another input parameter? Which is the best way to do it, through the configuration file or directly within the process?

In my config file:

params {
    initial_length = 10
    calculated_length = initial_length * 0.2 
}

Or in my process:

process Software_A {
    input:
    tuple val(id), path(file)

    output:
    tuple val(id), path("${id}_processed_file), emit: output

    script:
    """
    software_a -L ${params.initial_length*0.2} ${file} > ${id}_processed_file
    """
}

Any help would be appreciated!

thanks! :slight_smile:

It should be possible like this:

params {
    initial_length = 10
    calculated_length = params.initial_length * 0.2 
}

But I think the best practice is to do this in your entry workflow:

params {
    initial_length: Integer = 10
    calculated_length: Float?
}

workflow {
    calculated_length = params.calculated_length ?: params.initial_length * 0.2
}

The config approach is error-prone because it might not use the right value of params.calculated_length. Your example is simple but once you start including param overrides from different profiles / config files it can get messy