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

replace view with dump #450

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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: 18 additions & 12 deletions docs/hello_nextflow/02_hello_world.md
Original file line number Diff line number Diff line change
Expand Up @@ -1100,35 +1100,41 @@ 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:
If you want to see the impact of `.flatten()`, we can make use of `.dump()`, 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" }
.dump(tag: "After splitCsv" )
.flatten()
.view{ "After flatten: $it" }
.dump(tag: "After flatten" )
```

and add `-dump-channels` to your run command:

```bash
nextflow run hello-world.nf -dump-channels
```

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)
[DUMP: After splitCsv] ['Hello', 'Bonjour', 'Holà']
[DUMP: After flatten] 'Hello'
[DUMP: After flatten] 'Bonjour'
[DUMP: After flatten] 'Holà'
```

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.
Remove the `.dump()` operations before you continue.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we don't need to with dump?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rephrased to make it optional. I am terrified of updating all line numbers everywhere.


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

Expand All @@ -1152,17 +1158,17 @@ Looking at the outputs, we see each greeting was correctly extracted and process

!!! tip

While you're developing your pipeline, you can inspect the contents of any channel by adding the `.view()` operator to the name of the channel.
For example, if you add `greeting_ch.view()` anywhere in the workflow body, when you run the script, Nextflow will print the channel contents to standard out.
While you're developing your pipeline, you can inspect the contents of any channel by adding the `.dump()` operator to the name of the channel and add `-dump-channels` to the run command.
For example, if you add `greeting_ch.dump()` anywhere in the workflow body, when you run the script, Nextflow will print the channel contents to standard out.

You can also use this to inspect the effect of the operators.
For example, the output of `Channel.fromPath(params.input_file).splitCsv().view()` will look like this:
For example, the output of `Channel.fromPath(params.input_file).splitCsv().dump()` will look like this:

```console title="Output"
[Hello, Bonjour, Holà]
```

While the output of `Channel.fromPath(params.input_file).splitCsv().flatten().view()` will look like this:
While the output of `Channel.fromPath(params.input_file).splitCsv().flatten().dump()` will look like this:

```console title="Output"
Hello
Expand Down