diff --git a/modules/nf-core/kma/index/environment.yml b/modules/nf-core/kma/index/environment.yml new file mode 100644 index 00000000000..c8578084115 --- /dev/null +++ b/modules/nf-core/kma/index/environment.yml @@ -0,0 +1,7 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json +channels: + - bioconda + - conda-forge +dependencies: + - bioconda::kma=1.4.15 \ No newline at end of file diff --git a/modules/nf-core/kma/index/main.nf b/modules/nf-core/kma/index/main.nf new file mode 100644 index 00000000000..ebc700a997d --- /dev/null +++ b/modules/nf-core/kma/index/main.nf @@ -0,0 +1,52 @@ +process KMA_INDEX { + 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/kma:1.4.15--h577a1d6_1' : + 'biocontainers/kma:1.4.15--h577a1d6_1' }" + + input: + tuple val(meta), path(fasta) + + output: + tuple val(meta), path("kmaindex"), emit: index + path "versions.yml", emit: versions + + when: + task.ext.when == null || task.ext.when + + script: + def prefix = task.ext.prefix ?: "${fasta.baseName}" + def args = task.ext.args ?: '' + """ + mkdir kmaindex + kma \\ + index \\ + -i ${fasta} \\ + -o kmaindex/${prefix} \\ + $args + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + kma: \$(echo \$(kma_index -v 2>&1) | sed 's/^KMA_index-\$//') + END_VERSIONS + """ + + stub: + def prefix = task.ext.prefix ?: "${fasta.baseName}" + """ + mkdir kmaindex + + touch kmaindex/${prefix}.comp.b + touch kmaindex/${prefix}.length.b + touch kmaindex/${prefix}.name + touch kmaindex/${prefix}.seq.b + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + kma: \$(echo \$(kma_index -v 2>&1) | sed 's/^KMA_index-\$//') + END_VERSIONS + """ +} diff --git a/modules/nf-core/kma/index/meta.yml b/modules/nf-core/kma/index/meta.yml new file mode 100644 index 00000000000..32f054a962e --- /dev/null +++ b/modules/nf-core/kma/index/meta.yml @@ -0,0 +1,52 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/meta-schema.json +name: "kma_index" +description: This module wraps the index module of the KMA alignment tool. +keywords: + - alignment + - kma + - index + - database + - reads +tools: + - "kma": + description: "Rapid and precise alignment of raw reads against redundant databases with KMA" + homepage: "https://bitbucket.org/genomicepidemiology/kma/src/master/" + documentation: "https://bitbucket.org/genomicepidemiology/kma/src/master/" + tool_dev_url: "https://bitbucket.org/genomicepidemiology/kma/src/master/" + doi: "10.1186/s12859-018-2336-6" + licence: + ["http://www.apache.org/licenses/LICENSE-2.0"] + +input: + - - meta: + type: map + description: | + Groovy Map containing reference information + e.g. `[ id:'reference' ]` + - fasta: + type: file + description: (Multi-)FASTA file of your database sequences. + pattern: "*.{fa,fasta}" + +output: + - index: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. `[ id:'reference' ]` + - 'kmaindex': + type: directory + description: Directory of KMA index files + pattern: "*.{comp.b,length.b,name,seq.b}" + - versions: + - versions.yml: + type: file + description: File containing software versions + pattern: "versions.yml" + +authors: + - "@krannich479" +maintainers: + - "@krannich479" diff --git a/modules/nf-core/kma/index/tests/main.nf.test b/modules/nf-core/kma/index/tests/main.nf.test new file mode 100644 index 00000000000..04054c1789b --- /dev/null +++ b/modules/nf-core/kma/index/tests/main.nf.test @@ -0,0 +1,59 @@ + +nextflow_process { + + name "Test Process KMA_INDEX" + script "../main.nf" + process "KMA_INDEX" + + tag "modules" + tag "modules_nfcore" + tag "kma" + tag "kma/index" + + test("sarscov2 - fasta") { + + when { + process { + """ + input[0] = [ + [ id:'MT192765.1', single_end:false ], // meta map + file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta', checkIfExists: true) + ] + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + + } + + test("sarscov2 - fasta - stub") { + + options "-stub" + + when { + process { + """ + input[0] = [ + [ id:'MT192765.1', single_end:false ], // meta map + file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta', checkIfExists: true) + ] + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + + } + +} diff --git a/modules/nf-core/kma/index/tests/main.nf.test.snap b/modules/nf-core/kma/index/tests/main.nf.test.snap new file mode 100644 index 00000000000..93c0510e8cc --- /dev/null +++ b/modules/nf-core/kma/index/tests/main.nf.test.snap @@ -0,0 +1,92 @@ +{ + "sarscov2 - fasta - stub": { + "content": [ + { + "0": [ + [ + { + "id": "MT192765.1", + "single_end": false + }, + [ + "genome.comp.b:md5,d41d8cd98f00b204e9800998ecf8427e", + "genome.length.b:md5,d41d8cd98f00b204e9800998ecf8427e", + "genome.name:md5,d41d8cd98f00b204e9800998ecf8427e", + "genome.seq.b:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ] + ], + "1": [ + "versions.yml:md5,ba9763933bdc811b1e19e466cceae9c8" + ], + "index": [ + [ + { + "id": "MT192765.1", + "single_end": false + }, + [ + "genome.comp.b:md5,d41d8cd98f00b204e9800998ecf8427e", + "genome.length.b:md5,d41d8cd98f00b204e9800998ecf8427e", + "genome.name:md5,d41d8cd98f00b204e9800998ecf8427e", + "genome.seq.b:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ] + ], + "versions": [ + "versions.yml:md5,ba9763933bdc811b1e19e466cceae9c8" + ] + } + ], + "meta": { + "nf-test": "0.9.2", + "nextflow": "24.10.3" + }, + "timestamp": "2024-12-19T17:07:30.875020727" + }, + "sarscov2 - fasta": { + "content": [ + { + "0": [ + [ + { + "id": "MT192765.1", + "single_end": false + }, + [ + "genome.comp.b:md5,2d4075cee26606cfb9b3624f8d7fe260", + "genome.length.b:md5,aaded6f5e19db3f3292e7ff9cd0157ec", + "genome.name:md5,e98cac0e614ac65bb458f77245af7d32", + "genome.seq.b:md5,48647a9697263fe218ddc728c2d01641" + ] + ] + ], + "1": [ + "versions.yml:md5,ba9763933bdc811b1e19e466cceae9c8" + ], + "index": [ + [ + { + "id": "MT192765.1", + "single_end": false + }, + [ + "genome.comp.b:md5,2d4075cee26606cfb9b3624f8d7fe260", + "genome.length.b:md5,aaded6f5e19db3f3292e7ff9cd0157ec", + "genome.name:md5,e98cac0e614ac65bb458f77245af7d32", + "genome.seq.b:md5,48647a9697263fe218ddc728c2d01641" + ] + ] + ], + "versions": [ + "versions.yml:md5,ba9763933bdc811b1e19e466cceae9c8" + ] + } + ], + "meta": { + "nf-test": "0.9.2", + "nextflow": "24.10.3" + }, + "timestamp": "2024-12-19T17:07:24.8942212" + } +} \ No newline at end of file diff --git a/modules/nf-core/kma/index/tests/tags.yml b/modules/nf-core/kma/index/tests/tags.yml new file mode 100644 index 00000000000..7e914abebfe --- /dev/null +++ b/modules/nf-core/kma/index/tests/tags.yml @@ -0,0 +1,2 @@ +kma/index: + - "modules/nf-core/kma/index/**" diff --git a/modules/nf-core/kma/kma/environment.yml b/modules/nf-core/kma/kma/environment.yml new file mode 100644 index 00000000000..6bc1acaf1a9 --- /dev/null +++ b/modules/nf-core/kma/kma/environment.yml @@ -0,0 +1,7 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json +channels: + - bioconda + - conda-forge +dependencies: + - kma==1.4.15 \ No newline at end of file diff --git a/modules/nf-core/kma/kma/main.nf b/modules/nf-core/kma/kma/main.nf new file mode 100644 index 00000000000..ac3223ee995 --- /dev/null +++ b/modules/nf-core/kma/kma/main.nf @@ -0,0 +1,76 @@ +process KMA { + 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/kma:1.4.15--h577a1d6_1' : + 'biocontainers/kma:1.4.15--h577a1d6_1' }" + + input: + tuple val(meta) , path(reads) + tuple val(meta2), path(index) + val interleaved + val mat_format + + output: + tuple val(meta), path("*.res") , optional: true, emit: res + tuple val(meta), path("*.fsa") , optional: true, emit: fsa + tuple val(meta), path("*.aln") , optional: true, emit: aln + tuple val(meta), path("*.frag.gz") , optional: true, emit: frag + tuple val(meta), path("*.mat.gz") , optional: true, emit: mat // if mat_format == true + tuple val(meta), path("*.spa") , optional: true, emit: spa // if ext.args contains '-Sparse' (only output in this case) + 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}.${meta2.id}" + def input_style = interleaved ? "-int ${reads}" : "-ipe ${reads}" + def create_mat = mat_format ? "-matrix" : '' + """ + INDEX=`find -L ./ -name "*.name" | sed 's/\\.name\$//'` + + kma \\ + ${input_style} \\ + -o ${prefix} \\ + -t_db \$INDEX \\ + ${create_mat} \\ + $args + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + kma: \$(echo \$(kma -v 2>&1) | sed 's/^KMA-\$//') + END_VERSIONS + """ + + stub: + def prefix = task.ext.prefix ?: "${meta.id}.${meta2.id}" + def create_spa = task.ext.args.contains('-Sparse') + + if ( create_spa ) + """ + touch ${prefix}.spa + """ + else + """ + touch ${prefix}.res \\ + touch ${prefix}.fsa \\ + touch ${prefix}.aln \\ + touch ${prefix}.frag.gz + """ + + if ( mat_format ) + """ + touch ${prefix}.mat.gz + """ + + """ + cat <<-END_VERSIONS > versions.yml + "${task.process}": + kma: \$(echo \$(kma -v 2>&1) | sed 's/^KMA-\$//') + END_VERSIONS + """ +} diff --git a/modules/nf-core/kma/kma/meta.yml b/modules/nf-core/kma/kma/meta.yml new file mode 100644 index 00000000000..893a8dba65e --- /dev/null +++ b/modules/nf-core/kma/kma/meta.yml @@ -0,0 +1,118 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/meta-schema.json +name: "KMA" +description: Aligning reads to a DB via KMA alignment +keywords: + - fastq + - reads + - alignment + - kma +tools: + - "kma": + description: "Rapid and precise alignment of raw reads against redundant databases with KMA" + homepage: "https://bitbucket.org/genomicepidemiology/kma/src/master/" + documentation: "https://bitbucket.org/genomicepidemiology/kma/src/master/" + tool_dev_url: "https://bitbucket.org/genomicepidemiology/kma/src/master/" + doi: "10.1186/s12859-018-2336-6" + licence: + ["http://www.apache.org/licenses/LICENSE-2.0"] + +input: + - - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'sample' ] + - reads: + type: file + description: FASTQ files + pattern: "*.{fastq,fq}" + - - meta2: + type: map + description: | + Groovy Map containing reference index information + e.g. [ id:'reference' ] + - index: + type: file + description: kma database file generated via kma_index + pattern: "*.{comp.b,length.b,name,seq.b}" + - - interleaved: + type: boolean + description: use one interleaved fastq file (true) or two paired fastq files (false) + pattern: "true or false" + - - mat_format: + type: boolean + description: generate additional matrix file (true) or not (false) + pattern: "true or false" + +output: + - res: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'reference' ] + - '*.res': + type: file + description: A result overview giving the most common statistics for each mapped template. + pattern: "*.{res}" + - fsa: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'reference' ] + - '*.fsa': + type: file + description: The consensus sequences drawn from the alignments. + pattern: "*.{fsa}" + - aln: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'reference' ] + - '*.aln': + type: file + description: The consensus alignment of the reads against their template. + pattern: "*.{aln}" + - frag: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'reference' ] + - '*.frag.gz': + type: file + description: Mapping information on each mapped read, where the columns are read, number of equally well mapping templates, mapping score, start position, end position (w.r.t. template), the choosen template. + pattern: "*.{frag.gz}" + - mat: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'reference' ] + - '*.mat.gz': + type: file + description: Base counts on each position in each template, (only if -matrix is enabled). + pattern: "*.{mat.gz}" + - spa: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'reference' ] + - '*.spa': + type: file + description: Text file containing the top scoring references. Note that kma (v1.4.15) can only use spare alignment if the kma index was also build with the sparse option. + pattern: "*.{spa}" + - versions: + - versions.yml: + type: file + description: File containing software versions + pattern: "versions.yml" + +authors: + - "@Krannich479" +maintainers: + - "@Krannich479" diff --git a/modules/nf-core/kma/kma/tests/main.nf.test b/modules/nf-core/kma/kma/tests/main.nf.test new file mode 100644 index 00000000000..3e549565114 --- /dev/null +++ b/modules/nf-core/kma/kma/tests/main.nf.test @@ -0,0 +1,94 @@ +nextflow_process { + + name "Test Process KMA_KMA" + tag "modules" + tag "modules_nfcore" + tag "kma" + tag "kma/index" + tag "kma/kma" + + script "../main.nf" + process "KMA_KMA" + config "./nextflow.config" + + + setup { + run("KMA_INDEX") { + script "../../index/main.nf" + + params { + module_args = '-Sparse' + } + + process { + """ + input[0] = [ + [ id: 'MT192765.1', single_end:false ], + file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta', checkIfExists: true) + ] + """ + } + } + } + + + test("sarscov2 - fasta - sparse") { + + when { + + params{ + module_args = '-Sparse' + } + + process { + """ + input[0] = [ + [ id:'nfcore_testsample', single_end:false ], + [ + file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/fastq/test_1.fastq.gz', checkIfExists: true), + file(params.modules_testdata_base_path + 'genomics/sarscov2/illumina/fastq/test_2.fastq.gz', checkIfExists: true) + ] + input[1] = KMA_INDEX.out.index + input[2] = false + input[3] = false + ] + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + + } + +} + +/* + test("sarscov2 - fasta - stub") { + + options "-stub" + + when { + process { + """ + input[0] = [ + [ id:'MT192765.1', single_end:false ], // meta map + file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta', checkIfExists: true) + ] + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + + } +*/ diff --git a/modules/nf-core/kma/kma/tests/nextflow.config b/modules/nf-core/kma/kma/tests/nextflow.config new file mode 100644 index 00000000000..bbc0f7af709 --- /dev/null +++ b/modules/nf-core/kma/kma/tests/nextflow.config @@ -0,0 +1,11 @@ +process { + + withName: 'KMA_INDEX' { + ext.args = params.module_args + } + + withName: 'KMA' { + ext.args = params.module_args + } + +} \ No newline at end of file diff --git a/modules/nf-core/kma/kma/tests/tags.yml b/modules/nf-core/kma/kma/tests/tags.yml new file mode 100644 index 00000000000..e9aeb09fc87 --- /dev/null +++ b/modules/nf-core/kma/kma/tests/tags.yml @@ -0,0 +1,2 @@ +kma/kma: + - "modules/nf-core/kma/kma/**" \ No newline at end of file