'Input param not working as conditional switch in Nextflow processes

I am trying to pass in a parameter to Nextflow that I can use to turn a process on or off, to no avail.

Moreover, when I print the parameter in the log file the case always changes, which seems odd to me (i.e., TRUE turns to true). I have tried setting the conditional statement to match "TRUE" or "true", given this behavior, but neither seems to work.

Here is some code to illustrate the issue.

params.force = "FALSE"
params.in = 1

log.info """\
         Force: $params.force
         """
         .stripIndent()

process tester {
  input:
    val x from params.in

  output:
      stdout testerOut

  when:
    params.force == "TRUE"

  script:
      """
      echo "foo"
      """
  }

  testerOut.view()

If this file is saved as testnf and is run via "nextflow run testnf --force "TRUE" " the process will not run. The output is:

N E X T F L O W ~ version 21.10.0 Launching testnf [soggy_lorenz] - revision: a7399aad3c Force: true

[- ] process > tester -

The goal is for users to pass in parameters that turn off or on certain processes. This seems like a common use case, but I am stuck. Cheers for any help!



Solution 1:[1]

Nextflow automatically converts the --force TRUE param to a boolean, so just change it to:

params.force = "FALSE"
params.in = 1

log.info """\
         Force: $params.force
         """
         .stripIndent()

process tester {
  input:
    val x from params.in

  output:
      stdout testerOut

  when:
    params.force

  script:
      """
      echo "foo"
      """
  }

  testerOut.view()

output:

$ ~/nextflow run main.nf
N E X T F L O W  ~  version 21.10.6
Launching `main.nf` [high_hamilton] - revision: cac46af672
Force: FALSE

executor >  local (1)
[1e/5cb38e] process > tester [100%] 1 of 1 ?
foo

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pallie