-
Notifications
You must be signed in to change notification settings - Fork 195
nextflow format hello-nextflow/
#565
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
#!/usr/bin/env nextflow | ||
// Include modules | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the idea here that module includes should go before anything else? Is there a functional reason or is it purely stylistic? Any interactions wrt setting any variable values? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In principle, it's just a convention as it shouldn't matter where you put the includes In practice, users sometimes put the params first so that they are propagated to the included modules as a side effect. We are trying to move away from that pattern anyway |
||
include { sayHello } from './modules/sayHello.nf' | ||
include { convertToUpper } from './modules/convertToUpper.nf' | ||
include { collectGreetings } from './modules/collectGreetings.nf' | ||
include { cowpy } from './modules/cowpy.nf' | ||
|
||
|
||
/* | ||
* Pipeline parameters | ||
|
@@ -7,18 +13,13 @@ params.greeting = 'greetings.csv' | |
params.batch = 'test-batch' | ||
params.character = 'turkey' | ||
|
||
// Include modules | ||
include { sayHello } from './modules/sayHello.nf' | ||
include { convertToUpper } from './modules/convertToUpper.nf' | ||
include { collectGreetings } from './modules/collectGreetings.nf' | ||
include { cowpy } from './modules/cowpy.nf' | ||
|
||
workflow { | ||
|
||
// create a channel for inputs from a CSV file | ||
greeting_ch = Channel.fromPath(params.greeting) | ||
.splitCsv() | ||
.map { line -> line[0] } | ||
greeting_ch = Channel | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure I like having to put the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Honestly I agree. I would just need to add a special case in the formatter. Though I wonder if we would feel the same about any old There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For me I would do this for any old There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I imagine something like this: ch_samples
.filter { sample -> sample.n_reads >= 1_000_000 }
.map { sample -> sample.id } I think I prefer both calls to be on their own line. I think I treat channel factories differently in my head because the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the |
||
.fromPath(params.greeting) | ||
.splitCsv() | ||
.map { line -> line[0] } | ||
|
||
// emit a greeting | ||
sayHello(greeting_ch) | ||
|
@@ -30,7 +31,7 @@ workflow { | |
collectGreetings(convertToUpper.out.collect(), params.batch) | ||
|
||
// emit a message about the size of the batch | ||
collectGreetings.out.count.view { "There were $it greetings in this batch" } | ||
collectGreetings.out.count.view { "There were ${it} greetings in this batch" } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. are the extra curlies necessary here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also should we be explicitly naming the variable like we do later with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See my point above about curly braces. As for the implicit There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought I got all of the |
||
|
||
// generate ASCII art of the greetings with cowpy | ||
cowpy(collectGreetings.out.outfile, params.character) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,20 @@ | ||
#!/usr/bin/env nextflow | ||
workflow { | ||
|
||
// emit a greeting | ||
sayHello() | ||
} | ||
|
||
|
||
/* | ||
* Use echo to print 'Hello World!' to a file | ||
*/ | ||
process sayHello { | ||
|
||
output: | ||
path 'output.txt' | ||
path 'output.txt' | ||
|
||
script: | ||
""" | ||
echo 'Hello World!' > output.txt | ||
""" | ||
} | ||
|
||
workflow { | ||
|
||
// emit a greeting | ||
sayHello() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
#!/usr/bin/env nextflow | ||
workflow { | ||
|
||
// emit a greeting | ||
sayHello() | ||
} | ||
|
||
Comment on lines
+2
to
+7
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I dislike having workflow above processes. I use this order:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm debating whether to add an option to control the order (e.g. "Formatting > Entry workflow position") Or maybe just not try to re-order the definitions at all? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've always done processes first then workflows, but I'm coming around to it. I don't mind making @adamrtalbot feel uncomfortable, auto-formatters have that effect on everyone 😅 Though maybe this goes beyond what most formatters do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll survive if it gets reordered, but do we have a particular order that is preferred? It feels weird to be opinionated about something that isn't consequential (not that it's stopped me before). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't that what auto-formatters do? 😆 Basically no formatting is consequential. It's mostly for convention and consistency, so that folks get used to navigating pipeline code in the same way everywhere. Any colour, as long as it's black. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Most languages don't have this problem because they just have functions, no processes / workflows. I do think that most people put their workflows at the bottom. This is also the convention that Paolo used when he introduced DSL2 in the docs, which could explain it. I'm starting to think the formatter should just preserve the user's order for now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed - or at least make it opt in, off by default for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ..Maybe with includes as an exception? I do like having them at the top and alphabetically sorted 👀 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, feature flags / includes / params should go first no matter what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the |
||
|
||
/* | ||
* Use echo to print 'Hello World!' to a file | ||
|
@@ -8,16 +14,10 @@ process sayHello { | |
publishDir 'results', mode: 'copy' | ||
|
||
output: | ||
path 'output.txt' | ||
path 'output.txt' | ||
|
||
script: | ||
""" | ||
echo 'Hello World!' > output.txt | ||
""" | ||
} | ||
|
||
workflow { | ||
|
||
// emit a greeting | ||
sayHello() | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are the curly braces going to be mandatory? why do we need them?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are optional in certain cases like simple variable names. The formatter doesn't try to be smart here, it just always uses braces
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As for whether we should put them everywhere, there is a trade-off between consistency and shortcuts
Using curly braces everywhere requires a bit more typing but makes the code more consistent, therefore easier to read
Omitting the curly braces where possible saves a bit on typing but makes the code less consistent, thus the reader has to work a bit more to understand the different syntax forms
So I think it comes down to how much time we spend reading vs writing code. At least in software engineering, we spend way more time reading code, so I tend to favor consistency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's easier to teach consistency as well. So I like this change.