Mixed script pipeline

This pipeline shows how to use different scripting languages in a single Nextflow pipeline. The first process uses a Perl script to generate random number pairs, and the second process uses a Python script to calculate the average of each pair.

// Default parameter input
params.range = 100

// Perl process
process perlTask {
    output:
    stdout

    script:
    """
    #!/usr/bin/env perl
    use strict;
    use warnings;

    my \$count;
    my \$range = ${params.range};
    for (\$count = 0; \$count < 10; \$count++) {
        print rand(\$range) . ', ' . rand(\$range) . "\\n";
    }
    """
}

// Python process
process pyTask {
    input:
    stdin

    output:
    stdout

    script:
    """
    #!/usr/bin/env python
    import sys

    x = 0
    y = 0
    lines = 0
    for line in sys.stdin:
        items = line.strip().split(",")
        x += float(items[0])
        y += float(items[1])
        lines += 1

    print("avg: %s - %s" % ( x/lines, y/lines ))
    """
}

// Workflow block
workflow {
    perlTask | pyTask | view
}

Synopsis

This pipeline defines two processes:

perlTask: executes a Perl script that generates 10 pairs of random numbers within a configurable range and prints them to standard output

pyTask: executes a Python script that reads the pairs from standard input and calculates the average of each coordinate

Each process uses a shebang declaration at the start of its script block to specify the scripting language. Nextflow detects the shebang and executes the script using the appropriate interpreter.

The workflow block pipes the output of perlTask directly into pyTask, and then passes the result to the view operator to print it to the terminal.


Get started

To run this pipeline:

1. Install Nextflow (version 25.10 or later)

2. Create a new file named main.nf in your current directory

3. Copy and save the above script to your new file

4. Run your pipeline:

nextflow run main.nf

See Scripts à la carte for more information about using multiple scripting languages in Nextflow.