From 6355a331d97c8f12815926901404760feed3238c Mon Sep 17 00:00:00 2001 From: maxulysse Date: Fri, 25 Aug 2023 10:36:33 +0200 Subject: [PATCH 1/3] small refactor --- main.nf | 65 ++++++++++++++++++--------------------- workflows/synapse/main.nf | 14 --------- 2 files changed, 30 insertions(+), 49 deletions(-) diff --git a/main.nf b/main.nf index 5311164f..edb54fd8 100644 --- a/main.nf +++ b/main.nf @@ -1,20 +1,20 @@ #!/usr/bin/env nextflow /* -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +======================================================================================== nf-core/fetchngs -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +======================================================================================== Github : https://github.com/nf-core/fetchngs Website: https://nf-co.re/fetchngs Slack : https://nfcore.slack.com/channels/fetchngs ----------------------------------------------------------------------------------------- +======================================================================================== */ nextflow.enable.dsl = 2 /* -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +======================================================================================== VALIDATE & PRINT PARAMETER SUMMARY -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +======================================================================================== */ WorkflowMain.initialise(workflow, params, log) @@ -24,16 +24,21 @@ ch_input = file(params.input, checkIfExists: true) if (ch_input.isEmpty()) {exit 1, "File provided with --input is empty: ${ch_input.getName()}!"} // Read in ids from --input file -Channel - .from(file(params.input, checkIfExists: true)) +ch_ids = Channel.from(file(params.input, checkIfExists: true)) .splitCsv(header:false, sep:'', strip:true) .map { it[0] } .unique() - .set { ch_ids } + +// Auto-detect input type +def input_type = '' +if (WorkflowMain.isSraId(ch_input)) { input_type = 'sra' } +else if (WorkflowMain.isSynapseId(ch_input)) { input_type = 'synapse' } +else { exit 1, 'Ids provided via --input not recognised please make sure they are either SRA / ENA / GEO / DDBJ or Synapse ids!' } +if (params.input_type != input_type) { exit 1, "Ids auto-detected as ${input_type}. Please provide '--input_type ${input_type}' as a parameter to the pipeline!" } /* ======================================================================================== - IMPORT MODULES/SUBWORKFLOWS + IMPORT MODULES ======================================================================================== */ @@ -41,30 +46,19 @@ include { CUSTOM_DUMPSOFTWAREVERSIONS } from './modules/nf-core/custom/dumpsoftw include { MULTIQC_MAPPINGS_CONFIG } from './modules/local/multiqc_mappings_config' /* -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - NAMED WORKFLOW FOR PIPELINE -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +======================================================================================== + IMPORT WORKFLOWS +======================================================================================== */ -// Auto-detect input id type -def input_type = '' -if (WorkflowMain.isSraId(ch_input)) { - input_type = 'sra' -} else if (WorkflowMain.isSynapseId(ch_input)) { - input_type = 'synapse' -} else { - exit 1, 'Ids provided via --input not recognised please make sure they are either SRA / ENA / GEO / DDBJ or Synapse ids!' -} +if (params.input_type == 'sra') include { SRA } from './workflows/sra' +if (params.input_type == 'synapse') include { SYNAPSE } from './workflows/synapse' -if (params.input_type == input_type) { - if (params.input_type == 'sra') { - include { SRA } from './workflows/sra' - } else if (params.input_type == 'synapse') { - include { SYNAPSE } from './workflows/synapse' - } -} else { - exit 1, "Ids auto-detected as ${input_type}. Please provide '--input_type ${input_type}' as a parameter to the pipeline!" -} +/* +======================================================================================== + NAMED WORKFLOW FOR PIPELINE +======================================================================================== +*/ // // WORKFLOW: Run main nf-core/fetchngs analysis pipeline depending on type of identifier provided @@ -77,13 +71,13 @@ workflow NFCORE_FETCHNGS { // WORKFLOW: Download FastQ files for SRA / ENA / GEO / DDBJ ids // if (params.input_type == 'sra') { - SRA ( ch_ids ) + SRA(ch_ids) ch_versions = ch_versions.mix(SRA.out.versions) // // MODULE: Create a MultiQC config file with sample name mappings // if (params.sample_mapping_fields) { - MULTIQC_MAPPINGS_CONFIG (SRA.out.mappings) + MULTIQC_MAPPINGS_CONFIG(SRA.out.mappings) ch_versions = ch_versions.mix(MULTIQC_MAPPINGS_CONFIG.out.versions) } // @@ -127,11 +121,12 @@ workflow.onComplete { NfcoreTemplate.email(workflow, params, summary_params, projectDir, log) } NfcoreTemplate.summary(workflow, params, log) - WorkflowSra.curateSamplesheetWarn(log) + if (params.input_type == 'sra') { WorkflowSra.curateSamplesheetWarn(log) } + if (params.input_type == 'synapse') { WorkflowSynapse.curateSamplesheetWarn(log) } } /* -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +======================================================================================== THE END -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +======================================================================================== */ diff --git a/workflows/synapse/main.nf b/workflows/synapse/main.nf index 34c3e315..04bb32cb 100644 --- a/workflows/synapse/main.nf +++ b/workflows/synapse/main.nf @@ -125,20 +125,6 @@ workflow SYNAPSE { versions = ch_versions.unique() } -/* -======================================================================================== - COMPLETION EMAIL AND SUMMARY -======================================================================================== -*/ - -workflow.onComplete { - if (params.email || params.email_on_fail) { - NfcoreTemplate.email(workflow, params, summary_params, projectDir, log) - } - NfcoreTemplate.summary(workflow, params, log) - WorkflowSynapse.curateSamplesheetWarn(log) -} - /* ======================================================================================== THE END From 1be5ebca09466fe99306fd638dccb9e529652324 Mon Sep 17 00:00:00 2001 From: maxulysse Date: Fri, 25 Aug 2023 10:51:52 +0200 Subject: [PATCH 2/3] validate input in main.nf --- main.nf | 32 +++++++++++++++++++++++++++++++- workflows/sra/main.nf | 15 --------------- workflows/synapse/main.nf | 18 ++---------------- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/main.nf b/main.nf index edb54fd8..ef79d02b 100644 --- a/main.nf +++ b/main.nf @@ -36,6 +36,36 @@ else if (WorkflowMain.isSynapseId(ch_input)) { input_type = 'synapse' } else { exit 1, 'Ids provided via --input not recognised please make sure they are either SRA / ENA / GEO / DDBJ or Synapse ids!' } if (params.input_type != input_type) { exit 1, "Ids auto-detected as ${input_type}. Please provide '--input_type ${input_type}' as a parameter to the pipeline!" } +/* +======================================================================================== + VALIDATE INPUTS +======================================================================================== +*/ + +if (params.input_type == 'sra') { + def valid_params = [ + ena_metadata_fields : ['run_accession', 'experiment_accession', 'library_layout', 'fastq_ftp', 'fastq_md5'] + ] + + def summary_params = NfcoreSchema.paramsSummaryMap(workflow, params) + + // Validate input parameters + WorkflowSra.initialise(params, valid_params) +} + +if (params.input_type == 'synapse') { + + def summary_params = NfcoreSchema.paramsSummaryMap(workflow, params) + + // Create channel for synapse config + if (params.synapse_config) { + ch_synapse_config = file(params.synapse_config, checkIfExists: true) + } else { + exit 1, 'Please provide a Synapse config file for download authentication!' + } + +} + /* ======================================================================================== IMPORT MODULES @@ -84,7 +114,7 @@ workflow NFCORE_FETCHNGS { // WORKFLOW: Download FastQ files for Synapse ids // } else if (params.input_type == 'synapse') { - SYNAPSE ( ch_ids ) + SYNAPSE(ch_ids, ch_synapse_config) ch_versions = ch_versions.mix(SYNAPSE.out.versions) } diff --git a/workflows/sra/main.nf b/workflows/sra/main.nf index d4612cd0..d999d998 100644 --- a/workflows/sra/main.nf +++ b/workflows/sra/main.nf @@ -1,18 +1,3 @@ -/* -======================================================================================== - VALIDATE INPUTS -======================================================================================== -*/ - -def valid_params = [ - ena_metadata_fields : ['run_accession', 'experiment_accession', 'library_layout', 'fastq_ftp', 'fastq_md5'] -] - -def summary_params = NfcoreSchema.paramsSummaryMap(workflow, params) - -// Validate input parameters -WorkflowSra.initialise(params, valid_params) - /* ======================================================================================== IMPORT LOCAL MODULES/SUBWORKFLOWS diff --git a/workflows/synapse/main.nf b/workflows/synapse/main.nf index 04bb32cb..30d05f4f 100644 --- a/workflows/synapse/main.nf +++ b/workflows/synapse/main.nf @@ -1,18 +1,3 @@ -/* -======================================================================================== - VALIDATE INPUTS -======================================================================================== -*/ - -def summary_params = NfcoreSchema.paramsSummaryMap(workflow, params) - -// Create channel for synapse config -if (params.synapse_config) { - ch_synapse_config = file(params.synapse_config, checkIfExists: true) -} else { - exit 1, 'Please provide a Synapse config file for download authentication!' -} - /* ======================================================================================== IMPORT LOCAL MODULES/SUBWORKFLOWS @@ -34,7 +19,8 @@ include { SYNAPSE_MERGE_SAMPLESHEET } from '../../modules/local/synapse_merge_sa workflow SYNAPSE { take: - ids // channel: [ ids ] + ids // channel: [ ids ] + ch_synapse_config // channel: [ synapse_config ] main: ch_versions = Channel.empty() From 698fab108f7638736768cb9a67140ce6801bd3ad Mon Sep 17 00:00:00 2001 From: maxulysse Date: Fri, 25 Aug 2023 11:08:13 +0200 Subject: [PATCH 3/3] use error --- main.nf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.nf b/main.nf index ef79d02b..7575eeb8 100644 --- a/main.nf +++ b/main.nf @@ -21,7 +21,7 @@ WorkflowMain.initialise(workflow, params, log) // Check if --input file is empty ch_input = file(params.input, checkIfExists: true) -if (ch_input.isEmpty()) {exit 1, "File provided with --input is empty: ${ch_input.getName()}!"} +if (ch_input.isEmpty()) { error("File provided with --input is empty: ${ch_input.getName()}!") } // Read in ids from --input file ch_ids = Channel.from(file(params.input, checkIfExists: true)) @@ -33,8 +33,8 @@ ch_ids = Channel.from(file(params.input, checkIfExists: true)) def input_type = '' if (WorkflowMain.isSraId(ch_input)) { input_type = 'sra' } else if (WorkflowMain.isSynapseId(ch_input)) { input_type = 'synapse' } -else { exit 1, 'Ids provided via --input not recognised please make sure they are either SRA / ENA / GEO / DDBJ or Synapse ids!' } -if (params.input_type != input_type) { exit 1, "Ids auto-detected as ${input_type}. Please provide '--input_type ${input_type}' as a parameter to the pipeline!" } +else { error('Ids provided via --input not recognised please make sure they are either SRA / ENA / GEO / DDBJ or Synapse ids!') } +if (params.input_type != input_type) { error("Ids auto-detected as ${input_type}. Please provide '--input_type ${input_type}' as a parameter to the pipeline!") } /* ======================================================================================== @@ -61,7 +61,7 @@ if (params.input_type == 'synapse') { if (params.synapse_config) { ch_synapse_config = file(params.synapse_config, checkIfExists: true) } else { - exit 1, 'Please provide a Synapse config file for download authentication!' + error('Please provide a Synapse config file for download authentication!') } }