From 88e82153ae80c4a805a39554b23d1408718f6d9e Mon Sep 17 00:00:00 2001 From: Jonathan Manning Date: Thu, 14 Nov 2024 12:25:39 +0000 Subject: [PATCH 1/2] Better describe use of flatten --- docs/hello_nextflow/02_hello_world.md | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docs/hello_nextflow/02_hello_world.md b/docs/hello_nextflow/02_hello_world.md index f6f8842f..40aa80c3 100644 --- a/docs/hello_nextflow/02_hello_world.md +++ b/docs/hello_nextflow/02_hello_world.md @@ -1100,6 +1100,35 @@ greeting_ch = Channel.fromPath(params.input_file) .flatten() ``` +If you want to see the impact of `.flatten()`, we can make use of `.view()`, another operator, to demonstrate. Edit that section of code so it looks like: + +```groovy title="flatten usage" +// create a channel for inputs from a CSV file +greeting_ch = Channel.fromPath(params.input_file) + .splitCsv() + .view{ "After splitCsv: $it" } + .flatten() + .view{ "After flatten: $it" } +``` + +When you run this updated workflow, you'll see the difference: + +```console title="view output with and without flatten" +After splitCsv: [Hello, World] +After splitCsv: [Bonjour, Monde] +After splitCsv: [Holà, Mundo] +After flatten: Hello +After flatten: World +After flatten: Bonjour +After flatten: Monde +After flatten: Holà +After flatten: Mundo +``` + +As you can see, the flatten() operator has transformed the channel from containing arrays to containing individual elements. This can be useful when you want to process each item separately in your workflow. + +Remove the `.view()` operations before you continue. + ### 9.3. Run the workflow (one last time!) ```bash From fb0ad3d86efe28580da138d54663baa062a426f6 Mon Sep 17 00:00:00 2001 From: Jonathan Manning Date: Thu, 14 Nov 2024 14:38:49 +0000 Subject: [PATCH 2/2] correct console output --- docs/hello_nextflow/02_hello_world.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/docs/hello_nextflow/02_hello_world.md b/docs/hello_nextflow/02_hello_world.md index 40aa80c3..753b1829 100644 --- a/docs/hello_nextflow/02_hello_world.md +++ b/docs/hello_nextflow/02_hello_world.md @@ -1114,15 +1114,16 @@ greeting_ch = Channel.fromPath(params.input_file) When you run this updated workflow, you'll see the difference: ```console title="view output with and without flatten" -After splitCsv: [Hello, World] -After splitCsv: [Bonjour, Monde] -After splitCsv: [Holà, Mundo] +After splitCsv: [Hello, Bonjour, Holà] After flatten: Hello -After flatten: World After flatten: Bonjour -After flatten: Monde After flatten: Holà -After flatten: Mundo +[d3/1a6e23] Submitted process > sayHello (3) +[8f/d9e431] Submitted process > sayHello (1) +[e7/a088af] Submitted process > sayHello (2) +[1a/776e2e] Submitted process > convertToUpper (1) +[83/fb8eba] Submitted process > convertToUpper (2) +[ee/280f93] Submitted process > convertToUpper (3) ``` As you can see, the flatten() operator has transformed the channel from containing arrays to containing individual elements. This can be useful when you want to process each item separately in your workflow.