diff --git a/modules/samtools/bamtocram/main.nf b/modules/samtools/convert/main.nf similarity index 59% rename from modules/samtools/bamtocram/main.nf rename to modules/samtools/convert/main.nf index b49c308f..a7ec1bda 100644 --- a/modules/samtools/bamtocram/main.nf +++ b/modules/samtools/convert/main.nf @@ -1,5 +1,4 @@ -//There is a -L option to only output alignments in interval, might be an option for exons/panel data? -process SAMTOOLS_BAMTOCRAM { +process SAMTOOLS_CONVERT { tag "$meta.id" label 'process_medium' @@ -14,8 +13,9 @@ process SAMTOOLS_BAMTOCRAM { path fai output: - tuple val(meta), path("*.cram"), path("*.crai"), emit: cram_crai - path "versions.yml" , emit: versions + tuple val(meta), path("*.cram"), path("*.crai") , emit: cram_crai, optional: true + tuple val(meta), path("*.bam"), path("*.bai") , emit: bam_bai, optional:true + path "versions.yml" , emit: versions when: task.ext.when == null || task.ext.when @@ -23,9 +23,17 @@ process SAMTOOLS_BAMTOCRAM { script: def args = task.ext.args ?: '' def prefix = task.ext.prefix ?: "${meta.id}" + def file_type = input.getExtension() == "bam" ? "cram" : "bam" + """ - samtools view --threads ${task.cpus} --reference ${fasta} -C $args $input > ${prefix}.cram - samtools index -@${task.cpus} ${prefix}.cram + samtools view \\ + --threads ${task.cpus} \\ + --reference ${fasta} \\ + $args \\ + $input \\ + -o ${prefix}.${file_type} + + samtools index -@${task.cpus} ${prefix}.${file_type} cat <<-END_VERSIONS > versions.yml "${task.process}": diff --git a/modules/samtools/bamtocram/meta.yml b/modules/samtools/convert/meta.yml similarity index 84% rename from modules/samtools/bamtocram/meta.yml rename to modules/samtools/convert/meta.yml index 037704c6..506febb6 100644 --- a/modules/samtools/bamtocram/meta.yml +++ b/modules/samtools/convert/meta.yml @@ -1,5 +1,5 @@ -name: samtools_bamtocram -description: filter/convert and then index CRAM file +name: samtools_convert +description: convert and then index CRAM -> BAM or BAM -> CRAM file keywords: - view - index @@ -23,12 +23,12 @@ input: e.g. [ id:'test', single_end:false ] - input: type: file - description: BAM/SAM file - pattern: "*.{bam,sam}" + description: BAM/CRAM file + pattern: "*.{bam,cram}" - index: type: file - description: BAM/SAM index file - pattern: "*.{bai,sai}" + description: BAM/CRAM index file + pattern: "*.{bai,crai}" - fasta: type: file description: Reference file to create the CRAM file diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index ec7fc321..53aa44b9 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -1631,9 +1631,9 @@ samtools/bam2fq: - modules/samtools/bam2fq/** - tests/modules/samtools/bam2fq/** -samtools/bamtocram: - - modules/samtools/bamtocram/** - - tests/modules/samtools/bamtocram/** +samtools/convert: + - modules/samtools/convert/** + - tests/modules/samtools/convert/** samtools/collatefastq: - modules/samtools/collatefastq/** diff --git a/tests/modules/samtools/bamtocram/main.nf b/tests/modules/samtools/bamtocram/main.nf deleted file mode 100644 index b1743310..00000000 --- a/tests/modules/samtools/bamtocram/main.nf +++ /dev/null @@ -1,17 +0,0 @@ -#!/usr/bin/env nextflow - -nextflow.enable.dsl = 2 - -include { SAMTOOLS_BAMTOCRAM } from '../../../../modules/samtools/bamtocram/main.nf' - -workflow test_samtools_bamtocram { - - input = [ [ id:'test', single_end:false ], // meta map - file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true), - file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam_bai'], checkIfExists: true)] - - fasta = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) - fai = file(params.test_data['sarscov2']['genome']['genome_fasta_fai'], checkIfExists: true) - - SAMTOOLS_BAMTOCRAM ( input, fasta, fai ) -} \ No newline at end of file diff --git a/tests/modules/samtools/bamtocram/nextflow.config b/tests/modules/samtools/bamtocram/nextflow.config deleted file mode 100644 index 8730f1c4..00000000 --- a/tests/modules/samtools/bamtocram/nextflow.config +++ /dev/null @@ -1,5 +0,0 @@ -process { - - publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" } - -} diff --git a/tests/modules/samtools/bamtocram/test.yml b/tests/modules/samtools/bamtocram/test.yml deleted file mode 100644 index 3cb82902..00000000 --- a/tests/modules/samtools/bamtocram/test.yml +++ /dev/null @@ -1,9 +0,0 @@ -- name: samtools bamtocram test_samtools_bamtocram - command: nextflow run ./tests/modules/samtools/bamtocram -entry test_samtools_bamtocram -c ./tests/config/nextflow.config -c ./tests/modules/samtools/bamtocram/nextflow.config - tags: - - samtools/bamtocram - - samtools - files: - - path: output/samtools/test.cram - - path: output/samtools/test.cram.crai - - path: output/samtools/versions.yml diff --git a/tests/modules/samtools/convert/main.nf b/tests/modules/samtools/convert/main.nf new file mode 100644 index 00000000..01bdfe7f --- /dev/null +++ b/tests/modules/samtools/convert/main.nf @@ -0,0 +1,31 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { SAMTOOLS_CONVERT as SAMTOOLS_BAMTOCRAM } from '../../../../modules/samtools/convert/main.nf' +include { SAMTOOLS_CONVERT as SAMTOOLS_CRAMTOBAM } from '../../../../modules/samtools/convert/main.nf' + +workflow test_samtools_convert_bamtocram { + + input = [ [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true), + file(params.test_data['sarscov2']['illumina']['test_paired_end_sorted_bam_bai'], checkIfExists: true)] + + fasta = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) + fai = file(params.test_data['sarscov2']['genome']['genome_fasta_fai'], checkIfExists: true) + + SAMTOOLS_BAMTOCRAM ( input, fasta, fai ) +} + +workflow test_samtools_convert_cramtobam { + + input = [ [ id:'test', single_end:false ], // meta map + file(params.test_data['homo_sapiens']['illumina']['test_paired_end_recalibrated_sorted_cram'], checkIfExists: true), + file(params.test_data['homo_sapiens']['illumina']['test_paired_end_recalibrated_sorted_cram_crai'], checkIfExists: true) + ] + + fasta = file(params.test_data['homo_sapiens']['genome']['genome_fasta'], checkIfExists: true) + fai = file(params.test_data['homo_sapiens']['genome']['genome_fasta_fai'], checkIfExists: true) + + SAMTOOLS_CRAMTOBAM ( input, fasta, fai ) +} diff --git a/tests/modules/samtools/convert/nextflow.config b/tests/modules/samtools/convert/nextflow.config new file mode 100644 index 00000000..4f1e83f6 --- /dev/null +++ b/tests/modules/samtools/convert/nextflow.config @@ -0,0 +1,12 @@ +process { + + publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" } + + withName:SAMTOOLS_BAMTOCRAM{ + ext.args = "-C" + } + + withName:SAMTOOLS_CRAMTOBAM{ + ext.args = "-b" + } +} diff --git a/tests/modules/samtools/convert/test.yml b/tests/modules/samtools/convert/test.yml new file mode 100644 index 00000000..979f36ca --- /dev/null +++ b/tests/modules/samtools/convert/test.yml @@ -0,0 +1,21 @@ +- name: samtools convert test_samtools_convert_bamtocram + command: nextflow run tests/modules/samtools/convert -entry test_samtools_convert_bamtocram -c tests/config/nextflow.config + tags: + - samtools + - samtools/convert + files: + - path: output/samtools/test.cram + - path: output/samtools/test.cram.crai + - path: output/samtools/versions.yml + +- name: samtools convert test_samtools_convert_cramtobam + command: nextflow run tests/modules/samtools/convert -entry test_samtools_convert_cramtobam -c tests/config/nextflow.config + tags: + - samtools + - samtools/convert + files: + - path: output/samtools/test.bam + md5sum: c262b6dc15f9b480bdb47d6d018b4b56 + - path: output/samtools/test.bam.bai + md5sum: 6e8f5034f728401bfa841c8e70c62463 + - path: output/samtools/versions.yml