From 5cc90b8bc2e2a579f49b2f6ac3112efd1989a1a9 Mon Sep 17 00:00:00 2001 From: Usman Rashid Date: Fri, 6 Sep 2024 17:30:15 +1200 Subject: [PATCH] Added nf-test for ivar/consensus (#6568) * Added nf-test for ivar/consensus * Verion bump --- .../nf-core/ivar/consensus/environment.yml | 3 +- modules/nf-core/ivar/consensus/main.nf | 18 ++- .../nf-core/ivar/consensus/tests/main.nf.test | 100 +++++++++++++++ .../ivar/consensus/tests/main.nf.test.snap | 117 ++++++++++++++++++ .../ivar/consensus/tests/nextflow.config | 5 + tests/config/pytest_modules.yml | 3 - tests/modules/nf-core/ivar/consensus/main.nf | 29 ----- .../nf-core/ivar/consensus/nextflow.config | 9 -- tests/modules/nf-core/ivar/consensus/test.yml | 22 ---- 9 files changed, 239 insertions(+), 67 deletions(-) create mode 100644 modules/nf-core/ivar/consensus/tests/main.nf.test create mode 100644 modules/nf-core/ivar/consensus/tests/main.nf.test.snap create mode 100644 modules/nf-core/ivar/consensus/tests/nextflow.config delete mode 100644 tests/modules/nf-core/ivar/consensus/main.nf delete mode 100644 tests/modules/nf-core/ivar/consensus/nextflow.config delete mode 100644 tests/modules/nf-core/ivar/consensus/test.yml diff --git a/modules/nf-core/ivar/consensus/environment.yml b/modules/nf-core/ivar/consensus/environment.yml index c7b87d02480..75e6ef41745 100644 --- a/modules/nf-core/ivar/consensus/environment.yml +++ b/modules/nf-core/ivar/consensus/environment.yml @@ -2,6 +2,5 @@ name: ivar_consensus channels: - conda-forge - bioconda - - defaults dependencies: - - bioconda::ivar=1.4 + - bioconda::ivar=1.4.3 diff --git a/modules/nf-core/ivar/consensus/main.nf b/modules/nf-core/ivar/consensus/main.nf index 9786200e94c..d57d17642a9 100644 --- a/modules/nf-core/ivar/consensus/main.nf +++ b/modules/nf-core/ivar/consensus/main.nf @@ -4,8 +4,8 @@ process IVAR_CONSENSUS { conda "${moduleDir}/environment.yml" container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? - 'https://depot.galaxyproject.org/singularity/ivar:1.4--h6b7c446_1' : - 'biocontainers/ivar:1.4--h6b7c446_1' }" + 'https://depot.galaxyproject.org/singularity/ivar:1.4.3--h43eeafb_0' : + 'biocontainers/ivar:1.4.3--h43eeafb_0' }" input: tuple val(meta), path(bam) @@ -43,4 +43,18 @@ process IVAR_CONSENSUS { ivar: \$(echo \$(ivar version 2>&1) | sed 's/^.*iVar version //; s/ .*\$//') END_VERSIONS """ + + stub: + def prefix = task.ext.prefix ?: "${meta.id}" + def touch_mpileup = save_mpileup ? "touch ${prefix}.mpileup" : '' + """ + touch ${prefix}.fa + touch ${prefix}.qual.txt + $touch_mpileup + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + ivar: \$(echo \$(ivar version 2>&1) | sed 's/^.*iVar version //; s/ .*\$//') + END_VERSIONS + """ } diff --git a/modules/nf-core/ivar/consensus/tests/main.nf.test b/modules/nf-core/ivar/consensus/tests/main.nf.test new file mode 100644 index 00000000000..9255bed082e --- /dev/null +++ b/modules/nf-core/ivar/consensus/tests/main.nf.test @@ -0,0 +1,100 @@ + +nextflow_process { + + name "Test Process IVAR_CONSENSUS" + script "../main.nf" + process "IVAR_CONSENSUS" + config "./nextflow.config" + + tag "modules" + tag "modules_nfcore" + tag "ivar" + tag "ivar/consensus" + + test("test-ivar-consensus") { + + when { + process { + """ + input[0] = [ + [ id:'test'], + file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/bam/test.paired_end.bam', checkIfExists: true) + ] + input[1] = file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta', checkIfExists: true) + input[2] = false + + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot( + process.out.fasta, + file(process.out.qual[0][1]).name, // empty + process.out.mpileup, + process.out.versions, + file(process.out.versions[0]).readLines().collect { it.trim() } // Trap to catch conda version mismatches + ).match() + } + ) + } + } + + test("test-ivar-consensus-mpileup") { + + when { + process { + """ + input[0] = [ + [ id:'test'], + file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/bam/test.paired_end.bam', checkIfExists: true) + ] + input[1] = file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta', checkIfExists: true) + input[2] = true + + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot( + process.out.fasta, + file(process.out.qual[0][1]).name, // empty + file(process.out.mpileup[0][1]).name, // empty + process.out.versions + ).match() + } + ) + } + } + + test("test-ivar-consensus-mpileup-stub") { + options '-stub' + + when { + process { + """ + input[0] = [ + [ id:'test'], + file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/bam/test.paired_end.bam', checkIfExists: true) + ] + input[1] = file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta', checkIfExists: true) + input[2] = true + + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + } + +} diff --git a/modules/nf-core/ivar/consensus/tests/main.nf.test.snap b/modules/nf-core/ivar/consensus/tests/main.nf.test.snap new file mode 100644 index 00000000000..e220ecabb5e --- /dev/null +++ b/modules/nf-core/ivar/consensus/tests/main.nf.test.snap @@ -0,0 +1,117 @@ +{ + "test-ivar-consensus-mpileup-stub": { + "content": [ + { + "0": [ + [ + { + "id": "test" + }, + "test.fa:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "1": [ + [ + { + "id": "test" + }, + "test.qual.txt:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "2": [ + [ + { + "id": "test" + }, + "test.mpileup:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "3": [ + "versions.yml:md5,e652db2cbd4a8cd9b7482a01abe5e6b3" + ], + "fasta": [ + [ + { + "id": "test" + }, + "test.fa:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "mpileup": [ + [ + { + "id": "test" + }, + "test.mpileup:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "qual": [ + [ + { + "id": "test" + }, + "test.qual.txt:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "versions": [ + "versions.yml:md5,e652db2cbd4a8cd9b7482a01abe5e6b3" + ] + } + ], + "meta": { + "nf-test": "0.9.0", + "nextflow": "24.04.4" + }, + "timestamp": "2024-09-06T14:58:57.447441" + }, + "test-ivar-consensus-mpileup": { + "content": [ + [ + [ + { + "id": "test" + }, + "test.fa:md5,9e21a64818f4302b4dece5480fa5e8b8" + ] + ], + "test.qual.txt", + "test.mpileup", + [ + "versions.yml:md5,e652db2cbd4a8cd9b7482a01abe5e6b3" + ] + ], + "meta": { + "nf-test": "0.9.0", + "nextflow": "24.04.4" + }, + "timestamp": "2024-09-06T14:58:52.938906" + }, + "test-ivar-consensus": { + "content": [ + [ + [ + { + "id": "test" + }, + "test.fa:md5,9e21a64818f4302b4dece5480fa5e8b8" + ] + ], + "test.qual.txt", + [ + + ], + [ + "versions.yml:md5,e652db2cbd4a8cd9b7482a01abe5e6b3" + ], + [ + "\"IVAR_CONSENSUS\":", + "ivar: 1.4.3" + ] + ], + "meta": { + "nf-test": "0.9.0", + "nextflow": "24.04.4" + }, + "timestamp": "2024-09-06T14:58:48.289344" + } +} \ No newline at end of file diff --git a/modules/nf-core/ivar/consensus/tests/nextflow.config b/modules/nf-core/ivar/consensus/tests/nextflow.config new file mode 100644 index 00000000000..e34c650406f --- /dev/null +++ b/modules/nf-core/ivar/consensus/tests/nextflow.config @@ -0,0 +1,5 @@ +process { + withName: IVAR_CONSENSUS { + ext.args2 = '-aa -A -d 0 -Q 0' + } +} diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index c96ba47f166..cb964a33698 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -365,9 +365,6 @@ iphop/download: iphop/predict: - modules/nf-core/iphop/predict/** - tests/modules/nf-core/iphop/predict/** -ivar/consensus: - - modules/nf-core/ivar/consensus/** - - tests/modules/nf-core/ivar/consensus/** ivar/variants: - modules/nf-core/ivar/variants/** - tests/modules/nf-core/ivar/variants/** diff --git a/tests/modules/nf-core/ivar/consensus/main.nf b/tests/modules/nf-core/ivar/consensus/main.nf deleted file mode 100644 index 37ce0f8f17e..00000000000 --- a/tests/modules/nf-core/ivar/consensus/main.nf +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env nextflow - -nextflow.enable.dsl = 2 - -include { IVAR_CONSENSUS } from '../../../../../modules/nf-core/ivar/consensus/main.nf' - -workflow test_ivar_consensus { - - input = [ - [ id:'test'], - file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true) - ] - fasta = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) - save_mpileup = false - - IVAR_CONSENSUS ( input, fasta, save_mpileup) -} - -workflow test_ivar_consensus_mpileup { - - input = [ - [ id:'test'], - file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true) - ] - fasta = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) - save_mpileup = true - - IVAR_CONSENSUS ( input, fasta, save_mpileup) -} diff --git a/tests/modules/nf-core/ivar/consensus/nextflow.config b/tests/modules/nf-core/ivar/consensus/nextflow.config deleted file mode 100644 index 7407619ad57..00000000000 --- a/tests/modules/nf-core/ivar/consensus/nextflow.config +++ /dev/null @@ -1,9 +0,0 @@ -process { - - publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" } - - withName: IVAR_CONSENSUS { - ext.args2 = '-aa -A -d 0 -Q 0' - } - -} diff --git a/tests/modules/nf-core/ivar/consensus/test.yml b/tests/modules/nf-core/ivar/consensus/test.yml deleted file mode 100644 index b676caf11e1..00000000000 --- a/tests/modules/nf-core/ivar/consensus/test.yml +++ /dev/null @@ -1,22 +0,0 @@ -- name: ivar consensus test_ivar_consensus - command: nextflow run ./tests/modules/nf-core/ivar/consensus -entry test_ivar_consensus -c ./tests/config/nextflow.config -c ./tests/modules/nf-core/ivar/consensus/nextflow.config - tags: - - ivar - - ivar/consensus - files: - - path: output/ivar/test.fa - md5sum: 9e21a64818f4302b4dece5480fa5e8b8 - - path: output/ivar/test.qual.txt - md5sum: 68b329da9893e34099c7d8ad5cb9c940 - -- name: ivar consensus test_ivar_consensus_mpileup - command: nextflow run ./tests/modules/nf-core/ivar/consensus -entry test_ivar_consensus_mpileup -c ./tests/config/nextflow.config -c ./tests/modules/nf-core/ivar/consensus/nextflow.config - tags: - - ivar - - ivar/consensus - files: - - path: output/ivar/test.fa - md5sum: 9e21a64818f4302b4dece5480fa5e8b8 - - path: output/ivar/test.qual.txt - md5sum: 68b329da9893e34099c7d8ad5cb9c940 - - path: output/ivar/test.mpileup