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/channel.md
+64-52Lines changed: 64 additions & 52 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,7 +70,7 @@ Channels may be created explicitly using the following channel factory methods.
70
70
71
71
### empty
72
72
73
-
The `empty` factory method, by definition, creates a channel that doesn't emit any value.
73
+
The `channel.empty` factory method, by definition, creates a channel that doesn't emit any value.
74
74
75
75
See also: {ref}`operator-ifempty`.
76
76
@@ -79,13 +79,13 @@ See also: {ref}`operator-ifempty`.
79
79
### from
80
80
81
81
:::{deprecated} 19.09.0-edge
82
-
Use [of](#of) or [fromList](#fromlist) instead.
82
+
Use [channel.of](#of) or [channel.fromList](#fromlist) instead.
83
83
:::
84
84
85
-
The `from` method allows you to create a channel emitting any sequence of values that are specified as the method argument, for example:
85
+
The `channel.from` method allows you to create a channel emitting any sequence of values that are specified as the method argument, for example:
86
86
87
87
```groovy
88
-
ch = Channel.from( 1, 3, 5, 7 )
88
+
ch = channel.from( 1, 3, 5, 7 )
89
89
ch.subscribe { println "value: $it" }
90
90
```
91
91
@@ -101,25 +101,25 @@ value: 7
101
101
The following example shows how to create a channel from a *range* of numbers or strings:
102
102
103
103
```groovy
104
-
zeroToNine = Channel.from( 0..9 )
105
-
strings = Channel.from( 'A'..'Z' )
104
+
zeroToNine = channel.from( 0..9 )
105
+
strings = channel.from( 'A'..'Z' )
106
106
```
107
107
108
108
:::{note}
109
-
When the `from` argument is an object implementing the (Java) [Collection](http://docs.oracle.com/javase/7/docs/api/java/util/Collection.html) interface, the resulting channel emits the collection entries as individual items.
109
+
When the `channel.from` argument is an object implementing the (Java) [Collection](http://docs.oracle.com/javase/7/docs/api/java/util/Collection.html) interface, the resulting channel emits the collection entries as individual items.
110
110
:::
111
111
112
112
Thus the following two declarations produce an identical result even though in the first case the items are specified as multiple arguments while in the second case as a single list object argument:
113
113
114
114
```groovy
115
-
Channel.from( 1, 3, 5, 7, 9 )
116
-
Channel.from( [1, 3, 5, 7, 9] )
115
+
channel.from( 1, 3, 5, 7, 9 )
116
+
channel.from( [1, 3, 5, 7, 9] )
117
117
```
118
118
119
119
But when more than one argument is provided, they are always managed as *single* emissions. Thus, the following example creates a channel emitting three entries each of which is a list containing two elements:
The above line creates a channel and binds it to a [Path](http://docs.oracle.com/javase/7/docs/api/java/nio/file/Path.html) object for the specified file.
162
+
The above line creates a channel and binds it to a [Path](http://docs.oracle.com/javase/7/docs/api/java/nio/file/Path.html)
163
+
object for the specified file.
162
164
163
165
:::{note}
164
-
`fromPath` does not check whether the file exists.
166
+
`channel.fromPath` does not check whether the file exists.
165
167
:::
166
168
167
-
Whenever the `fromPath` argument contains a `*` or `?` wildcard character it is interpreted as a [glob][glob] path matcher. For example:
169
+
Whenever the `channel.fromPath` argument contains a `*` or `?` wildcard character it is interpreted as a [glob][glob] path matcher.
The first line returns a channel emitting the files ending with the suffix `.fa` in the `data` folder *and* recursively in all its sub-folders. While the second one only emits the files which have the same suffix in *any* sub-folder in the `data` path. Finally the last example emits two files: `data/file_1.fq` and `data/file_2.fq`.
@@ -193,15 +196,15 @@ As in Linux Bash, the `*` wildcard does not catch hidden files (i.e. files whose
193
196
Multiple paths or glob patterns can be specified using a list:
The first example returns all hidden files in the specified path. The second one returns all hidden files ending with the `.fa` suffix. Finally the last example returns all files (hidden and non-hidden) in that path.
@@ -211,8 +214,8 @@ By default a [glob][glob] pattern only looks for regular file paths that match t
211
214
You can use the `type` option specifying the value `file`, `dir` or `any` in order to define what kind of paths you want. For example:
The first example will return all *directory* paths ending with the `b` suffix, while the second will return any file or directory starting with a `a` prefix.
@@ -244,10 +247,11 @@ Available options:
244
247
245
248
### fromFilePairs
246
249
247
-
The `fromFilePairs` method creates a channel emitting the file pairs matching a [glob][glob] pattern provided by the user. The matching files are emitted as tuples in which the first element is the grouping key of the matching pair and the second element is the list of files (sorted in lexicographical order). For example:
250
+
The `channel.fromFilePairs` method creates a channel emitting the file pairs matching a [glob][glob] pattern provided
251
+
by the user. The matching files are emitted as tuples in which the first element is the grouping key of the matching pair and the second element is the list of files (sorted in lexicographical order). For example:
248
252
249
253
```groovy
250
-
Channel
254
+
channel
251
255
.fromFilePairs('/my/data/SRR*_{1,2}.fastq')
252
256
.view()
253
257
```
@@ -270,13 +274,13 @@ The glob pattern must contain at least one `*` wildcard character.
270
274
Multiple glob patterns can be specified using a list:
Alternatively, it is possible to implement a custom file pair grouping strategy providing a closure which, given the current file as parameter, returns the grouping key. For example:
.view { ext, files -> "Files with the extension $ext are $files" }
282
286
```
@@ -311,10 +315,10 @@ Available options:
311
315
:::{versionadded} 19.04.0
312
316
:::
313
317
314
-
The `fromSRA` method queries the [NCBI SRA](https://www.ncbi.nlm.nih.gov/sra) database and returns a channel emitting the FASTQ files matching the specified criteria i.e project or accession number(s). For example:
318
+
The `channel.fromSRA` method queries the [NCBI SRA](https://www.ncbi.nlm.nih.gov/sra) database and returns a channel emitting the FASTQ files matching the specified criteria i.e project or accession number(s). For example:
315
319
316
320
```groovy
317
-
Channel
321
+
channel
318
322
.fromSRA('SRP043510')
319
323
.view()
320
324
```
@@ -335,7 +339,7 @@ Multiple accession IDs can be specified using a list object:
335
339
336
340
```groovy
337
341
ids = ['ERR908507', 'ERR908506', 'ERR908505']
338
-
Channel
342
+
channel
339
343
.fromSRA(ids)
340
344
.view()
341
345
```
@@ -356,7 +360,7 @@ To access the ESearch API, you must provide your [NCBI API keys](https://ncbiins
356
360
357
361
- The `apiKey` option:
358
362
```groovy
359
-
Channel.fromSRA(ids, apiKey:'0123456789abcdef')
363
+
channel.fromSRA(ids, apiKey:'0123456789abcdef')
360
364
```
361
365
362
366
- The `NCBI_API_KEY` variable in your environment:
@@ -385,14 +389,15 @@ Available options:
385
389
:::{versionadded} 19.10.0
386
390
:::
387
391
388
-
The `of` method allows you to create a channel that emits the arguments provided to it, for example:
392
+
The `channel.of` method allows you to create a channel that emits the arguments provided to it, for example:
389
393
390
394
```groovy
391
-
ch = Channel.of( 1, 3, 5, 7 )
395
+
ch = channel.of( 1, 3, 5, 7 )
392
396
ch.view { "value: $it" }
393
397
```
394
398
395
-
The first line in this example creates a variable `ch` which holds a channel object. This channel emits the arguments supplied to the `of` method. Thus the second line prints the following:
399
+
The first line in this example creates a variable `ch` which holds a channel object. This channel emits the arguments
400
+
supplied to the `of` method. Thus the second line prints the following:
396
401
397
402
```
398
403
value: 1
@@ -404,7 +409,7 @@ value: 7
404
409
Ranges of values are expanded accordingly:
405
410
406
411
```groovy
407
-
Channel
412
+
channel
408
413
.of(1..23, 'X', 'Y')
409
414
.view()
410
415
```
@@ -422,37 +427,42 @@ X
422
427
Y
423
428
```
424
429
425
-
See also: [fromList](#fromlist) factory method.
430
+
See also: [channel.fromList](#fromlist) factory method.
426
431
427
432
(channel-value)=
428
433
429
434
### value
430
435
431
-
The `value` method is used to create a value channel. An optional (not `null`) argument can be specified to bind the channel to a specific value. For example:
436
+
The `channel.value` method is used to create a value channel. An optional (not `null`) argument can be specified to bind
437
+
the channel to a specific value. For example:
432
438
433
439
```groovy
434
-
expl1 = Channel.value()
435
-
expl2 = Channel.value( 'Hello there' )
436
-
expl3 = Channel.value( [1,2,3,4,5] )
440
+
expl1 = channel.value()
441
+
expl2 = channel.value( 'Hello there' )
442
+
expl3 = channel.value( [1,2,3,4,5] )
437
443
```
438
444
439
-
The first line in the example creates an 'empty' variable. The second line creates a channel and binds a string to it. The third line creates a channel and binds a list object to it that will be emitted as a single value.
445
+
The first line in the example creates an 'empty' variable. The second line creates a channel and binds a string to it.
446
+
The third line creates a channel and binds a list object to it that will be emitted as a single value.
440
447
441
448
(channel-watchpath)=
442
449
443
450
### watchPath
444
451
445
-
The `watchPath` method watches a folder for one or more files matching a specified pattern. As soon as there is a file that meets the specified condition, it is emitted over the channel that is returned by the `watchPath` method. The condition on files to watch can be specified by using `*` or `?` wildcard characters i.e. by specifying a [glob][glob] path matching criteria.
452
+
The `channel.watchPath` method watches a folder for one or more files matching a specified pattern. As soon as there
453
+
is a file that meets the specified condition, it is emitted over the channel that is returned by the `watchPath` method.
454
+
The condition on files to watch can be specified by using `*` or `?` wildcard characters i.e. by specifying a [glob][glob] path matching criteria.
446
455
447
456
For example:
448
457
449
458
```groovy
450
-
Channel
459
+
channel
451
460
.watchPath( '/path/*.fa' )
452
461
.subscribe { println "Fasta file: $it" }
453
462
```
454
463
455
-
By default it watches only for new files created in the specified folder. Optionally, it is possible to provide a second argument that specifies what event(s) to watch. The supported events are:
464
+
By default it watches only for new files created in the specified folder. Optionally, it is possible to provide a second
465
+
argument that specifies what event(s) to watch. The supported events are:
456
466
457
467
-`create`: A new file is created (default)
458
468
-`modify`: A file is modified
@@ -461,15 +471,17 @@ By default it watches only for new files created in the specified folder. Option
461
471
You can specify more than one of these events by using a comma separated string as shown below:
462
472
463
473
```groovy
464
-
Channel
474
+
channel
465
475
.watchPath( '/path/*.fa', 'create,modify' )
466
476
.subscribe { println "File created or modified: $it" }
467
477
```
468
478
469
479
:::{warning}
470
-
The `watchPath` factory waits endlessly for files that match the specified pattern and event(s), which means that it will cause your pipeline to run forever. Consider using the `take` or `until` operator to close the channel when a certain condition is met (e.g. after receiving 10 files, receiving a file named `DONE`).
480
+
The `channel.watchPath` factory waits endlessly for files that match the specified pattern and event(s), which means
481
+
that it will cause your pipeline to run forever. Consider using the `take` or `until` operator to close the channel when
482
+
a certain condition is met (e.g. after receiving 10 files, receiving a file named `DONE`).
471
483
:::
472
484
473
-
See also: [fromPath](#frompath) factory method.
485
+
See also: [channel.fromPath](#frompath) factory method.
0 commit comments