From 6208ac9799c7878bd4d58dac228d988c080127af Mon Sep 17 00:00:00 2001 From: FelixKrueger Date: Mon, 16 Mar 2020 17:49:39 +0000 Subject: [PATCH] Added functional Trim Galore module --- tools/trim_galore/main.nf | 124 +++++++++++++++++++------ tools/trim_galore/meta.yml | 10 +- tools/trim_galore/test/main.nf | 32 +++++-- tools/trim_galore/test/nextflow.config | 2 + 4 files changed, 124 insertions(+), 44 deletions(-) mode change 100644 => 100755 tools/trim_galore/test/main.nf create mode 100644 tools/trim_galore/test/nextflow.config diff --git a/tools/trim_galore/main.nf b/tools/trim_galore/main.nf index 8bccd6ef..3a4e8496 100644 --- a/tools/trim_galore/main.nf +++ b/tools/trim_galore/main.nf @@ -1,35 +1,101 @@ -process trim_galore { - tag "$sample_id" - publishDir "${params.outdir}/trim_galore", mode: 'copy', - saveAs: {filename -> - if (filename.indexOf("_fastqc") > 0) "FastQC/$filename" - else if (filename.indexOf("trimming_report.txt") > 0) "logs/$filename" - else filename - } +nextflow.preview.dsl=2 - container 'quay.io/biocontainers/trim-galore:0.6.5--0' +params.singlecell = '' +params.rrbs = '' +params.pbat = '' +params.single_end = false - input: - tuple sample_id, path(reads) +params.trim_nextseq = 0 - output: - tuple name, path("*fq.gz") - path "*trimming_report.txt" - path "*_fastqc.{zip,html}" +params.clip_r1 = 0 +params.clip_r2 = 0 +params.three_prime_clip_r1 = 0 +params.three_prime_clip_r2 = 0 + + +process TRIM_GALORE { + + // container 'quay.io/biocontainers/trim-galore:0.6.5--0' // maybe later + // tag "$sample_id" + + input: + tuple val (name), path (reads) + val (outdir) + val (trim_galore_args) + val (verbose) + + output: + tuple val(name), path ("*fq.gz"), emit: reads + path "*trimming_report.txt", optional: true, emit: report + + // Trimming reports are not generated for e.g. --hardtrim5, --clock etc + // saveAs: {filename -> + // else if (filename.indexOf("trimming_report.txt") > 0) "logs/$filename" + // else filename + // } + + publishDir "${outdir}/trim_galore", + mode: "copy", overwrite: true script: - c_r1 = clip_r1 > 0 ? "--clip_r1 ${clip_r1}" : '' - c_r2 = clip_r2 > 0 ? "--clip_r2 ${clip_r2}" : '' - tpc_r1 = three_prime_clip_r1 > 0 ? "--three_prime_clip_r1 ${three_prime_clip_r1}" : '' - tpc_r2 = three_prime_clip_r2 > 0 ? "--three_prime_clip_r2 ${three_prime_clip_r2}" : '' - nextseq = params.trim_nextseq > 0 ? "--nextseq ${params.trim_nextseq}" : '' - if (params.singleEnd) { - """ - trim_galore --fastqc --gzip $c_r1 $tpc_r1 $nextseq $reads - """ - } else { - """ - trim_galore --paired --fastqc --gzip $c_r1 $c_r2 $tpc_r1 $tpc_r2 $nextseq $reads - """ - } + if (verbose){ + println ("[MODULE] TRIM GALORE ARGS: " + trim_galore_args) + } + + trim_galore_args += " --gzip " // we like small files + + pairedString = 0 + if (reads instanceof List) { + pairedString = 1 + trim_galore_args += " --paired " + } + + if (params.clip_r1 > 0){ + trim_galore_args += " --clip_r1 ${params.clip_r1} " + } + if (params.clip_r2 > 0){ + trim_galore_args += " --clip_r2 ${params.clip_r2} " + } + if (params.three_prime_clip_r1> 0){ + trim_galore_args += " --three_prime_clip_r1 ${params.three_prime_clip_r1} " + } + if (params.three_prime_clip_r2 > 0){ + trim_galore_args += " --three_prime_clip_r2 ${params.three_prime_clip_r2} " + } + + if (params.trim_nextseq > 0){ + trim_galore_args += " --nextseq ${params.trim_nextseq} " + } + + + // Pre-set parameters for certain bisulfite-seq applications + if (params.singlecell){ + trim_galore_args += " --clip_r1 6 " + if (pairedString == 1){ + trim_galore_args += " --clip_r2 6 " + } + } + if (params.rrbs){ + trim_galore_args += " --rrbs " + } + if (params.pbat){ + trim_galore_args += " --clip_r1 $params.pbat " + if (pairedString == 1){ + trim_galore_args += " --clip_r2 $params.pbat " + } + } + + """ + module load trim_galore + trim_galore $trim_galore_args $reads + """ + } + + + + + + + + diff --git a/tools/trim_galore/meta.yml b/tools/trim_galore/meta.yml index 45fe46fb..d6944fb6 100644 --- a/tools/trim_galore/meta.yml +++ b/tools/trim_galore/meta.yml @@ -34,10 +34,8 @@ output: type: file description: Trim Galore! trimming report pattern: *trimming_report.txt - - - - fastqc_report: - type: file - description: FastQC report - pattern: *_fastqc.{zip,html} + authors: - - @ewels + - + - @ewels + - @FelixKrueger diff --git a/tools/trim_galore/test/main.nf b/tools/trim_galore/test/main.nf old mode 100644 new mode 100755 index 5fb89109..7f49567f --- a/tools/trim_galore/test/main.nf +++ b/tools/trim_galore/test/main.nf @@ -1,13 +1,27 @@ #!/usr/bin/env nextflow -echo true +nextflow.preview.dsl=2 -cheers = Channel.from 'Bonjour', 'Ciao', 'Hello', 'Hola' +params.outdir = "." // gets set in the nextflow.config files (to './results/trim_galore') +params.verbose = false +params.trim_galore_args = '' +// trim_galore_args are best passed into the workflow in the following manner, e.g.: +// --trim_galore_args="--clip_r1 10 --clip_r2 15 -j 2" + +if (params.verbose){ + println ("[WORKFLOW] TRIM GALORE ARGS: " + params.trim_galore_args) +} + +// TODO: check the output files in some way +// include '../../../nf-core/module_testing/check_process_outputs.nf' +include '../main.nf' // params (clip_r1: 6, clip_r2: 10) // how to pass additional parameters + +ch_read_files = Channel + .fromFilePairs('../../../test-datasets/test*{1,2}.fastq.gz',size:-1) + // .view() // to check whether the input channel works + +workflow { + + main: + TRIM_GALORE (ch_read_files, params.outdir, params.trim_galore_args, params.verbose) -process sayHello { - input: - val x from cheers - script: - """ - echo '$x world!' - """ } diff --git a/tools/trim_galore/test/nextflow.config b/tools/trim_galore/test/nextflow.config new file mode 100644 index 00000000..63c458ca --- /dev/null +++ b/tools/trim_galore/test/nextflow.config @@ -0,0 +1,2 @@ +// docker.enabled = true +params.outdir = './results'