diff --git a/modules/nf-core/samtools/samples/environment.yml b/modules/nf-core/samtools/samples/environment.yml new file mode 100644 index 00000000000..bac7feb287b --- /dev/null +++ b/modules/nf-core/samtools/samples/environment.yml @@ -0,0 +1,7 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json +channels: + - conda-forge + - bioconda +dependencies: + - "bioconda::samtools=1.22.1" diff --git a/modules/nf-core/samtools/samples/main.nf b/modules/nf-core/samtools/samples/main.nf new file mode 100644 index 00000000000..0dc190cbd1b --- /dev/null +++ b/modules/nf-core/samtools/samples/main.nf @@ -0,0 +1,66 @@ +process SAMTOOLS_SAMPLES { + 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/samtools:1.22.1--h96c455f_0': + 'biocontainers/samtools:1.22.1--h96c455f_0' }" + + input: + tuple val(meta) , path(bam) , path(bai) + tuple val(meta2), path(fasta), path(fai) + + output: + tuple val(meta), path("*.tsv"), emit: tsv + 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}" + // Wrapping fasta in a list in case there is exactly one (in that case it's a bare path) + def fasta_arg = fasta ? [fasta].flatten().collect { "-f $it" }.join(' ') : '' + def out_arg = "-o ${prefix}.tsv" + def bai_arg = args.contains('-X') ? bai : '' + """ + samtools samples \\ + $args \\ + $fasta_arg \\ + $out_arg \\ + $bam \\ + $bai_arg + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//') + END_VERSIONS + """ + + stub: + def args = task.ext.args ?: '' + def prefix = task.ext.prefix ?: "${meta.id}" + // Write header if requested because the output will likely be parsed by Nextflow + def headers = '' + if (args.contains('-h\\n')) { + headers = "#SM\tPATH" + if (args.contains('-i')) { + headers += "\tINDEX" + } + if (fasta) { + headers += "\tREFERENCE" + } + } + """ + echo $args + + echo -ne "$headers" > ${prefix}.tsv + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + samtools: \$(echo \$(samtools --version 2>&1) | sed 's/^.*samtools //; s/Using.*\$//') + END_VERSIONS + """ +} diff --git a/modules/nf-core/samtools/samples/meta.yml b/modules/nf-core/samtools/samples/meta.yml new file mode 100644 index 00000000000..ff04e802a04 --- /dev/null +++ b/modules/nf-core/samtools/samples/meta.yml @@ -0,0 +1,71 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/meta-schema.json +name: "samtools_samples" +description: | + Write sample names and path to reference genome of an alignment to a text file. +keywords: + - samples + - bam + - cram + - genomics +tools: + - samtools: + description: | + SAMtools is a set of utilities for interacting with and post-processing + short DNA sequence read alignments in the SAM, BAM and CRAM formats, written by Heng Li. + These files are generated as output by short read aligners like BWA. + homepage: http://www.htslib.org/ + documentation: http://www.htslib.org/doc/samtools.html + doi: 10.1093/bioinformatics/btp352 + licence: ["MIT"] + identifier: biotools:samtools + +input: + - - meta: + type: map + description: Groovy Map containing sample information. e.g. `[ id:'sample1' + ]` + - bam: + type: file + description: alignment file + pattern: "*.{bam,sam,cram}" + ontologies: + - edam: http://edamontology.org/format_2572 # BAM + - edam: http://edamontology.org/format_2573 # SAM + - edam: http://edamontology.org/format_3462 # CRAM + - bai: + type: file + description: index file for the alignment + pattern: "*.{bai,crai}" + - - meta2: + type: map + description: Groovy Map containing reference information. + - fasta: + type: file + description: reference genome file (optional) + pattern: "*.{fasta,fa,fna}" + ontologies: + - edam: http://edamontology.org/format_1929 # FASTA + - fai: + type: file + description: index file for the reference genome (optional) + pattern: "*.fai" +output: + tsv: + - - meta: + type: map + description: Groovy Map containing sample information. e.g. `[ id:'sample1' ]` + - "*.tsv": + type: file + description: tab-separated file containing sample names, BAM filename and optionally reference genome path + pattern: "*.tsv" + versions: + - versions.yml: + type: file + description: File containing software versions + pattern: versions.yml + ontologies: + - edam: http://edamontology.org/format_3750 # YAML +authors: + - "@Schmytzi" +maintainers: + - "@Schmytzi" diff --git a/modules/nf-core/samtools/samples/tests/main.nf.test b/modules/nf-core/samtools/samples/tests/main.nf.test new file mode 100644 index 00000000000..2769e43b02c --- /dev/null +++ b/modules/nf-core/samtools/samples/tests/main.nf.test @@ -0,0 +1,115 @@ +nextflow_process { + + name "Test Process SAMTOOLS_SAMPLES" + script "../main.nf" + process "SAMTOOLS_SAMPLES" + + tag "modules" + tag "modules_nfcore" + tag "samtools" + tag "samtools/samples" + + test("sarscov2 - [bam, bai], []") { + when { + process { + """ + input[0] = [ + [ id:'test', single_end:false ], + 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[1] = [ [], [], [] ] + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + + } + + test("sarscov2 - [bam, bai], [fasta, fai]") { + when { + process { + """ + input[0] = [ + [ id:'test', single_end:false ], + 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[1] = [ + [ id : 'sarscov2' ], + file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta', checkIfExists: true), + file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta.fai', checkIfExists: true) + ] + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + + } + + + + test("sarscov2 - [bam, bai], [] - stub") { + + options "-stub" + + when { + process { + """ + input[0] = [ + [ id:'test', single_end:false ], + 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[1] = [ [], [], [] ] + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + } + + test("sarscov2 - [bam, bai], [fasta, fai] - stub") { + options "-stub" + when { + process { + """ + input[0] = [ + [ id:'test', single_end:false ], + 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[1] = [ + [ id : 'sarscov2' ], + file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta', checkIfExists: true), + file(params.modules_testdata_base_path + 'genomics/sarscov2/genome/genome.fasta.fai', checkIfExists: true) + ] + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + + }} diff --git a/modules/nf-core/samtools/samples/tests/main.nf.test.snap b/modules/nf-core/samtools/samples/tests/main.nf.test.snap new file mode 100644 index 00000000000..31009be0ae4 --- /dev/null +++ b/modules/nf-core/samtools/samples/tests/main.nf.test.snap @@ -0,0 +1,142 @@ +{ + "sarscov2 - [bam, bai], [] - stub": { + "content": [ + { + "0": [ + [ + { + "id": "test", + "single_end": false + }, + "test.tsv:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "1": [ + "versions.yml:md5,22787e093202243f0113dac1dec9586f" + ], + "tsv": [ + [ + { + "id": "test", + "single_end": false + }, + "test.tsv:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "versions": [ + "versions.yml:md5,22787e093202243f0113dac1dec9586f" + ] + } + ], + "meta": { + "nf-test": "0.9.2", + "nextflow": "25.04.5" + }, + "timestamp": "2025-10-31T10:33:18.753345922" + }, + "sarscov2 - [bam, bai], [fasta, fai]": { + "content": [ + { + "0": [ + [ + { + "id": "test", + "single_end": false + }, + "test.tsv:md5,c0299b95ede533c8fdf8190b32edf3c1" + ] + ], + "1": [ + "versions.yml:md5,22787e093202243f0113dac1dec9586f" + ], + "tsv": [ + [ + { + "id": "test", + "single_end": false + }, + "test.tsv:md5,c0299b95ede533c8fdf8190b32edf3c1" + ] + ], + "versions": [ + "versions.yml:md5,22787e093202243f0113dac1dec9586f" + ] + } + ], + "meta": { + "nf-test": "0.9.2", + "nextflow": "25.04.5" + }, + "timestamp": "2025-10-31T10:38:41.413689014" + }, + "sarscov2 - [bam, bai], []": { + "content": [ + { + "0": [ + [ + { + "id": "test", + "single_end": false + }, + "test.tsv:md5,89b11a0b32cd311fb370feac23ed8b8a" + ] + ], + "1": [ + "versions.yml:md5,22787e093202243f0113dac1dec9586f" + ], + "tsv": [ + [ + { + "id": "test", + "single_end": false + }, + "test.tsv:md5,89b11a0b32cd311fb370feac23ed8b8a" + ] + ], + "versions": [ + "versions.yml:md5,22787e093202243f0113dac1dec9586f" + ] + } + ], + "meta": { + "nf-test": "0.9.2", + "nextflow": "25.04.5" + }, + "timestamp": "2025-10-31T10:35:35.165854514" + }, + "sarscov2 - [bam, bai], [fasta, fai] - stub": { + "content": [ + { + "0": [ + [ + { + "id": "test", + "single_end": false + }, + "test.tsv:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "1": [ + "versions.yml:md5,22787e093202243f0113dac1dec9586f" + ], + "tsv": [ + [ + { + "id": "test", + "single_end": false + }, + "test.tsv:md5,d41d8cd98f00b204e9800998ecf8427e" + ] + ], + "versions": [ + "versions.yml:md5,22787e093202243f0113dac1dec9586f" + ] + } + ], + "meta": { + "nf-test": "0.9.2", + "nextflow": "25.04.5" + }, + "timestamp": "2025-10-31T10:38:52.403523794" + } +} \ No newline at end of file