Processes (typed)

New in version 25.10.0.

Note

This feature requires the strict syntax to be enabled (NXF_SYNTAX_PARSER=v2).

Process inputs and outputs can be defined using static types:

process hello {
    input:
    message: String

    output:
    file('hello.txt')

    script:
    """
    echo '${message}' > hello.txt
    """
}

See Process (typed) for a full description of the process syntax. See Migrating to static types for more information on migrating existing code to static types.

Inputs

The input: section is used to declare the inputs of a process. An input declaration in a typed process consists of a name and a type:

process fastqc {
    input:
    (meta, fastq): Tuple<Map,Path>
    extra_args: String

    script:
    """
    echo 'meta: ${meta}`
    echo 'fastq: ${fastq}'
    echo 'extra_args: ${extra_args}'
    """
}

Any of the standard types can be used as type annotations (except for Channel and Value, which can only be used in workflows).

File inputs

Inputs of type Path or a collection of Path (e.g. Set<Path>) are automatically staged into the task directory.

By default, the task will fail if any input receives a null value. You can mark an input as nullable by appending ? to the type annotation:

process cat_opt {
    input:
    input: Path?

    stage:
    stageAs 'input.txt', input

    output:
    stdout()

    script:
    '''
    [[ -f input.txt ]] && cat input.txt || echo 'empty input'
    '''
}

Stage directives

The stage: section can be specified after the input: section. You can use it to specify custom staging behavior using stage directives. These directives serve the same purpose as input qualifiers such as env and stdin in the legacy syntax.

The env directive declares an environment variable in terms of task inputs:

process echo_env {
    input:
    hello: String

    stage:
    env 'HELLO', hello

    script:
    '''
    echo "$HELLO world!"
    '''
}

The stdin directive defines the standard input of the task script:

process cat {
    input:
    message: String

    stage:
    stdin message

    script:
    """
    cat -
    """
}

The stageAs directive stages an input file (or files) under a custom file pattern:

process blast {
    input:
    fasta: Path

    stage:
    stageAs 'query.fa', fasta

    script:
    """
    blastp -query query.fa -db nr
    """
}

The file pattern can also reference task inputs:

process grep {
    input:
    id: String
    fasta: Path

    stage:
    stageAs "${id}.fa", fasta

    script:
    """
    cat ${id}.fa | grep '>'
    """
}

See Typed inputs and outputs for the set of available stage directives.

Outputs

The output: section is used to declare the outputs of a typed process. An output declaration in a typed process consists of a name, an optional type, and an output value:

process echo {
    input:
    message: String

    output:
    out_env: String = env('MESSAGE')
    out_file: Path = file('message.txt')
    out_std: String = stdout()

    script:
    """
    export MESSAGE='${message}'

    echo \$MESSAGE > message.txt

    cat message.txt
    """
}

When there is only one output, the name can be omitted:

process echo {
    input:
    message: String

    output:
    stdout()

    script:
    """
    echo '${message}'
    """
}

See Typed inputs and outputs for the set of available output functions.

File outputs

You can use the file() and files() functions in the output: section to get a single file or collection of output files from the task directory.

By default, the file() function will fail if the specified file is not present in the task directory. You can specify optional: true to allow the file to be missing, in which case the file() function will return null. For example:

process foo {
    output:
    file('output.txt', optional: true)

    script:
    """
    exit 0
    """
}

Topics

The topic: section is used to emit values to a topic channel. A topic emission consists of an output value and a topic name:

process cat {
    input:
    message: Path

    output:
    stdout()

    topic:
    tuple('bash', eval('bash --version')) >> 'versions'
    tuple('cat', eval('cat --version')) >> 'versions'

    script:
    """
    cat ${message}
    """
}

Topic emissions can use the same output functions that are available in the output: section.

Script

The script: and exec: sections behave the same way as legacy processes.

Stub

The stub: section behaves the same way as legacy processes.

Directives

Directives behave the same way as legacy processes.