Nextflow Example
Example
Let’s start with a very simple toy example for echo’ing the text “Hello World!” And then we’ll build to our bioinformatics example.
First, create a process called HELLO with our shell command:
process HELLO {
script:
"""
echo "Hello World!"
"""
}
Then we execute this process in our workflow:
workflow {
HELLO()
}
Create a New File called main.nf
We can create a new file called main.nf with these lines.
process HELLO {
script:
"""
echo "Hello World!"
"""
}
workflow {
HELLO()
}
Make some changes
process hello {
output:
path 'hello.txt'
script:
"""
echo 'Hello world!' > hello.txt
"""
}
We want to send the text to a file called ‘hello.txt.’ Now we can update our shell command to send the text to a file, and we can add an output in our process to define our file name and since out output is a file, we’ll specify the type of output as a path.
Run main.nf in terminal and show it still went to ‘work’ directory
This was better, but we still have to dig around for the file, so let’s add one more thing to our process.
Add a publishDir
Now let’s try sending our output to a directory called ‘results’ - we can add a publishDir to our process and specify the mode “copy” is safest, but you can do other things like move or even create links to the file.
Re-run the main.nf in the terminal and show where the file goes to results but since we did copy, it still does go to work.
process hello {
publishDir "results/" , mode: "copy"
output:
path 'hello.txt'
script:
"""
echo 'Hello world!' > hello.txt
"""
}