Variable Inputs

Overview

  • Tutorial: 15 min

    Objectives:
    • Learn how to use command line inputs.

input directive defines the data or parameters that a process requires to execute.

 1#!/usr/bin/env nextflow
 2
 3process sayHello {
 4
 5    publishDir 'results', mode: 'copy'
 6
 7    input:
 8        val message
 9
10    output:
11        path 'output.txt'
12
13    script:
14    """
15    echo '$message' > output.txt
16    """
17}
18
19workflow {
20    sayHello(params.message)
21}

Explanation

The val prefix indicates that message is a single value. Instead of hardcoding it (sayHello(‘Hello World!’)), we can params, Nextflow’s built-in system for command-line inputs. Declaring params.<parameter_name> allows passing –<parameter_name> when running the workflow.

To pass a value from the commandline and run the workflow we use the command:

1nextflow run 3_input.nf --message 'Good Morning!'

Exercise

  • What happens when you dont pass a message?

1nextflow run 3_input.nf

Key Points

  1. The input directive specifies the required data or parameters for a process.

  2. The val prefix defines message as a single value, which can be passed dynamically instead of hardcoding it.

  3. Nextflow’s params system allows command-line input.