Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/Footer.astro
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ import LogoSeqera from "../../public/img/assets/Logo_Seqera_white.svg";
<li>
<a
class="text-white font-inter text-xs font-normal leading-normal"
href="/mixing-scripting-languages.html">Mixing scripting languages</a
href="/mixing-scripting-languages.html">Mixed script pipeline</a
>
</li>
<li>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Menu/Menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ const Menu = ({}) => {
</li>
<li>
<a href="/mixing-scripting-languages.html" tabIndex={0}>
Mixing scripting languages
Mixed script pipeline
</a>
</li>
<li>
Expand Down
2 changes: 1 addition & 1 deletion src/components/SideNavigation/ExamplesSideNav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ExamplesSideNav = () => {
},
{
id: 'mixing-scripting-languages',
title: 'Mixing scripting languages',
title: 'Mixed script pipeline',
href: 'mixing-scripting-languages.html'
},
{
Expand Down
2 changes: 2 additions & 0 deletions src/pages/basic-pipeline.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ The `output` block (outside the workflow) defines where and how each output shou

<br>

### Get started

To run this pipeline:

<p style="padding-left: 40px;">1. <a href="https://docs.seqera.io/nextflow/install">Install Nextflow</a> (version 25.10 or later)</p>
Expand Down
72 changes: 49 additions & 23 deletions src/pages/mixing-scripting-languages.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,47 @@
---
title: Multiple inputs
title: Mixed script pipeline
layout: "@layouts/ExampleLayout.astro"
---

<div class="blg-summary example">
<h2>Mixing scripting languages</h2>
<h2>Mixed script pipeline</h2>

<p class="">
With Nextflow, you are not limited to Bash scripts -- you can use any scripting language! In other words, for each <i>process</i> you can use the language that best fits the specific task or that you simply prefer.
<p class="" >
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.
</p>

```groovy
#!/usr/bin/env nextflow

// Default parameter input
params.range = 100

/*
* A trivial Perl script that produces a list of number pairs
*/
// Perl process
process perlTask {
output:
stdout

shell:
'''
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";
my \$count;
my \$range = ${params.range};
for (\$count = 0; \$count < 10; \$count++) {
print rand(\$range) . ', ' . rand(\$range) . "\\n";
}
'''
"""
}

/*
* A Python script which parses the output of the previous script
*/
// Python process
process pyTask {
input:
stdin

output:
stdout

script:
"""
#!/usr/bin/env python
import sys
Expand All @@ -63,6 +59,7 @@ process pyTask {
"""
}

// Workflow block
workflow {
perlTask | pyTask | view
}
Expand All @@ -72,9 +69,38 @@ workflow {

### Synopsis

In the above example we define a simple pipeline with two processes.
This pipeline defines two processes:

<p style="padding-left: 40px;">&#8226; <code>perlTask</code>: executes a Perl script that generates 10 pairs of random numbers within a configurable range and prints them to standard output</p>

<p style="padding-left: 40px;">&#8226; <code>pyTask</code>: executes a Python script that reads the pairs from standard input and calculates the average of each coordinate</p>

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.

<br>

### Get started

To run this pipeline:

<p style="padding-left: 40px;">1. <a href="https://docs.seqera.io/nextflow/install">Install Nextflow</a> (version 25.10 or later)</p>

<p style="padding-left: 40px;">2. Create a new file named <code>main.nf</code> in your current directory</p>

<p style="padding-left: 40px;">3. Copy and save the above script to your new file</p>

<p style="padding-left: 40px;">4. Run your pipeline:</p>

<div style="padding-left: 60px; margin-top: 1rem;">

```
nextflow run main.nf
```

</div>

The first process executes a Perl script, because the script block definition starts
with a Perl _shebang_ declaration (line 14). Since Perl uses the `$` character for variables, we use the special `shell` block instead of the normal `script` block to easily distinguish the Perl variables from the Nextflow variables.
<br>

In the same way, the second process will execute a Python script, because the script block starts with a Python shebang (line 36).
See [Scripts à la carte](https://docs.seqera.io/nextflow/process#scripts-%C3%A0-la-carte) for more information about using multiple scripting languages in Nextflow.
Loading