Skip to content

Commit

Permalink
Fix: Remove all system.exit(1) from code and replace with correct error
Browse files Browse the repository at this point in the history
  • Loading branch information
adamrtalbot committed Aug 1, 2023
1 parent 750dfe6 commit 3d99354
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 67 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Credits

### Software dependencies

Special thanks to the following for their code contributions to the release:

- [Friederike Hanssen](https://github.com/FriederikeHanssen)
Expand Down
2 changes: 1 addition & 1 deletion lib/NfcoreSchema.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ class NfcoreSchema {
}

if (has_error) {
System.exit(1)
Nextflow.error("")
}
}

Expand Down
10 changes: 4 additions & 6 deletions lib/WorkflowCommons.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ class WorkflowCommons {
//
private static void genomeExistsError(params, log) {
if (params.genomes && params.genome && !params.genomes.containsKey(params.genome)) {
log.error "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
Nextflow.error("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
" Genome '${params.genome}' not found in any config files provided to the pipeline.\n" +
" Currently, the available genome keys are:\n" +
" ${params.genomes.keySet().join(", ")}\n" +
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
System.exit(1)
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
}
}

Expand Down Expand Up @@ -121,14 +120,13 @@ class WorkflowCommons {
def intersect = bed_contigs.intersect(fai_contigs)
if (intersect.size() != bed_contigs.size()) {
def diff = bed_contigs.minus(intersect).sort()
log.error "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
Nextflow.error("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
" Contigs in primer BED file do not match those in the reference genome:\n\n" +
" ${diff.join('\n ')}\n\n" +
" Please check:\n" +
" - Primer BED file supplied with --primer_bed\n" +
" - Genome FASTA file supplied with --fasta\n" +
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
System.exit(1)
"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
}
}

Expand Down
24 changes: 8 additions & 16 deletions lib/WorkflowIllumina.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -14,53 +14,45 @@ class WorkflowIllumina {

// Generic parameter validation
if (!valid_params['protocols'].contains(params.protocol)) {
log.error "Invalid option: '${params.protocol}'. Valid options for '--protocol': ${valid_params['protocols'].join(', ')}."
System.exit(1)
Nextflow.error("Invalid option: '${params.protocol}'. Valid options for '--protocol': ${valid_params['protocols'].join(', ')}.")
}

if (!params.fasta) {
log.error "Genome fasta file not specified with e.g. '--fasta genome.fa' or via a detectable config file."
System.exit(1)
Nextflow.error("Genome fasta file not specified with e.g. '--fasta genome.fa' or via a detectable config file.")
}

if (!params.skip_kraken2 && !params.kraken2_db) {
if (!params.kraken2_db_name) {
log.error "Please specify a valid name to build Kraken2 database for host e.g. '--kraken2_db_name human'."
System.exit(1)
Nextflow.error("Please specify a valid name to build Kraken2 database for host e.g. '--kraken2_db_name human'.")
}
}

// Variant calling parameter validation
if (params.variant_caller) {
if (!valid_params['variant_callers'].contains(params.variant_caller)) {
log.error "Invalid option: ${params.variant_caller}. Valid options for '--variant_caller': ${valid_params['variant_callers'].join(', ')}."
System.exit(1)
Nextflow.error("Invalid option: ${params.variant_caller}. Valid options for '--variant_caller': ${valid_params['variant_callers'].join(', ')}.")
}
}

// Consensus calling parameter validation
if (params.consensus_caller) {
if (!valid_params['consensus_callers'].contains(params.consensus_caller)) {
log.error "Invalid option: ${params.consensus_caller}. Valid options for '--consensus_caller': ${valid_params['consensus_callers'].join(', ')}."
System.exit(1)
Nextflow.error("Invalid option: ${params.consensus_caller}. Valid options for '--consensus_caller': ${valid_params['consensus_callers'].join(', ')}.")
}
}

if (params.protocol == 'amplicon' && !params.skip_variants && !params.primer_bed) {
log.error "To perform variant calling in amplicon mode please provide a valid primer BED file e.g. '--primer_bed primers.bed'."
System.exit(1)
Nextflow.error("To perform variant calling in amplicon mode please provide a valid primer BED file e.g. '--primer_bed primers.bed'.")
}

// Assembly parameter validation
def assemblers = params.assemblers ? params.assemblers.split(',').collect{ it.trim().toLowerCase() } : []
if ((valid_params['assemblers'] + assemblers).unique().size() != valid_params['assemblers'].size()) {
log.error "Invalid option: ${params.assemblers}. Valid options for '--assemblers': ${valid_params['assemblers'].join(', ')}."
System.exit(1)
Nextflow.error("Invalid option: ${params.assemblers}. Valid options for '--assemblers': ${valid_params['assemblers'].join(', ')}.")
}

if (!valid_params['spades_modes'].contains(params.spades_mode)) {
log.error "Invalid option: ${params.spades_mode}. Valid options for '--spades_modes': ${valid_params['spades_modes'].join(', ')}."
System.exit(1)
Nextflow.error("Invalid option: ${params.spades_mode}. Valid options for '--spades_modes': ${valid_params['spades_modes'].join(', ')}.")
}
}

Expand Down
24 changes: 9 additions & 15 deletions lib/WorkflowMain.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,15 @@ class WorkflowMain {
// Check sequencing platform
def platformList = ['illumina', 'nanopore']
if (!params.platform) {
log.error "Platform not specified with e.g. '--platform illumina'. Valid options: ${platformList.join(', ')}."
System.exit(1)
Nextflow.error("Platform not specified with e.g. '--platform illumina'. Valid options: ${platformList.join(', ')}.")
} else if (!platformList.contains(params.platform)) {
log.error "Invalid platform option: '${params.platform}'. Valid options: ${platformList.join(', ')}."
System.exit(1)
Nextflow.error("Invalid platform option: '${params.platform}'. Valid options: ${platformList.join(', ')}.")
}

// Check Nextclade dataset parameters
if (!params.skip_consensus && !params.skip_nextclade) {
if (!params.nextclade_dataset && !params.nextclade_dataset_name) {
log.error "Nextclade dataset not specified with '--nextclade_dataset' or '--nextclade_dataset_name'. A list of available datasets can be obtained using the Nextclade 'nextclade dataset list' command."
System.exit(1)
Nextflow.error("Nextclade dataset not specified with '--nextclade_dataset' or '--nextclade_dataset_name'. A list of available datasets can be obtained using the Nextclade 'nextclade dataset list' command.")
}
}
}
Expand All @@ -120,33 +117,30 @@ class WorkflowMain {
if (genome_map.containsKey(primer_set_version)) {
genome_map = genome_map[ primer_set_version ]
} else {
log.error "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
Nextflow.error("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
" --primer_set_version '${primer_set_version}' not found!\n\n" +
" Currently, the available primer set version keys are: ${genome_map.keySet().join(", ")}\n\n" +
" Please check:\n" +
" - The value provided to --primer_set_version (currently '${primer_set_version}')\n" +
" - The value provided to --primer_set (currently '${primer_set}')\n" +
" - The value provided to --genome (currently '${params.genome}')\n" +
" - Any custom config files provided to the pipeline.\n\n" + support_link
System.exit(1)
" - Any custom config files provided to the pipeline.\n\n" + support_link)
}
} else {
log.error "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
Nextflow.error("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
" --primer_set '${primer_set}' not found!\n\n" +
" Currently, the available primer set keys are: ${genome_map.keySet().join(", ")}\n\n" +
" Please check:\n" +
" - The value provided to --primer_set (currently '${primer_set}')\n" +
" - The value provided to --genome (currently '${params.genome}')\n" +
" - Any custom config files provided to the pipeline.\n\n" + support_link
System.exit(1)
" - Any custom config files provided to the pipeline.\n\n" + support_link)
}
} else {
log.error "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
Nextflow.error("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n" +
" Genome '${params.genome}' does not contain any primer sets!\n\n" +
" Please check:\n" +
" - The value provided to --genome (currently '${params.genome}')\n" +
" - Any custom config files provided to the pipeline.\n\n" + support_link
System.exit(1)
" - Any custom config files provided to the pipeline.\n\n" + support_link)
}
}
if (genome_map.containsKey(attribute)) {
Expand Down
27 changes: 9 additions & 18 deletions lib/WorkflowNanopore.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -12,50 +12,41 @@ class WorkflowNanopore {

// Generic parameter validation
if (!params.fasta) {
log.error "Genome fasta file not specified with e.g. '--fasta genome.fa' or via a detectable config file."
System.exit(1)
Nextflow.error("Genome fasta file not specified with e.g. '--fasta genome.fa' or via a detectable config file.")
}

if (!params.primer_bed) {
log.error "Primer BED file not specified with e.g. '--primer_bed primers.bed' or via a detectable config file."
System.exit(1)
Nextflow.error("Primer BED file not specified with e.g. '--primer_bed primers.bed' or via a detectable config file.")
}

if (!params.artic_scheme) {
log.error "ARTIC scheme not specified with e.g. --artic_scheme 'nCoV-2019' or via a detectable config file."
System.exit(1)
Nextflow.error("ARTIC scheme not specified with e.g. --artic_scheme 'nCoV-2019' or via a detectable config file.")
}

if (!valid_params['artic_minion_caller'].contains(params.artic_minion_caller)) {
log.error "Invalid option: ${params.artic_minion_caller}. Valid options for '--artic_minion_caller': ${valid_params['artic_minion_caller'].join(', ')}."
System.exit(1)
Nextflow.error("Invalid option: ${params.artic_minion_caller}. Valid options for '--artic_minion_caller': ${valid_params['artic_minion_caller'].join(', ')}.")
}

if (!valid_params['artic_minion_aligner'].contains(params.artic_minion_aligner)) {
log.error "Invalid option: ${params.artic_minion_aligner}. Valid options for '--artic_minion_aligner': ${valid_params['artic_minion_aligner'].join(', ')}."
System.exit(1)
Nextflow.error("Invalid option: ${params.artic_minion_aligner}. Valid options for '--artic_minion_aligner': ${valid_params['artic_minion_aligner'].join(', ')}.")
}

if (!params.fastq_dir) {
log.error "Please specify a valid folder containing ONT basecalled fastq files generated by guppy_barcoder or guppy_basecaller e.g. '--fastq_dir ./20191023_1522_MC-110615_0_FAO93606_12bf9b4f/fastq_pass/"
System.exit(1)
Nextflow.error("Please specify a valid folder containing ONT basecalled fastq files generated by guppy_barcoder or guppy_basecaller e.g. '--fastq_dir ./20191023_1522_MC-110615_0_FAO93606_12bf9b4f/fastq_pass/")
}

if (params.artic_minion_caller == 'nanopolish') {
if (!params.fast5_dir) {
log.error "Please specify a valid folder containing ONT fast5 files e.g. '--fast5_dir ./20191023_1522_MC-110615_0_FAO93606_12bf9b4f/fast5_pass/"
System.exit(1)
Nextflow.error("Please specify a valid folder containing ONT fast5 files e.g. '--fast5_dir ./20191023_1522_MC-110615_0_FAO93606_12bf9b4f/fast5_pass/")
}
if (!params.sequencing_summary) {
log.error "Please specify a valid ONT sequencing summary file e.g. '--sequencing_summary ./20191023_1522_MC-110615_0_FAO93606_12bf9b4f/sequencing_summary.txt"
System.exit(1)
Nextflow.error("Please specify a valid ONT sequencing summary file e.g. '--sequencing_summary ./20191023_1522_MC-110615_0_FAO93606_12bf9b4f/sequencing_summary.txt")
}
}

if (params.artic_minion_caller == 'medaka') {
if (!params.artic_minion_medaka_model) {
log.error "Please specify the '--artic_minion_medaka_model' parameter too if using the '--artic_minion_caller medaka' workflow.\nSee https://github.com/nanoporetech/medaka"
System.exit(1)
Nextflow.error("Please specify the '--artic_minion_medaka_model' parameter too if using the '--artic_minion_caller medaka' workflow.\nSee https://github.com/nanoporetech/medaka")
}
}
}
Expand Down
21 changes: 10 additions & 11 deletions workflows/nanopore.nf
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ workflow NANOPORE {
.filter { it[1] == null }
.filter { it[-1] >= params.min_barcode_reads }
.map { it -> [ "${it[0]}\t${it[-1]}" ] }
.collect()
.map {
.collect()
.map {
tsv_data ->
def header = ['Barcode', 'Read count']
WorkflowCommons.multiqcTsvFromList(tsv_data, header)
Expand All @@ -194,8 +194,8 @@ workflow NANOPORE {
ch_fastq_dirs
.filter { it[-1] == null }
.map { it -> [ "${it[1]}\t${it[0]}" ] }
.collect()
.map {
.collect()
.map {
tsv_data ->
def header = ['Sample', 'Missing barcode']
WorkflowCommons.multiqcTsvFromList(tsv_data, header)
Expand All @@ -218,8 +218,7 @@ workflow NANOPORE {
.map { it -> [ 'SAMPLE_1', 'single_barcode', it, 10000000 ] }
.set{ ch_fastq_dirs }
} else {
log.error "Please specify a valid folder containing ONT basecalled, barcoded fastq files generated by guppy_barcoder or guppy_basecaller e.g. '--fastq_dir ./20191023_1522_MC-110615_0_FAO93606_12bf9b4f/fastq_pass/"
System.exit(1)
error "Please specify a valid folder containing ONT basecalled, barcoded fastq files generated by guppy_barcoder or guppy_basecaller e.g. '--fastq_dir ./20191023_1522_MC-110615_0_FAO93606_12bf9b4f/fastq_pass/"
}

//
Expand All @@ -239,7 +238,7 @@ workflow NANOPORE {
ch_pass_fail_barcode_count
.fail
.collect()
.map {
.map {
tsv_data ->
def header = ['Sample', 'Barcode count']
WorkflowCommons.multiqcTsvFromList(tsv_data, header)
Expand Down Expand Up @@ -278,7 +277,7 @@ workflow NANOPORE {
ch_pass_fail_guppyplex_count
.fail
.collect()
.map {
.map {
tsv_data ->
def header = ['Sample', 'Read count']
WorkflowCommons.multiqcTsvFromList(tsv_data, header)
Expand Down Expand Up @@ -410,13 +409,13 @@ workflow NANOPORE {
NEXTCLADE_RUN
.out
.csv
.map {
.map {
meta, csv ->
def clade = WorkflowCommons.getNextcladeFieldMapFromCsv(csv)['clade']
return [ "$meta.id\t$clade" ]
}
.collect()
.map {
.collect()
.map {
tsv_data ->
def header = ['Sample', 'clade']
WorkflowCommons.multiqcTsvFromList(tsv_data, header)
Expand Down

0 comments on commit 3d99354

Please sign in to comment.