diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ef51b9962..6b97f3c755 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ - ([#2415](https://github.com/nf-core/tools/pull/2415#issuecomment-1709847086)) Add autoMounts for apptainer. - Remove `igenomes_base` from the schema, so that nf-validation doesn't create a file path and throw errors offline for s3 objects. - Update Gitpod profile resources to reflect base environment settings. +- ([#2430](https://github.com/nf-core/tools/pull/2430)) - Use INITIALISE subworkflow to start pipeline and validate parameters etc. ### Download diff --git a/nf_core/pipeline-template/lib/WorkflowMain.groovy b/nf_core/pipeline-template/lib/WorkflowMain.groovy index 5824dae2fb..9049d0b27c 100755 --- a/nf_core/pipeline-template/lib/WorkflowMain.groovy +++ b/nf_core/pipeline-template/lib/WorkflowMain.groovy @@ -2,54 +2,8 @@ // This file holds several functions specific to the main.nf workflow in the {{ name }} pipeline // -import nextflow.Nextflow - class WorkflowMain { - // - // Citation string for pipeline - // - public static String citation(workflow) { - return "If you use ${workflow.manifest.name} for your analysis please cite:\n\n" + - // TODO nf-core: Add Zenodo DOI for pipeline after first release - //"* The pipeline\n" + - //" https://doi.org/10.5281/zenodo.XXXXXXX\n\n" + - "* The nf-core framework\n" + - " https://doi.org/10.1038/s41587-020-0439-x\n\n" + - "* Software dependencies\n" + - " https://github.com/${workflow.manifest.name}/blob/master/CITATIONS.md" - } - - - // - // Validate parameters and print summary to screen - // - public static void initialise(workflow, params, log) { - - // Print workflow version and exit on --version - if (params.version) { - String workflow_version = NfcoreTemplate.version(workflow) - log.info "${workflow.manifest.name} ${workflow_version}" - System.exit(0) - } - - // Check that a -profile or Nextflow config has been provided to run the pipeline - NfcoreTemplate.checkConfigProvided(workflow, log) - - // Check that conda channels are set-up correctly - if (workflow.profile.tokenize(',').intersect(['conda', 'mamba']).size() >= 1) { - Utils.checkCondaChannels(log) - } - - // Check AWS batch settings - NfcoreTemplate.awsBatch(workflow, params) - - // Check input has been provided - if (!params.input) { - Nextflow.error("Please provide an input samplesheet to the pipeline e.g. '--input samplesheet.csv'") - } - } - {%- if igenomes %} // // Get attribute from genome config file e.g. fasta diff --git a/nf_core/pipeline-template/main.nf b/nf_core/pipeline-template/main.nf index 3d632eb8c5..606c56cd21 100644 --- a/nf_core/pipeline-template/main.nf +++ b/nf_core/pipeline-template/main.nf @@ -30,23 +30,7 @@ params.fasta = WorkflowMain.getGenomeAttribute(params, 'fasta') ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -include { validateParameters; paramsHelp } from 'plugin/nf-validation' - -// Print help message if needed -if (params.help) { - def logo = NfcoreTemplate.logo(workflow, params.monochrome_logs) - def citation = '\n' + WorkflowMain.citation(workflow) + '\n' - def String command = "nextflow run ${workflow.manifest.name} --input samplesheet.csv --genome GRCh37 -profile docker" - log.info logo + paramsHelp(command) + citation + NfcoreTemplate.dashedLine(params.monochrome_logs) - System.exit(0) -} - -// Validate input parameters -if (params.validate_params) { - validateParameters() -} - -WorkflowMain.initialise(workflow, params, log) +include { INITIALISE } from './subworkflows/nf-core/initialise/main.nf' /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -60,6 +44,8 @@ include { {{ short_name|upper }} } from './workflows/{{ short_name }}' // WORKFLOW: Run main {{ name }} analysis pipeline // workflow {{ prefix_nodash|upper }}_{{ short_name|upper }} { + log.info NfcoreTemplate.logo(workflow, params.monochrome_logs) + INITIALISE(params.version, params.help, params.validate_params) {{ short_name|upper }} () } diff --git a/nf_core/pipeline-template/modules.json b/nf_core/pipeline-template/modules.json index 2154873150..49486fb7f9 100644 --- a/nf_core/pipeline-template/modules.json +++ b/nf_core/pipeline-template/modules.json @@ -21,6 +21,15 @@ "installed_by": ["modules"] } } + }, + "subworkflows": { + "nf-core": { + "initialise": { + "branch": "master", + "git_sha": "2a3d1b469385914c4eeca70f36bc378473049d93", + "installed_by": ["subworkflows"] + } + } } } } diff --git a/nf_core/pipeline-template/subworkflows/nf-core/initialise/main.nf b/nf_core/pipeline-template/subworkflows/nf-core/initialise/main.nf new file mode 100644 index 0000000000..0cbd37993b --- /dev/null +++ b/nf_core/pipeline-template/subworkflows/nf-core/initialise/main.nf @@ -0,0 +1,68 @@ +// This is a reimplementation of the basic initialise methods in the nf-core template +// The role of this subworkflow is to check the input parameters and print help messages +// Use this to start your nf-core pipeline + +include { paramsHelp; paramsSummaryLog; paramsSummaryMap; validateParameters } from 'plugin/nf-validation' + +workflow INITIALISE { + + take: + version // bool + help // bool + validate_params // bool + + main: + + // Print workflow version and exit on --version + if (version) { + String version_string = "" + + if (workflow.manifest.version) { + def prefix_v = workflow.manifest.version[0] != 'v' ? 'v' : '' + version_string += "${prefix_v}${workflow.manifest.version}" + } + + if (workflow.commitId) { + def git_shortsha = workflow.commitId.substring(0, 7) + version_string += "-g${git_shortsha}" + } + log.info "${workflow.manifest.name} ${version_string}" + System.exit(0) + } + + // Print citation for nf-core + def citation = "If you use ${workflow.manifest.name} for your analysis please cite:\n\n" + + "* The nf-core framework\n" + + " https://doi.org/10.1038/s41587-020-0439-x\n\n" + + "* Software dependencies\n" + + " ${workflow.manifest.homePage}/blob/master/CITATIONS.md" + log.info citation + + // Print help message if needed + if (params.help) { + def String command = "nextflow run ${workflow.manifest.name} --input samplesheet.csv -profile docker" + log.info paramsHelp(command) + System.exit(0) + } + + if ( params.validate_params != false ){ + validateParameters() + } + + if (workflow.profile == 'standard' && workflow.configFiles.size() <= 1) { + log.warn "[$workflow.manifest.name] You are attempting to run the pipeline without any custom configuration!\n\n" + + "This will be dependent on your local compute environment but can be achieved via one or more of the following:\n" + + " (1) Using an existing pipeline profile e.g. `-profile docker` or `-profile singularity`\n" + + " (2) Using an existing nf-core/configs for your Institution e.g. `-profile crick` or `-profile uppmax`\n" + + " (3) Using your own local custom config e.g. `-c /path/to/your/custom.config`\n\n" + + "Please refer to the quick start section and usage docs for the pipeline.\n " + } + + log.info paramsSummaryLog(workflow) + + summary_params = paramsSummaryMap(workflow) + + emit: + summary_params + +} diff --git a/nf_core/pipeline-template/subworkflows/nf-core/initialise/meta.yml b/nf_core/pipeline-template/subworkflows/nf-core/initialise/meta.yml new file mode 100644 index 0000000000..1d36484790 --- /dev/null +++ b/nf_core/pipeline-template/subworkflows/nf-core/initialise/meta.yml @@ -0,0 +1,33 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/subworkflows/yaml-schema.json +name: "initialise" +description: Validate input parameters and print help messages +keywords: + - admin + - check + - help + - version +components: [] +input: + - version: + type: boolean + description: | + Structure: val(version) + Boolean to show the pipeline version and exit. + - help: + type: boolean + description: | + Structure: val(help) + Boolean to show the pipeline help message and exit. + - validate_params: + type: boolean + description: | + Structure: val(validate_params) + Whether to validate the parameters prior to starting the pipeline. +output: + - summary_params: + type: value + description: | + Structure: val(summary_params) + A map of the parameters used in the pipeline. +authors: + - "@adamrtalbot" diff --git a/nf_core/pipeline-template/workflows/pipeline.nf b/nf_core/pipeline-template/workflows/pipeline.nf index 9dfb0155f1..74fcedfa0a 100644 --- a/nf_core/pipeline-template/workflows/pipeline.nf +++ b/nf_core/pipeline-template/workflows/pipeline.nf @@ -4,16 +4,7 @@ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -include { paramsSummaryLog; paramsSummaryMap } from 'plugin/nf-validation' - -def logo = NfcoreTemplate.logo(workflow, params.monochrome_logs) -def citation = '\n' + WorkflowMain.citation(workflow) + '\n' -def summary_params = paramsSummaryMap(workflow) - -// Print parameter summary log to screen -log.info logo + paramsSummaryLog(workflow) + citation - -Workflow{{ short_name[0]|upper }}{{ short_name[1:] }}.initialise(params, log) +include { paramsSummaryMap } from 'plugin/nf-validation' /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -59,6 +50,9 @@ include { CUSTOM_DUMPSOFTWAREVERSIONS } from '../modules/nf-core/custom/dumpsoft // Info required for completion email and summary def multiqc_report = [] +// Get map of parameter values +def summary_params = paramsSummaryMap(workflow) + workflow {{ short_name|upper }} { ch_versions = Channel.empty() diff --git a/tests/subworkflows/remove.py b/tests/subworkflows/remove.py index 53a948778b..d07a0fa336 100644 --- a/tests/subworkflows/remove.py +++ b/tests/subworkflows/remove.py @@ -12,6 +12,10 @@ def test_subworkflows_remove_uninstalled_subworkflow(self): def test_subworkflows_remove_subworkflow(self): """Test removing subworkflow and all it's dependencies after installing it""" + # Remove initialise subworkflow for clean slate + self.subworkflow_remove.remove("initialise") + + # Install subworkflow self.subworkflow_install.install("bam_sort_stats_samtools") subworkflow_path = Path(self.subworkflow_install.dir, "subworkflows", "nf-core") @@ -34,6 +38,10 @@ def test_subworkflows_remove_subworkflow(self): def test_subworkflows_remove_subworkflow_keep_installed_module(self): """Test removing subworkflow and all it's dependencies after installing it, except for a separately installed module""" + # Remove initialise subworkflow for clean slate + self.subworkflow_remove.remove("initialise") + + # Install subworkflow and module self.subworkflow_install.install("bam_sort_stats_samtools") self.mods_install.install("samtools/index") @@ -44,6 +52,7 @@ def test_subworkflows_remove_subworkflow_keep_installed_module(self): mod_json_before = ModulesJson(self.pipeline_dir).get_modules_json() assert self.subworkflow_remove.remove("bam_sort_stats_samtools") + mod_json_after = ModulesJson(self.pipeline_dir).get_modules_json() assert Path.exists(subworkflow_path) is False diff --git a/tests/subworkflows/update.py b/tests/subworkflows/update.py index 698086e186..6ff2387096 100644 --- a/tests/subworkflows/update.py +++ b/tests/subworkflows/update.py @@ -162,6 +162,9 @@ def test_update_with_config_dont_update(self): def test_update_with_config_fix_all(self): """Fix the version of all nf-core subworkflows""" + # Remove intialise + self.subworkflow_remove.remove("initialise") + # Install subworkflow at the latest version assert self.subworkflow_install.install("fastq_align_bowtie2")