Skip to content

Commit b641d67

Browse files
committed
Normalise channel docs
Signed-off-by: Paolo Di Tommaso <[email protected]>
1 parent b480ee0 commit b641d67

File tree

1 file changed

+64
-52
lines changed

1 file changed

+64
-52
lines changed

docs/channel.md

Lines changed: 64 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ Channels may be created explicitly using the following channel factory methods.
7070

7171
### empty
7272

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.
7474

7575
See also: {ref}`operator-ifempty`.
7676

@@ -79,13 +79,13 @@ See also: {ref}`operator-ifempty`.
7979
### from
8080

8181
:::{deprecated} 19.09.0-edge
82-
Use [of](#of) or [fromList](#fromlist) instead.
82+
Use [channel.of](#of) or [channel.fromList](#fromlist) instead.
8383
:::
8484

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:
8686

8787
```groovy
88-
ch = Channel.from( 1, 3, 5, 7 )
88+
ch = channel.from( 1, 3, 5, 7 )
8989
ch.subscribe { println "value: $it" }
9090
```
9191

@@ -101,25 +101,25 @@ value: 7
101101
The following example shows how to create a channel from a *range* of numbers or strings:
102102

103103
```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' )
106106
```
107107

108108
:::{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.
110110
:::
111111

112112
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:
113113

114114
```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] )
117117
```
118118

119119
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:
120120

121121
```groovy
122-
Channel.from( [1, 2], [5,6], [7,9] )
122+
channel.from( [1, 2], [5,6], [7,9] )
123123
```
124124

125125
(channel-fromlist)=
@@ -129,10 +129,10 @@ Channel.from( [1, 2], [5,6], [7,9] )
129129
:::{versionadded} 19.10.0
130130
:::
131131

132-
The `fromList` method allows you to create a channel emitting the values provided as a list of elements, for example:
132+
The `channel.fromList` method allows you to create a channel emitting the values provided as a list of elements, for example:
133133

134134
```groovy
135-
Channel
135+
channel
136136
.fromList( ['a', 'b', 'c', 'd'] )
137137
.view { "value: $it" }
138138
```
@@ -146,28 +146,31 @@ value: c
146146
value: d
147147
```
148148

149-
See also: [of](#of) factory method.
149+
See also: [channel.of](#of) factory method.
150150

151151
(channel-path)=
152152

153153
### fromPath
154154

155-
You can create a channel emitting one or more file paths by using the `fromPath` method and specifying a path string as an argument. For example:
155+
You can create a channel emitting one or more file paths by using the `channel.fromPath` method and specifying a path
156+
string as an argument. For example:
156157

157158
```groovy
158-
myFileChannel = Channel.fromPath( '/data/some/bigfile.txt' )
159+
myFileChannel = channel.fromPath( '/data/some/bigfile.txt' )
159160
```
160161

161-
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.
162164

163165
:::{note}
164-
`fromPath` does not check whether the file exists.
166+
`channel.fromPath` does not check whether the file exists.
165167
:::
166168

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.
170+
For example:
168171

169172
```groovy
170-
myFileChannel = Channel.fromPath( '/data/big/*.txt' )
173+
myFileChannel = channel.fromPath( '/data/big/*.txt' )
171174
```
172175

173176
This example creates a channel and emits as many `Path` items as there are files with `txt` extension in the `/data/big` folder.
@@ -179,9 +182,9 @@ Two asterisks, i.e. `**`, works like `*` but crosses directory boundaries. This
179182
For example:
180183

181184
```groovy
182-
files = Channel.fromPath( 'data/**.fa' )
183-
moreFiles = Channel.fromPath( 'data/**/*.fa' )
184-
pairFiles = Channel.fromPath( 'data/file_{1,2}.fq' )
185+
files = channel.fromPath( 'data/**.fa' )
186+
moreFiles = channel.fromPath( 'data/**/*.fa' )
187+
pairFiles = channel.fromPath( 'data/file_{1,2}.fq' )
185188
```
186189

187190
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
193196
Multiple paths or glob patterns can be specified using a list:
194197

195198
```groovy
196-
Channel.fromPath( ['/some/path/*.fq', '/other/path/*.fastq'] )
199+
channel.fromPath( ['/some/path/*.fq', '/other/path/*.fastq'] )
197200
```
198201

199202
In order to include hidden files, you need to start your pattern with a period character or specify the `hidden: true` option. For example:
200203

201204
```groovy
202-
expl1 = Channel.fromPath( '/path/.*' )
203-
expl2 = Channel.fromPath( '/path/.*.fa' )
204-
expl3 = Channel.fromPath( '/path/*', hidden: true )
205+
expl1 = channel.fromPath( '/path/.*' )
206+
expl2 = channel.fromPath( '/path/.*.fa' )
207+
expl3 = channel.fromPath( '/path/*', hidden: true )
205208
```
206209

207210
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
211214
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:
212215

213216
```groovy
214-
myFileChannel = Channel.fromPath( '/path/*b', type: 'dir' )
215-
myFileChannel = Channel.fromPath( '/path/a*', type: 'any' )
217+
myFileChannel = channel.fromPath( '/path/*b', type: 'dir' )
218+
myFileChannel = channel.fromPath( '/path/a*', type: 'any' )
216219
```
217220

218221
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:
244247

245248
### fromFilePairs
246249

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:
248252

249253
```groovy
250-
Channel
254+
channel
251255
.fromFilePairs('/my/data/SRR*_{1,2}.fastq')
252256
.view()
253257
```
@@ -270,13 +274,13 @@ The glob pattern must contain at least one `*` wildcard character.
270274
Multiple glob patterns can be specified using a list:
271275

272276
```groovy
273-
Channel.fromFilePairs( ['/some/data/SRR*_{1,2}.fastq', '/other/data/QFF*_{1,2}.fastq'] )
277+
channel.fromFilePairs( ['/some/data/SRR*_{1,2}.fastq', '/other/data/QFF*_{1,2}.fastq'] )
274278
```
275279

276280
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:
277281

278282
```groovy
279-
Channel
283+
channel
280284
.fromFilePairs('/some/data/*', size: -1) { file -> file.extension }
281285
.view { ext, files -> "Files with the extension $ext are $files" }
282286
```
@@ -311,10 +315,10 @@ Available options:
311315
:::{versionadded} 19.04.0
312316
:::
313317

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:
315319

316320
```groovy
317-
Channel
321+
channel
318322
.fromSRA('SRP043510')
319323
.view()
320324
```
@@ -335,7 +339,7 @@ Multiple accession IDs can be specified using a list object:
335339

336340
```groovy
337341
ids = ['ERR908507', 'ERR908506', 'ERR908505']
338-
Channel
342+
channel
339343
.fromSRA(ids)
340344
.view()
341345
```
@@ -356,7 +360,7 @@ To access the ESearch API, you must provide your [NCBI API keys](https://ncbiins
356360

357361
- The `apiKey` option:
358362
```groovy
359-
Channel.fromSRA(ids, apiKey:'0123456789abcdef')
363+
channel.fromSRA(ids, apiKey:'0123456789abcdef')
360364
```
361365

362366
- The `NCBI_API_KEY` variable in your environment:
@@ -385,14 +389,15 @@ Available options:
385389
:::{versionadded} 19.10.0
386390
:::
387391

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:
389393

390394
```groovy
391-
ch = Channel.of( 1, 3, 5, 7 )
395+
ch = channel.of( 1, 3, 5, 7 )
392396
ch.view { "value: $it" }
393397
```
394398

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:
396401

397402
```
398403
value: 1
@@ -404,7 +409,7 @@ value: 7
404409
Ranges of values are expanded accordingly:
405410

406411
```groovy
407-
Channel
412+
channel
408413
.of(1..23, 'X', 'Y')
409414
.view()
410415
```
@@ -422,37 +427,42 @@ X
422427
Y
423428
```
424429

425-
See also: [fromList](#fromlist) factory method.
430+
See also: [channel.fromList](#fromlist) factory method.
426431

427432
(channel-value)=
428433

429434
### value
430435

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:
432438

433439
```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] )
437443
```
438444

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.
440447

441448
(channel-watchpath)=
442449

443450
### watchPath
444451

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.
446455

447456
For example:
448457

449458
```groovy
450-
Channel
459+
channel
451460
.watchPath( '/path/*.fa' )
452461
.subscribe { println "Fasta file: $it" }
453462
```
454463

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:
456466

457467
- `create`: A new file is created (default)
458468
- `modify`: A file is modified
@@ -461,15 +471,17 @@ By default it watches only for new files created in the specified folder. Option
461471
You can specify more than one of these events by using a comma separated string as shown below:
462472

463473
```groovy
464-
Channel
474+
channel
465475
.watchPath( '/path/*.fa', 'create,modify' )
466476
.subscribe { println "File created or modified: $it" }
467477
```
468478

469479
:::{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`).
471483
:::
472484

473-
See also: [fromPath](#frompath) factory method.
485+
See also: [channel.fromPath](#frompath) factory method.
474486

475487
[glob]: http://docs.oracle.com/javase/tutorial/essential/io/fileOps.html#glob

0 commit comments

Comments
 (0)