From ca7f050a8fb6fefefc31910098a4abd35002fecd Mon Sep 17 00:00:00 2001 From: Daniel Schmitz Date: Fri, 15 Nov 2024 15:55:28 +0100 Subject: [PATCH] Imported module from branch trgt --- modules/nf-core/trgt/plot/environment.yml | 6 + modules/nf-core/trgt/plot/main.nf | 56 ++++++++ modules/nf-core/trgt/plot/meta.yml | 94 ++++++++++++ modules/nf-core/trgt/plot/tests/main.nf.test | 136 ++++++++++++++++++ .../nf-core/trgt/plot/tests/main.nf.test.snap | 68 +++++++++ .../nf-core/trgt/plot/tests/nextflow.config | 6 + 6 files changed, 366 insertions(+) create mode 100644 modules/nf-core/trgt/plot/environment.yml create mode 100644 modules/nf-core/trgt/plot/main.nf create mode 100644 modules/nf-core/trgt/plot/meta.yml create mode 100644 modules/nf-core/trgt/plot/tests/main.nf.test create mode 100644 modules/nf-core/trgt/plot/tests/main.nf.test.snap create mode 100644 modules/nf-core/trgt/plot/tests/nextflow.config diff --git a/modules/nf-core/trgt/plot/environment.yml b/modules/nf-core/trgt/plot/environment.yml new file mode 100644 index 00000000000..614dc872b7b --- /dev/null +++ b/modules/nf-core/trgt/plot/environment.yml @@ -0,0 +1,6 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json +channels: + - conda-forge + - bioconda +dependencies: + - "bioconda::trgt=1.2.0" diff --git a/modules/nf-core/trgt/plot/main.nf b/modules/nf-core/trgt/plot/main.nf new file mode 100644 index 00000000000..f60fd8a150c --- /dev/null +++ b/modules/nf-core/trgt/plot/main.nf @@ -0,0 +1,56 @@ +process TRGT_PLOT { + tag "$meta.id" + label 'process_low' + + conda "${moduleDir}/environment.yml" + container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? + 'https://depot.galaxyproject.org/singularity/trgt:1.2.0--h9ee0642_0': + 'biocontainers/trgt:1.2.0--h9ee0642_0' }" + + input: + tuple val(meta) , path(bam), path(bai), path(vcf), path(tbi), val(repeat_id) + tuple val(meta2), path(fasta) + tuple val(meta3), path(fai) + tuple val(meta4), path(repeats) + + output: + tuple val(meta), path("*.{png,pdf,svg}"), emit: plot + path "versions.yml" , emit: versions + + when: + task.ext.when == null || task.ext.when + + script: + def args = task.ext.args ?: '' + def prefix = task.ext.prefix ?: "${meta.id}_${repeat_id}" + // If user didn't specify an output path, plot to PNG + def output_arg = args.contains("--image") || args.contains("-o") ? "" : "--image ${prefix}.png" + + """ + trgt plot \\ + $args \\ + --genome ${fasta} \\ + --repeats ${repeats} \\ + --spanning-reads ${bam} \\ + --vcf ${vcf} \\ + --repeat-id ${repeat_id} \\ + $output_arg + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + trgt: \$(trgt --version |& sed '1!d ; s/trgt //') + END_VERSIONS + """ + + stub: + def args = task.ext.args ?: '' + def prefix = task.ext.prefix ?: "${meta.id}" + """ + touch ${prefix}.png + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + trgt: \$(trgt --version |& sed '1!d ; s/trgt //') + END_VERSIONS + """ +} diff --git a/modules/nf-core/trgt/plot/meta.yml b/modules/nf-core/trgt/plot/meta.yml new file mode 100644 index 00000000000..b1052d8c742 --- /dev/null +++ b/modules/nf-core/trgt/plot/meta.yml @@ -0,0 +1,94 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/meta-schema.json +name: "trgt_plot" +description: Visualize tandem repeats genotyped by TRGT +keywords: + - trgt + - repeat expansion + - plotting + - pacbio + - genomics +tools: + - "trgt": + description: "Tandem repeat genotyping and visualization from PacBio HiFi data" + homepage: "https://github.com/PacificBiosciences/trgt" + documentation: "https://github.com/PacificBiosciences/trgt/blob/main/docs/tutorial.md" + tool_dev_url: "https://github.com/PacificBiosciences/trgt" + doi: "10.1038/s41587-023-02057-3" + licence: + ["Pacific Biosciences Software License (https://github.com/PacificBiosciences/trgt/blob/main/LICENSE.md)"] + +input: + - - meta: + type: map + description: | + Groovy Map containing sample information + e.g. `[ id:'sample1', single_end:false ]` + - bam: + type: file + description: "Sorted reads spanning tandem repeat from TRGT output" + pattern: "*.bam" + - bai: + type: file + description: "Index for reads" + pattern: "*.bai" + - vcf: + type: file + description: "Sorted tandem repeat genotypes called by TRGT" + pattern: "*.vcf.gz" + - tbi: + type: file + description: "Index for genotypes" + pattern: "*.{tbi,csi}" + - repeat_id: + type: string + description: "ID of tandem repeat to plot" + - - meta2: + type: map + description: | + Groovy map containing reference information + e.g. `[ id: 'genome' ]` + - fasta: + type: file + description: "FASTA reference file" + pattern: "*.{fasta,fa,fna}" + - - meta3: + type: map + description: | + Groovy map containing reference information + e.g. `[ id: 'genome' ]` + - fai: + type: file + description: "Index for FASTA file" + pattern: "*.fai" + - - meta4: + type: map + description: | + Groovy map containing repeat information + e.g. `[ id: 'repeats' ]` + - repeats: + type: file + description: "BED file with repeat coordinates and structure" + pattern: "*.bed" + +output: + - plot: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. `[ id:'sample1', single_end:false ]` + - "*.{png,pdf,svg}": + type: file + description: "Plot of region and reads spanning tandem repeat" + pattern: "*.{png,pdf,svg}" + - versions: + - "versions.yml": + type: file + description: File containing software versions + pattern: "versions.yml" + +authors: + - "@Schmytzi" +maintainers: + - "@Schmytzi" diff --git a/modules/nf-core/trgt/plot/tests/main.nf.test b/modules/nf-core/trgt/plot/tests/main.nf.test new file mode 100644 index 00000000000..7a549ddfe09 --- /dev/null +++ b/modules/nf-core/trgt/plot/tests/main.nf.test @@ -0,0 +1,136 @@ +// nf-core modules test trgt/plot +nextflow_process { + + name "Test Process TRGT_PLOT" + script "../main.nf" + process "TRGT_PLOT" + config "./nextflow.config" + + tag "modules" + tag "modules_nfcore" + tag "trgt" + tag "trgt/plot" + tag "trgt/genotype" + tag "samtools/faidx" + tag "samtools/sort" + tag "samtools/index" + tag "bcftools/sort" + tag "gunzip" + + setup { + run("GUNZIP"){ + script "../../../gunzip/main.nf" + process { + """ + input[0] = [ + [ id : 'chr22' ], + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/chr22_chr22_KI270734v1_random/sequence/genome.fa.gz', checkIfExists: true) + ] + """ + } + } + run("SAMTOOLS_FAIDX"){ + script "../../../samtools/faidx/main.nf" + process { + """ + input[0] = GUNZIP.out.gunzip + input[1] = [[],[]] + """ + } + } + run("TRGT_GENOTYPE"){ + script "../../genotype/main.nf" + process { + """ + input[0] = [ + [ id:'test' ], + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/pacbio/bam/test.sorted.bam', checkIfExists: true), + file(params.modules_testdata_base_path + 'genomics/homo_sapiens/pacbio/bam/test.sorted.bam.bai', checkIfExists: true), + 'XX' + ] + input[1] = GUNZIP.out.gunzip + input[2] = SAMTOOLS_FAIDX.out.fai + input[3] = Channel.of('chr22\t18890357\t18890451\tID=TEST;MOTIFS=AT;STRUC=(AT)n') + .collectFile(name : 'repeats.bed', newLine: false) + .map { file -> [ [ id : 'chr22' ], file ] } + """ + } + } + run("SAMTOOLS_SORT"){ + script "../../../samtools/sort/main.nf" + process { + """ + input[0] = TRGT_GENOTYPE.out.bam + input[1] = [[],[]] + """ + } + } + run("SAMTOOLS_INDEX"){ + script "../../../samtools/index/main.nf" + process { + """ + input[0] = SAMTOOLS_SORT.out.bam + """ + } + } + run("BCFTOOLS_SORT"){ + script "../../../bcftools/sort/main.nf" + process { + """ + input[0] = TRGT_GENOTYPE.out.vcf + """ + } + } + } + + test("homo sapiens - [bam, bai, vcf, TEST], fasta, fai, bed") { + when { + process { + """ + input[0] = SAMTOOLS_SORT.out.bam + .join(SAMTOOLS_INDEX.out.bai) + .join(BCFTOOLS_SORT.out.vcf) + .join(BCFTOOLS_SORT.out.tbi) + .map { tuple -> tuple + 'TEST' } + input[1] = GUNZIP.out.gunzip + input[2] = SAMTOOLS_FAIDX.out.fai + input[3] = Channel.of('chr22\t18890357\t18890451\tID=TEST;MOTIFS=AT;STRUC=(AT)n') + .collectFile(name : 'repeats.bed', newLine: false) + .map { file -> [ [ id : 'chr22' ], file ] } + """ + } + } + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + } + + test("homo sapiens - [bam, bai, vcf, TEST], fasta, fai, bed - stub") { + options "-stub" + when { + process { + """ + input[0] = SAMTOOLS_SORT.out.bam + .join(SAMTOOLS_INDEX.out.bai) + .join(BCFTOOLS_SORT.out.vcf) + .join(BCFTOOLS_SORT.out.tbi) + .map { tuple -> tuple + 'TEST' } + input[1] = GUNZIP.out.gunzip + input[2] = SAMTOOLS_FAIDX.out.fai + input[3] = Channel.of('chr22\t18890357\t18890451\tID=TEST;MOTIFS=AT;STRUC=(AT)n') + .collectFile(name : 'repeats.bed', newLine: false) + .map { file -> [ [ id : 'chr22' ], file ] } + """ + } + } + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + } +} diff --git a/modules/nf-core/trgt/plot/tests/main.nf.test.snap b/modules/nf-core/trgt/plot/tests/main.nf.test.snap new file mode 100644 index 00000000000..eac223ab1e0 --- /dev/null +++ b/modules/nf-core/trgt/plot/tests/main.nf.test.snap @@ -0,0 +1,68 @@ +{ + "homo sapiens - [bam, bai, vcf, TEST], fasta, fai, bed - stub": { + "content": [ + { + "0": [ + [ + { + "id": "test" + }, + "test.png:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "1": [ + "versions.yml:md5,24cc939a0b88728bae8a2102feaf542c" + ], + "plot": [ + [ + { + "id": "test" + }, + "test.png:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "versions": [ + "versions.yml:md5,24cc939a0b88728bae8a2102feaf542c" + ] + } + ], + "meta": { + "nf-test": "0.9.0", + "nextflow": "24.04.4" + }, + "timestamp": "2024-11-14T16:10:13.150678363" + }, + "homo sapiens - [bam, bai, vcf, TEST], fasta, fai, bed": { + "content": [ + { + "0": [ + [ + { + "id": "test" + }, + "test_TEST.png:md5,32a2b217628e72817d7ec848a648029d" + ] + ], + "1": [ + "versions.yml:md5,24cc939a0b88728bae8a2102feaf542c" + ], + "plot": [ + [ + { + "id": "test" + }, + "test_TEST.png:md5,32a2b217628e72817d7ec848a648029d" + ] + ], + "versions": [ + "versions.yml:md5,24cc939a0b88728bae8a2102feaf542c" + ] + } + ], + "meta": { + "nf-test": "0.9.0", + "nextflow": "24.04.4" + }, + "timestamp": "2024-11-14T16:11:37.679432214" + } +} \ No newline at end of file diff --git a/modules/nf-core/trgt/plot/tests/nextflow.config b/modules/nf-core/trgt/plot/tests/nextflow.config new file mode 100644 index 00000000000..7b9314db3e7 --- /dev/null +++ b/modules/nf-core/trgt/plot/tests/nextflow.config @@ -0,0 +1,6 @@ +process { + withName: "BCFTOOLS_SORT" { + ext.args = "--write-index=tbi --output-type z" + ext.prefix = "sorted_" + } +}