Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User-defined nested param does not evaluate properly within config file #2247

Closed
jamesbaye opened this issue Jul 28, 2021 · 3 comments
Closed
Milestone

Comments

@jamesbaye
Copy link
Contributor

jamesbaye commented Jul 28, 2021

Bug report

Expected behavior and actual behavior

Evaluating a nested parameter in nextflow.config does not return the user-specified value.

Steps to reproduce the problem

nextflow.config:

params {
    foo = true
    bar = params.foo ? "foo is true" : "foo is false"

    nested.foo = true
    nested.bar = params.nested.foo ? "nested foo is true" : "nested foo is false"
}

main.nf:

#!/usr/bin/env nextflow

nextflow.enable.dsl = 2

workflow {
    print "$params.foo $params.bar"
    print "$params.nested.foo $params.nested.bar"
}

Program output

nextflow run main.nf --nested.foo false --foo false

false foo is false
false nested foo is true // expected: "nested foo is false"

Oddly, the return value is as expected if line order is switched in config file:
nextflow.config:

params {
    foo = true
    nested.foo = true

    bar = params.foo ? "foo is true" : "foo is false"
    nested.bar = params.nested.foo ? "nested foo is true" : "nested foo is false"
}

Environment

  • Nextflow version: 21.04.1.5556
  • Java version: 1.8.0_282
  • Operating system: CentOS Linux release 7.9.2009
  • Bash version: 4.2.46(2)-release
@abhi18av
Copy link
Member

abhi18av commented Jul 29, 2021

Hi @jamesbaye ,

This is a very interesting observation!

I had the hypothesis that nextflow.config is file always meant to be used to specify the parameters declaratively, rather than a sophisticated programming logic in there.

To test this, modified the script a little bit and added the evaluation part to the main.nf as well, as shown below.

#!/usr/bin/env nextflow

nextflow.enable.dsl = 2

workflow {

    print "nested.foo: $params.nested.foo - nested.bar: $params.nested.bar"

    def derived_nested_bar =   params.nested.foo ? "nested.foo is true" : "nested.foo is false"

    print "nested.foo: $params.nested.foo - derived_nested_bar: $derived_nested_bar"
}

The config file used was

params {
    nested.foo = true
    nested.bar = nested.foo ? "nested foo is true" : "nested foo is false"
}


The results for the command invocation were

(base) bash-5.0$ nextflow run main.nf --nested.foo false --foo false

N E X T F L O W  ~  version 21.04.2
Launching `main.nf` [ecstatic_fourier] - revision: 1edf06339b
nested.foo: false - nested.bar: nested foo is true
nested.foo: false - derived_nested_bar: nested.foo is false  // <-- As expected


I imagine that the reason this happens is because, the nextflow.config file goes through a parsing process to convert it into Groovy classes (Nextflow is a Groovy DSL) and the config file parser does not cater to sophisticated logic within that file.

That logic works perfectly fine once it is expressed into a xyz.nf` i.e. nextflow file which takes care of those derivations.

Oddly, the return value is as expected if line order is switched in config file:

To me, the aforementioned observation is troubling and unexpected 😶

@abhi18av
Copy link
Member

abhi18av commented Sep 3, 2021

Related #1982

@abhi18av
Copy link
Member

abhi18av commented Dec 9, 2021

A fix has been merged recently for this and would be available in the next edge release i.e. 21.12-edge .

@pditommaso pditommaso added this to the 22.04.0 milestone Dec 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants