From fbaef17db03a4126fc4d0cfbdbe821e343cfba6e Mon Sep 17 00:00:00 2001 From: Matthias Zepper Date: Fri, 8 Mar 2024 21:33:36 +0100 Subject: [PATCH 1/5] Improve the extra_args parameter consolidation so it can override presets from the config. --- subworkflows/local/align_star/nextflow.config | 40 ++++++++++++------- .../nextflow.config | 14 +++++-- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/subworkflows/local/align_star/nextflow.config b/subworkflows/local/align_star/nextflow.config index 68bfef562..a7eb7683c 100644 --- a/subworkflows/local/align_star/nextflow.config +++ b/subworkflows/local/align_star/nextflow.config @@ -1,20 +1,32 @@ if (!params.skip_alignment && params.aligner == 'star_salmon') { process { withName: '.*:ALIGN_STAR:STAR_ALIGN|.*:ALIGN_STAR:STAR_ALIGN_IGENOMES' { - ext.args = { [ - '--quantMode TranscriptomeSAM', - '--twopassMode Basic', - '--outSAMtype BAM Unsorted', - '--readFilesCommand zcat', - '--runRNGseed 0', - '--outFilterMultimapNmax 20', - '--alignSJDBoverhangMin 1', - '--outSAMattributes NH HI AS NM MD', - '--quantTranscriptomeBan Singleend', - '--outSAMstrandField intronMotif', - params.save_unaligned ? '--outReadsUnmapped Fastx' : '', - params.extra_star_align_args ? params.extra_star_align_args.split("\\s(?=--)") : '' - ].flatten().unique(false).join(' ').trim() } + ext.args = { + def preset_args = [ + '--quantMode TranscriptomeSAM', + '--twopassMode Basic', + '--outSAMtype BAM Unsorted', + '--readFilesCommand zcat', + '--runRNGseed 0', + '--outFilterMultimapNmax 20', + '--alignSJDBoverhangMin 1', + '--outSAMattributes NH HI AS NM MD', + '--quantTranscriptomeBan Singleend', + '--outSAMstrandField intronMotif', + params.save_unaligned ? '--outReadsUnmapped Fastx' : '' + ] + + def extra_args = params.extra_star_align_args ? params.extra_star_align_args.split("\\s(?=--)").unique() : [] + + extra_args.each { extra_arg -> + def extra_arg_key = extra_arg.split(' ')[0] + preset_args = preset_args.findAll { !it.startsWith(extra_arg_key) } + preset_args.add(extra_arg) + } + + preset_args.join(' ').trim() + } + publishDir = [ [ path: { "${params.outdir}/${params.aligner}/log" }, diff --git a/subworkflows/nf-core/fastq_fastqc_umitools_trimgalore/nextflow.config b/subworkflows/nf-core/fastq_fastqc_umitools_trimgalore/nextflow.config index 7279111e5..875813b91 100644 --- a/subworkflows/nf-core/fastq_fastqc_umitools_trimgalore/nextflow.config +++ b/subworkflows/nf-core/fastq_fastqc_umitools_trimgalore/nextflow.config @@ -13,10 +13,16 @@ if (!params.skip_trimming) { process { withName: '.*:FASTQ_FASTQC_UMITOOLS_TRIMGALORE:TRIMGALORE' { ext.args = { - [ - "--fastqc_args '-t ${task.cpus}'", - params.extra_trimgalore_args ? params.extra_trimgalore_args.split("\\s(?=--)") : '' - ].flatten().unique(false).join(' ').trim() + def preset_args = ["--fastqc_args '-t ${task.cpus}'"] + def extra_args = params.extra_trimgalore_args ? params.extra_trimgalore_args.split("\\s(?=--)").unique() : [] + + extra_args.each { extra_arg -> + def extra_arg_key = extra_arg.split(' ')[0] + preset_args = preset_args.findAll { !it.startsWith(extra_arg_key) } + preset_args.add(extra_arg) + } + + preset_args.join(' ').trim() } publishDir = [ [ From 0d7e0f529bdb8fbbd489f56693c95f48400ff5c4 Mon Sep 17 00:00:00 2001 From: Matthias Zepper Date: Fri, 8 Mar 2024 21:56:36 +0100 Subject: [PATCH 2/5] Changelog update. --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b04986a7..a3ae93973 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ Thank you to everyone else that has contributed by reporting bugs, enhancements - [PR #1245](https://github.com/nf-core/rnaseq/pull/1245) - nf test quantify rsem - [PR #1246](https://github.com/nf-core/rnaseq/pull/1246) - nf-test quantify pseudoalignment - [PR #1247](https://github.com/nf-core/rnaseq/pull/1247) - nf-test prepare_genome +- [PR #1248](https://github.com/nf-core/rnaseq/pull/1248) - Improved ext.args consolidation for STAR and TRIMGALORE extra_args parameters - [PR #1249](https://github.com/nf-core/rnaseq/pull/1249) - Include nf-tests for rsem_merge_counts module - [PR #1250](https://github.com/nf-core/rnaseq/pull/1250) - Remove all tags.yml files because the testing system has changed - [PR #1251](https://github.com/nf-core/rnaseq/pull/1251) - Replace deseq2qc paths From 934019e2271f9abf79aff968277f0700eacf215a Mon Sep 17 00:00:00 2001 From: Matthias Zepper Date: Tue, 16 Apr 2024 19:57:24 +0200 Subject: [PATCH 3/5] Implement Jonathan Manning's map-method for extra argument consolidation for the local STAR alignment subworkflow. --- subworkflows/local/align_star/nextflow.config | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/subworkflows/local/align_star/nextflow.config b/subworkflows/local/align_star/nextflow.config index a7eb7683c..4cecc6c3a 100644 --- a/subworkflows/local/align_star/nextflow.config +++ b/subworkflows/local/align_star/nextflow.config @@ -2,29 +2,34 @@ if (!params.skip_alignment && params.aligner == 'star_salmon') { process { withName: '.*:ALIGN_STAR:STAR_ALIGN|.*:ALIGN_STAR:STAR_ALIGN_IGENOMES' { ext.args = { - def preset_args = [ - '--quantMode TranscriptomeSAM', - '--twopassMode Basic', - '--outSAMtype BAM Unsorted', - '--readFilesCommand zcat', - '--runRNGseed 0', - '--outFilterMultimapNmax 20', - '--alignSJDBoverhangMin 1', - '--outSAMattributes NH HI AS NM MD', - '--quantTranscriptomeBan Singleend', - '--outSAMstrandField intronMotif', - params.save_unaligned ? '--outReadsUnmapped Fastx' : '' - ] + // Function to convert argument strings into a map + def argsToMap(String args) { + args.split("\\s(?=--)").collectEntries { + def (key, value) = it.trim().split(/\s+/, 2) + [(key): value] + } + } - def extra_args = params.extra_star_align_args ? params.extra_star_align_args.split("\\s(?=--)").unique() : [] + // Initialize the map with preconfigured values + def preset_args_map = argsToMap(""" + --quantMode TranscriptomeSAM + --twopassMode Basic + --outSAMtype BAM Unsorted + --readFilesCommand zcat + --runRNGseed 0 + --outFilterMultimapNmax 20 + --alignSJDBoverhangMin 1 + --outSAMattributes NH HI AS NM MD + --quantTranscriptomeBan Singleend + --outSAMstrandField intronMotif + ${params.save_unaligned ? '--outReadsUnmapped Fastx' : ''} + """.trim()) - extra_args.each { extra_arg -> - def extra_arg_key = extra_arg.split(' ')[0] - preset_args = preset_args.findAll { !it.startsWith(extra_arg_key) } - preset_args.add(extra_arg) - } + // Consolidate the extra arguments + def final_args_map = preset_args_map + (params.extra_star_align_args ? argsToMap(params.extra_star_align_args) : [:]) - preset_args.join(' ').trim() + // Convert the map back to a list and then to a single string + final_args_map.collect { key, value -> "${key} ${value}" }.join(' ').trim() } publishDir = [ From 802758588323a62ffc2c0b708c35c3571322b1f9 Mon Sep 17 00:00:00 2001 From: Matthias Zepper Date: Tue, 16 Apr 2024 19:58:12 +0200 Subject: [PATCH 4/5] Implement Jonathan Manning's map-method for extra argument consolidation for the FastQC-UMItools-Trimgalore subworkflow.. --- .../nextflow.config | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/subworkflows/nf-core/fastq_fastqc_umitools_trimgalore/nextflow.config b/subworkflows/nf-core/fastq_fastqc_umitools_trimgalore/nextflow.config index 875813b91..15682cffa 100644 --- a/subworkflows/nf-core/fastq_fastqc_umitools_trimgalore/nextflow.config +++ b/subworkflows/nf-core/fastq_fastqc_umitools_trimgalore/nextflow.config @@ -13,16 +13,24 @@ if (!params.skip_trimming) { process { withName: '.*:FASTQ_FASTQC_UMITOOLS_TRIMGALORE:TRIMGALORE' { ext.args = { - def preset_args = ["--fastqc_args '-t ${task.cpus}'"] - def extra_args = params.extra_trimgalore_args ? params.extra_trimgalore_args.split("\\s(?=--)").unique() : [] - - extra_args.each { extra_arg -> - def extra_arg_key = extra_arg.split(' ')[0] - preset_args = preset_args.findAll { !it.startsWith(extra_arg_key) } - preset_args.add(extra_arg) + // Function to convert argument strings into a map + def argsToMap(String args) { + args.split("\\s(?=--)").collectEntries { + def (key, value) = it.trim().split(/\s+/, 2) + [(key): value] + } } - preset_args.join(' ').trim() + // Initialize the map with preconfigured values + def preset_args_map = argsToMap(""" + --fastqc_args '-t ${task.cpus}' + """.trim()) + + // Consolidate the extra arguments + def final_args_map = preset_args_map + (params.extra_trimgalore_args ? argsToMap(params.extra_trimgalore_args) : [:]) + + // Convert the map back to a list and then to a single string + final_args_map.collect { key, value -> "${key} ${value}" }.join(' ').trim() } publishDir = [ [ From 6ab2e44636d513ca6ad2e8e9fea539c9173febc0 Mon Sep 17 00:00:00 2001 From: Matthias Zepper <6963520+MatthiasZepper@users.noreply.github.com> Date: Wed, 17 Apr 2024 12:24:43 +0200 Subject: [PATCH 5/5] Apply @pinin4fjords (Jonathan Manning)'s suggestions from code review Co-authored-by: Jonathan Manning --- subworkflows/local/align_star/nextflow.config | 6 +++--- .../fastq_fastqc_umitools_trimgalore/nextflow.config | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/subworkflows/local/align_star/nextflow.config b/subworkflows/local/align_star/nextflow.config index 4cecc6c3a..119eb6e4a 100644 --- a/subworkflows/local/align_star/nextflow.config +++ b/subworkflows/local/align_star/nextflow.config @@ -3,10 +3,10 @@ if (!params.skip_alignment && params.aligner == 'star_salmon') { withName: '.*:ALIGN_STAR:STAR_ALIGN|.*:ALIGN_STAR:STAR_ALIGN_IGENOMES' { ext.args = { // Function to convert argument strings into a map - def argsToMap(String args) { + def argsToMap = { String args -> args.split("\\s(?=--)").collectEntries { - def (key, value) = it.trim().split(/\s+/, 2) - [(key): value] + def parts = it.trim().split(/\s+/, 2) + [(parts.first()): parts.last()] } } diff --git a/subworkflows/nf-core/fastq_fastqc_umitools_trimgalore/nextflow.config b/subworkflows/nf-core/fastq_fastqc_umitools_trimgalore/nextflow.config index 15682cffa..6de6b513d 100644 --- a/subworkflows/nf-core/fastq_fastqc_umitools_trimgalore/nextflow.config +++ b/subworkflows/nf-core/fastq_fastqc_umitools_trimgalore/nextflow.config @@ -14,10 +14,10 @@ if (!params.skip_trimming) { withName: '.*:FASTQ_FASTQC_UMITOOLS_TRIMGALORE:TRIMGALORE' { ext.args = { // Function to convert argument strings into a map - def argsToMap(String args) { + def argsToMap = { String args -> args.split("\\s(?=--)").collectEntries { - def (key, value) = it.trim().split(/\s+/, 2) - [(key): value] + def parts = it.trim().split(/\s+/, 2) + [(parts.first()): parts.last()] } }