From 1d7b013f0854775d6ee5dcdfbea36a3f01469271 Mon Sep 17 00:00:00 2001 From: Ben Sherman Date: Wed, 29 Nov 2023 19:24:38 -0600 Subject: [PATCH 1/3] Use annotation API Signed-off-by: Ben Sherman --- lib/Sample.groovy | 14 ++++++++++++++ main.nf | 6 +++--- modules/fastqc/main.nf | 29 ++++++++++++++++------------- modules/index/main.nf | 25 ++++++++++++++----------- modules/multiqc/main.nf | 27 +++++++++++++++------------ modules/quant/main.nf | 29 ++++++++++++++++------------- 6 files changed, 78 insertions(+), 52 deletions(-) create mode 100644 lib/Sample.groovy diff --git a/lib/Sample.groovy b/lib/Sample.groovy new file mode 100644 index 0000000..e66a53d --- /dev/null +++ b/lib/Sample.groovy @@ -0,0 +1,14 @@ + +import java.nio.file.Path +import nextflow.io.ValueObject +import nextflow.util.KryoHelper + +@ValueObject +class Sample { + String id + List reads + + static { + KryoHelper.register(Sample) + } +} diff --git a/main.nf b/main.nf index 77d2d70..512c125 100755 --- a/main.nf +++ b/main.nf @@ -51,9 +51,9 @@ include { MULTIQC } from './modules/multiqc' * main script flow */ workflow { - read_pairs_ch = channel.fromFilePairs( params.reads, checkIfExists: true ) - RNASEQ( params.transcriptome, read_pairs_ch ) - MULTIQC( RNASEQ.out, params.multiqc ) + read_pairs_ch = channel.fromFilePairs( params.reads, checkIfExists: true ).map { args -> new Sample(*args) } + RNASEQ( file(params.transcriptome), read_pairs_ch ) + MULTIQC( RNASEQ.out, file(params.multiqc) ) } /* diff --git a/modules/fastqc/main.nf b/modules/fastqc/main.nf index cd58cbb..fb7befb 100644 --- a/modules/fastqc/main.nf +++ b/modules/fastqc/main.nf @@ -1,18 +1,21 @@ params.outdir = 'results' -process FASTQC { - tag "FASTQC on $sample_id" - conda 'fastqc=0.12.1' - publishDir params.outdir, mode:'copy' - - input: - tuple val(sample_id), path(reads) - - output: - path "fastqc_${sample_id}_logs" - - script: +@ProcessFn( + directives={ + tag { "FASTQC on $sample.id" } + conda 'fastqc=0.12.1' + publishDir params.outdir, mode:'copy' + }, + inputs={ + path { sample.reads } + }, + outputs={ + path { "fastqc_${sample.id}_logs" } + }, + script=true +) +def FASTQC(Sample sample) { """ - fastqc.sh "$sample_id" "$reads" + fastqc.sh "$sample.id" "${sample.reads.join(' ')}" """ } diff --git a/modules/index/main.nf b/modules/index/main.nf index de55e46..48a0d3c 100644 --- a/modules/index/main.nf +++ b/modules/index/main.nf @@ -1,15 +1,18 @@ -process INDEX { - tag "$transcriptome.simpleName" - conda 'salmon=1.10.2' - - input: - path transcriptome - - output: - path 'index' - - script: +@ProcessFn( + directives={ + tag { transcriptome.simpleName } + conda 'salmon=1.10.2' + }, + inputs={ + path { transcriptome } + }, + outputs={ + path 'index' + }, + script=true +) +def INDEX(Path transcriptome) { """ salmon index --threads $task.cpus -t $transcriptome -i index """ diff --git a/modules/multiqc/main.nf b/modules/multiqc/main.nf index a390282..7af90c6 100644 --- a/modules/multiqc/main.nf +++ b/modules/multiqc/main.nf @@ -1,17 +1,20 @@ params.outdir = 'results' -process MULTIQC { - conda 'multiqc=1.17' - publishDir params.outdir, mode:'copy' - - input: - path('*') - path(config) - - output: - path('multiqc_report.html') - - script: +@ProcessFn( + directives={ + conda 'multiqc=1.17' + publishDir params.outdir, mode:'copy' + }, + inputs={ + path { files }, stageAs: '*' + path { config } + }, + outputs={ + path('multiqc_report.html') + }, + script=true +) +def MULTIQC(List files, Path config) { """ cp $config/* . echo "custom_logo: \$PWD/logo.png" >> multiqc_config.yaml diff --git a/modules/quant/main.nf b/modules/quant/main.nf index 8459597..1006cd1 100644 --- a/modules/quant/main.nf +++ b/modules/quant/main.nf @@ -1,17 +1,20 @@ -process QUANT { - tag "$pair_id" - conda 'salmon=1.10.2' - - input: - path index - tuple val(pair_id), path(reads) - - output: - path pair_id - - script: +@ProcessFn( + directives={ + tag { pair.id } + conda 'salmon=1.10.2' + }, + inputs={ + path { index } + path { pair.reads } + }, + outputs={ + path { pair.id } + }, + script=true +) +def QUANT(Path index, Sample pair) { """ - salmon quant --threads $task.cpus --libType=U -i $index -1 ${reads[0]} -2 ${reads[1]} -o $pair_id + salmon quant --threads $task.cpus --libType=U -i $index -1 ${pair.reads[0]} -2 ${pair.reads[1]} -o $pair.id """ } From 6250d42002f873721b2060d93577c212f3969fc2 Mon Sep 17 00:00:00 2001 From: Ben Sherman Date: Fri, 1 Dec 2023 07:50:51 -0600 Subject: [PATCH 2/3] Add WorkflowFn annotation Signed-off-by: Ben Sherman --- main.nf | 3 ++- modules/rnaseq.nf | 19 +++++++------------ 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/main.nf b/main.nf index 512c125..f473f83 100755 --- a/main.nf +++ b/main.nf @@ -50,7 +50,8 @@ include { MULTIQC } from './modules/multiqc' /* * main script flow */ -workflow { +@WorkflowFn(main=true) +def MAIN() { read_pairs_ch = channel.fromFilePairs( params.reads, checkIfExists: true ).map { args -> new Sample(*args) } RNASEQ( file(params.transcriptome), read_pairs_ch ) MULTIQC( RNASEQ.out, file(params.multiqc) ) diff --git a/modules/rnaseq.nf b/modules/rnaseq.nf index 2f607c1..79c6a07 100644 --- a/modules/rnaseq.nf +++ b/modules/rnaseq.nf @@ -4,16 +4,11 @@ include { INDEX } from './index' include { QUANT } from './quant' include { FASTQC } from './fastqc' -workflow RNASEQ { - take: - transcriptome - read_pairs_ch - - main: - INDEX(transcriptome) - FASTQC(read_pairs_ch) - QUANT(INDEX.out, read_pairs_ch) - - emit: - QUANT.out | concat(FASTQC.out) | collect +@WorkflowFn +def RNASEQ(transcriptome, read_pairs_ch) { + INDEX(transcriptome) + FASTQC(read_pairs_ch) + QUANT(INDEX.out, read_pairs_ch) + | concat(FASTQC.out) + | collect } \ No newline at end of file From 9cef76afbe221731f7e187d2c8694bfb4cd8523e Mon Sep 17 00:00:00 2001 From: Ben Sherman Date: Fri, 8 Dec 2023 22:15:53 -0600 Subject: [PATCH 3/3] Update process outputs Signed-off-by: Ben Sherman --- modules/fastqc/main.nf | 5 +++-- modules/index/main.nf | 5 +++-- modules/multiqc/main.nf | 3 ++- modules/quant/main.nf | 3 ++- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/fastqc/main.nf b/modules/fastqc/main.nf index fb7befb..bc49aed 100644 --- a/modules/fastqc/main.nf +++ b/modules/fastqc/main.nf @@ -10,12 +10,13 @@ params.outdir = 'results' path { sample.reads } }, outputs={ - path { "fastqc_${sample.id}_logs" } + path '$file0', { "fastqc_${sample.id}_logs" } + emit { path('$file0') } }, script=true ) def FASTQC(Sample sample) { """ - fastqc.sh "$sample.id" "${sample.reads.join(' ')}" + fastqc.sh "$sample.id" "$sample.reads" """ } diff --git a/modules/index/main.nf b/modules/index/main.nf index 48a0d3c..b6dee3a 100644 --- a/modules/index/main.nf +++ b/modules/index/main.nf @@ -5,10 +5,11 @@ conda 'salmon=1.10.2' }, inputs={ - path { transcriptome } + path { transcriptome } }, outputs={ - path 'index' + path '$file0', 'index' + emit { path('$file0') } }, script=true ) diff --git a/modules/multiqc/main.nf b/modules/multiqc/main.nf index 7af90c6..44e4144 100644 --- a/modules/multiqc/main.nf +++ b/modules/multiqc/main.nf @@ -10,7 +10,8 @@ params.outdir = 'results' path { config } }, outputs={ - path('multiqc_report.html') + path '$file0', 'multiqc_report.html' + emit { path('$file0') } }, script=true ) diff --git a/modules/quant/main.nf b/modules/quant/main.nf index 1006cd1..97522d7 100644 --- a/modules/quant/main.nf +++ b/modules/quant/main.nf @@ -9,7 +9,8 @@ path { pair.reads } }, outputs={ - path { pair.id } + path '$file0', { pair.id } + emit { path('$file0') } }, script=true )