Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better describe use of flatten #449

Merged
merged 2 commits into from
Nov 14, 2024
Merged
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
30 changes: 30 additions & 0 deletions docs/hello_nextflow/02_hello_world.md
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,36 @@ 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, Bonjour, Holà]
After flatten: Hello
After flatten: Bonjour
After flatten: Holà
[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.

Remove the `.view()` operations before you continue.

### 9.3. Run the workflow (one last time!)

```bash
Expand Down
Loading