Skip to content

Commit 2cf8fda

Browse files
authored
Merge pull request #541 from nextflow-io/workflows_of_workflows
Add workflows of workflows side quest
2 parents 09b226c + 562a66e commit 2cf8fda

File tree

11 files changed

+615
-1
lines changed

11 files changed

+615
-1
lines changed

docs/side_quests/workflows_of_workflows.md

Lines changed: 457 additions & 0 deletions
Large diffs are not rendered by default.

main.nf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
1-
// This main.nf script has intentionally been left blank to run on Seqera Platform
1+
include { GREETING_WORKFLOW } from './workflows/greeting'
2+
3+
workflow {
4+
Channel.from('Alice', 'Bob', 'Charlie') | GREETING_WORKFLOW
5+
6+
GREETING_WORKFLOW.out.greetings_ch.view { "Original: $it" }
7+
GREETING_WORKFLOW.out.timestamped_ch.view { "Timestamped: $it" }
8+
}

mkdocs.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ nav:
2020
- hello_nextflow/06_hello_config.md
2121
- Side Quests:
2222
- side_quests/nf-test.md
23+
- side_quests/workflows_of_workflows.md
2324
- hello_nextflow/survey.md
2425
- hello_nextflow/next_steps.md
2526
- Nextflow for Genomics:
@@ -189,6 +190,7 @@ plugins:
189190
- advanced/index.md
190191
- advanced/orientation.md
191192
- side_quests/nf-test.md
193+
- side_quests/workflows_of_workflows.md
192194
- nf4_science/genomics/03_modules.md
193195
- nf4_science/genomics/04_testing.md
194196

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
include { GREETING_WORKFLOW } from './workflows/greeting'
2+
include { TRANSFORM_WORKFLOW } from './workflows/transform'
3+
4+
workflow {
5+
names = Channel.from('Alice', 'Bob', 'Charlie')
6+
7+
// Run the greeting workflow
8+
GREETING_WORKFLOW(names)
9+
10+
// Run the transform workflow
11+
TRANSFORM_WORKFLOW(GREETING_WORKFLOW.out.timestamped)
12+
13+
// View results
14+
TRANSFORM_WORKFLOW.out.upper.view { "Uppercase: $it" }
15+
TRANSFORM_WORKFLOW.out.reversed.view { "Reversed: $it" }
16+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
include { VALIDATE_NAME } from '../modules/validate_name'
2+
include { SAY_HELLO } from '../modules/say_hello'
3+
include { TIMESTAMP_GREETING } from '../modules/timestamp_greeting'
4+
5+
workflow GREETING_WORKFLOW {
6+
take:
7+
names_ch // Input channel with names
8+
9+
main:
10+
// Chain processes: validate -> create greeting -> add timestamp
11+
validated_ch = VALIDATE_NAME(names_ch)
12+
greetings_ch = SAY_HELLO(validated_ch)
13+
timestamped_ch = TIMESTAMP_GREETING(greetings_ch)
14+
15+
emit:
16+
greetings = greetings_ch // Original greetings
17+
timestamped = timestamped_ch // Timestamped greetings
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
include { SAY_HELLO_UPPER } from '../modules/say_hello_upper'
2+
include { REVERSE_TEXT } from '../modules/reverse_text'
3+
4+
workflow TRANSFORM_WORKFLOW {
5+
take:
6+
input_ch // Input channel with messages
7+
8+
main:
9+
// Apply transformations in sequence
10+
upper_ch = SAY_HELLO_UPPER(input_ch)
11+
reversed_ch = REVERSE_TEXT(upper_ch)
12+
13+
emit:
14+
upper = upper_ch // Uppercase greetings
15+
reversed = reversed_ch // Reversed uppercase greetings
16+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Use a text manipulation tool to reverse the text in a file
3+
*/
4+
process REVERSE_TEXT {
5+
publishDir 'results', mode: 'copy'
6+
7+
tag "reversing ${input_file}"
8+
9+
input:
10+
path input_file
11+
12+
output:
13+
path "REVERSED-${input_file}"
14+
15+
script:
16+
"""
17+
cat '${input_file}' | rev > 'REVERSED-${input_file}'
18+
"""
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env nextflow
2+
3+
/*
4+
* Use echo to print 'Hello World!' to a file
5+
*/
6+
process SAY_HELLO {
7+
publishDir 'results', mode: 'copy'
8+
9+
tag "greeting ${name}"
10+
11+
input:
12+
val name
13+
14+
output:
15+
path "${name}-output.txt"
16+
17+
script:
18+
"""
19+
echo 'Hello, ${name}!' > "${name}-output.txt"
20+
"""
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env nextflow
2+
3+
/*
4+
* Use a text replacement tool to convert the greeting to uppercase
5+
*/
6+
process SAY_HELLO_UPPER {
7+
publishDir 'results', mode: 'copy'
8+
9+
tag "converting ${input_file}"
10+
11+
input:
12+
path input_file
13+
14+
output:
15+
path "UPPER-${input_file}"
16+
17+
script:
18+
"""
19+
cat '${input_file}' | tr '[a-z]' '[A-Z]' > 'UPPER-${input_file}'
20+
"""
21+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
process TIMESTAMP_GREETING {
2+
tag "adding timestamp to greeting"
3+
4+
input:
5+
path greeting_file
6+
7+
output:
8+
path 'timestamped_*.txt'
9+
10+
script:
11+
def base_name = greeting_file.baseName
12+
"""
13+
echo "[\$(date '+%Y-%m-%d %H:%M:%S')] \$(cat $greeting_file)" > timestamped_${base_name}.txt
14+
"""
15+
}

0 commit comments

Comments
 (0)