Skip to content

Commit a48ac58

Browse files
bentshermanchristopher-hakkaartpditommaso
authored
Document formal script syntax (#5336)
Signed-off-by: Ben Sherman <[email protected]> Signed-off-by: Christopher Hakkaart <[email protected]> Signed-off-by: Paolo Di Tommaso <[email protected]> Co-authored-by: Christopher Hakkaart <[email protected]> Co-authored-by: Paolo Di Tommaso <[email protected]>
1 parent ffdd381 commit a48ac58

Some content is hidden

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

61 files changed

+1416
-579
lines changed

docs/channel.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ process foo {
5252
5353
workflow {
5454
result = foo(1)
55-
result.view { "Result: ${it}" }
55+
result.view { file -> "Result: ${file}" }
5656
}
5757
```
5858

docs/config.md

Lines changed: 47 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,65 @@ You can use the `-C <config-file>` option to use a single configuration file and
2222

2323
## Syntax
2424

25-
A Nextflow configuration file is a simple text file containing a set of properties defined using the syntax:
25+
The Nextflow configuration syntax is based on the Nextflow script syntax. It is designed for setting configuration options in a declarative manner while also allowing for dynamic expressions where appropriate.
26+
27+
A Nextflow config file may consist of any number of *assignments*, *blocks*, and *includes*. Config files may also contain comments in the same manner as scripts.
28+
29+
See {ref}`syntax-page` for more information about the Nextflow script syntax.
30+
31+
### Assignments
32+
33+
A config assignment consists of a config option and an expression separated by an equals sign:
2634

2735
```groovy
28-
name = value
36+
workDir = 'work'
37+
docker.enabled = true
38+
process.maxErrors = 10
2939
```
3040

31-
Please note, string values need to be wrapped in quotation characters while numbers and boolean values (`true`, `false`) do not. Also note that values are typed. This means that, for example, `1` is different from `'1'` — the former is interpreted as the number one, while the latter is interpreted as a string value.
41+
A config option consists of an *option name* prefixed by any number of *scopes* separated by dots. Config scopes are used to group related config options. See {ref}`config-options` for the full set of config options.
42+
43+
The expression is typically a literal value such as a number, boolean, or string. However, any expression can be used:
3244

33-
### Variables
45+
```groovy
46+
params.helper_file = "${projectDir}/assets/helper.txt"
47+
```
3448

35-
Configuration properties can be used as variables in the configuration file by using the usual `$propertyName` or `${expression}` syntax.
49+
### Blocks
3650

37-
For example:
51+
A config scope can also be specified as a block, which may contain multiple configuration options. For example:
3852

3953
```groovy
40-
propertyOne = 'world'
41-
anotherProp = "Hello $propertyOne"
42-
customPath = "$PATH:/my/app/folder"
54+
// dot syntax
55+
docker.enabled = true
56+
docker.runOptions = '-u $(id -u):$(id -g)'
57+
58+
// block syntax
59+
docker {
60+
enabled = true
61+
runOptions = '-u $(id -u):$(id -g)'
62+
}
4363
```
4464

45-
Please note, the usual rules for {ref}`string-interpolation` are applied, thus a string containing a variable reference must be wrapped in double-quote chars instead of single-quote chars.
65+
As a result, deeply nested config options can be assigned in various ways. For example, the following three assignments are equivalent:
4666

47-
The same mechanism allows you to access environment variables defined in the hosting system. Any variable name not defined in the Nextflow configuration file(s) is interpreted to be a reference to an environment variable with that name. So, in the above example, the property `customPath` is defined as the current system `PATH` to which the string `/my/app/folder` is appended.
67+
```groovy
68+
executor.retry.maxAttempt = 5
4869
49-
### Comments
70+
executor {
71+
retry.maxAttempt = 5
72+
}
5073
51-
Configuration files use the same conventions for comments used by the Groovy or Java programming languages. Thus, use `//` to comment a single line, or `/*` .. `*/` to comment a block on multiple lines.
74+
executor {
75+
retry {
76+
maxAttempt = 5
77+
}
78+
}
79+
```
5280

5381
### Includes
5482

55-
A configuration file can include one or more configuration files using the keyword `includeConfig`. For example:
83+
A configuration file can include any number of other configuration files using the `includeConfig` keyword:
5684

5785
```groovy
5886
process.executor = 'sge'
@@ -62,7 +90,11 @@ process.memory = '10G'
6290
includeConfig 'path/foo.config'
6391
```
6492

65-
When a relative path is used, it is resolved against the actual location of the including file.
93+
Relative paths are resolved against the location of the including file.
94+
95+
:::{note}
96+
Config includes can also be specified within config blocks. However, config files should only be included at the top level or in a [profile](#config-profiles) so that the included config file is valid on its own and in the context in which it is included.
97+
:::
6698

6799
## Constants
68100

@@ -79,22 +111,6 @@ The following constants are globally available in a Nextflow configuration file:
79111
`projectDir`
80112
: The directory where the main script is located.
81113

82-
## Config scopes
83-
84-
Configuration settings can be organized in different scopes by dot prefixing the property names with a scope identifier, or grouping the properties in the same scope using the curly brackets notation. For example:
85-
86-
```groovy
87-
alpha.x = 1
88-
alpha.y = 'string value..'
89-
90-
beta {
91-
p = 2
92-
q = 'another string ..'
93-
}
94-
```
95-
96-
See {ref}`config-options` for the full list of config settings.
97-
98114
(config-params)=
99115

100116
## Parameters

docs/developer/plugins.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ This page describes how to create, test, and publish third-party plugins.
77

88
The best way to get started with your own plugin is to refer to the [nf-hello](https://github.com/nextflow-io/nf-hello) repository. This repository provides a minimal plugin implementation with several examples of different extension points and instructions for building, testing, and publishing.
99

10+
Plugins can be written in Java or Groovy.
11+
1012
The minimal dependencies are as follows:
1113

1214
```groovy
@@ -151,7 +153,7 @@ Refer to the source code of Nextflow's built-in executors to see how to implemen
151153
:::{versionadded} 22.09.0-edge
152154
:::
153155

154-
Plugins can define custom Groovy functions, which can then be included into Nextflow pipelines.
156+
Plugins can define custom functions, which can then be included in Nextflow pipelines.
155157

156158
To implement a custom function, create a class in your plugin that extends the `PluginExtensionPoint` class, and implement your function with the `Function` annotation:
157159

docs/dsl1.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ In DSL1, the entire Nextflow pipeline must be defined in a single file (e.g. `ma
8888
DSL2 introduces the concept of "module scripts" (or "modules" for short), which are Nextflow scripts that can be "included" by other scripts. While modules are not essential to migrating to DSL2, nor are they mandatory in DSL2 by any means, modules can help you organize a large pipeline into multiple smaller files, and take advantage of modules created by others. Check out the {ref}`module-page` to get started.
8989

9090
:::{note}
91-
With DSL2, the Groovy shell used by Nextflow also imposes a 64KB size limit on pipeline scripts, so if your DSL1 script is very large, you may need to split your script into modules anyway to avoid this limit.
91+
DSL2 scripts cannot exceed 64 KB in size. Large DSL1 scripts may need to be split into modules to avoid this limit.
9292
:::
9393

9494
## Deprecations

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ fusion
111111
:caption: Reference
112112
:maxdepth: 1
113113
114+
reference/syntax
114115
reference/cli
115116
reference/config
116117
reference/env-vars

docs/module.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
# Modules
44

5-
In Nextflow, a **module** is a script that may contain functions, processes, and workflows (collectively referred to as *components*). A module can be included in other modules or pipeline scripts and even shared across workflows.
5+
Nextflow scripts can include **definitions** (workflows, processes, and functions) from other scripts. When a script is included in this way, it is referred to as a **module**. Modules can be included by other modules or pipeline scripts and can even be shared across workflows.
66

77
:::{note}
88
Modules were introduced in DSL2. If you are still using DSL1, see the {ref}`dsl1-page` page to learn how to migrate your Nextflow pipelines to DSL2.
99
:::
1010

1111
## Module inclusion
1212

13-
A component defined in a module script can be imported into another Nextflow script using the `include` keyword.
13+
You can include any definition from a module into a Nextflow script using the `include` keyword.
1414

1515
For example:
1616

@@ -23,7 +23,7 @@ workflow {
2323
}
2424
```
2525

26-
The above snippet imports a process named `foo`, defined in the module script, into the main execution context. This way, `foo` can be invoked in the `workflow` scope.
26+
The above snippet imports a process named `foo`, defined in the module, into the main execution context. This way, `foo` can be invoked in the `workflow` scope.
2727

2828
Nextflow implicitly looks for the script file `./some/module.nf`, resolving the path against the *including* script location.
2929

@@ -57,7 +57,7 @@ Module directories allow the use of module scoped binaries scripts. See [Module
5757

5858
## Multiple inclusions
5959

60-
A Nextflow script can include any number of modules, and an `include` statement can import any number of components from a module. Multiple components can be included from the same module by using the syntax shown below:
60+
A Nextflow script can include any number of modules, and an `include` statement can import any number of definitions from a module. Multiple definitions can be included from the same module by using the syntax shown below:
6161

6262
```groovy
6363
include { foo; bar } from './some/module'
@@ -73,7 +73,7 @@ workflow {
7373

7474
## Module aliases
7575

76-
When including a module component, it's possible to specify an *alias* with the `as` keyword. Aliasing allows you to avoid module name clashes, by assigning them different names in the including context. For example:
76+
When including definition from a module, it's possible to specify an *alias* with the `as` keyword. Aliasing allows you to avoid module name clashes, by assigning them different names in the including context. For example:
7777

7878
```groovy
7979
include { foo } from './some/module'
@@ -85,7 +85,7 @@ workflow {
8585
}
8686
```
8787

88-
You can even include the same component multiple times under different names:
88+
You can also include the same definition multiple times under different names:
8989

9090
```groovy
9191
include { foo; foo as bar } from './some/module'
@@ -96,13 +96,15 @@ workflow {
9696
}
9797
```
9898

99+
(module-params)=
100+
99101
## Module parameters
100102

101103
:::{deprecated} 24.07.0-edge
102-
As a best practice, parameters should be used in the entry workflow and passed to functions / processes / workflows as explicit inputs.
104+
As a best practice, parameters should be used in the entry workflow and passed to workflows, processes, and functions as explicit inputs.
103105
:::
104106

105-
A module script can define parameters using the same syntax as a Nextflow workflow script:
107+
A module can define parameters using the same syntax as a Nextflow workflow script:
106108

107109
```groovy
108110
params.foo = 'Hello'
@@ -182,9 +184,9 @@ Ciao world!
182184

183185
## Module templates
184186

185-
The module script can be defined in an external {ref}`template <process-template>` file. The template file can be placed in the `templates` directory where the module script is located.
187+
Process script {ref}`templates <process-template>` can be included alongside a module in the `templates` directory.
186188

187-
For example, suppose we have a project L with a module script that defines two processes, P1 and P2, both of which use templates. The template files can be made available in the local `templates` directory:
189+
For example, suppose we have a project L with a module that defines two processes, P1 and P2, both of which use templates. The template files can be made available in the local `templates` directory:
188190

189191
```
190192
Project L
@@ -208,15 +210,15 @@ Pipeline B
208210
└── main.nf
209211
```
210212

211-
With the possibility to keep the template files inside the project L, A and B can use the modules defined in L without any changes. A future project C would do the same, just cloning L (if not available on the system) and including its module script.
213+
With the possibility to keep the template files inside the project L, A and B can use the modules defined in L without any changes. A future project C would do the same, just cloning L (if not available on the system) and including its module.
212214

213215
Beside promoting the sharing of modules across pipelines, there are several advantages to keeping the module template under the script path:
214216

215-
1. module components are *self-contained*,
216-
2. module components can be tested independently from the pipeline(s) that import them,
217-
3. it is possible to create libraries of module components.
217+
1. Modules are self-contained
218+
2. Modules can be tested independently from the pipeline(s) that import them
219+
3. Modules can be made into libraries
218220

219-
Ultimately, having multiple template locations allows a more structured organization within the same project. If a project has several module components, and all of them use templates, the project could group module scripts and their templates as needed. For example:
221+
Having multiple template locations enables a structured project organization. If a project has several modules, and they all use templates, the project could group module scripts and their templates as needed. For example:
220222

221223
```
222224
baseDir

docs/overview.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,9 @@ Read the {ref}`executor-page` to learn more about the Nextflow executors.
9595

9696
## Scripting language
9797

98-
Nextflow is designed to have a minimal learning curve, without having to pick up a new programming language. In most cases, users can utilise their current skills to develop Nextflow workflows. However, it also provides a powerful scripting DSL.
98+
Nextflow is a workflow language based on [Java](https://en.wikipedia.org/wiki/Java_(programming_language)) and [Groovy](https://groovy-lang.org/). It is designed to simplify writing scalable and reproducible pipelines. In most cases, users can leverage their existing programming skills to develop Nextflow pipelines without the steep learning curve that usually comes with a new programming language.
9999

100-
Nextflow scripting is an extension of the [Groovy programming language](<http://en.wikipedia.org/wiki/Groovy_(programming_language)>), which in turn is a super-set of the Java programming language. Groovy can be considered as Python for Java in that it simplifies the writing of code and is more approachable.
101-
102-
Read the {ref}`script-page` section to learn about the Nextflow scripting language.
100+
See {ref}`script-page` for more information about the Nextflow scripting language.
103101

104102
## Configuration options
105103

0 commit comments

Comments
 (0)