diff --git a/hello-nextflow/hello-channels.nf b/hello-nextflow/hello-channels.nf index 6236eea21..207fd2e66 100644 --- a/hello-nextflow/hello-channels.nf +++ b/hello-nextflow/hello-channels.nf @@ -1,4 +1,15 @@ #!/usr/bin/env nextflow +/* + * Pipeline parameters + */ +params.greeting = 'Holà mundo!' + +workflow { + + // emit a greeting + sayHello(params.greeting) +} + /* * Use echo to print 'Hello World!' to a file @@ -8,24 +19,13 @@ process sayHello { publishDir 'results', mode: 'copy' input: - val greeting + val greeting output: - path 'output.txt' + path 'output.txt' script: """ - echo '$greeting' > output.txt + echo '${greeting}' > output.txt """ } - -/* - * Pipeline parameters - */ -params.greeting = 'Holà mundo!' - -workflow { - - // emit a greeting - sayHello(params.greeting) -} diff --git a/hello-nextflow/hello-config.nf b/hello-nextflow/hello-config.nf index f187831d1..e113fc9f2 100644 --- a/hello-nextflow/hello-config.nf +++ b/hello-nextflow/hello-config.nf @@ -1,4 +1,10 @@ #!/usr/bin/env nextflow +// 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' + /* * 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 + .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" } // generate ASCII art of the greetings with cowpy cowpy(collectGreetings.out.outfile, params.character) diff --git a/hello-nextflow/hello-containers.nf b/hello-nextflow/hello-containers.nf index 8764606bf..dc1e6b413 100644 --- a/hello-nextflow/hello-containers.nf +++ b/hello-nextflow/hello-containers.nf @@ -1,4 +1,9 @@ #!/usr/bin/env nextflow +// Include modules +include { sayHello } from './modules/sayHello.nf' +include { convertToUpper } from './modules/convertToUpper.nf' +include { collectGreetings } from './modules/collectGreetings.nf' + /* * Pipeline parameters @@ -6,17 +11,13 @@ params.greeting = 'greetings.csv' params.batch = 'test-batch' -// Include modules -include { sayHello } from './modules/sayHello.nf' -include { convertToUpper } from './modules/convertToUpper.nf' -include { collectGreetings } from './modules/collectGreetings.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 + .fromPath(params.greeting) + .splitCsv() + .map { line -> line[0] } // emit a greeting sayHello(greeting_ch) @@ -28,5 +29,5 @@ 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" } } diff --git a/hello-nextflow/hello-modules.nf b/hello-nextflow/hello-modules.nf index ccf29abd6..05c6c60f0 100644 --- a/hello-nextflow/hello-modules.nf +++ b/hello-nextflow/hello-modules.nf @@ -1,4 +1,31 @@ #!/usr/bin/env nextflow +/* + * Pipeline parameters + */ +params.greeting = 'greetings.csv' +params.batch = 'test-batch' + +workflow { + + // create a channel for inputs from a CSV file + greeting_ch = Channel + .fromPath(params.greeting) + .splitCsv() + .map { line -> line[0] } + + // emit a greeting + sayHello(greeting_ch) + + // convert the greeting to uppercase + convertToUpper(sayHello.out) + + // collect all the greetings into one file + 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" } +} + /* * Use echo to print 'Hello World!' to a file @@ -8,14 +35,14 @@ process sayHello { publishDir 'results', mode: 'copy' input: - val greeting + val greeting output: - path "${greeting}-output.txt" + path "${greeting}-output.txt" script: """ - echo '$greeting' > '$greeting-output.txt' + echo '${greeting}' > '${greeting}-output.txt' """ } @@ -27,14 +54,14 @@ process convertToUpper { publishDir 'results', mode: 'copy' input: - path input_file + path input_file output: - path "UPPER-${input_file}" + path "UPPER-${input_file}" script: """ - cat '$input_file' | tr '[a-z]' '[A-Z]' > 'UPPER-${input_file}' + cat '${input_file}' | tr '[a-z]' '[A-Z]' > 'UPPER-${input_file}' """ } @@ -46,42 +73,16 @@ process collectGreetings { publishDir 'results', mode: 'copy' input: - path input_files - val batch_name + path input_files + val batch_name output: - path "COLLECTED-${batch_name}-output.txt" , emit: outfile - val count_greetings , emit: count + path "COLLECTED-${batch_name}-output.txt", emit: outfile + val count_greetings, emit: count script: - count_greetings = input_files.size() + count_greetings = input_files.size() """ cat ${input_files} > 'COLLECTED-${batch_name}-output.txt' """ } - -/* - * Pipeline parameters - */ -params.greeting = 'greetings.csv' -params.batch = 'test-batch' - -workflow { - - // create a channel for inputs from a CSV file - greeting_ch = Channel.fromPath(params.greeting) - .splitCsv() - .map { line -> line[0] } - - // emit a greeting - sayHello(greeting_ch) - - // convert the greeting to uppercase - convertToUpper(sayHello.out) - - // collect all the greetings into one file - 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" } -} diff --git a/hello-nextflow/hello-workflow.nf b/hello-nextflow/hello-workflow.nf index 0f54be80c..ce3f06b22 100644 --- a/hello-nextflow/hello-workflow.nf +++ b/hello-nextflow/hello-workflow.nf @@ -1,4 +1,21 @@ #!/usr/bin/env nextflow +/* + * Pipeline parameters + */ +params.greeting = 'greetings.csv' + +workflow { + + // create a channel for inputs from a CSV file + greeting_ch = Channel + .fromPath(params.greeting) + .splitCsv() + .map { line -> line[0] } + + // emit a greeting + sayHello(greeting_ch) +} + /* * Use echo to print 'Hello World!' to a file @@ -8,29 +25,13 @@ process sayHello { publishDir 'results', mode: 'copy' input: - val greeting + val greeting output: - path "${greeting}-output.txt" + path "${greeting}-output.txt" script: """ - echo '$greeting' > '$greeting-output.txt' + echo '${greeting}' > '${greeting}-output.txt' """ } - -/* - * Pipeline parameters - */ -params.greeting = 'greetings.csv' - -workflow { - - // create a channel for inputs from a CSV file - greeting_ch = Channel.fromPath(params.greeting) - .splitCsv() - .map { line -> line[0] } - - // emit a greeting - sayHello(greeting_ch) -} diff --git a/hello-nextflow/hello-world.nf b/hello-nextflow/hello-world.nf index 4f672da2b..5c1de21b5 100644 --- a/hello-nextflow/hello-world.nf +++ b/hello-nextflow/hello-world.nf @@ -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() -} diff --git a/hello-nextflow/solutions/1-hello-world/hello-world-3.nf b/hello-nextflow/solutions/1-hello-world/hello-world-3.nf index f2e4b3344..49f80d993 100644 --- a/hello-nextflow/solutions/1-hello-world/hello-world-3.nf +++ b/hello-nextflow/solutions/1-hello-world/hello-world-3.nf @@ -1,4 +1,10 @@ #!/usr/bin/env nextflow +workflow { + + // emit a greeting + sayHello() +} + /* * 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() -} diff --git a/hello-nextflow/solutions/1-hello-world/hello-world-4.nf b/hello-nextflow/solutions/1-hello-world/hello-world-4.nf index 6236eea21..207fd2e66 100644 --- a/hello-nextflow/solutions/1-hello-world/hello-world-4.nf +++ b/hello-nextflow/solutions/1-hello-world/hello-world-4.nf @@ -1,4 +1,15 @@ #!/usr/bin/env nextflow +/* + * Pipeline parameters + */ +params.greeting = 'Holà mundo!' + +workflow { + + // emit a greeting + sayHello(params.greeting) +} + /* * Use echo to print 'Hello World!' to a file @@ -8,24 +19,13 @@ process sayHello { publishDir 'results', mode: 'copy' input: - val greeting + val greeting output: - path 'output.txt' + path 'output.txt' script: """ - echo '$greeting' > output.txt + echo '${greeting}' > output.txt """ } - -/* - * Pipeline parameters - */ -params.greeting = 'Holà mundo!' - -workflow { - - // emit a greeting - sayHello(params.greeting) -} diff --git a/hello-nextflow/solutions/2-hello-channels/hello-channels-1.nf b/hello-nextflow/solutions/2-hello-channels/hello-channels-1.nf index 6190b616a..d05c42cba 100644 --- a/hello-nextflow/solutions/2-hello-channels/hello-channels-1.nf +++ b/hello-nextflow/solutions/2-hello-channels/hello-channels-1.nf @@ -1,4 +1,18 @@ #!/usr/bin/env nextflow +/* + * Pipeline parameters + */ +params.greeting = 'Holà mundo!' + +workflow { + + // create a channel for inputs + greeting_ch = Channel.of('Hello Channels!') + + // emit a greeting + sayHello(greeting_ch) +} + /* * Use echo to print 'Hello World!' to a file @@ -8,27 +22,13 @@ process sayHello { publishDir 'results', mode: 'copy' input: - val greeting + val greeting output: - path 'output.txt' + path 'output.txt' script: """ - echo '$greeting' > output.txt + echo '${greeting}' > output.txt """ } - -/* - * Pipeline parameters - */ -params.greeting = 'Holà mundo!' - -workflow { - - // create a channel for inputs - greeting_ch = Channel.of('Hello Channels!') - - // emit a greeting - sayHello(greeting_ch) -} diff --git a/hello-nextflow/solutions/2-hello-channels/hello-channels-2.nf b/hello-nextflow/solutions/2-hello-channels/hello-channels-2.nf index 5e7a2d50f..9bdc274a2 100644 --- a/hello-nextflow/solutions/2-hello-channels/hello-channels-2.nf +++ b/hello-nextflow/solutions/2-hello-channels/hello-channels-2.nf @@ -1,4 +1,18 @@ #!/usr/bin/env nextflow +/* + * Pipeline parameters + */ +params.greeting = 'Holà mundo!' + +workflow { + + // create a channel for inputs + greeting_ch = Channel.of('Hello', 'Bonjour', 'Holà') + + // emit a greeting + sayHello(greeting_ch) +} + /* * Use echo to print 'Hello World!' to a file @@ -8,27 +22,13 @@ process sayHello { publishDir 'results', mode: 'copy' input: - val greeting + val greeting output: - path "${greeting}-output.txt" + path "${greeting}-output.txt" script: """ - echo '$greeting' > '$greeting-output.txt' + echo '${greeting}' > '${greeting}-output.txt' """ } - -/* - * Pipeline parameters - */ -params.greeting = 'Holà mundo!' - -workflow { - - // create a channel for inputs - greeting_ch = Channel.of('Hello','Bonjour','Holà') - - // emit a greeting - sayHello(greeting_ch) -} diff --git a/hello-nextflow/solutions/2-hello-channels/hello-channels-3.nf b/hello-nextflow/solutions/2-hello-channels/hello-channels-3.nf index 49de2cb65..274cad00a 100644 --- a/hello-nextflow/solutions/2-hello-channels/hello-channels-3.nf +++ b/hello-nextflow/solutions/2-hello-channels/hello-channels-3.nf @@ -1,4 +1,24 @@ #!/usr/bin/env nextflow +/* + * Pipeline parameters + */ +params.greeting = 'Holà mundo' + +workflow { + + greetings_array = ['Hello', 'Bonjour', 'Holà'] + + // create a channel for inputs + greeting_ch = Channel + .of(greetings_array) + .view { "Before flatten: ${it}" } + .flatten() + .view { "After flatten: ${it}" } + + // emit a greeting + sayHello(greeting_ch) +} + /* * Use echo to print 'Hello World!' to a file @@ -8,32 +28,13 @@ process sayHello { publishDir 'results', mode: 'copy' input: - val greeting + val greeting output: - path "${greeting}-output.txt" + path "${greeting}-output.txt" script: """ - echo '$greeting' > '$greeting-output.txt' + echo '${greeting}' > '${greeting}-output.txt' """ } - -/* - * Pipeline parameters - */ -params.greeting = 'Holà mundo' - -workflow { - - greetings_array = ['Hello','Bonjour','Holà'] - - // create a channel for inputs - greeting_ch = Channel.of(greetings_array) - .view { "Before flatten: $it" } - .flatten() - .view { "After flatten: $it" } - - // emit a greeting - sayHello(greeting_ch) -} diff --git a/hello-nextflow/solutions/2-hello-channels/hello-channels-4.nf b/hello-nextflow/solutions/2-hello-channels/hello-channels-4.nf index 449366b81..047e74cf8 100644 --- a/hello-nextflow/solutions/2-hello-channels/hello-channels-4.nf +++ b/hello-nextflow/solutions/2-hello-channels/hello-channels-4.nf @@ -1,4 +1,26 @@ #!/usr/bin/env nextflow +/* + * Pipeline parameters + */ +params.greeting = 'greetings.csv' + +workflow { + + greetings_array = ['Hello', 'Bonjour', 'Holà'] + + // create a channel for inputs from a CSV file + greeting_ch = Channel + .fromPath(params.greeting) + .view { "Before splitCsv: ${it}" } + .splitCsv() + .view { "After splitCsv: ${it}" } + .map { line -> line[0] } + .view { "After map: ${it}" } + + // emit a greeting + sayHello(greeting_ch) +} + /* * Use echo to print 'Hello World!' to a file @@ -8,34 +30,13 @@ process sayHello { publishDir 'results', mode: 'copy' input: - val greeting + val greeting output: - path "${greeting}-output.txt" + path "${greeting}-output.txt" script: """ - echo '$greeting' > '$greeting-output.txt' + echo '${greeting}' > '${greeting}-output.txt' """ } - -/* - * Pipeline parameters - */ -params.greeting = 'greetings.csv' - -workflow { - - greetings_array = ['Hello','Bonjour','Holà'] - - // create a channel for inputs from a CSV file - greeting_ch = Channel.fromPath(params.greeting) - .view { "Before splitCsv: $it" } - .splitCsv() - .view { "After splitCsv: $it" } - .map { line -> line[0] } - .view { "After map: $it" } - - // emit a greeting - sayHello(greeting_ch) -} diff --git a/hello-nextflow/solutions/3-hello-workflow/hello-workflow-1.nf b/hello-nextflow/solutions/3-hello-workflow/hello-workflow-1.nf index 9516d600f..bf5bed9dd 100644 --- a/hello-nextflow/solutions/3-hello-workflow/hello-workflow-1.nf +++ b/hello-nextflow/solutions/3-hello-workflow/hello-workflow-1.nf @@ -1,4 +1,24 @@ #!/usr/bin/env nextflow +/* + * Pipeline parameters + */ +params.greeting = 'greetings.csv' + +workflow { + + // create a channel for inputs from a CSV file + greeting_ch = Channel + .fromPath(params.greeting) + .splitCsv() + .map { line -> line[0] } + + // emit a greeting + sayHello(greeting_ch) + + // convert the greeting to uppercase + convertToUpper(sayHello.out) +} + /* * Use echo to print 'Hello World!' to a file @@ -8,14 +28,14 @@ process sayHello { publishDir 'results', mode: 'copy' input: - val greeting + val greeting output: - path "${greeting}-output.txt" + path "${greeting}-output.txt" script: """ - echo '$greeting' > '$greeting-output.txt' + echo '${greeting}' > '${greeting}-output.txt' """ } @@ -27,32 +47,13 @@ process convertToUpper { publishDir 'results', mode: 'copy' input: - path input_file + path input_file output: - path "UPPER-${input_file}" + path "UPPER-${input_file}" script: """ - cat '$input_file' | tr '[a-z]' '[A-Z]' > 'UPPER-${input_file}' + cat '${input_file}' | tr '[a-z]' '[A-Z]' > 'UPPER-${input_file}' """ } - -/* - * Pipeline parameters - */ -params.greeting = 'greetings.csv' - -workflow { - - // create a channel for inputs from a CSV file - greeting_ch = Channel.fromPath(params.greeting) - .splitCsv() - .map { line -> line[0] } - - // emit a greeting - sayHello(greeting_ch) - - // convert the greeting to uppercase - convertToUpper(sayHello.out) -} diff --git a/hello-nextflow/solutions/3-hello-workflow/hello-workflow-2.nf b/hello-nextflow/solutions/3-hello-workflow/hello-workflow-2.nf index f51792417..35e4dbc1d 100644 --- a/hello-nextflow/solutions/3-hello-workflow/hello-workflow-2.nf +++ b/hello-nextflow/solutions/3-hello-workflow/hello-workflow-2.nf @@ -1,4 +1,31 @@ #!/usr/bin/env nextflow +/* + * Pipeline parameters + */ +params.greeting = 'greetings.csv' + +workflow { + + // create a channel for inputs from a CSV file + greeting_ch = Channel + .fromPath(params.greeting) + .splitCsv() + .map { line -> line[0] } + + // emit a greeting + sayHello(greeting_ch) + + // convert the greeting to uppercase + convertToUpper(sayHello.out) + + // collect all the greetings into one file + collectGreetings(convertToUpper.out.collect()) + + // optional view statements + convertToUpper.out.view { "Before collect: ${it}" } + convertToUpper.out.collect().view { "After collect: ${it}" } +} + /* * Use echo to print 'Hello World!' to a file @@ -8,14 +35,14 @@ process sayHello { publishDir 'results', mode: 'copy' input: - val greeting + val greeting output: - path "${greeting}-output.txt" + path "${greeting}-output.txt" script: """ - echo '$greeting' > '$greeting-output.txt' + echo '${greeting}' > '${greeting}-output.txt' """ } @@ -27,14 +54,14 @@ process convertToUpper { publishDir 'results', mode: 'copy' input: - path input_file + path input_file output: - path "UPPER-${input_file}" + path "UPPER-${input_file}" script: """ - cat '$input_file' | tr '[a-z]' '[A-Z]' > 'UPPER-${input_file}' + cat '${input_file}' | tr '[a-z]' '[A-Z]' > 'UPPER-${input_file}' """ } @@ -46,39 +73,13 @@ process collectGreetings { publishDir 'results', mode: 'copy' input: - path input_files + path input_files output: - path "COLLECTED-output.txt" + path "COLLECTED-output.txt" script: """ cat ${input_files} > 'COLLECTED-output.txt' """ } - -/* - * Pipeline parameters - */ -params.greeting = 'greetings.csv' - -workflow { - - // create a channel for inputs from a CSV file - greeting_ch = Channel.fromPath(params.greeting) - .splitCsv() - .map { line -> line[0] } - - // emit a greeting - sayHello(greeting_ch) - - // convert the greeting to uppercase - convertToUpper(sayHello.out) - - // collect all the greetings into one file - collectGreetings(convertToUpper.out.collect()) - - // optional view statements - convertToUpper.out.view { "Before collect: $it" } - convertToUpper.out.collect().view { "After collect: $it" } -} diff --git a/hello-nextflow/solutions/3-hello-workflow/hello-workflow-3.nf b/hello-nextflow/solutions/3-hello-workflow/hello-workflow-3.nf index 65ac85ce0..fbd2c2647 100644 --- a/hello-nextflow/solutions/3-hello-workflow/hello-workflow-3.nf +++ b/hello-nextflow/solutions/3-hello-workflow/hello-workflow-3.nf @@ -1,4 +1,32 @@ #!/usr/bin/env nextflow +/* + * Pipeline parameters + */ +params.greeting = 'greetings.csv' +params.batch = 'test-batch' + +workflow { + + // create a channel for inputs from a CSV file + greeting_ch = Channel + .fromPath(params.greeting) + .splitCsv() + .map { line -> line[0] } + + // emit a greeting + sayHello(greeting_ch) + + // convert the greeting to uppercase + convertToUpper(sayHello.out) + + // collect all the greetings into one file + collectGreetings(convertToUpper.out.collect(), params.batch) + + // optional view statements + convertToUpper.out.view { "Before collect: ${it}" } + convertToUpper.out.collect().view { "After collect: ${it}" } +} + /* * Use echo to print 'Hello World!' to a file @@ -8,14 +36,14 @@ process sayHello { publishDir 'results', mode: 'copy' input: - val greeting + val greeting output: - path "${greeting}-output.txt" + path "${greeting}-output.txt" script: """ - echo '$greeting' > '$greeting-output.txt' + echo '${greeting}' > '${greeting}-output.txt' """ } @@ -27,14 +55,14 @@ process convertToUpper { publishDir 'results', mode: 'copy' input: - path input_file + path input_file output: - path "UPPER-${input_file}" + path "UPPER-${input_file}" script: """ - cat '$input_file' | tr '[a-z]' '[A-Z]' > 'UPPER-${input_file}' + cat '${input_file}' | tr '[a-z]' '[A-Z]' > 'UPPER-${input_file}' """ } @@ -46,41 +74,14 @@ process collectGreetings { publishDir 'results', mode: 'copy' input: - path input_files - val batch_name + path input_files + val batch_name output: - path "COLLECTED-${batch_name}-output.txt" + path "COLLECTED-${batch_name}-output.txt" script: """ cat ${input_files} > 'COLLECTED-${batch_name}-output.txt' """ } - -/* - * Pipeline parameters - */ -params.greeting = 'greetings.csv' -params.batch = 'test-batch' - -workflow { - - // create a channel for inputs from a CSV file - greeting_ch = Channel.fromPath(params.greeting) - .splitCsv() - .map { line -> line[0] } - - // emit a greeting - sayHello(greeting_ch) - - // convert the greeting to uppercase - convertToUpper(sayHello.out) - - // collect all the greetings into one file - collectGreetings(convertToUpper.out.collect(), params.batch) - - // optional view statements - convertToUpper.out.view { "Before collect: $it" } - convertToUpper.out.collect().view { "After collect: $it" } -} diff --git a/hello-nextflow/solutions/3-hello-workflow/hello-workflow-4.nf b/hello-nextflow/solutions/3-hello-workflow/hello-workflow-4.nf index 92af832e7..05c6c60f0 100644 --- a/hello-nextflow/solutions/3-hello-workflow/hello-workflow-4.nf +++ b/hello-nextflow/solutions/3-hello-workflow/hello-workflow-4.nf @@ -1,4 +1,31 @@ #!/usr/bin/env nextflow +/* + * Pipeline parameters + */ +params.greeting = 'greetings.csv' +params.batch = 'test-batch' + +workflow { + + // create a channel for inputs from a CSV file + greeting_ch = Channel + .fromPath(params.greeting) + .splitCsv() + .map { line -> line[0] } + + // emit a greeting + sayHello(greeting_ch) + + // convert the greeting to uppercase + convertToUpper(sayHello.out) + + // collect all the greetings into one file + 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" } +} + /* * Use echo to print 'Hello World!' to a file @@ -8,14 +35,14 @@ process sayHello { publishDir 'results', mode: 'copy' input: - val greeting + val greeting output: - path "${greeting}-output.txt" + path "${greeting}-output.txt" script: """ - echo '$greeting' > '$greeting-output.txt' + echo '${greeting}' > '${greeting}-output.txt' """ } @@ -27,14 +54,14 @@ process convertToUpper { publishDir 'results', mode: 'copy' input: - path input_file + path input_file output: - path "UPPER-${input_file}" + path "UPPER-${input_file}" script: """ - cat '$input_file' | tr '[a-z]' '[A-Z]' > 'UPPER-${input_file}' + cat '${input_file}' | tr '[a-z]' '[A-Z]' > 'UPPER-${input_file}' """ } @@ -46,46 +73,16 @@ process collectGreetings { publishDir 'results', mode: 'copy' input: - path input_files - val batch_name + path input_files + val batch_name output: - path "COLLECTED-${batch_name}-output.txt" , emit: outfile - val count_greetings , emit: count + path "COLLECTED-${batch_name}-output.txt", emit: outfile + val count_greetings, emit: count script: - count_greetings = input_files.size() + count_greetings = input_files.size() """ cat ${input_files} > 'COLLECTED-${batch_name}-output.txt' """ } - -/* - * Pipeline parameters - */ -params.greeting = 'greetings.csv' -params.batch = 'test-batch' - -workflow { - - // create a channel for inputs from a CSV file - greeting_ch = Channel.fromPath(params.greeting) - .splitCsv() - .map { line -> line[0] } - - // emit a greeting - sayHello(greeting_ch) - - // convert the greeting to uppercase - convertToUpper(sayHello.out) - - // collect all the greetings into one file - 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" } - - // optional view statements - //convertToUpper.out.view { "Before collect: $it" } - //convertToUpper.out.collect().view { "After collect: $it" } -} diff --git a/hello-nextflow/solutions/4-hello-modules/hello-modules-2.nf b/hello-nextflow/solutions/4-hello-modules/hello-modules-2.nf index 0d384c479..57f0f16b3 100644 --- a/hello-nextflow/solutions/4-hello-modules/hello-modules-2.nf +++ b/hello-nextflow/solutions/4-hello-modules/hello-modules-2.nf @@ -1,4 +1,34 @@ #!/usr/bin/env nextflow +// Include modules +include { sayHello } from './modules/sayHello.nf' + +/* + * Pipeline parameters + */ +params.greeting = 'greetings.csv' +params.batch = 'test-batch' + +workflow { + + // create a channel for inputs from a CSV file + greeting_ch = Channel + .fromPath(params.greeting) + .splitCsv() + .map { line -> line[0] } + + // emit a greeting + sayHello(greeting_ch) + + // convert the greeting to uppercase + convertToUpper(sayHello.out) + + // collect all the greetings into one file + 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" } +} + /* * Use a text replacement tool to convert the greeting to uppercase @@ -8,14 +38,14 @@ process convertToUpper { publishDir 'results', mode: 'copy' input: - path input_file + path input_file output: - path "UPPER-${input_file}" + path "UPPER-${input_file}" script: """ - cat '$input_file' | tr '[a-z]' '[A-Z]' > 'UPPER-${input_file}' + cat '${input_file}' | tr '[a-z]' '[A-Z]' > 'UPPER-${input_file}' """ } @@ -27,45 +57,16 @@ process collectGreetings { publishDir 'results', mode: 'copy' input: - path input_files - val batch_name + path input_files + val batch_name output: - path "COLLECTED-${batch_name}-output.txt" , emit: outfile - val count_greetings , emit: count + path "COLLECTED-${batch_name}-output.txt", emit: outfile + val count_greetings, emit: count script: - count_greetings = input_files.size() + count_greetings = input_files.size() """ cat ${input_files} > 'COLLECTED-${batch_name}-output.txt' """ } - -/* - * Pipeline parameters - */ -params.greeting = 'greetings.csv' -params.batch = 'test-batch' - -// Include modules -include { sayHello } from './modules/sayHello.nf' - -workflow { - - // create a channel for inputs from a CSV file - greeting_ch = Channel.fromPath(params.greeting) - .splitCsv() - .map { line -> line[0] } - - // emit a greeting - sayHello(greeting_ch) - - // convert the greeting to uppercase - convertToUpper(sayHello.out) - - // collect all the greetings into one file - 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" } -} diff --git a/hello-nextflow/solutions/4-hello-modules/hello-modules-3.nf b/hello-nextflow/solutions/4-hello-modules/hello-modules-3.nf index e34edebed..aded02a5b 100644 --- a/hello-nextflow/solutions/4-hello-modules/hello-modules-3.nf +++ b/hello-nextflow/solutions/4-hello-modules/hello-modules-3.nf @@ -1,26 +1,7 @@ #!/usr/bin/env nextflow - -/* - * Collect uppercase greetings into a single output file - */ -process collectGreetings { - - publishDir 'results', mode: 'copy' - - input: - path input_files - val batch_name - - output: - path "COLLECTED-${batch_name}-output.txt" , emit: outfile - val count_greetings , emit: count - - script: - count_greetings = input_files.size() - """ - cat ${input_files} > 'COLLECTED-${batch_name}-output.txt' - """ -} +// Include modules +include { sayHello } from './modules/sayHello.nf' +include { convertToUpper } from './modules/convertToUpper.nf' /* * Pipeline parameters @@ -28,16 +9,13 @@ process collectGreetings { params.greeting = 'greetings.csv' params.batch = 'test-batch' -// Include modules -include { sayHello } from './modules/sayHello.nf' -include { convertToUpper } from './modules/convertToUpper.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 + .fromPath(params.greeting) + .splitCsv() + .map { line -> line[0] } // emit a greeting sayHello(greeting_ch) @@ -49,5 +27,28 @@ 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" } +} + + +/* + * Collect uppercase greetings into a single output file + */ +process collectGreetings { + + publishDir 'results', mode: 'copy' + + input: + path input_files + val batch_name + + output: + path "COLLECTED-${batch_name}-output.txt", emit: outfile + val count_greetings, emit: count + + script: + count_greetings = input_files.size() + """ + cat ${input_files} > 'COLLECTED-${batch_name}-output.txt' + """ } diff --git a/hello-nextflow/solutions/4-hello-modules/hello-modules-4.nf b/hello-nextflow/solutions/4-hello-modules/hello-modules-4.nf index 8764606bf..dc1e6b413 100644 --- a/hello-nextflow/solutions/4-hello-modules/hello-modules-4.nf +++ b/hello-nextflow/solutions/4-hello-modules/hello-modules-4.nf @@ -1,4 +1,9 @@ #!/usr/bin/env nextflow +// Include modules +include { sayHello } from './modules/sayHello.nf' +include { convertToUpper } from './modules/convertToUpper.nf' +include { collectGreetings } from './modules/collectGreetings.nf' + /* * Pipeline parameters @@ -6,17 +11,13 @@ params.greeting = 'greetings.csv' params.batch = 'test-batch' -// Include modules -include { sayHello } from './modules/sayHello.nf' -include { convertToUpper } from './modules/convertToUpper.nf' -include { collectGreetings } from './modules/collectGreetings.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 + .fromPath(params.greeting) + .splitCsv() + .map { line -> line[0] } // emit a greeting sayHello(greeting_ch) @@ -28,5 +29,5 @@ 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" } } diff --git a/hello-nextflow/solutions/4-hello-modules/modules/collectGreetings.nf b/hello-nextflow/solutions/4-hello-modules/modules/collectGreetings.nf index 849bba4b6..615af082a 100644 --- a/hello-nextflow/solutions/4-hello-modules/modules/collectGreetings.nf +++ b/hello-nextflow/solutions/4-hello-modules/modules/collectGreetings.nf @@ -6,15 +6,15 @@ process collectGreetings { publishDir 'results', mode: 'copy' input: - path input_files - val batch_name + path input_files + val batch_name output: - path "COLLECTED-${batch_name}-output.txt" , emit: outfile - val count_greetings , emit: count + path "COLLECTED-${batch_name}-output.txt", emit: outfile + val count_greetings, emit: count script: - count_greetings = input_files.size() + count_greetings = input_files.size() """ cat ${input_files} > 'COLLECTED-${batch_name}-output.txt' """ diff --git a/hello-nextflow/solutions/4-hello-modules/modules/convertToUpper.nf b/hello-nextflow/solutions/4-hello-modules/modules/convertToUpper.nf index b2689e8e9..5d56eaaf9 100644 --- a/hello-nextflow/solutions/4-hello-modules/modules/convertToUpper.nf +++ b/hello-nextflow/solutions/4-hello-modules/modules/convertToUpper.nf @@ -8,13 +8,13 @@ process convertToUpper { publishDir 'results', mode: 'copy' input: - path input_file + path input_file output: - path "UPPER-${input_file}" + path "UPPER-${input_file}" script: """ - cat '$input_file' | tr '[a-z]' '[A-Z]' > 'UPPER-${input_file}' + cat '${input_file}' | tr '[a-z]' '[A-Z]' > 'UPPER-${input_file}' """ } diff --git a/hello-nextflow/solutions/4-hello-modules/modules/sayHello.nf b/hello-nextflow/solutions/4-hello-modules/modules/sayHello.nf index 6005ad54c..a1f4bc968 100644 --- a/hello-nextflow/solutions/4-hello-modules/modules/sayHello.nf +++ b/hello-nextflow/solutions/4-hello-modules/modules/sayHello.nf @@ -8,13 +8,13 @@ process sayHello { publishDir 'results', mode: 'copy' input: - val greeting + val greeting output: - path "${greeting}-output.txt" + path "${greeting}-output.txt" script: """ - echo '$greeting' > '$greeting-output.txt' + echo '${greeting}' > '${greeting}-output.txt' """ } diff --git a/hello-nextflow/solutions/5-hello-containers/hello-containers-2.nf b/hello-nextflow/solutions/5-hello-containers/hello-containers-2.nf index f187831d1..e113fc9f2 100644 --- a/hello-nextflow/solutions/5-hello-containers/hello-containers-2.nf +++ b/hello-nextflow/solutions/5-hello-containers/hello-containers-2.nf @@ -1,4 +1,10 @@ #!/usr/bin/env nextflow +// 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' + /* * 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 + .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" } // generate ASCII art of the greetings with cowpy cowpy(collectGreetings.out.outfile, params.character) diff --git a/hello-nextflow/solutions/5-hello-containers/modules/cowpy.nf b/hello-nextflow/solutions/5-hello-containers/modules/cowpy.nf index 60b739b62..4c97164cf 100644 --- a/hello-nextflow/solutions/5-hello-containers/modules/cowpy.nf +++ b/hello-nextflow/solutions/5-hello-containers/modules/cowpy.nf @@ -8,14 +8,14 @@ process cowpy { container 'community.wave.seqera.io/library/cowpy:1.1.5--3db457ae1977a273' input: - path input_file - val character + path input_file + val character output: - path "cowpy-${input_file}" + path "cowpy-${input_file}" script: """ - cat $input_file | cowpy -c "$character" > cowpy-${input_file} + cat ${input_file} | cowpy -c "${character}" > cowpy-${input_file} """ } diff --git a/hello-nextflow/solutions/6-hello-config/modules/cowpy.nf b/hello-nextflow/solutions/6-hello-config/modules/cowpy.nf index 2bc7ed612..eace1319e 100644 --- a/hello-nextflow/solutions/6-hello-config/modules/cowpy.nf +++ b/hello-nextflow/solutions/6-hello-config/modules/cowpy.nf @@ -9,14 +9,14 @@ process cowpy { conda 'conda-forge::cowpy==1.1.5' input: - path input_file - val character + path input_file + val character output: - path "cowpy-${input_file}" + path "cowpy-${input_file}" script: """ - cat $input_file | cowpy -c "$character" > cowpy-${input_file} + cat ${input_file} | cowpy -c "${character}" > cowpy-${input_file} """ }