Skip to content

Commit fcaafd3

Browse files
authored
Merge pull request #141 from nextflow-io/update/examples
Update nf-schema examples
2 parents 9c9ad0f + e18016b commit fcaafd3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+433
-121
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ jobs:
5151
with:
5252
name: test-reports-jdk-${{ matrix.java_version }}
5353
path: |
54-
./plugins/nf-schema/build/reports/tests/test/**
54+
./plugins/nf-schema/build/reports/tests/test/**

.github/workflows/examples.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Check examples
2+
on:
3+
push:
4+
tags-ignore:
5+
- '*'
6+
pull_request:
7+
jobs:
8+
check_examples:
9+
name: Check examples output
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v3
15+
with:
16+
fetch-depth: 1
17+
submodules: true
18+
19+
- name: Setup Java 21
20+
uses: actions/setup-java@v3
21+
with:
22+
java-version: 21
23+
distribution: 'adopt'
24+
architecture: x64
25+
cache: gradle
26+
27+
- name: Setup Nextflow
28+
uses: nf-core/setup-nextflow@v2
29+
with:
30+
version: "latest-stable"
31+
32+
- name: Install nf-schema
33+
run: make install
34+
35+
- name: Check examples
36+
run: bash examples/check_examples.sh

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
3. Rework the deprecated `paramsHelp()` function to allow pipeline developers a fully fledged alternative to the help messages created via the configuration options. This change enables the use of dynamic help message with the strict configuration syntax introduced in Nextflow 25.04.0.
1515
4. Updated the error message when the JSON schema file is invalid to include the full file name.
1616
5. The ANSI log setting of Nextflow is now used to determine whether or not the log should be monochrome. This setting will take priority over the `validation.monochromeLogs` configuration option.
17-
6. Refactored logic for parsing the `jsonschema` validation result into a new `ValidationResult` class.
17+
6. Updated the examples in the [examples](examples/) directory and added automatic checking for validity of these examples.
18+
7. Refactored logic for parsing the `jsonschema` validation result into a new `ValidationResult` class.
1819

1920
## Bug fixes
2021

docs/nextflow_schema/nextflow_schema_examples.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,5 @@ It is used as a test fixture in the nf-schema package [here](https://github.com/
1818
```json
1919
--8<-- "src/testResources/nextflow_schema.json"
2020
```
21+
22+
Even more examples can be found in the plugin [`examples` directory](../../examples) in the GitHub repository.

docs/nextflow_schema/sample_sheet_schema_examples.md

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,6 @@ description: Example JSON Schema for a Nextflow pipeline `nextflow_schema.json`
99
The nf-core/rnaseq pipeline was one of the first to have a sample sheet schema.
1010
You can see this, used for validating sample sheets with `--input` here: [`assets/schema_input.json`](https://github.com/nf-core/rnaseq/blob/5671b65af97fe78a2f9b4d05d850304918b1b86e/assets/schema_input.json).
1111

12-
!!! tip
13-
14-
Note the approach used for validating filenames in the `fastq_2` column.
15-
The column is optional, so if a `pattern` was supplied by itself then validation would fail
16-
when no string is supplied.
17-
18-
Instead, we say that the string must _either_ match that pattern or it must have a
19-
`maxLength` of `0` (an empty string).
20-
2112
```json
2213
{
2314
"$schema": "https://json-schema.org/draft/2020-12/schema",
@@ -71,3 +62,5 @@ It is used as a test fixture in the nf-schema package [here](https://github.com/
7162
```json
7263
--8<-- "src/testResources/schema_input.json"
7364
```
65+
66+
Even more examples can be found in the plugin [`examples` directory](../../examples) in the GitHub repository.

examples/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# nf-schema examples
2+
3+
This directory contains example files for the nf-schema project.
4+
5+
1. [Help Message](./helpMessage/) contains a pipeline that generates a help message for a given schema.
6+
2. [Parameter summary log](./paramSummaryLog/) contains a pipeline that generates a summary log of the parameters used in a given schema.
7+
3. [Parameter summary map](./paramSummaryMap/) contains a pipeline that generates a summary map of the parameters used in a given schema. The difference between with the previous example is that this one produces a machine readable data structure instead of a human readable output string.
8+
4. [Basic samplesheet conversion](./samplesheetToListBasic/) contains a pipeline that converts a samplesheet to a list that can be easily converted to a channel for usage in the pipeline.
9+
5. [Samplesheet conversion with meta](./samplesheetToListMeta/) contains a pipeline that converts a samplesheet to a list that can be easily converted to a channel for usage in the pipeline. This example contains a meta map.
10+
6. [Samplesheet conversion order](./samplesheetToListOrder/) contains a pipeline that converts a samplesheet to a list. This example is used to explain the order of the fields in the samplesheet can be changed freely while maintaining the same output list order. The output order is based on the order of the fields in the schema.
11+
7. [Validate Parameters](./validateParameters/) contains a pipeline that validates the parameters used in a given schema.
12+
8. [Fail unrecognized parameters](./failUnrecognizedParameters/) contains a pipeline that fails when unrecognized parameters are used in a given schema.
13+
9. [Warning unrecognized parameters](./warningUnrecognizedParameters/) contains a pipeline that warns when unrecognized parameters are used in a given schema.

examples/check_examples.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
script_dir=$(dirname "$0")
2+
plugin_version=$(grep 'version =' "$script_dir/../build.gradle" | awk -F "'" '{print $2}')
3+
4+
echo "Testing examples with nf-schema version $plugin_version"
5+
6+
failures=0
7+
ignore_values='runName|launchDir|workDir|Check script|projectDir|userName|configFiles'
8+
9+
run_example() {
10+
echo "Running example command: $command"
11+
output=$(eval $command 2>&1 | tail -n +5 | grep -vE "$ignore_values")
12+
13+
expected_text=$(cat $expected_output | tail -n +5 | grep -vE "$ignore_values")
14+
15+
echo "Comparing with expected output: $expected_output"
16+
if [ "$output" == "$expected_text" ]; then
17+
echo "Test passed!"
18+
else
19+
failures=$((failures + 1))
20+
echo "Test failed!"
21+
diff <(echo "$output") <(echo "$expected_text")
22+
fi
23+
}
24+
25+
for example in $script_dir/*/pipeline/main.nf
26+
do
27+
example_dir=$(dirname "$example")
28+
if compgen -G "$example_dir/../options*.txt" > /dev/null; then
29+
for option in $example_dir/../options*.txt
30+
do
31+
command="COLUMNS=1000 nextflow run $example -plugins nf-schema@$plugin_version $(cat $option)"
32+
expected_output=$(echo $option | sed -e 's/options/log/')
33+
run_example
34+
done
35+
else
36+
command="COLUMNS=1000 nextflow run $example -plugins nf-schema@$plugin_version"
37+
expected_output="$(dirname $example)/../log.txt"
38+
run_example
39+
fi
40+
done
41+
42+
if [ $failures -eq 0 ]; then
43+
echo "All tests passed!"
44+
else
45+
echo "$failures test(s) failed."
46+
exit 1
47+
fi

examples/helpMessage/README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Help Message
2+
3+
This example demonstrates how to generate a help message for a given schema using the nf-schema plugin.
4+
5+
There are two example log files provided in this directory:
6+
- `log.txt`: This log file shows the output when running the pipeline with the `--help` option. It contains the help message generated for the schema.
7+
- `log_outdir.txt`: This log file shows the output when running the pipeline with the `--help outdir` option. It contains the help message for the `outdir` parameter specifically.

examples/helpMessage/log.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
N E X T F L O W ~ version 25.04.6
3+
4+
Launching `examples/helpMessage/pipeline/main.nf` [nauseous_hoover] DSL2 - revision: 629cc11c05
5+
6+
7+
This is a help message for the pipeline.
8+
It provides information about the parameters and usage.
9+
10+
Typical pipeline command:
11+
12+
nextflow run my_pipeline --input input_file.csv
13+
14+
--help [boolean, string] Show the help message for all top level parameters. When a parameter is given to `--help`, the full help message of that parameter will be printed.
15+
--helpFull [boolean] Show the help message for all non-hidden parameters.
16+
--showHidden [boolean] Show all hidden parameters in the help message. This needs to be used in combination with `--help` or `--helpFull`.
17+
18+
Input/output options
19+
--input [string] Path to comma-separated file containing information about the samples in the experiment.
20+
--outdir [string] The output directory where the results will be saved. You have to use absolute paths to storage on Cloud infrastructure.
21+
--help [boolean] Show the help message for the pipeline. [default: false]
22+
23+
------------------------------------------------------
24+
25+
For more information, please refer to the documentation.
26+
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
N E X T F L O W ~ version 25.04.6
3+
4+
Launching `examples/helpMessage/pipeline/main.nf` [fabulous_boyd] DSL2 - revision: 629cc11c05
5+
6+
7+
This is a help message for the pipeline.
8+
It provides information about the parameters and usage.
9+
10+
Typical pipeline command:
11+
12+
nextflow run my_pipeline --input input_file.csv
13+
14+
--outdir
15+
type : string
16+
format : directory-path
17+
description: The output directory where the results will be saved. You have to use absolute paths to storage on Cloud infrastructure.
18+
------------------------------------------------------
19+
20+
For more information, please refer to the documentation.
21+

0 commit comments

Comments
 (0)