nextflow-io / nextflow

A DSL for data-driven computational pipelines
http://nextflow.io
Apache License 2.0
2.75k stars 628 forks source link

if else statement causes input value to go out of scope #1677

Closed jhrf closed 4 years ago

jhrf commented 4 years ago

nextflow.log

Bug report

An if statement used to control the output directory of a process causes a process input value to be unrecognised by nextflow.

I assume what is happening is that the if statement is somehow pushing the input val to be moved out of scope?

It should be noted that I am using DSL2

Expected behavior and actual behavior

Expected behaviour:

The if statement triggers successfully and output files are deposited to the correct directory specificed by publishDir

Actual behaviour:

The program fails to run because the valid process input parameter cannot be found. An error is thrown.

Steps to reproduce the problem

Notice how process bar is successfully compiled without an if statement, but the almost identical process foo throws an error.

nextflow.preview.dsl=2

workflow {
    sample_id_channel = Channel.from('sample_id')
    input_file_channel = Channel.fromPath('./bar.txt')

    bar(input_file_channel, sample_id_channel)
    foo(input_file_channel, sample_id_channel)
}

process bar{

    publishDir "${sample_id}", mode: "copy"

    input:
        file input_file
        val sample_id

    """
    echo "Hello World!"
    """
}

process foo {

    if(true){
        publishDir "${sample_id}", mode: "copy"
    } else {
       publishDir "baz", mode: "copy"
    }

    input:
        file input_file
        val sample_id

    """
    echo "Goodbye World!"
    """
}

Command line:

nextflow run <path_to_script_above>

Program output

Launching `bug_report.nf` [trusting_ptolemy] - revision: 5714eb608f
WARN: DSL 2 IS AN EXPERIMENTAL FEATURE UNDER DEVELOPMENT -- SYNTAX MAY CHANGE IN FUTURE RELEASE
[-        ] process > bar -
No such variable: sample_id

 -- Check script 'bug_report.nf' at line: 28 or see '.nextflow.log' file for more details

Environment

Additional context

None

pditommaso commented 4 years ago

The publlishDir should not be included within a condition statement. Use instead a conditional expression, eg.

process foo {
    publishDir "${ true ? sample_id : 'baz' }", mode: "copy"
    input:
        file input_file
        val sample_id

    """
    echo "Goodbye World!"
    """
}