Skip to content

Commit

Permalink
Improve docs for process path input/output arity
Browse files Browse the repository at this point in the history
Signed-off-by: Ben Sherman <[email protected]>
  • Loading branch information
bentsherman committed Mar 3, 2025
1 parent fedf593 commit dbe1db7
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions docs/process.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,27 +473,11 @@ workflow {
}
```

:::{versionadded} 23.09.0-edge
:::

By default, `path` inputs will accept any number of files and stage them accordingly. The `arity` option can be used to enforce the expected number of files, either as a number or a range.

For example:

```nextflow
input:
path('one.txt', arity: '1') // exactly one file is expected
path('pair_*.txt', arity: '2') // exactly two files are expected
path('many_*.txt', arity: '1..*') // one or more files are expected
```

When a task is executed, Nextflow will check whether the received files for each path input match the declared arity, and fail if they do not.

:::{note}
Process `path` inputs have nearly the same interface as described in {ref}`stdlib-types-path`, with one difference which is relevant when files are staged into a subdirectory. Given the following input:

```nextflow
path x, name: 'my-dir/*'
path x, name: 'my-dir/file.txt'
```

In this case, `x.name` returns the file name with the parent directory (e.g. `my-dir/file.txt`), whereas normally it would return the file name (e.g. `file.txt`). You can use `x.fileName.name` to get the file name.
Expand Down Expand Up @@ -532,12 +516,12 @@ seq1 seq2 seq3

The target input file name may contain the `*` and `?` wildcards, which can be used to control the name of staged files. The following table shows how the wildcards are replaced depending on the cardinality of the received input collection.

| Cardinality | Name pattern | Staged file names |
| Arity | Name pattern | Staged file names |
| ----------- | ------------ | ------------------------------------------------------------------------------------------------------- |
| any | `*` | named as the source file |
| 1 | `file*.ext` | `file.ext` |
| 1 | `file?.ext` | `file1.ext` |
| 1 | `file??.ext` | `file01.ext` |
| one | `file*.ext` | `file.ext` |
| one | `file?.ext` | `file1.ext` |
| one | `file??.ext` | `file01.ext` |
| many | `file*.ext` | `file1.ext`, `file2.ext`, `file3.ext`, .. |
| many | `file?.ext` | `file1.ext`, `file2.ext`, `file3.ext`, .. |
| many | `file??.ext` | `file01.ext`, `file02.ext`, `file03.ext`, .. |
Expand Down Expand Up @@ -568,6 +552,22 @@ workflow {
Rewriting input file names according to a named pattern is an extra feature and not at all required. The normal file input syntax introduced in the {ref}`process-input-path` section is valid for collections of multiple files as well. To handle multiple input files while preserving the original file names, use a variable identifier or the `*` wildcard.
:::

:::{versionadded} 23.09.0-edge
:::

The `arity` option can be used to enforce the expected number of files, either as a number or a range.

For example:

```nextflow
input:
path('one.txt', arity: '1') // exactly one file is expected
path('pair_*.txt', arity: '2') // exactly two files are expected
path('many_*.txt', arity: '1..*') // one or more files are expected
```

When a task is executed, Nextflow will check whether the received files for each path input match the declared arity, and fail if they do not. When the arity is `'1'`, the corresponding input or output variable will be a single file; otherwise, it will be a list of files.

### Dynamic input file names

When the input file name is specified by using the `name` option or a string literal, you can also use other input values as variables in the file name string. For example:
Expand Down

0 comments on commit dbe1db7

Please sign in to comment.