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
+128-5Lines changed: 128 additions & 5 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
@@ -73,7 +75,7 @@ process cat_opt {
73
75
input: Path?
74
76
75
77
stage:
76
-
stageAs 'input.txt', input
78
+
stageAs input, 'input.txt'
77
79
78
80
output:
79
81
stdout()
@@ -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,12 @@ process cat {
123
200
}
124
201
```
125
202
203
+
### Custom file staging
204
+
205
+
:::{versionchanged} 26.04.0
206
+
The method signature for`stageAs` was changed from `(filePattern, value)` to `(value, filePattern)`.
207
+
:::
208
+
126
209
The `stageAs` directive stages an input file (or files) under a custom file pattern:
127
210
128
211
```nextflow
@@ -131,7 +214,7 @@ process blast {
131
214
fasta: Path
132
215
133
216
stage:
134
-
stageAs 'query.fa', fasta
217
+
stageAs fasta, 'query.fa'
135
218
136
219
script:
137
220
"""
@@ -149,7 +232,7 @@ process grep {
149
232
fasta: Path
150
233
151
234
stage:
152
-
stageAs "${id}.fa", fasta
235
+
stageAs fasta, "${id}.fa"
153
236
154
237
script:
155
238
"""
@@ -222,6 +305,46 @@ process foo {
222
305
}
223
306
```
224
307
308
+
### Structured outputs
309
+
310
+
Whereas legacy process outputs could only be structured using specific qualifiers like `val` and `tuple`, typed process outputs are regular values.
311
+
312
+
The `record()` standard library functioncan be used to create a record:
313
+
314
+
```nextflow
315
+
process fastqc {
316
+
input:
317
+
sample: Record {
318
+
id: String
319
+
fastq: Path
320
+
}
321
+
322
+
output:
323
+
record(
324
+
id: sample.id,
325
+
fastqc: file('fastqc_logs')
326
+
)
327
+
328
+
script:
329
+
// ...
330
+
}
331
+
```
332
+
333
+
The `tuple()` standard library functioncan be used to create a tuple:
334
+
335
+
```nextflow
336
+
process fastqc {
337
+
input:
338
+
(id, fastq): Tuple<String,Path>
339
+
340
+
output:
341
+
tuple(id, file('fastqc_logs'))
342
+
343
+
script:
344
+
// ...
345
+
}
346
+
```
347
+
225
348
## Topics
226
349
227
350
The `topic:` section emits values to {ref}`topic channels <channel-topic>`. A topic emission consists of an output value and a topic name:
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.
0 commit comments