Search code examples
groovynextflow

nextflow-groovy: set input parameters and check


I'd like to know and understand how to put/set parameters for the pipeline for which I've put some test/check. I've looked at few github repositories at nf-core sarek but I don't have understanding of the format used there. So, I'm writing my own structure based on similar lines.

I've main.nf, check.nf and nextflow.config files. The control from main.nf goes to check.nf (in subworkflow dir), parameters are set from nextflow.config or provided by user as -params-file file.json

I execute on command line as:
nextflow run test_input.nf -c nextflow.config -params-file nextflow-params.json

I've few question(s):

main.nf

include { input_check } from './subworkflows/check.nf'

workflow {
    input_check()
 
}

nextflow.config

params{
    file_csv=null
    out_dir=null
    data_type=null    
}

Do I need to write script, output in the check.nf?

./subworkflows/check.nf

process input_check {

    output:
    stdout
    
    script:
    println("hello inside input check")
    if(!params.data_type){
        error("no data type specified --data_type: wgs or wes or rna")
    }
    if(! params.file_csv){
        error("no input file csv provided --file_csv")
        exit 1
    }
    if(! params.out_dir){
        error("no output dir provided --out_dir")
        exit 1
    }    

    """
    """
}

Do I need the threex2 double quotes? there are not used for anything. If I do not use them I get weird/random error from nextflow.

Let me know if I've missed anything.


Solution

  • The approach taken by the nf-core Sarek pipeline, is to perform the parameter checks/validation in the main workflow script. This way, we can minimize the number of processes we need to run to complete the workflow. For example:

    if(!params.data_type) {
        error("no data type specified --data_type: wgs or wes or rna")
    }
    if(!params.file_csv) {
        error("no input file csv provided --file_csv")
    }
    if(!params.out_dir) {
        error("no output dir provided --out_dir")
    }
    
    include { foo } from './subworkflows/foo.nf'
    
    
    workflow {
    
        foo()
    }