From c5abf7acbb2943bf09f4025cacbbcc2bc2292637 Mon Sep 17 00:00:00 2001 From: Felix Lenner <52530259+fellen31@users.noreply.github.com> Date: Wed, 10 Jul 2024 09:56:56 +0200 Subject: [PATCH] Fix bcftools plugin split (#5942) --- modules/nf-core/bcftools/pluginsplit/main.nf | 20 +- .../bcftools/pluginsplit/tests/main.nf.test | 192 ++++++++++++++ .../pluginsplit/tests/main.nf.test.snap | 240 ++++++++++++++++++ .../pluginsplit/tests/nextflow.config | 5 + .../bcftools/pluginsplit/tests/tags.yml | 2 + tests/config/pytest_modules.yml | 3 - .../nf-core/bcftools/pluginsplit/main.nf | 48 ---- .../bcftools/pluginsplit/nextflow.config | 5 - .../nf-core/bcftools/pluginsplit/test.yml | 23 -- 9 files changed, 453 insertions(+), 85 deletions(-) create mode 100644 modules/nf-core/bcftools/pluginsplit/tests/main.nf.test create mode 100644 modules/nf-core/bcftools/pluginsplit/tests/main.nf.test.snap create mode 100644 modules/nf-core/bcftools/pluginsplit/tests/nextflow.config create mode 100644 modules/nf-core/bcftools/pluginsplit/tests/tags.yml delete mode 100644 tests/modules/nf-core/bcftools/pluginsplit/main.nf delete mode 100644 tests/modules/nf-core/bcftools/pluginsplit/nextflow.config delete mode 100644 tests/modules/nf-core/bcftools/pluginsplit/test.yml diff --git a/modules/nf-core/bcftools/pluginsplit/main.nf b/modules/nf-core/bcftools/pluginsplit/main.nf index 83de8f966d5..082802be709 100644 --- a/modules/nf-core/bcftools/pluginsplit/main.nf +++ b/modules/nf-core/bcftools/pluginsplit/main.nf @@ -15,8 +15,10 @@ process BCFTOOLS_PLUGINSPLIT { path(targets) output: - tuple val(meta), path("*.{vcf,vcf.gz,bcf,bcf.gz}") , emit: vcf - path "versions.yml" , emit: versions + tuple val(meta), path("*.{vcf,vcf.gz,bcf,bcf.gz}"), emit: vcf + tuple val(meta), path("*.tbi") , emit: tbi, optional: true + tuple val(meta), path("*.csi") , emit: csi, optional: true + path "versions.yml" , emit: versions when: task.ext.when == null || task.ext.when @@ -32,6 +34,7 @@ process BCFTOOLS_PLUGINSPLIT { """ bcftools plugin split \\ + ${args} \\ ${vcf} \\ ${samples_arg} \\ ${groups_arg} \\ @@ -56,12 +59,17 @@ process BCFTOOLS_PLUGINSPLIT { args.contains("--output-type z") || args.contains("-Oz") ? "vcf.gz" : args.contains("--output-type v") || args.contains("-Ov") ? "vcf" : "vcf" - + def index = args.contains("--write-index=tbi") || args.contains("-W=tbi") ? "tbi" : + args.contains("--write-index=csi") || args.contains("-W=csi") ? "csi" : + args.contains("--write-index") || args.contains("-W") ? "csi" : + "" def determination_file = samples ?: targets + def create_cmd = extension.matches("vcf|bcf") ? "touch " : "echo '' | gzip > " + def create_files = "cut -f 3 ${determination_file} | sed -e 's/\$/.${extension}/' > files.txt; while IFS= read -r filename; do ${create_cmd} \"\$filename\"; done < files.txt" + def create_index = index.matches("csi|tbi") ? "cut -f 3 ${determination_file} | sed -e 's/\$/.${extension}.${index}/' > indices.txt; touch \$( files.txt - - touch \$( versions.yml "${task.process}": diff --git a/modules/nf-core/bcftools/pluginsplit/tests/main.nf.test b/modules/nf-core/bcftools/pluginsplit/tests/main.nf.test new file mode 100644 index 00000000000..e3160851893 --- /dev/null +++ b/modules/nf-core/bcftools/pluginsplit/tests/main.nf.test @@ -0,0 +1,192 @@ +nextflow_process { + + name "Test Process BCFTOOLS_PLUGINSPLIT" + script "../main.nf" + process "BCFTOOLS_PLUGINSPLIT" + + tag "modules" + tag "modules_nfcore" + tag "bcftools" + tag "bcftools/pluginsplit" + + test("homo_sapiens - [ vcf, tbi ], samples, [], [], []") { + + when { + process { + """ + input[0] = [ + [ id:'test', single_end:false ], // meta map + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz', checkIfExists: true), + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz.tbi', checkIfExists: true) + ] + input[1] = Channel.of("normal\t-\tnormal", "tumour\t-\ttumour") + .collectFile(name:"samples.txt", newLine:true) + input[2] = [] + input[3] = [] + input[4] = [] + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + + } + + test("homo_sapiens - [ vcf, tbi ], [], groups, regions, targets") { + + when { + process { + """ + input[0] = [ + [ id:'test', single_end:false ], // meta map + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz', checkIfExists: true), + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz.tbi', checkIfExists: true) + ] + input[1] = [] + input[2] = Channel.of("normal\t-\tnormal", "tumour\t-\ttumour") + .collectFile(name:"samples.txt", newLine:true) + input[3] = file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.bed', checkIfExists: true) + input[4] = file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.multi_intervals.bed', checkIfExists: true) + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out.match).match() } + + ) + } + + } + + test("homo_sapiens - [ vcf, tbi ], [], groups, regions, targets - tbi") { + + config "./nextflow.config" + + when { + process { + """ + input[0] = [ + [ id:'test', single_end:false ], // meta map + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz', checkIfExists: true), + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz.tbi', checkIfExists: true) + ] + input[1] = [] + input[2] = Channel.of("normal\t-\tnormal", "tumour\t-\ttumour") + .collectFile(name:"samples.txt", newLine:true) + input[3] = file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.bed', checkIfExists: true) + input[4] = file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.multi_intervals.bed', checkIfExists: true) + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot( + process.out.vcf, + process.out.tbi.get(0).get(1).find { file(it).name.matches("normal.vcf.gz.tbi|tumor.vcf.gz.tbi") }, + ) } + ) + } + + } + + test("homo_sapiens - [ vcf, tbi ], samples, [], [], [] -stub") { + + options "-stub" + + when { + process { + """ + input[0] = [ + [ id:'test', single_end:false ], // meta map + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz', checkIfExists: true), + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz.tbi', checkIfExists: true) + ] + input[1] = Channel.of("normal\t-\tnormal", "tumour\t-\ttumour") + .collectFile(name:"samples.txt", newLine:true) + input[2] = [] + input[3] = [] + input[4] = [] + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + + } + + test("homo_sapiens - [ vcf, tbi ], [], groups, regions, targets -stub") { + + options "-stub" + + when { + process { + """ + input[0] = [ + [ id:'test', single_end:false ], // meta map + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz', checkIfExists: true), + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz.tbi', checkIfExists: true) + ] + input[1] = [] + input[2] = Channel.of("normal\t-\tnormal", "tumour\t-\ttumour") + .collectFile(name:"samples.txt", newLine:true) + input[3] = file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.bed', checkIfExists: true) + input[4] = file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.multi_intervals.bed', checkIfExists: true) + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + + } + + test("homo_sapiens - [ vcf, tbi ], [], groups, regions, targets - tbi -stub") { + + config "./nextflow.config" + options "-stub" + + when { + process { + """ + input[0] = [ + [ id:'test', single_end:false ], // meta map + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz', checkIfExists: true), + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/illumina/gatk/paired_mutect2_calls/test_test2_paired_mutect2_calls.vcf.gz.tbi', checkIfExists: true) + ] + input[1] = [] + input[2] = Channel.of("normal\t-\tnormal", "tumour\t-\ttumour") + .collectFile(name:"samples.txt", newLine:true) + input[3] = file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.bed', checkIfExists: true) + input[4] = file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.multi_intervals.bed', checkIfExists: true) + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + + } +} diff --git a/modules/nf-core/bcftools/pluginsplit/tests/main.nf.test.snap b/modules/nf-core/bcftools/pluginsplit/tests/main.nf.test.snap new file mode 100644 index 00000000000..66c3c1dda5e --- /dev/null +++ b/modules/nf-core/bcftools/pluginsplit/tests/main.nf.test.snap @@ -0,0 +1,240 @@ +{ + "homo_sapiens - [ vcf, tbi ], samples, [], [], [] -stub": { + "content": [ + { + "0": [ + [ + { + "id": "test", + "single_end": false + }, + [ + "normal.vcf:md5,d41d8cd98f00b204e9800998ecf8427e", + "tumour.vcf:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ] + ], + "1": [ + + ], + "2": [ + + ], + "3": [ + "versions.yml:md5,8625f8c08503e47d029d48430c0bfccc" + ], + "csi": [ + + ], + "tbi": [ + + ], + "vcf": [ + [ + { + "id": "test", + "single_end": false + }, + [ + "normal.vcf:md5,d41d8cd98f00b204e9800998ecf8427e", + "tumour.vcf:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ] + ], + "versions": [ + "versions.yml:md5,8625f8c08503e47d029d48430c0bfccc" + ] + } + ], + "meta": { + "nf-test": "0.8.4", + "nextflow": "24.04.2" + }, + "timestamp": "2024-07-09T15:56:42.307673651" + }, + "homo_sapiens - [ vcf, tbi ], [], groups, regions, targets": { + "content": null, + "meta": { + "nf-test": "0.8.4", + "nextflow": "24.04.2" + }, + "timestamp": "2024-07-09T15:56:21.498991402" + }, + "homo_sapiens - [ vcf, tbi ], [], groups, regions, targets - tbi -stub": { + "content": [ + { + "0": [ + [ + { + "id": "test", + "single_end": false + }, + [ + "15000.vcf.gz:md5,68b329da9893e34099c7d8ad5cb9c940", + "40001.vcf.gz:md5,68b329da9893e34099c7d8ad5cb9c940" + ] + ] + ], + "1": [ + [ + { + "id": "test", + "single_end": false + }, + [ + "15000.vcf.gz.tbi:md5,d41d8cd98f00b204e9800998ecf8427e", + "40001.vcf.gz.tbi:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ] + ], + "2": [ + + ], + "3": [ + "versions.yml:md5,8625f8c08503e47d029d48430c0bfccc" + ], + "csi": [ + + ], + "tbi": [ + [ + { + "id": "test", + "single_end": false + }, + [ + "15000.vcf.gz.tbi:md5,d41d8cd98f00b204e9800998ecf8427e", + "40001.vcf.gz.tbi:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ] + ], + "vcf": [ + [ + { + "id": "test", + "single_end": false + }, + [ + "15000.vcf.gz:md5,68b329da9893e34099c7d8ad5cb9c940", + "40001.vcf.gz:md5,68b329da9893e34099c7d8ad5cb9c940" + ] + ] + ], + "versions": [ + "versions.yml:md5,8625f8c08503e47d029d48430c0bfccc" + ] + } + ], + "meta": { + "nf-test": "0.8.4", + "nextflow": "24.04.2" + }, + "timestamp": "2024-07-09T15:57:04.483688966" + }, + "homo_sapiens - [ vcf, tbi ], samples, [], [], []": { + "content": [ + { + "0": [ + [ + { + "id": "test", + "single_end": false + }, + [ + "normal.vcf:md5,69cfc4bf92bf3e2847081a2026a4d3bb", + "tumour.vcf:md5,08fa5c8d5561c2a8d7c300cb0eea1042" + ] + ] + ], + "1": [ + + ], + "2": [ + + ], + "3": [ + "versions.yml:md5,8625f8c08503e47d029d48430c0bfccc" + ], + "csi": [ + + ], + "tbi": [ + + ], + "vcf": [ + [ + { + "id": "test", + "single_end": false + }, + [ + "normal.vcf:md5,69cfc4bf92bf3e2847081a2026a4d3bb", + "tumour.vcf:md5,08fa5c8d5561c2a8d7c300cb0eea1042" + ] + ] + ], + "versions": [ + "versions.yml:md5,8625f8c08503e47d029d48430c0bfccc" + ] + } + ], + "meta": { + "nf-test": "0.8.4", + "nextflow": "24.04.2" + }, + "timestamp": "2024-07-09T15:56:10.033818589" + }, + "homo_sapiens - [ vcf, tbi ], [], groups, regions, targets -stub": { + "content": [ + { + "0": [ + [ + { + "id": "test", + "single_end": false + }, + [ + "15000.vcf:md5,d41d8cd98f00b204e9800998ecf8427e", + "40001.vcf:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ] + ], + "1": [ + + ], + "2": [ + + ], + "3": [ + "versions.yml:md5,8625f8c08503e47d029d48430c0bfccc" + ], + "csi": [ + + ], + "tbi": [ + + ], + "vcf": [ + [ + { + "id": "test", + "single_end": false + }, + [ + "15000.vcf:md5,d41d8cd98f00b204e9800998ecf8427e", + "40001.vcf:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ] + ], + "versions": [ + "versions.yml:md5,8625f8c08503e47d029d48430c0bfccc" + ] + } + ], + "meta": { + "nf-test": "0.8.4", + "nextflow": "24.04.2" + }, + "timestamp": "2024-07-09T15:56:53.641165787" + } +} \ No newline at end of file diff --git a/modules/nf-core/bcftools/pluginsplit/tests/nextflow.config b/modules/nf-core/bcftools/pluginsplit/tests/nextflow.config new file mode 100644 index 00000000000..9b9a4783a57 --- /dev/null +++ b/modules/nf-core/bcftools/pluginsplit/tests/nextflow.config @@ -0,0 +1,5 @@ +process { + withName: 'BCFTOOLS_PLUGINSPLIT' { + ext.args = '--write-index=tbi --output-type z' + } +} diff --git a/modules/nf-core/bcftools/pluginsplit/tests/tags.yml b/modules/nf-core/bcftools/pluginsplit/tests/tags.yml new file mode 100644 index 00000000000..2f29ef18ac8 --- /dev/null +++ b/modules/nf-core/bcftools/pluginsplit/tests/tags.yml @@ -0,0 +1,2 @@ +bcftools/pluginsplit: + - "modules/nf-core/bcftools/pluginsplit/**" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 3672a771f06..92a100680f9 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -103,9 +103,6 @@ bcftools/convert: bcftools/merge: - modules/nf-core/bcftools/merge/** - tests/modules/nf-core/bcftools/merge/** -bcftools/pluginsplit: - - modules/nf-core/bcftools/pluginsplit/** - - tests/modules/nf-core/bcftools/pluginsplit/** bcftools/roh: - modules/nf-core/bcftools/roh/** - tests/modules/nf-core/bcftools/roh/** diff --git a/tests/modules/nf-core/bcftools/pluginsplit/main.nf b/tests/modules/nf-core/bcftools/pluginsplit/main.nf deleted file mode 100644 index abc615788d5..00000000000 --- a/tests/modules/nf-core/bcftools/pluginsplit/main.nf +++ /dev/null @@ -1,48 +0,0 @@ -#!/usr/bin/env nextflow - -nextflow.enable.dsl = 2 - -include { BCFTOOLS_PLUGINSPLIT } from '../../../../../modules/nf-core/bcftools/pluginsplit/main.nf' - -workflow test_bcftools_pluginsplit { - - input = [ - [ id:'test', single_end:false ], // meta map - file(params.test_data['homo_sapiens']['illumina']['test_test2_paired_mutect2_calls_vcf_gz'], checkIfExists: true), - file(params.test_data['homo_sapiens']['illumina']['test_test2_paired_mutect2_calls_vcf_gz_tbi'], checkIfExists: true) - ] - - samples = Channel.of("normal\t-\tnormal", "tumour\t-\ttumour") - .collectFile(name:"samples.txt", newLine:true) - - BCFTOOLS_PLUGINSPLIT ( - input, - samples, - [], - [], - [] - ) -} - -workflow test_bcftools_pluginsplit_full { - - input = [ - [ id:'test', single_end:false ], // meta map - file(params.test_data['homo_sapiens']['illumina']['test_test2_paired_mutect2_calls_vcf_gz'], checkIfExists: true), - file(params.test_data['homo_sapiens']['illumina']['test_test2_paired_mutect2_calls_vcf_gz_tbi'], checkIfExists: true) - ] - - groups = Channel.of("normal\t-\tnormal", "tumour\t-\ttumour") - .collectFile(name:"samples.txt", newLine:true) - - regions = file(params.test_data['homo_sapiens']['genome']['genome_bed'], checkIfExists: true) - targets = file(params.test_data['homo_sapiens']['genome']['genome_multi_interval_bed'], checkIfExists: true) - - BCFTOOLS_PLUGINSPLIT ( - input, - [], - groups, - regions, - targets - ) -} diff --git a/tests/modules/nf-core/bcftools/pluginsplit/nextflow.config b/tests/modules/nf-core/bcftools/pluginsplit/nextflow.config deleted file mode 100644 index 50f50a7a357..00000000000 --- a/tests/modules/nf-core/bcftools/pluginsplit/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/bcftools/pluginsplit/test.yml b/tests/modules/nf-core/bcftools/pluginsplit/test.yml deleted file mode 100644 index 48ecbfbff86..00000000000 --- a/tests/modules/nf-core/bcftools/pluginsplit/test.yml +++ /dev/null @@ -1,23 +0,0 @@ -- name: bcftools pluginsplit test_bcftools_pluginsplit - command: nextflow run ./tests/modules/nf-core/bcftools/pluginsplit -entry test_bcftools_pluginsplit -c ./tests/config/nextflow.config -c ./tests/modules/nf-core/bcftools/pluginsplit/nextflow.config - tags: - - bcftools - - bcftools/pluginsplit - files: - - path: output/bcftools/normal.vcf - md5sum: 69cfc4bf92bf3e2847081a2026a4d3bb - - path: output/bcftools/tumour.vcf - md5sum: 08fa5c8d5561c2a8d7c300cb0eea1042 - - path: output/bcftools/versions.yml - -- name: bcftools pluginsplit test_bcftools_pluginsplit_full - command: nextflow run ./tests/modules/nf-core/bcftools/pluginsplit -entry test_bcftools_pluginsplit_full -c ./tests/config/nextflow.config -c ./tests/modules/nf-core/bcftools/pluginsplit/nextflow.config - tags: - - bcftools - - bcftools/pluginsplit - files: - - path: output/bcftools/normal.vcf - md5sum: 78e962c3a724790b27041f28a4180600 - - path: output/bcftools/tumour.vcf - md5sum: 3008a0a06a2f319897fa04ea0018fcdd - - path: output/bcftools/versions.yml