Skip to content

Commit

Permalink
INITIALISE uses take and emit (nf-core#3852)
Browse files Browse the repository at this point in the history
* INTIALISE suboworkflow uses take and emit for better modularity

Changes:
 - INTIALISE subworkflow now uses a take to determine what to do
 - Use of take makes it work more portable (i.e. use your own params values!)
 - Emits the parameter summary map

* prettier

* INITIALISE meta.yml updated

* eclint
  • Loading branch information
adamrtalbot authored Sep 21, 2023
1 parent 709d347 commit 7b55a46
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 46 deletions.
99 changes: 56 additions & 43 deletions subworkflows/nf-core/initialise/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,67 @@
// 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; validateParameters } from 'plugin/nf-validation'
include { paramsHelp; paramsSummaryLog; paramsSummaryMap; validateParameters } from 'plugin/nf-validation'

workflow INITIALISE {

// Print workflow version and exit on --version
if (params.version) {
String version_string = ""
take:
version // bool
help // bool
validate_params // bool

if (workflow.manifest.version) {
def prefix_v = workflow.manifest.version[0] != 'v' ? 'v' : ''
version_string += "${prefix_v}${workflow.manifest.version}"
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 (workflow.commitId) {
def git_shortsha = workflow.commitId.substring(0, 7)
version_string += "-g${git_shortsha}"
if ( params.validate_params != false ){
validateParameters()
}
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_parameters != 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)

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

}
20 changes: 20 additions & 0 deletions subworkflows/nf-core/initialise/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@ keywords:
- version
modules:
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"
6 changes: 5 additions & 1 deletion tests/subworkflows/nf-core/initialise/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,9 @@ nextflow.enable.dsl = 2
include { INITIALISE } from '../../../../subworkflows/nf-core/initialise/main.nf'

workflow test_initialise {
INITIALISE ( )
INITIALISE (
params.version,
params.help,
params.validate_params
)
}
2 changes: 1 addition & 1 deletion tests/subworkflows/nf-core/initialise/nextflow.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
params {
help = false
version = false
validate_parameters = false
validate_params = false
test_data = null
monochrome_logs = true
}
Expand Down
2 changes: 1 addition & 1 deletion tests/subworkflows/nf-core/initialise/nextflow_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"description": "Define where the pipeline should find input data and save output data.",
"required": ["outdir"],
"properties": {
"validate_parameters": {
"validate_params": {
"type": "boolean",
"description": "Validate parameters?",
"default": true,
Expand Down

0 comments on commit 7b55a46

Please sign in to comment.