From 96b452cc91a208996c8a6934512ec207464277da Mon Sep 17 00:00:00 2001 From: Usman Rashid Date: Mon, 2 Sep 2024 13:10:52 +1200 Subject: [PATCH 1/2] Added nf-test for goat/taxonsearch --- modules/nf-core/goat/taxonsearch/main.nf | 15 ++ .../goat/taxonsearch/tests/main.nf.test | 107 ++++++++++++++ .../goat/taxonsearch/tests/main.nf.test.snap | 134 ++++++++++++++++++ .../goat/taxonsearch/tests/nextflow.config | 5 + tests/config/pytest_modules.yml | 3 - .../modules/nf-core/goat/taxonsearch/main.nf | 44 ------ .../nf-core/goat/taxonsearch/nextflow.config | 8 -- .../modules/nf-core/goat/taxonsearch/test.yml | 26 ---- 8 files changed, 261 insertions(+), 81 deletions(-) create mode 100644 modules/nf-core/goat/taxonsearch/tests/main.nf.test create mode 100644 modules/nf-core/goat/taxonsearch/tests/main.nf.test.snap create mode 100644 modules/nf-core/goat/taxonsearch/tests/nextflow.config delete mode 100644 tests/modules/nf-core/goat/taxonsearch/main.nf delete mode 100644 tests/modules/nf-core/goat/taxonsearch/nextflow.config delete mode 100644 tests/modules/nf-core/goat/taxonsearch/test.yml diff --git a/modules/nf-core/goat/taxonsearch/main.nf b/modules/nf-core/goat/taxonsearch/main.nf index 62c12baac35..07a14d83cc5 100644 --- a/modules/nf-core/goat/taxonsearch/main.nf +++ b/modules/nf-core/goat/taxonsearch/main.nf @@ -33,4 +33,19 @@ process GOAT_TAXONSEARCH { goat: \$(goat-cli --version | cut -d' ' -f2) END_VERSIONS """ + + stub: + def args = task.ext.args ?: '' + def prefix = task.ext.prefix ?: "${meta.id}" + input = taxa_file ? "-f ${taxa_file}" : "-t \"${taxon}\"" + if (!taxon && !taxa_file) error "No input. Valid input: single taxon identifier or a .txt file with identifiers" + if (taxon && taxa_file ) error "Only one input is required: a single taxon identifier or a .txt file with identifiers" + """ + touch ${prefix}.tsv + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + goat: \$(goat-cli --version | cut -d' ' -f2) + END_VERSIONS + """ } diff --git a/modules/nf-core/goat/taxonsearch/tests/main.nf.test b/modules/nf-core/goat/taxonsearch/tests/main.nf.test new file mode 100644 index 00000000000..09b0a7b8f69 --- /dev/null +++ b/modules/nf-core/goat/taxonsearch/tests/main.nf.test @@ -0,0 +1,107 @@ + +nextflow_process { + + name "Test Process GOAT_TAXONSEARCH" + script "../main.nf" + process "GOAT_TAXONSEARCH" + config "./nextflow.config" + + tag "modules" + tag "modules_nfcore" + tag "goat" + tag "goat/taxonsearch" + + test("test-goat-taxonsearch-single-species") { + + when { + process { + """ + input[0] = [ + [ id:'test_single_species' ], // meta map + taxon = 'Meles meles', + [] + ] + + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + } + + test("test-goat-taxonsearch-genus-id") { + + when { + process { + """ + input[0] = [ + [ id:'test_genus_id' ], // meta map + taxon = '7215', + [] + ] + + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + } + + test("test-goat-taxonsearch-species") { + + when { + process { + """ + input[0] = [ + [ id:'test_species' ], // meta map + taxon = '', + file('https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/delete_me/goat_taxonsearch/taxonomy_ids.txt', checkIfExists: true) + ] + + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + } + + test("test-goat-taxonsearch-species-stub") { + options '-stub' + + when { + process { + """ + input[0] = [ + [ id:'test_species' ], // meta map + taxon = '', + file('https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/delete_me/goat_taxonsearch/taxonomy_ids.txt', checkIfExists: true) + ] + + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + } + +} diff --git a/modules/nf-core/goat/taxonsearch/tests/main.nf.test.snap b/modules/nf-core/goat/taxonsearch/tests/main.nf.test.snap new file mode 100644 index 00000000000..b5f7a7de9cf --- /dev/null +++ b/modules/nf-core/goat/taxonsearch/tests/main.nf.test.snap @@ -0,0 +1,134 @@ +{ + "test-goat-taxonsearch-species": { + "content": [ + { + "0": [ + [ + { + "id": "test_species" + }, + "test_species.tsv:md5,31d1bc139e5e507015e2ab0581708633" + ] + ], + "1": [ + "versions.yml:md5,d07de5ffeab892f448b03802528bfbbb" + ], + "taxonsearch": [ + [ + { + "id": "test_species" + }, + "test_species.tsv:md5,31d1bc139e5e507015e2ab0581708633" + ] + ], + "versions": [ + "versions.yml:md5,d07de5ffeab892f448b03802528bfbbb" + ] + } + ], + "meta": { + "nf-test": "0.9.0", + "nextflow": "24.04.4" + }, + "timestamp": "2024-09-02T13:10:06.012895" + }, + "test-goat-taxonsearch-species-stub": { + "content": [ + { + "0": [ + [ + { + "id": "test_species" + }, + "test_species.tsv:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "1": [ + "versions.yml:md5,d07de5ffeab892f448b03802528bfbbb" + ], + "taxonsearch": [ + [ + { + "id": "test_species" + }, + "test_species.tsv:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "versions": [ + "versions.yml:md5,d07de5ffeab892f448b03802528bfbbb" + ] + } + ], + "meta": { + "nf-test": "0.9.0", + "nextflow": "24.04.4" + }, + "timestamp": "2024-09-02T13:10:10.398213" + }, + "test-goat-taxonsearch-genus-id": { + "content": [ + { + "0": [ + [ + { + "id": "test_genus_id" + }, + "test_genus_id.tsv:md5,31d1bc139e5e507015e2ab0581708633" + ] + ], + "1": [ + "versions.yml:md5,d07de5ffeab892f448b03802528bfbbb" + ], + "taxonsearch": [ + [ + { + "id": "test_genus_id" + }, + "test_genus_id.tsv:md5,31d1bc139e5e507015e2ab0581708633" + ] + ], + "versions": [ + "versions.yml:md5,d07de5ffeab892f448b03802528bfbbb" + ] + } + ], + "meta": { + "nf-test": "0.9.0", + "nextflow": "24.04.4" + }, + "timestamp": "2024-09-02T13:09:58.101426" + }, + "test-goat-taxonsearch-single-species": { + "content": [ + { + "0": [ + [ + { + "id": "test_single_species" + }, + "test_single_species.tsv:md5,31d1bc139e5e507015e2ab0581708633" + ] + ], + "1": [ + "versions.yml:md5,d07de5ffeab892f448b03802528bfbbb" + ], + "taxonsearch": [ + [ + { + "id": "test_single_species" + }, + "test_single_species.tsv:md5,31d1bc139e5e507015e2ab0581708633" + ] + ], + "versions": [ + "versions.yml:md5,d07de5ffeab892f448b03802528bfbbb" + ] + } + ], + "meta": { + "nf-test": "0.9.0", + "nextflow": "24.04.4" + }, + "timestamp": "2024-09-02T13:09:51.117911" + } +} \ No newline at end of file diff --git a/modules/nf-core/goat/taxonsearch/tests/nextflow.config b/modules/nf-core/goat/taxonsearch/tests/nextflow.config new file mode 100644 index 00000000000..e642f2642cc --- /dev/null +++ b/modules/nf-core/goat/taxonsearch/tests/nextflow.config @@ -0,0 +1,5 @@ +process { + withName: GOAT_TAXONSEARCH { + ext.args = '-l -b' + } +} diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 5569dad183d..495d9d2e186 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -320,9 +320,6 @@ glimpse2/concordance: glnexus: - modules/nf-core/glnexus/** - tests/modules/nf-core/glnexus/** -goat/taxonsearch: - - modules/nf-core/goat/taxonsearch/** - - tests/modules/nf-core/goat/taxonsearch/** goleft/indexsplit: - modules/nf-core/goleft/indexsplit/** - tests/modules/nf-core/goleft/indexsplit/** diff --git a/tests/modules/nf-core/goat/taxonsearch/main.nf b/tests/modules/nf-core/goat/taxonsearch/main.nf deleted file mode 100644 index cc8db9235d6..00000000000 --- a/tests/modules/nf-core/goat/taxonsearch/main.nf +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env nextflow - -nextflow.enable.dsl = 2 - -include { GOAT_TAXONSEARCH } from '../../../../../modules/nf-core/goat/taxonsearch/main.nf' - -// -// Test with genus name (Canis) -// -workflow test_goat_taxonsearch_single_species { - - input = [ - [ id:'test_single_species' ], // meta map - taxon = 'Meles meles', - [] - ] - GOAT_TAXONSEARCH ( input ) -} - -// -// Test with genus (Drosophila, fruit flies) using NCBI taxonomy ID -// -workflow test_goat_taxonsearch_genus_id { - - input = [ - [ id:'test_genus_id' ], // meta map - taxon = '7215', - [] - ] - GOAT_TAXONSEARCH ( input ) -} - -// -// Test with multiple species from a taxa file -// -workflow test_goat_taxonsearch_species { - - input = [ - [ id:'test_species' ], // meta map - taxon = '', - file('https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/delete_me/goat_taxonsearch/taxonomy_ids.txt', checkIfExists: true) - ] - GOAT_TAXONSEARCH ( input ) -} diff --git a/tests/modules/nf-core/goat/taxonsearch/nextflow.config b/tests/modules/nf-core/goat/taxonsearch/nextflow.config deleted file mode 100644 index 3796e7a3d36..00000000000 --- a/tests/modules/nf-core/goat/taxonsearch/nextflow.config +++ /dev/null @@ -1,8 +0,0 @@ -process { - - publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" } - - withName: GOAT_TAXONSEARCH { - ext.args = '-l -b' - } -} diff --git a/tests/modules/nf-core/goat/taxonsearch/test.yml b/tests/modules/nf-core/goat/taxonsearch/test.yml deleted file mode 100644 index 23ebb75fe0e..00000000000 --- a/tests/modules/nf-core/goat/taxonsearch/test.yml +++ /dev/null @@ -1,26 +0,0 @@ -- name: goat taxonsearch test_goat_taxonsearch_single_species - command: nextflow run ./tests/modules/nf-core/goat/taxonsearch -entry test_goat_taxonsearch_single_species -c ./tests/config/nextflow.config -c ./tests/modules/nf-core/goat/taxonsearch/nextflow.config - tags: - - goat/taxonsearch - - goat - files: - - path: output/goat/test_single_species.tsv - md5sum: ed5b0afc7a6cf2f4b558882c10b35ef7 - -- name: goat taxonsearch test_goat_taxonsearch_genus_id - command: nextflow run ./tests/modules/nf-core/goat/taxonsearch -entry test_goat_taxonsearch_genus_id -c ./tests/config/nextflow.config -c ./tests/modules/nf-core/goat/taxonsearch/nextflow.config - tags: - - goat/taxonsearch - - goat - files: - - path: output/goat/test_genus_id.tsv - md5sum: 2cc41abbbc21b4b66f4d5126cfbba2bc - -- name: goat taxonsearch test_goat_taxonsearch_species - command: nextflow run ./tests/modules/nf-core/goat/taxonsearch -entry test_goat_taxonsearch_species -c ./tests/config/nextflow.config -c ./tests/modules/nf-core/goat/taxonsearch/nextflow.config - tags: - - goat/taxonsearch - - goat - files: - - path: output/goat/test_species.tsv - md5sum: ac73acd73dea9cb4734b5e4e154d128e From 4fc703884452b7fb07a1b8d5f6f3b87a997c1eed Mon Sep 17 00:00:00 2001 From: Usman Rashid Date: Tue, 3 Sep 2024 10:13:44 +1200 Subject: [PATCH 2/2] Added suggested changes --- modules/nf-core/goat/taxonsearch/tests/main.nf.test | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/nf-core/goat/taxonsearch/tests/main.nf.test b/modules/nf-core/goat/taxonsearch/tests/main.nf.test index 09b0a7b8f69..c4e765adb27 100644 --- a/modules/nf-core/goat/taxonsearch/tests/main.nf.test +++ b/modules/nf-core/goat/taxonsearch/tests/main.nf.test @@ -18,7 +18,7 @@ nextflow_process { """ input[0] = [ [ id:'test_single_species' ], // meta map - taxon = 'Meles meles', + 'Meles meles', [] ] @@ -41,7 +41,7 @@ nextflow_process { """ input[0] = [ [ id:'test_genus_id' ], // meta map - taxon = '7215', + '7215', [] ] @@ -64,8 +64,8 @@ nextflow_process { """ input[0] = [ [ id:'test_species' ], // meta map - taxon = '', - file('https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/delete_me/goat_taxonsearch/taxonomy_ids.txt', checkIfExists: true) + '', + file('https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/generic/txt/species_names.txt', checkIfExists: true) ] """ @@ -88,8 +88,8 @@ nextflow_process { """ input[0] = [ [ id:'test_species' ], // meta map - taxon = '', - file('https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/delete_me/goat_taxonsearch/taxonomy_ids.txt', checkIfExists: true) + '', + file('https://raw.githubusercontent.com/nf-core/test-datasets/modules/data/generic/txt/species_names.txt', checkIfExists: true) ] """