From d1e4c1977912284d6c4c1a1b351968cb6fcf1b6d Mon Sep 17 00:00:00 2001 From: Jonathan Manning Date: Wed, 17 Jul 2024 10:24:25 +0100 Subject: [PATCH 1/4] rrna sequences make more sense as a channel of FASTAs --- .../nf-core/fastq_qc_trim_filter_setstrandedness/main.nf | 5 ++--- .../nf-core/fastq_qc_trim_filter_setstrandedness/meta.yml | 6 +++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/main.nf b/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/main.nf index ac8217ee905..cd69166f37a 100644 --- a/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/main.nf +++ b/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/main.nf @@ -91,7 +91,7 @@ workflow FASTQ_QC_TRIM_FILTER_SETSTRANDEDNESS { ch_salmon_index // channel: /path/to/salmon/index/ (optional) ch_sortmerna_index // channel: /path/to/sortmerna/index/ (optional) ch_bbsplit_index // channel: /path/to/bbsplit/index/ (optional) - ch_ribo_db // channel: /path/to/ Text file containing paths to fasta files (one per line) that will be used to create the database for SortMeRNA. (optional) + ch_rrna_fastas // channel: one or more fasta files containing rrna sequences to be passed to SortMeRNA (optional) skip_bbsplit // boolean: Skip BBSplit for removal of non-reference genome reads. skip_fastqc // boolean: true/false skip_trimming // boolean: true/false @@ -233,8 +233,7 @@ workflow FASTQ_QC_TRIM_FILTER_SETSTRANDEDNESS { // MODULE: Remove ribosomal RNA reads // if (remove_ribo_rna) { - ch_sortmerna_fastas = Channel.from(ch_ribo_db.readLines()) - .map { row -> file(row, checkIfExists: true) } + ch_sortmerna_fastas = ch_rrna_fastas .collect() .map{ ['rrna_refs', it] } diff --git a/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/meta.yml b/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/meta.yml index cf7cd885f01..6f92f56a0a0 100644 --- a/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/meta.yml +++ b/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/meta.yml @@ -47,11 +47,11 @@ input: - ch_bbsplit_index: type: file description: Path to directory or tar.gz archive for pre-built BBSplit index - - ch_ribo_db: + - ch_rrna_fastas: type: file description: | - Channel with text file containing paths to fasta files (one per line) - that will be used to create the database for SortMeRNA + Channel containing one or more FASTA files containing rRNA sequences + for use with SortMeRNA - skip_bbsplit: type: boolean description: Whether to skip BBSplit for removal of non-reference genome reads From d41517e03cd875b9b469a0d27e31c7afd9d2250f Mon Sep 17 00:00:00 2001 From: Jonathan Manning Date: Wed, 17 Jul 2024 10:44:41 +0100 Subject: [PATCH 2/4] Also update tests --- .../tests/main.nf.test | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.nf.test b/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.nf.test index ad5eef7256b..038af9e305c 100644 --- a/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.nf.test +++ b/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.nf.test @@ -33,9 +33,6 @@ nextflow_workflow { ] ]) - ch_ribo_db = file('ribo_db.txt') - ch_ribo_db.append('https://raw.githubusercontent.com/biocore/sortmerna/v4.3.4/data/rRNA_databases/rfam-5.8s-database-id98.fasta') - input[0] = ch_reads input[1] = Channel.of(file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.fasta', checkIfExists: true)) // ch_fasta input[2] = Channel.of(file(params.modules_testdata_base_path + "genomics/homo_sapiens/genome/transcriptome.fasta", checkIfExists: true)) // ch_transcript_fasta @@ -43,7 +40,7 @@ nextflow_workflow { input[4] = [] // ch_salmon_index input[5] = [] // ch_sortmerna_index input[6] = [] // ch_bbsplit_index - input[7] = ch_ribo_db // ch_ribo_db + input[7] = Channel.of(file('https://raw.githubusercontent.com/biocore/sortmerna/v4.3.4/data/rRNA_databases/rfam-5.8s-database-id98.fasta', checkIfExists: true)) // ch_rrna_fastas input[8] = true // skip_bbsplit input[9] = false // skip_fastqc input[10] = false // skip_trimming @@ -91,9 +88,6 @@ nextflow_workflow { ] ]) - ch_ribo_db = file('ribo_db.txt') - ch_ribo_db.append('https://raw.githubusercontent.com/biocore/sortmerna/v4.3.4/data/rRNA_databases/rfam-5.8s-database-id98.fasta') - input[0] = ch_reads input[1] = Channel.of(file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.fasta', checkIfExists: true)) // ch_fasta input[2] = Channel.of(file(params.modules_testdata_base_path + "genomics/homo_sapiens/genome/transcriptome.fasta", checkIfExists: true)) // ch_transcript_fasta @@ -101,7 +95,7 @@ nextflow_workflow { input[4] = [] // ch_salmon_index input[5] = [] // ch_sortmerna_index input[6] = [] // ch_bbsplit_index - input[7] = ch_ribo_db // ch_ribo_db + input[7] = Channel.of(file('https://raw.githubusercontent.com/biocore/sortmerna/v4.3.4/data/rRNA_databases/rfam-5.8s-database-id98.fasta', checkIfExists: true)) // ch_rrna_fastas input[8] = true // skip_bbsplit input[9] = false // skip_fastqc input[10] = false // skip_trimming From 5319cb946aa63ff77c1a5f86b5949faa9c53abb7 Mon Sep 17 00:00:00 2001 From: Jonathan Manning Date: Wed, 17 Jul 2024 10:59:13 +0100 Subject: [PATCH 3/4] Add function test to swf --- .../tests/main.nf.test | 114 ++++++++++++++++++ 1 file changed, 114 insertions(+) diff --git a/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.nf.test b/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.nf.test index 038af9e305c..e9f2cc61129 100644 --- a/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.nf.test +++ b/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.nf.test @@ -130,4 +130,118 @@ nextflow_workflow { ) } } + + // + // Test function for deriving strandedness from Salmon numbers + // + + test("Test Function getSalmonInferredStrandedness unstranded") { + + function "getSalmonInferredStrandedness" + + when { + function { + """ + import groovy.json.JsonOutput + + // Define the JSON contents for the test + def json_contents = JsonOutput.toJson([ + "SF": 0, + "SR": 0, + "ISF": 100, + "ISR": 100, + "IU": 0, + "U": 0 + ]) + def jsonFile = file("${workDir}/salmonUnstranded.json") + jsonFile.write(json_contents) + + input[0] = jsonFile + input[1] = 0.8 + input[2] = 0.1 + """ + } + } + + then { + assertAll( + { assert function.success }, + { assert snapshot(function.result).match() } + ) + } + + } + + test("Test Function getSalmonInferredStrandedness forward") { + + function "getSalmonInferredStrandedness" + + when { + function { + """ + import groovy.json.JsonOutput + + def json_contents = JsonOutput.toJson([ + "SF": 0, + "SR": 0, + "ISF": 100, + "ISR": 0, + "IU": 0, + "U": 0 + ]) + def jsonFile = file("${workDir}/salmonForward.json") + jsonFile.write(json_contents) + + input[0] = jsonFile + input[1] = 0.8 + input[2] = 0.1 + """ + } + } + + then { + assertAll( + { assert function.success }, + { assert snapshot(function.result).match() } + ) + } + + } + + test("Test Function getSalmonInferredStrandedness reverse") { + + function "getSalmonInferredStrandedness" + + when { + function { + """ + import groovy.json.JsonOutput + + def json_contents = JsonOutput.toJson([ + "SF": 0, + "SR": 0, + "ISF": 0, + "ISR": 100, + "IU": 0, + "U": 0 + ]) + def jsonFile = file("${workDir}/salmonReverse.json") + jsonFile.write(json_contents) + + input[0] = jsonFile + input[1] = 0.8 + input[2] = 0.1 + """ + } + } + + then { + assertAll( + { assert function.success }, + { assert snapshot(function.result).match() } + ) + } + + } + } From e9fde2d1f5d38e2ed61c217aef44e23e8ed07103 Mon Sep 17 00:00:00 2001 From: Jonathan Manning Date: Wed, 17 Jul 2024 10:30:21 +0000 Subject: [PATCH 4/4] Fix up subworkflow function testing --- .../tests/main.function.nf.test | 118 ++++++++++++++++++ .../tests/main.function.nf.test.snap | 47 +++++++ .../tests/main.nf.test | 112 ----------------- .../tests/main.nf.test.snap | 40 +++--- 4 files changed, 185 insertions(+), 132 deletions(-) create mode 100644 subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.function.nf.test create mode 100644 subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.function.nf.test.snap diff --git a/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.function.nf.test b/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.function.nf.test new file mode 100644 index 00000000000..57fcd302bf5 --- /dev/null +++ b/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.function.nf.test @@ -0,0 +1,118 @@ +nextflow_function { + + name "Test Functions" + script "../main.nf" + + // + // Test function for deriving strandedness from Salmon numbers + // + + test("Test Function getSalmonInferredStrandedness unstranded") { + + function "getSalmonInferredStrandedness" + + when { + function { + """ + import groovy.json.JsonOutput + + // Define the JSON contents for the test + def json_contents = JsonOutput.toJson([ + "SF": 0, + "SR": 0, + "ISF": 100, + "ISR": 100, + "IU": 0, + "U": 0 + ]) + def jsonFile = file("${workDir}/salmonUnstranded.json") + jsonFile.write(json_contents) + + input[0] = jsonFile + input[1] = 0.8 + input[2] = 0.1 + """ + } + } + + then { + assertAll( + { assert function.success }, + { assert snapshot(function.result).match() } + ) + } + + } + + test("Test Function getSalmonInferredStrandedness forward") { + + function "getSalmonInferredStrandedness" + + when { + function { + """ + import groovy.json.JsonOutput + + def json_contents = JsonOutput.toJson([ + "SF": 0, + "SR": 0, + "ISF": 100, + "ISR": 0, + "IU": 0, + "U": 0 + ]) + def jsonFile = file("${workDir}/salmonForward.json") + jsonFile.write(json_contents) + + input[0] = jsonFile + input[1] = 0.8 + input[2] = 0.1 + """ + } + } + + then { + assertAll( + { assert function.success }, + { assert snapshot(function.result).match() } + ) + } + + } + + test("Test Function getSalmonInferredStrandedness reverse") { + + function "getSalmonInferredStrandedness" + + when { + function { + """ + import groovy.json.JsonOutput + + def json_contents = JsonOutput.toJson([ + "SF": 0, + "SR": 0, + "ISF": 0, + "ISR": 100, + "IU": 0, + "U": 0 + ]) + def jsonFile = file("${workDir}/salmonReverse.json") + jsonFile.write(json_contents) + + input[0] = jsonFile + input[1] = 0.8 + input[2] = 0.1 + """ + } + } + + then { + assertAll( + { assert function.success }, + { assert snapshot(function.result).match() } + ) + } + + } +} diff --git a/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.function.nf.test.snap b/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.function.nf.test.snap new file mode 100644 index 00000000000..4b4e2e87401 --- /dev/null +++ b/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.function.nf.test.snap @@ -0,0 +1,47 @@ +{ + "Test Function getSalmonInferredStrandedness forward": { + "content": [ + { + "inferred_strandedness": "forward", + "forwardFragments": 100.0, + "reverseFragments": 0.0, + "unstrandedFragments": 0.0 + } + ], + "meta": { + "nf-test": "0.8.4", + "nextflow": "24.04.3" + }, + "timestamp": "2024-07-17T10:28:59.284820592" + }, + "Test Function getSalmonInferredStrandedness unstranded": { + "content": [ + { + "inferred_strandedness": "unstranded", + "forwardFragments": 50.0, + "reverseFragments": 50.0, + "unstrandedFragments": 0.0 + } + ], + "meta": { + "nf-test": "0.8.4", + "nextflow": "24.04.3" + }, + "timestamp": "2024-07-17T10:28:47.514036696" + }, + "Test Function getSalmonInferredStrandedness reverse": { + "content": [ + { + "inferred_strandedness": "reverse", + "forwardFragments": 0.0, + "reverseFragments": 100.0, + "unstrandedFragments": 0.0 + } + ], + "meta": { + "nf-test": "0.8.4", + "nextflow": "24.04.3" + }, + "timestamp": "2024-07-17T10:29:11.43961965" + } +} \ No newline at end of file diff --git a/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.nf.test b/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.nf.test index e9f2cc61129..5242f2bee6c 100644 --- a/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.nf.test +++ b/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.nf.test @@ -131,117 +131,5 @@ nextflow_workflow { } } - // - // Test function for deriving strandedness from Salmon numbers - // - - test("Test Function getSalmonInferredStrandedness unstranded") { - - function "getSalmonInferredStrandedness" - - when { - function { - """ - import groovy.json.JsonOutput - - // Define the JSON contents for the test - def json_contents = JsonOutput.toJson([ - "SF": 0, - "SR": 0, - "ISF": 100, - "ISR": 100, - "IU": 0, - "U": 0 - ]) - def jsonFile = file("${workDir}/salmonUnstranded.json") - jsonFile.write(json_contents) - - input[0] = jsonFile - input[1] = 0.8 - input[2] = 0.1 - """ - } - } - - then { - assertAll( - { assert function.success }, - { assert snapshot(function.result).match() } - ) - } - - } - - test("Test Function getSalmonInferredStrandedness forward") { - - function "getSalmonInferredStrandedness" - - when { - function { - """ - import groovy.json.JsonOutput - - def json_contents = JsonOutput.toJson([ - "SF": 0, - "SR": 0, - "ISF": 100, - "ISR": 0, - "IU": 0, - "U": 0 - ]) - def jsonFile = file("${workDir}/salmonForward.json") - jsonFile.write(json_contents) - - input[0] = jsonFile - input[1] = 0.8 - input[2] = 0.1 - """ - } - } - - then { - assertAll( - { assert function.success }, - { assert snapshot(function.result).match() } - ) - } - - } - - test("Test Function getSalmonInferredStrandedness reverse") { - - function "getSalmonInferredStrandedness" - - when { - function { - """ - import groovy.json.JsonOutput - - def json_contents = JsonOutput.toJson([ - "SF": 0, - "SR": 0, - "ISF": 0, - "ISR": 100, - "IU": 0, - "U": 0 - ]) - def jsonFile = file("${workDir}/salmonReverse.json") - jsonFile.write(json_contents) - - input[0] = jsonFile - input[1] = 0.8 - input[2] = 0.1 - """ - } - } - - then { - assertAll( - { assert function.success }, - { assert snapshot(function.result).match() } - ) - } - - } } diff --git a/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.nf.test.snap b/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.nf.test.snap index 21bdb2492e3..98534931769 100644 --- a/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.nf.test.snap +++ b/subworkflows/nf-core/fastq_qc_trim_filter_setstrandedness/tests/main.nf.test.snap @@ -14,17 +14,17 @@ ], "meta": { "nf-test": "0.8.4", - "nextflow": "23.10.1" + "nextflow": "24.04.3" }, - "timestamp": "2024-02-24T16:19:13.057802" + "timestamp": "2024-07-17T10:24:00.044553245" }, "trimgalore_test_pe_reads_2_lines": { "content": "eccf3e9e74589ff01c77fce7f4548e41", "meta": { "nf-test": "0.8.4", - "nextflow": "23.10.1" + "nextflow": "24.04.3" }, - "timestamp": "2024-02-24T17:44:07.667653" + "timestamp": "2024-07-17T10:24:26.838793051" }, "fastp_test_pe_reads_1_size": { "content": [ @@ -32,9 +32,9 @@ ], "meta": { "nf-test": "0.8.4", - "nextflow": "23.10.1" + "nextflow": "24.04.3" }, - "timestamp": "2024-02-24T17:43:46.173892" + "timestamp": "2024-07-17T10:23:59.889337984" }, "trimgalore_test_pe_reads_1_size": { "content": [ @@ -42,25 +42,25 @@ ], "meta": { "nf-test": "0.8.4", - "nextflow": "23.10.1" + "nextflow": "24.04.3" }, - "timestamp": "2024-02-24T17:44:07.642318" + "timestamp": "2024-07-17T10:24:26.778599725" }, "trimgalore_test_pe_reads_1_lines": { "content": "3868fc1caf09367141d2bbf47e158823", "meta": { "nf-test": "0.8.4", - "nextflow": "23.10.1" + "nextflow": "24.04.3" }, - "timestamp": "2024-02-24T17:44:07.641186" + "timestamp": "2024-07-17T10:24:26.774975135" }, "fastp_test_pe_reads_2_lines": { "content": "eccf3e9e74589ff01c77fce7f4548e41", "meta": { "nf-test": "0.8.4", - "nextflow": "23.10.1" + "nextflow": "24.04.3" }, - "timestamp": "2024-02-24T17:43:46.235022" + "timestamp": "2024-07-17T10:23:59.997625278" }, "fastp_test_pe_reads_2_size": { "content": [ @@ -68,9 +68,9 @@ ], "meta": { "nf-test": "0.8.4", - "nextflow": "23.10.1" + "nextflow": "24.04.3" }, - "timestamp": "2024-02-24T17:43:46.242006" + "timestamp": "2024-07-17T10:24:00.042449965" }, "trimgalore_test_pe_reads_2_size": { "content": [ @@ -78,17 +78,17 @@ ], "meta": { "nf-test": "0.8.4", - "nextflow": "23.10.1" + "nextflow": "24.04.3" }, - "timestamp": "2024-02-24T17:44:07.668644" + "timestamp": "2024-07-17T10:24:26.841434261" }, "fastp_test_pe_reads_1_lines": { "content": "3868fc1caf09367141d2bbf47e158823", "meta": { "nf-test": "0.8.4", - "nextflow": "23.10.1" + "nextflow": "24.04.3" }, - "timestamp": "2024-02-24T17:43:46.161535" + "timestamp": "2024-07-17T10:23:59.882844295" }, "trimgalore_read_count": { "content": [ @@ -105,8 +105,8 @@ ], "meta": { "nf-test": "0.8.4", - "nextflow": "23.10.1" + "nextflow": "24.04.3" }, - "timestamp": "2024-02-24T17:44:07.669435" + "timestamp": "2024-07-17T10:24:26.84402498" } } \ No newline at end of file