Defining optional input parameters
Using the DLS2 module framework, we can define passage of optional parameters using a configuration
proprietary to the process scope
, the task.ext
mapping (or dictionary). In nf-core
, the convention
is to load task.ext.args
with all optional parameters acceptable by the process.
This does not work perfectly for our use-cases, and instead, we use the whole task.ext
as a
parameters map. To define an optional parameter param1
through task.ext
, add the following to
the process script section, before the script definition (in """ """
) :
def args_for_cmd1 = task.ext.param1 ? "<parameter flag for param1 if needed> $task.ext.param1"
: '<empty string or what to do if not supplied>'
Then, use args_for_cmd1
in the script. Defining the actual value for the parameters is done
by means of .config
files, inside the process
scope. A global affectation of the parameter
is as simple as :
process {
task.ext.param1 = "<my global value>"
}
Doing so will affect ALL processes. To scope to a specific process, use the
process selectors
(withName:
or withLabel:
) :
process {
withName: "PROCESS1" {
task.ext.param1 = "<scoped to PROCESS1 value>"
}
}
You can define the selector on multiple levels and use glob matching, making it so that it is possible to affect the processes inside a specific workflow as well :
process {
withName: "WORKFLOW_X*" {
task.ext.param1 = "<scoped to processes in WORKFLOW_X value>"
}
}
Important
Modules inherit selectors. Thus, a module renamed at import (import {A as B}
)
will be affected both by the selection withName: "A"
and withName: "B"
. However,
parameters defined by B
will have precedence on those define in A
.
Important
The same stands for selectors defined on multiple levels, implicit (withName: WORKFLOW_X*
)
or explicit (withName: WORKFLOW_Y:B
).