You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/process-typed.md
+118-2Lines changed: 118 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,7 +52,7 @@ process fastqc {
52
52
53
53
script:
54
54
"""
55
-
echo 'meta: ${meta}`
55
+
echo 'meta: ${meta}'
56
56
echo 'fastq: ${fastq}'
57
57
echo 'extra_args: ${extra_args}'
58
58
"""
@@ -65,6 +65,8 @@ All {ref}`standard types <stdlib-types>` except for the dataflow types (`Channel
65
65
66
66
Nextflow automatically stages `Path` inputs and `Path` collections (such as `Set<Path>`) into the task directory.
67
67
68
+
### Nullable inputs
69
+
68
70
By default, tasks fail if any input receives a `null` value. To allow `null` values, add `?` to the type annotation:
69
71
70
72
```nextflow
@@ -85,10 +87,83 @@ process cat_opt {
85
87
}
86
88
```
87
89
88
-
### Stage directives
90
+
### Record inputs
91
+
92
+
Inputs with type`Record` can declare the name and type of each record field:
93
+
94
+
```nextflow
95
+
process fastqc {
96
+
input:
97
+
sample: Record {
98
+
id: String
99
+
fastq: Path
100
+
}
101
+
102
+
script:
103
+
"""
104
+
echo 'id: ${sample.id}'
105
+
echo 'fastq: ${sample.fastq}'
106
+
"""
107
+
}
108
+
```
109
+
110
+
In this example, the record is staged into the task as `sample`, and `sample.fastq` is staged as an input file since the `fastq` field is declared with type`Path`.
111
+
112
+
When the process is invoked, the incoming record should contain the specified fields, or else the run will fail. If the record has additional fields not declared by the process input, they are ignored.
113
+
114
+
:::{tip}
115
+
Record inputs are a useful way to selecta subset of fields from a larger record. This way, the process only stages what it needs, allowing you to keep related data together in your workflow logic.
116
+
:::
117
+
118
+
You can achieve the same behavior using an external record type:
119
+
120
+
```nextflow
121
+
process fastqc {
122
+
input:
123
+
sample: Sample
124
+
125
+
script:
126
+
"""
127
+
echo 'id: ${sample.id}'
128
+
echo 'fastq: ${sample.fastq}'
129
+
"""
130
+
}
131
+
132
+
record Sample {
133
+
id: String
134
+
fastq: Path
135
+
}
136
+
```
137
+
138
+
This approach is useful when the record type can be re-used elsewhere in the pipeline.
139
+
140
+
### Tuple inputs
141
+
142
+
Inputs with type`Tuple` can declare the name of each tuple component:
143
+
144
+
```nextflow
145
+
process fastqc {
146
+
input:
147
+
(id, fastq): Tuple<String,Path>
148
+
149
+
script:
150
+
"""
151
+
echo 'id: ${id}'
152
+
echo 'fastq: ${fastq}'
153
+
"""
154
+
}
155
+
```
156
+
157
+
This pattern is called *tuple destructuring*. Each tuple component is staged into the task the same way as an individual input.
158
+
159
+
The generic types inside the `Tuple<...>` annotation specify the type of each tuple compomnent and should match the component names. In the above example, `id` has type`String` and `fastq` has type`Path`.
160
+
161
+
## Stage directives
89
162
90
163
The `stage:` section defines custom staging behavior using *stage directives*. It should be specified after the `input:` section. These directives serve the same purpose as input qualifiers such as `env` and `stdin`in the legacy syntax.
91
164
165
+
### Environment variables
166
+
92
167
The `env` directive declares an environment variable in terms of task inputs:
93
168
94
169
```nextflow
@@ -106,6 +181,8 @@ process echo_env {
106
181
}
107
182
```
108
183
184
+
### Standard input (stdin)
185
+
109
186
The `stdin` directive defines the standard input of the task script:
110
187
111
188
```nextflow
@@ -123,6 +200,8 @@ process cat {
123
200
}
124
201
```
125
202
203
+
### Custom file staging
204
+
126
205
The `stageAs` directive stages an input file (or files) under a custom file pattern:
127
206
128
207
```nextflow
@@ -222,6 +301,43 @@ process foo {
222
301
}
223
302
```
224
303
304
+
### Structured outputs
305
+
306
+
Whereas legacy process outputs could only be structured using specific qualifiers like `val` and `tuple`, typed process outputs are regular values.
307
+
308
+
The `record()` standard library functioncan be used to create a record:
The following operations are supported for records:
791
+
792
+
`+ : (Record, Record) -> Record`
793
+
: Given two records, returns a new record containing the fields and values of both records. When a field is present in both records, the value of the right-hand record takes precedence.
794
+
795
+
The following methods are available for a record:
796
+
797
+
`subMap( keys: Iterable<String> ) -> Record`
798
+
: Returns a new record containing only the given fields.
Copy file name to clipboardExpand all lines: docs/strict-syntax.md
+24-8Lines changed: 24 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,14 +50,29 @@ def json = new groovy.json.JsonSlurper().parseText(json_file.text)
50
50
51
51
Some users use classes in Nextflow to define helper functions or custom types. Helper functions should be defined as standalone functions in Nextflow. Custom types should be moved to the `lib` directory.
52
52
53
-
:::{note}
54
-
Enums, a special type of class, are supported, but they cannot be included across modules at this time.
55
-
:::
53
+
You can use an enum type to model a choice between a fixed set of categories:
56
54
57
-
:::{note}
58
-
Record types will be addressed in a future version of the Nextflow language specification.
55
+
```nextflow
56
+
enum Color {
57
+
RED,
58
+
GREEN,
59
+
BLUE
60
+
}
61
+
```
62
+
63
+
:::{versionadded} 26.04.0
59
64
:::
60
65
66
+
You can use a record type to model a composition of multiple values:
67
+
68
+
```nextflow
69
+
record FastqPair {
70
+
id: String
71
+
fastq_1: Path
72
+
fastq_2: Path
73
+
}
74
+
```
75
+
61
76
### Mixing script declarations and statements
62
77
63
78
In the strict syntax, a script may contain any of the following top-level declarations:
@@ -230,13 +245,14 @@ In the strict syntax, use `System.getenv()` instead:
230
245
println "PWD = ${System.getenv('PWD')}"
231
246
```
232
247
233
-
:::{versionadded} 24.04.0
234
-
The `env()` function should be used instead of `System.getenv()`:
248
+
:::{versionadded} 25.04.0
249
+
:::
250
+
251
+
Use the `env()` function instead of `System.getenv()`:
0 commit comments