-
Notifications
You must be signed in to change notification settings - Fork 735
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add nfschema plugin subwf * fix nf-test version and nf-core lint * adjust to review comments * update test name * appease linting --------- Co-authored-by: Maxime U Garcia <max.u.garcia@gmail.com>
- Loading branch information
Showing
6 changed files
with
304 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
117
subworkflows/nf-core/utils_nfschema_plugin/tests/main.nf.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!') } } | ||
) | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
subworkflows/nf-core/utils_nfschema_plugin/tests/nextflow.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
plugins { | ||
id "nf-schema@2.1.0" | ||
} | ||
|
||
validation { | ||
parametersSchema = "${projectDir}/subworkflows/nf-core/utils_nfschema_plugin/tests/nextflow_schema.json" | ||
monochromeLogs = true | ||
} |
96 changes: 96 additions & 0 deletions
96
subworkflows/nf-core/utils_nfschema_plugin/tests/nextflow_schema.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |