Checking contents of ParamsMap with 'Access to undefined parameter' warning?

I have the params variable declared in nextflow.config. I would like to determine which variables within params have been declared. The ‘in’ operator seems to work, but gives a warning when I use it to check if a nonexistant parameter exists in params. Example:

params = {
a = 1
b = 2

print(“c” in params)

WARN: Access to undefined parameter c – Initialise it to a default value eg. params.c = some_value

Is there a way to check that doesn’t produce this warning?

My version of your code doesn’t work at all, is it the contents of the Nextflow script or configuration?

Nextflow is fairly lenient about accessing parameters that aren’t defined, it will throw a warning and continue. You should be able to access the contents of params in all the ways that Groovy supports with maps:

params.a = "a"
params.b = "b"

workflow {
    println params.a
    println params.b
    println params.c
    println params?.c
    println params?["c"]
    println params.get("c")

    if ( !params.c ) {
        println "c is not defined!"

My bad, that was sloppy of me. Here’s the accurate description:

nextflow.config contains:

params {
a = 1
b = 2
} contains:

workflow {
    print("c" in params)

Both print statements generate the error

WARN: Access to undefined parameter `c` -- Initialise it to a default value eg. `params.c = some_value`

With the former returning false and the latter null.

I’d like a way to be able to inspect params to determine whether it contains a given value without generating a warning.

You can use containsKey() which should not trigger the warning: