Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nfschema plugin subwf #6217

Merged
merged 9 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,8 @@ jobs:

- name: Install nf-test
uses: nf-core/setup-nf-test@v1
with:
version: ${{ env.NFTEST_VER }}

- name: Setup apptainer
if: matrix.profile == 'singularity'
Expand Down
46 changes: 46 additions & 0 deletions subworkflows/nf-core/utils_nfschema_plugin/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// Subworkflow that uses the nf-schema plugin to validate parameters and render the parameter summary
//

include { paramsSummaryLog } from 'plugin/nf-schema'
include { validateParameters } from 'plugin/nf-schema'

workflow UTILS_NFSCHEMA_PLUGIN {

take:
input_workflow // workflow: the workflow object used by nf-schema to get metadata from the workflow
validate_params // boolean: validate the parameters
parameters_schema // string: path to the parameters JSON schema.
// this has to be the same as the schema given to `validation.parametersSchema`
// when this input is empty it will automatically use the configured schema or
// "${projectDir}/nextflow_schema.json" as default. This input should not be empty
// for meta pipelines

main:

//
// Print parameter summary to stdout. This will display the parameters
// that differ from the default given in the JSON schema
//
if(parameters_schema) {
log.info paramsSummaryLog(input_workflow, parameters_schema:parameters_schema)
} else {
log.info paramsSummaryLog(input_workflow)
}

//
// Validate the parameters using nextflow_schema.json or the schema
// given via the validation.parametersSchema configuration option
//
if(validate_params) {
if(parameters_schema) {
validateParameters(parameters_schema:parameters_schema)
} else {
validateParameters()
}
}

emit:
dummy_emit = true
}

35 changes: 35 additions & 0 deletions subworkflows/nf-core/utils_nfschema_plugin/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/subworkflows/yaml-schema.json
name: "utils_nfschema_plugin"
description: Run nf-schema to validate parameters and create a summary of changed parameters
keywords:
- validation
- JSON schema
- plugin
- parameters
- summary
components: []
input:
- input_workflow:
type: object
description: |
The workflow object of the used pipeline.
This object contains meta data used to create the params summary log
- validate_params:
type: boolean
description: Validate the parameters and error if invalid.
- parameters_schema:
type: string
description: |
Path to the parameters JSON schema.
This has to be the same as the schema given to the `validation.parametersSchema` config
option. When this input is empty it will automatically use the configured schema or
"${projectDir}/nextflow_schema.json" as default. The schema should not be given in this way
for meta pipelines.
output:
- dummy_emit:
type: boolean
description: Dummy emit to make nf-core subworkflows lint happy
authors:
- "@nvnieuwk"
maintainers:
- "@nvnieuwk"
117 changes: 117 additions & 0 deletions subworkflows/nf-core/utils_nfschema_plugin/tests/main.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
nextflow_workflow {

name "Test Subworkflow UTILS_NFSCHEMA_PLUGIN"
script "../main.nf"
workflow "UTILS_NFSCHEMA_PLUGIN"

tag "subworkflows"
tag "subworkflows_nfcore"
tag "subworkflows/utils_nfschema_plugin"
tag "plugin/nf-schema"

config "./nextflow.config"

test("Should run nothing") {

when {

params {
test_data = ''
}

workflow {
"""
validate_params = false
input[0] = workflow
input[1] = validate_params
input[2] = ""
"""
}
}

then {
assertAll(
{ assert workflow.success }
)
}
}

test("Should validate params") {

when {

params {
test_data = ''
outdir = 1
}

workflow {
"""
validate_params = true
input[0] = workflow
input[1] = validate_params
input[2] = ""
"""
}
}

then {
assertAll(
{ assert workflow.failed },
{ assert workflow.stdout.any { it.contains('ERROR ~ Validation of pipeline parameters failed!') } }
)
}
}

test("Should run nothing - custom schema") {

when {

params {
test_data = ''
}

workflow {
"""
validate_params = false
input[0] = workflow
input[1] = validate_params
input[2] = "${projectDir}/subworkflows/nf-core/utils_nfschema_plugin/tests/nextflow_schema.json"
"""
}
}

then {
assertAll(
{ assert workflow.success }
)
}
}

test("Should validate params - custom schema") {

when {

params {
test_data = ''
outdir = 1
}

workflow {
"""
validate_params = true
input[0] = workflow
input[1] = validate_params
input[2] = "${projectDir}/subworkflows/nf-core/utils_nfschema_plugin/tests/nextflow_schema.json"
"""
}
}

then {
assertAll(
{ assert workflow.failed },
{ assert workflow.stdout.any { it.contains('ERROR ~ Validation of pipeline parameters failed!') } }
)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
plugins {
id "[email protected]"
}

validation {
parametersSchema = "${projectDir}/subworkflows/nf-core/utils_nfschema_plugin/tests/nextflow_schema.json"
nvnieuwk marked this conversation as resolved.
Show resolved Hide resolved
monochromeLogs = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://raw.githubusercontent.com/./master/nextflow_schema.json",
"title": ". pipeline parameters",
"description": "",
"type": "object",
"$defs": {
"input_output_options": {
"title": "Input/output options",
"type": "object",
"fa_icon": "fas fa-terminal",
"description": "Define where the pipeline should find input data and save output data.",
"required": ["outdir"],
"properties": {
"validate_params": {
"type": "boolean",
"description": "Validate parameters?",
"default": true,
"hidden": true
},
"outdir": {
"type": "string",
"format": "directory-path",
"description": "The output directory where the results will be saved. You have to use absolute paths to storage on Cloud infrastructure.",
"fa_icon": "fas fa-folder-open"
},
"test_data_base": {
"type": "string",
"default": "https://raw.githubusercontent.com/nf-core/test-datasets/modules",
"description": "Base for test data directory",
"hidden": true
},
"test_data": {
"type": "string",
"description": "Fake test data param",
"hidden": true
}
}
},
"generic_options": {
"title": "Generic options",
"type": "object",
"fa_icon": "fas fa-file-import",
"description": "Less common options for the pipeline, typically set in a config file.",
"help_text": "These options are common to all nf-core pipelines and allow you to customise some of the core preferences for how the pipeline runs.\n\nTypically these options would be set in a Nextflow config file loaded for all pipeline runs, such as `~/.nextflow/config`.",
"properties": {
"help": {
"type": "boolean",
"description": "Display help text.",
"fa_icon": "fas fa-question-circle",
"hidden": true
},
"version": {
"type": "boolean",
"description": "Display version and exit.",
"fa_icon": "fas fa-question-circle",
"hidden": true
},
"logo": {
"type": "boolean",
"default": true,
"description": "Display nf-core logo in console output.",
"fa_icon": "fas fa-image",
"hidden": true
},
"singularity_pull_docker_container": {
"type": "boolean",
"description": "Pull Singularity container from Docker?",
"hidden": true
},
"publish_dir_mode": {
"type": "string",
"default": "copy",
"description": "Method used to save pipeline results to output directory.",
"help_text": "The Nextflow `publishDir` option specifies which intermediate files should be saved to the output directory. This option tells the pipeline what method should be used to move these files. See [Nextflow docs](https://www.nextflow.io/docs/latest/process.html#publishdir) for details.",
"fa_icon": "fas fa-copy",
"enum": ["symlink", "rellink", "link", "copy", "copyNoFollow", "move"],
"hidden": true
},
"monochrome_logs": {
"type": "boolean",
"description": "Use monochrome_logs",
"hidden": true
}
}
}
},
"allOf": [
{
"$ref": "#/$defs/input_output_options"
},
{
"$ref": "#/$defs/generic_options"
}
]
}
Loading