Nextflow printing help message even when params.help is false
1
1
Entering edit mode
2.1 years ago

Hi Everyone. I was trying to add help section to my nextflow script as given below:

nextflow.enable.dsl=2
params.ref = "resources/sequence.fasta"
params.outdir="results/00_indexes"
params.runidx="bwa"
params.help = false    

// Help Section
log.info """
Step 0: Indexing
=============================================
Usage:
    nextflow run idx.nf --ref ${params.ref} --outdir ${params.outdir} --runidx ${params.runidx}
Input:
    * --ref: Path of reference file. Defult [${params.ref}]
    * --outdir: name of output directory. Default [${params.outdir}]
    * --runidx: Name of tool to run indexing. Valid values are "bwa" and "dragmap". Default [${params.runidx}]
"""


process DRAGMAPINDEX{
    publishDir "$params.outdir", mode: 'copy'
    input:
    path (fasta)
    output:
    path "*"
    script:
    """
    mkdir dragmapidx
    cp $fasta dragmapidx/
    samtools faidx dragmapidx/$fasta 
    gatk CreateSequenceDictionary -R dragmapidx/$fasta  
    dragen-os --build-hash-table true --ht-reference dragmapidx/$fasta  --output-directory dragmapidx --ht-num-threads 20
    gatk ComposeSTRTableFile -R dragmapidx/$fasta -O dragmapidx/str_table.tsv
    """
}


process BWAINDEX{
    publishDir "$params.outdir", mode: 'copy'
    input:
    path (fasta)
    output:
    path "*"
    script:
    """
    mkdir bwaidx
    cp $fasta bwaidx/
    bwa index bwaidx/$fasta
    gatk CreateSequenceDictionary -R bwaidx/$fasta
    samtools faidx bwaidx/$fasta
    """
}

fa_ch=Channel.fromPath(params.ref, checkIfExists: true)

if (params.help) {
    log.info 'This is test pipeline'
    exit 0
}


workflow {
if ("${params.runidx}" == "bwa"){
 BWAINDEX(fa_ch)
} else if ("${params.runidx}" == "dragmap"){
  DRAGMAPINDEX(fa_ch)
  } else {
  exit 1,  "Invalid argument passed to --runidx"
  }
}

This pipeline behaves nicely when I run it with nextflow run idx.nf --help however it still prints the help message when I run nextflow run idx.nf. That is unnecessary printing of help section.

N E X T F L O W  ~  version 21.10.6
Launching `idx.nf` [tender_monod] - revision: 5342c1bda0

Step 0: Indexing
=============================================
Usage:
    nextflow run idx.nf --ref resources/sequence.fasta --outdir results/00_indexes --runidx bwa
Input:
    * --ref: Path of reference file. Defult [resources/sequence.fasta]
    * --outdir: name of output directory. Default [results/00_indexes]
    * --runidx: Name of tool to run indexing. Valid values are "bwa" and "dragmap". Default [bwa]

executor >  local (1)
[ce/99a3c5] process > BWAINDEX (1) [100%] 1 of 1 ✔
nextflow align bwa alignment • 1.1k views
ADD COMMENT
5
Entering edit mode
2.1 years ago

there is no reserved word for 'help'. This is just another key of the associative map 'params'. So , just test the variable like for a regular programming language.

if( params.help ) {

log.info """
Step 0: Indexing
=============================================
Usage:
    nextflow run idx.nf --ref ${params.ref} --outdir ${params.outdir} --runidx ${params.runidx}
Input:
    * --ref: Path of reference file. Defult [${params.ref}]
    * --outdir: name of output directory. Default [${params.outdir}]
    * --runidx: Name of tool to run indexing. Valid values are "bwa" and "dragmap". Default [${params.runidx}]
"""
    exit 0
}
ADD COMMENT
0
Entering edit mode

Keeping the help statement explicitly within if conditional block worked.

ADD REPLY

Login before adding your answer.

Traffic: 1633 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6