Passing results from within a process into a conditional workflow in nextflow

135 Views Asked by At

I'm having trouble getting the results of a calculation done within a process to determine which downstream processes to execute within a nextflow pipeline. The following example recapitulates what I'm trying to do fairly well, although I'd of course be open to alternative strategies that enable similar results.

In this example there are multiple files that are run through the first process 'check', all with varying lengths of lines. Files with more than 100 lines are considered "long." In essence, I want to be able to alter the course of the pipeline based on results in that process.

#!/usr/bin/env nextflow
nextflow.enable.dsl=2

process check {
    input:
    path(file)

    output:
    env long_files

    script:
    """
    lines=\$(cat $file | wc -l)

    if [ \${lines} < 100 ]
    then
        long_files=0
    else
        long_files=1
    fi
    """
}

workflow {
    
    check(file)

    check
        .out
        .long_files
        .toInteger()
        .sum()
        .set { ch_number_long_files }

    if ( ch_number_long_files == 0 ) {
        println "There are zero long files!"
    } 
    else if ( ch_number_long_files > 0 ) {
        println "There are some long files!"
    }
    else {
        println "Counting long files failed!"
    }

}

When I run my actual pipeline I get the following error, referring to the line with the 'else if' statement:

Cannot compare groovyx.gpars.dataflow.DataflowVariable with value 'DataflowVariable(value=null)' and java.lang.Integer with value '0'

Thanks in advance for any help or tips on this!! I'm especially mystified as to how the first 'if' statement can evaluate correctly but somehow by the 'else if' the ch_number_long_files appears to become null.

Edit: My guess is I don't actually have a value channel with ch_number_long_files, and so it gets consumed, but my efforts to coerce the 0 or 1 value into being reusable have all yielded similar error messages.

0

There are 0 best solutions below