From 0aef8ea90e874d4ebabc0909a2fefa0cc36b179d Mon Sep 17 00:00:00 2001 From: Thanh Lee Date: Thu, 27 Jun 2024 14:31:31 +0100 Subject: [PATCH] nf-test for pilon (#5293) * nf-test for pilon * linting for license * Add stub and extra test * Swap to testdata_base_path * Add missing END_VERSIONS and alignment * Add optional outputs to stub --------- Co-authored-by: Simon Pearce <24893913+SPPearce@users.noreply.github.com> --- modules/nf-core/pilon/main.nf | 25 +- modules/nf-core/pilon/meta.yml | 9 +- modules/nf-core/pilon/tests/main.nf.test | 116 ++++++ modules/nf-core/pilon/tests/main.nf.test.snap | 334 ++++++++++++++++++ modules/nf-core/pilon/tests/tags.yml | 2 + tests/config/pytest_modules.yml | 3 - tests/modules/nf-core/pilon/main.nf | 20 -- tests/modules/nf-core/pilon/nextflow.config | 5 - tests/modules/nf-core/pilon/test.yml | 8 - 9 files changed, 481 insertions(+), 41 deletions(-) create mode 100644 modules/nf-core/pilon/tests/main.nf.test create mode 100644 modules/nf-core/pilon/tests/main.nf.test.snap create mode 100644 modules/nf-core/pilon/tests/tags.yml delete mode 100644 tests/modules/nf-core/pilon/main.nf delete mode 100644 tests/modules/nf-core/pilon/nextflow.config delete mode 100644 tests/modules/nf-core/pilon/test.yml diff --git a/modules/nf-core/pilon/main.nf b/modules/nf-core/pilon/main.nf index ff610b0ad14..8e476db8e8c 100644 --- a/modules/nf-core/pilon/main.nf +++ b/modules/nf-core/pilon/main.nf @@ -9,7 +9,7 @@ process PILON { input: tuple val(meta), path(fasta) - tuple val(meta_bam), path(bam), path(bai) + tuple val(meta2), path(bam), path(bai) val pilon_mode output: @@ -24,8 +24,8 @@ process PILON { task.ext.when == null || task.ext.when script: - def args = task.ext.args ?: '' - def prefix = task.ext.prefix ?: "${meta.id}" + def args = task.ext.args ?: '' + def prefix = task.ext.prefix ?: "${meta.id}" def valid_mode = ["frags", "jumps", "unpaired", "bam"] if ( !valid_mode.contains(pilon_mode) ) { error "Unrecognised mode to run Pilon. Options: ${valid_mode.join(', ')}" } """ @@ -39,5 +39,24 @@ process PILON { cat <<-END_VERSIONS > versions.yml "${task.process}": pilon: \$(echo \$(pilon --version) | sed 's/^.*version //; s/ .*\$//' ) + END_VERSIONS """ + + stub: + def prefix = task.ext.prefix ?: "${meta.id}" + def valid_mode = ["frags", "jumps", "unpaired", "bam"] + if ( !valid_mode.contains(pilon_mode) ) { error "Unrecognised mode to run Pilon. Options: ${valid_mode.join(', ')}" } + """ + touch ${prefix}.fasta + touch ${prefix}.vcf + touch ${prefix}.change + touch ${prefix}.bed + touch ${prefix}.wig + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + pilon: \$(echo \$(pilon --version) | sed 's/^.*version //; s/ .*\$//' ) + END_VERSIONS + """ + } diff --git a/modules/nf-core/pilon/meta.yml b/modules/nf-core/pilon/meta.yml index 6a395a204e2..7a11c4dde1a 100644 --- a/modules/nf-core/pilon/meta.yml +++ b/modules/nf-core/pilon/meta.yml @@ -11,17 +11,22 @@ tools: documentation: "https://github.com/broadinstitute/pilon/wiki/Requirements-&-Usage" tool_dev_url: "https://github.com/broadinstitute/pilon" doi: "10.1371/journal.pone.0112963" - licence: "['GPL v2']" + licence: ["GPL-2.0-or-later"] input: - meta: type: map description: | - Groovy Map containing sample information + Groovy Map containing sample information for the fasta e.g. [ id:'test', single_end:false ] - fasta: type: file description: FASTA of the input genome pattern: "*.{fasta}" + - meta2: + type: map + description: | + Groovy Map containing sample information for the bam file + e.g. [ id:'test', single_end:false ] - bam: type: file description: BAM file of reads aligned to the input genome diff --git a/modules/nf-core/pilon/tests/main.nf.test b/modules/nf-core/pilon/tests/main.nf.test new file mode 100644 index 00000000000..2d09e8b85a6 --- /dev/null +++ b/modules/nf-core/pilon/tests/main.nf.test @@ -0,0 +1,116 @@ +nextflow_process { + + name "Test Process PILON" + script "../main.nf" + process "PILON" + + tag "modules" + tag "modules_nfcore" + tag "pilon" + + + test("homo sapiens bam") { + + when { + process { + """ + input[0] = [ [ id:'test', single_end:false ], // meta map + file(params.modules_testdata_base_path + "genomics/homo_sapiens/genome/genome.fasta", checkIfExists: true) + ] + input[1] = [ [ id:'test', single_end:false ], // meta map + file(params.modules_testdata_base_path + "genomics/homo_sapiens/illumina/bam/test.paired_end.sorted.bam", checkIfExists: true), + file(params.modules_testdata_base_path + "genomics/homo_sapiens/illumina/bam/test.paired_end.sorted.bam.bai", checkIfExists: true), + ] + input[2] = "bam" + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + + } + + test("homo sapiens bam - stub") { + options "-stub" + when { + process { + """ + input[0] = [ [ id:'test', single_end:false ], // meta map + file(params.modules_testdata_base_path + "genomics/homo_sapiens/genome/genome.fasta", checkIfExists: true) + ] + input[1] = [ [ id:'test', single_end:false ], // meta map + file(params.modules_testdata_base_path + "genomics/homo_sapiens/illumina/bam/test.paired_end.sorted.bam", checkIfExists: true), + file(params.modules_testdata_base_path + "genomics/homo_sapiens/illumina/bam/test.paired_end.sorted.bam.bai", checkIfExists: true), + ] + input[2] = "bam" + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + + } + + test("homo sapiens frags") { + + when { + process { + """ + input[0] = [ [ id:'test', single_end:false ], // meta map + file(params.modules_testdata_base_path + "genomics/homo_sapiens/genome/genome.fasta", checkIfExists: true) + ] + input[1] = [ [ id:'test', single_end:false ], // meta map + file(params.modules_testdata_base_path + "genomics/homo_sapiens/illumina/bam/test.paired_end.sorted.bam", checkIfExists: true), + file(params.modules_testdata_base_path + "genomics/homo_sapiens/illumina/bam/test.paired_end.sorted.bam.bai", checkIfExists: true), + ] + input[2] = "frags" + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + + } + + test("homo sapiens frags - stub") { + options "-stub" + when { + process { + """ + input[0] = [ [ id:'test', single_end:false ], // meta map + file(params.modules_testdata_base_path + "genomics/homo_sapiens/genome/genome.fasta", checkIfExists: true) + ] + input[1] = [ [ id:'test', single_end:false ], // meta map + file(params.modules_testdata_base_path + "genomics/sarscov2/illumina/bam/test.paired_end.sorted.bam", checkIfExists: true), + file(params.modules_testdata_base_path + "genomics/sarscov2/illumina/bam/test.paired_end.sorted.bam.bai", checkIfExists: true), + ] + input[2] = "frags" + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + + } + +} diff --git a/modules/nf-core/pilon/tests/main.nf.test.snap b/modules/nf-core/pilon/tests/main.nf.test.snap new file mode 100644 index 00000000000..91208228b89 --- /dev/null +++ b/modules/nf-core/pilon/tests/main.nf.test.snap @@ -0,0 +1,334 @@ +{ + "homo sapiens bam - stub": { + "content": [ + { + "0": [ + [ + { + "id": "test", + "single_end": false + }, + "test.fasta:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "1": [ + [ + { + "id": "test", + "single_end": false + }, + "test.vcf:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "2": [ + [ + { + "id": "test", + "single_end": false + }, + "test.change:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "3": [ + [ + { + "id": "test", + "single_end": false + }, + "test.bed:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "4": [ + [ + { + "id": "test", + "single_end": false + }, + "test.wig:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "5": [ + "versions.yml:md5,73f60b48e5c3838296b66520b61a551a" + ], + "change_record": [ + [ + { + "id": "test", + "single_end": false + }, + "test.change:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "improved_assembly": [ + [ + { + "id": "test", + "single_end": false + }, + "test.fasta:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "tracks_bed": [ + [ + { + "id": "test", + "single_end": false + }, + "test.bed:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "tracks_wig": [ + [ + { + "id": "test", + "single_end": false + }, + "test.wig:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "vcf": [ + [ + { + "id": "test", + "single_end": false + }, + "test.vcf:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "versions": [ + "versions.yml:md5,73f60b48e5c3838296b66520b61a551a" + ] + } + ], + "meta": { + "nf-test": "0.8.4", + "nextflow": "24.04.2" + }, + "timestamp": "2024-06-27T13:18:02.740029689" + }, + "homo sapiens bam": { + "content": [ + { + "0": [ + [ + { + "id": "test", + "single_end": false + }, + "test.fasta:md5,2e881994820a5a641da9ea594ab4958f" + ] + ], + "1": [ + + ], + "2": [ + + ], + "3": [ + + ], + "4": [ + + ], + "5": [ + "versions.yml:md5,73f60b48e5c3838296b66520b61a551a" + ], + "change_record": [ + + ], + "improved_assembly": [ + [ + { + "id": "test", + "single_end": false + }, + "test.fasta:md5,2e881994820a5a641da9ea594ab4958f" + ] + ], + "tracks_bed": [ + + ], + "tracks_wig": [ + + ], + "vcf": [ + + ], + "versions": [ + "versions.yml:md5,73f60b48e5c3838296b66520b61a551a" + ] + } + ], + "meta": { + "nf-test": "0.8.4", + "nextflow": "24.04.2" + }, + "timestamp": "2024-06-14T11:20:04.988498289" + }, + "homo sapiens frags": { + "content": [ + { + "0": [ + [ + { + "id": "test", + "single_end": false + }, + "test.fasta:md5,2e881994820a5a641da9ea594ab4958f" + ] + ], + "1": [ + + ], + "2": [ + + ], + "3": [ + + ], + "4": [ + + ], + "5": [ + "versions.yml:md5,73f60b48e5c3838296b66520b61a551a" + ], + "change_record": [ + + ], + "improved_assembly": [ + [ + { + "id": "test", + "single_end": false + }, + "test.fasta:md5,2e881994820a5a641da9ea594ab4958f" + ] + ], + "tracks_bed": [ + + ], + "tracks_wig": [ + + ], + "vcf": [ + + ], + "versions": [ + "versions.yml:md5,73f60b48e5c3838296b66520b61a551a" + ] + } + ], + "meta": { + "nf-test": "0.8.4", + "nextflow": "24.04.2" + }, + "timestamp": "2024-06-14T11:29:53.995788701" + }, + "homo sapiens frags - stub": { + "content": [ + { + "0": [ + [ + { + "id": "test", + "single_end": false + }, + "test.fasta:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "1": [ + [ + { + "id": "test", + "single_end": false + }, + "test.vcf:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "2": [ + [ + { + "id": "test", + "single_end": false + }, + "test.change:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "3": [ + [ + { + "id": "test", + "single_end": false + }, + "test.bed:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "4": [ + [ + { + "id": "test", + "single_end": false + }, + "test.wig:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "5": [ + "versions.yml:md5,73f60b48e5c3838296b66520b61a551a" + ], + "change_record": [ + [ + { + "id": "test", + "single_end": false + }, + "test.change:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "improved_assembly": [ + [ + { + "id": "test", + "single_end": false + }, + "test.fasta:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "tracks_bed": [ + [ + { + "id": "test", + "single_end": false + }, + "test.bed:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "tracks_wig": [ + [ + { + "id": "test", + "single_end": false + }, + "test.wig:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "vcf": [ + [ + { + "id": "test", + "single_end": false + }, + "test.vcf:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "versions": [ + "versions.yml:md5,73f60b48e5c3838296b66520b61a551a" + ] + } + ], + "meta": { + "nf-test": "0.8.4", + "nextflow": "24.04.2" + }, + "timestamp": "2024-06-27T13:18:31.732478412" + } +} \ No newline at end of file diff --git a/modules/nf-core/pilon/tests/tags.yml b/modules/nf-core/pilon/tests/tags.yml new file mode 100644 index 00000000000..0d94efba1d7 --- /dev/null +++ b/modules/nf-core/pilon/tests/tags.yml @@ -0,0 +1,2 @@ +pilon: + - "modules/nf-core/pilon/**" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index a0f69406b34..8b987cb0801 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -1235,9 +1235,6 @@ picard/sortsam: picard/sortvcf: - modules/nf-core/picard/sortvcf/** - tests/modules/nf-core/picard/sortvcf/** -pilon: - - modules/nf-core/pilon/** - - tests/modules/nf-core/pilon/** pindel/pindel: - modules/nf-core/pindel/pindel/** - tests/modules/nf-core/pindel/pindel/** diff --git a/tests/modules/nf-core/pilon/main.nf b/tests/modules/nf-core/pilon/main.nf deleted file mode 100644 index 7adfb149a80..00000000000 --- a/tests/modules/nf-core/pilon/main.nf +++ /dev/null @@ -1,20 +0,0 @@ -#!/usr/bin/env nextflow - -nextflow.enable.dsl = 2 - -include { PILON } from '../../../../modules/nf-core/pilon/main.nf' - -workflow test_pilon { - - input = [ - [ id:'test', single_end:false ], // meta map - file(params.test_data['homo_sapiens']['genome']['genome_fasta'], checkIfExists: true) - ] - - bam_tuple_ch = Channel.of([ [ id:'test', single_end:false ], // meta map - file(params.test_data['homo_sapiens']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true), - file(params.test_data['homo_sapiens']['illumina']['test_paired_end_sorted_bam_bai'], checkIfExists: true), - ]) - - PILON ( input, bam_tuple_ch, "bam" ) -} diff --git a/tests/modules/nf-core/pilon/nextflow.config b/tests/modules/nf-core/pilon/nextflow.config deleted file mode 100644 index 50f50a7a357..00000000000 --- a/tests/modules/nf-core/pilon/nextflow.config +++ /dev/null @@ -1,5 +0,0 @@ -process { - - publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" } - -} \ No newline at end of file diff --git a/tests/modules/nf-core/pilon/test.yml b/tests/modules/nf-core/pilon/test.yml deleted file mode 100644 index 2e36a64d5fe..00000000000 --- a/tests/modules/nf-core/pilon/test.yml +++ /dev/null @@ -1,8 +0,0 @@ -- name: pilon test_pilon - command: nextflow run ./tests/modules/nf-core/pilon -entry test_pilon -c ./tests/config/nextflow.config -c ./tests/modules/nf-core/pilon/nextflow.config - tags: - - pilon - files: - - path: output/pilon/test.fasta - md5sum: 2e881994820a5a641da9ea594ab4958f - - path: output/pilon/versions.yml