diff --git a/modules/nf-core/jvarkit/vcf2table/environment.yml b/modules/nf-core/jvarkit/vcf2table/environment.yml new file mode 100644 index 00000000000..18aee65ed61 --- /dev/null +++ b/modules/nf-core/jvarkit/vcf2table/environment.yml @@ -0,0 +1,8 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json +channels: + - conda-forge + - bioconda +dependencies: + - "bioconda:bcftools=1.20" + - "bioconda::jvarkit=2024.08.25" diff --git a/modules/nf-core/jvarkit/vcf2table/main.nf b/modules/nf-core/jvarkit/vcf2table/main.nf new file mode 100644 index 00000000000..f701a6b487e --- /dev/null +++ b/modules/nf-core/jvarkit/vcf2table/main.nf @@ -0,0 +1,63 @@ +process JVARKIT_VCF2TABLE { + tag "$meta.id" + label 'process_single' + + conda "${moduleDir}/environment.yml" + container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? + 'https://depot.galaxyproject.org/singularity/jvarkit:2024.08.25--hdfd78af_1': + 'biocontainers/jvarkit:2024.08.25--hdfd78af_1' }" + + input: + tuple val(meta), path(vcf), path(tbi), path(regions_file) + tuple val(meta2), path(pedigree) + output: + tuple val(meta), path("*.${extension}"), emit: output + path "versions.yml" , emit: versions + + when: + task.ext.when == null || task.ext.when + + script: + def args1 = task.ext.args1 ?: '' + def args2 = task.ext.args2 ?: '' + def prefix = task.ext.prefix ?: "${meta.id}" + def ped = pedigree?"--pedigree \"${pedigree}\"":"" + def regions_file = regions_file? (tbi ? " --regions-file" : " --targets-file")+" \"${regions_file}\" ":"" + extension = getFileExtension(args2); /* custom function, see below */ + + if ("$vcf" == "${prefix}.${extension}") error "Input and output names are the same, set prefix in module configuration to disambiguate!" + """ + mkdir -p TMP + + bcftools view ${regions_file} -O v ${args1} "${vcf}" |\\ + jvarkit -Xmx${task.memory.giga}g -XX:-UsePerfData -Djava.io.tmpdir=TMP vcf2table ${ped} ${args2} > "${prefix}.${extension}" + + rm -rf TMP + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + bcftools: \$(bcftools --version 2>&1 | head -n1 | sed 's/^.*bcftools //; s/ .*\$//') + jvarkit: \$(jvarkit -v) + END_VERSIONS + """ + + stub: + def args2 = task.ext.args2 ?: '' + extension = getFileExtension(args2); /* custom function, see below */ + def prefix = task.ext.prefix ?: "${meta.id}" + """ + touch "${prefix}.${extension}" + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + bcftools: \$(bcftools --version 2>&1 | head -n1 | sed 's/^.*bcftools //; s/ .*\$//') + jvarkit: \$(jvarkit -v) + END_VERSIONS + """ +} + + +// Custom Function to get VCF extension +String getFileExtension(String args) { + return args.contains("--format html") ? "html" : "txt" +} diff --git a/modules/nf-core/jvarkit/vcf2table/meta.yml b/modules/nf-core/jvarkit/vcf2table/meta.yml new file mode 100644 index 00000000000..4170d11f775 --- /dev/null +++ b/modules/nf-core/jvarkit/vcf2table/meta.yml @@ -0,0 +1,75 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/meta-schema.json +name: "jvarkit_vcf2table" +description: Convert VCF to a user friendly table +keywords: + - vcf + - bcf + - text + - html + - visualization +tools: + - "jvarkit": + description: "Java utilities for Bioinformatics." + homepage: "https://github.com/lindenb/jvarkit" + documentation: "https://jvarkit.readthedocs.io/" + tool_dev_url: "https://github.com/lindenb/jvarkit" + doi: "10.6084/m9.figshare.1425030" + licence: ["MIT"] + args_id: "$args2" + identifier: "" + - "bcftools": + description: | + View, subset and filter VCF or BCF files by position and filtering expression. Convert between VCF and BCF + homepage: "http://samtools.github.io/bcftools/bcftools.html" + documentation: "http://www.htslib.org/doc/bcftools.html" + doi: "10.1093/bioinformatics/btp352" + licence: ["MIT"] + args_id: "$args1" + identifier: "biotools:samtools" +input: + - - "meta": + type: map + description: | + Groovy Map containing VCF information + e.g. [ id:'genome' ] + - vcf: + type: file + description: Input vcf/bcf file + pattern: "*.{vcf,bcf,vcf.gz,bcf.gz}" + - tbi: + type: file + description: Optional index file for the VCF + pattern: "*.{tbi,csi}" + - regions_file: + type: file + description: Optional. Restrict to regions listed in a file + pattern: "*.{bed,bed.gz,txt,tsv}" + - - meta2: + type: map + description: | + Groovy Map containing pedigree information + - pedigree: + type: file + description: Optional pedigree for jvarkit + pattern: "*.{ped,pedigree}" +output: + - output: + - meta: + type: map + description: | + Groovy Map containing VCF information + e.g. [ id:'test', single_end:false ] + - "*.${extension}": + type: file + description: Output file + pattern: "*.{txt,html}" + - versions: + - "versions.yml": + type: file + description: File containing software versions + pattern: "versions.yml" +authors: + - "@lindenb" +maintainers: + - "@lindenb" diff --git a/modules/nf-core/jvarkit/vcf2table/tests/main.nf.test b/modules/nf-core/jvarkit/vcf2table/tests/main.nf.test new file mode 100644 index 00000000000..0a0c41607cb --- /dev/null +++ b/modules/nf-core/jvarkit/vcf2table/tests/main.nf.test @@ -0,0 +1,76 @@ +nextflow_process { + + name "Test Process JVARKIT_VCF2TABLE" + script "../main.nf" + process "JVARKIT_VCF2TABLE" + config "./nextflow.config" + + tag "modules" + tag "modules_nfcore" + tag "jvarkit" + tag "jvarkit/vcf2table" + + test("sarscov2 - vcf") { + + when { + process { + """ + input[0] =[ + [id:"vcf_test"], + file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/vcf/test.vcf', checkIfExists: true), + [], + [] + ] + input[1] = [ [] , [] ] + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert path(process.out.output[0][1]).text.startsWith(">>MT192765.1:197/G (n. 1)")}, + { assert snapshot( + path(process.out.output[0][1]), + process.out.versions + ).match() + } + ) + } + + } + + + + test("sarscov2 - vcf - stub") { + + options "-stub" + + when { + process { + """ + input[0] =[ + [id:"vcf_test"], + file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/vcf/test.vcf', checkIfExists: true), + [], + [] + ] + input[1] = [ [] , [] ] + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot( + path(process.out.output[0][1]), + process.out.versions + ).match() + } + ) + } + + } + +} diff --git a/modules/nf-core/jvarkit/vcf2table/tests/main.nf.test.snap b/modules/nf-core/jvarkit/vcf2table/tests/main.nf.test.snap new file mode 100644 index 00000000000..de05e2fd64f --- /dev/null +++ b/modules/nf-core/jvarkit/vcf2table/tests/main.nf.test.snap @@ -0,0 +1,30 @@ +{ + "sarscov2 - vcf": { + "content": [ + "vcf_test.txt:md5,91513583ed7c0d0e63bb046c03419460", + [ + "versions.yml:md5,0c4f207f3c21b881974f056ea9f863c7" + ] + ], + "meta": { + "nf-test": "0.9.0", + "nextflow": "24.04.4" + }, + "timestamp": "2024-09-03T14:00:13.118369362" + }, + + "sarscov2 - vcf - stub": { + "content": [ + "vcf_test.txt:md5,d41d8cd98f00b204e9800998ecf8427e", + [ + "versions.yml:md5,0c4f207f3c21b881974f056ea9f863c7" + ] + ], + "meta": { + "nf-test": "0.9.0", + "nextflow": "24.04.4" + }, + "timestamp": "2024-09-03T14:00:13.118369362" + } + +} diff --git a/modules/nf-core/jvarkit/vcf2table/tests/nextflow.config b/modules/nf-core/jvarkit/vcf2table/tests/nextflow.config new file mode 100644 index 00000000000..a7272c8356e --- /dev/null +++ b/modules/nf-core/jvarkit/vcf2table/tests/nextflow.config @@ -0,0 +1,7 @@ +process { + + withName: JVARKIT_VCF2TABLE { + ext.args2=" --hide NO_CALL " + } + +} diff --git a/modules/nf-core/jvarkit/vcf2table/tests/tags.yml b/modules/nf-core/jvarkit/vcf2table/tests/tags.yml new file mode 100644 index 00000000000..de823e3f6b3 --- /dev/null +++ b/modules/nf-core/jvarkit/vcf2table/tests/tags.yml @@ -0,0 +1,2 @@ +jvarkit/vcf2table: + - "modules/nf-core/jvarkit/vcf2table/**"