diff --git a/modules/bamtools/convert/main.nf b/modules/bamtools/convert/main.nf new file mode 100644 index 00000000..141e762d --- /dev/null +++ b/modules/bamtools/convert/main.nf @@ -0,0 +1,38 @@ +process BAMTOOLS_CONVERT { + tag "$meta.id" + label 'process_low' + + conda (params.enable_conda ? "bioconda::bamtools=2.5.1" : null) + container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? + 'https://depot.galaxyproject.org/singularity/bamtools:2.5.1--h9a82719_9' : + 'quay.io/biocontainers/bamtools:2.5.1--h9a82719_9' }" + + input: + tuple val(meta), path(bam) + + output: + tuple val(meta), path("*.{bed,fasta,fastq,json,pileup,sam,yaml}"), emit: data + path "versions.yml" , emit: versions + + script: + def args = task.ext.args ?: '' + def prefix = task.ext.prefix ?: "${meta.id}" + def test = args ==~ /-format (bed|fasta|fastq|json|pileup|sam|yaml)/ + if ( test == false ) error "-format option must be provided in args. Possible values: bed fasta fastq json pileup sam yaml" + m = args =~ /-format ([a-z]+)/ + ext = m[0][1] + + + """ + bamtools \\ + convert \\ + $args \\ + -in $bam \\ + -out ${prefix}.${ext} + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + bamtools: \$( bamtools --version | grep -e 'bamtools' | sed 's/^.*bamtools //' ) + END_VERSIONS + """ +} diff --git a/modules/bamtools/convert/meta.yml b/modules/bamtools/convert/meta.yml new file mode 100644 index 00000000..acc7e4df --- /dev/null +++ b/modules/bamtools/convert/meta.yml @@ -0,0 +1,52 @@ +name: bamtools_convert +description: BamTools provides both a programmer's API and an end-user's toolkit for handling BAM files. +keywords: + - bamtools + - bamtools/convert + - bam + - convert + - bed + - fasta + - fastq + - json + - pileup + - sam + - yaml +tools: + - bamtools: + description: C++ API & command-line toolkit for working with BAM data + homepage: http://github.com/pezmaster31/bamtools + documentation: https://github.com/pezmaster31/bamtools/wiki + tool_dev_url: http://github.com/pezmaster31/bamtools + doi: "" + licence: ['MIT'] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - bam: + type: file + description: BAM file + pattern: "*.bam" + +output: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - versions: + type: file + description: File containing software versions + pattern: "versions.yml" + ## TODO nf-core: Delete / customise this example output + - out: + type: file + description: The data in the asked format (bed, fasta, fastq, json, pileup, sam, yaml) + pattern: "*.{bed,fasta,fastq,json,pileup,sam,yaml}" + +authors: + - "@sguizard" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 2321c918..7ed2cf53 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -46,6 +46,10 @@ bamaligncleaner: - modules/bamaligncleaner/** - tests/modules/bamaligncleaner/** +bamtools/convert: + - modules/bamtools/convert/** + - tests/modules/bamtools/convert/** + bamtools/split: - modules/bamtools/split/** - tests/modules/bamtools/split/** diff --git a/tests/modules/bamtools/convert/main.nf b/tests/modules/bamtools/convert/main.nf new file mode 100644 index 00000000..bf57f248 --- /dev/null +++ b/tests/modules/bamtools/convert/main.nf @@ -0,0 +1,104 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { BAMTOOLS_CONVERT as BAMTOOLS_CONVERT_EXT_ERROR } from '../../../../modules/bamtools/convert/main.nf' +include { BAMTOOLS_CONVERT as BAMTOOLS_CONVERT_NOEXT_ERROR } from '../../../../modules/bamtools/convert/main.nf' +include { BAMTOOLS_CONVERT as BAMTOOLS_CONVERT_BED } from '../../../../modules/bamtools/convert/main.nf' +include { BAMTOOLS_CONVERT as BAMTOOLS_CONVERT_FASTA } from '../../../../modules/bamtools/convert/main.nf' +include { BAMTOOLS_CONVERT as BAMTOOLS_CONVERT_FASTQ } from '../../../../modules/bamtools/convert/main.nf' +include { BAMTOOLS_CONVERT as BAMTOOLS_CONVERT_JSON } from '../../../../modules/bamtools/convert/main.nf' +include { BAMTOOLS_CONVERT as BAMTOOLS_CONVERT_PILEUP } from '../../../../modules/bamtools/convert/main.nf' +include { BAMTOOLS_CONVERT as BAMTOOLS_CONVERT_SAM } from '../../../../modules/bamtools/convert/main.nf' +include { BAMTOOLS_CONVERT as BAMTOOLS_CONVERT_YAML } from '../../../../modules/bamtools/convert/main.nf' + +workflow test_bamtools_convert_ext_error { + + input = [ + [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true) + ] + + BAMTOOLS_CONVERT_EXT_ERROR ( input ) +} + +workflow test_bamtools_convert_noext_error { + + input = [ + [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true) + ] + + BAMTOOLS_CONVERT_NOEXT_ERROR ( input ) +} + +workflow test_bamtools_convert_bed { + + input = [ + [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true) + ] + + BAMTOOLS_CONVERT_BED ( input ) +} + +workflow test_bamtools_convert_fasta { + + input = [ + [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true) + ] + + BAMTOOLS_CONVERT_FASTA ( input ) +} + +workflow test_bamtools_convert_fastq { + + input = [ + [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true) + ] + + BAMTOOLS_CONVERT_FASTQ ( input ) +} + +workflow test_bamtools_convert_json { + + input = [ + [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true) + ] + + BAMTOOLS_CONVERT_JSON ( input ) +} + +workflow test_bamtools_convert_pileup { + + input = [ + [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true) + ] + + BAMTOOLS_CONVERT_PILEUP ( input ) +} + +workflow test_bamtools_convert_sam { + + input = [ + [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true) + ] + + BAMTOOLS_CONVERT_SAM ( input ) +} + +workflow test_bamtools_convert_yaml { + + input = [ + [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true) + ] + + BAMTOOLS_CONVERT_YAML ( input ) +} + diff --git a/tests/modules/bamtools/convert/nextflow.config b/tests/modules/bamtools/convert/nextflow.config new file mode 100644 index 00000000..ae8fe345 --- /dev/null +++ b/tests/modules/bamtools/convert/nextflow.config @@ -0,0 +1,41 @@ +process { + + publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" } + + withName: BAMTOOLS_CONVERT_EXT_ERROR { + ext.args = "-format vcf" + } + + withName: BAMTOOLS_CONVERT_NOEXT_ERROR { + ext.args = "" + } + + withName: BAMTOOLS_CONVERT_BED { + ext.args = "-format bed" + } + + withName: BAMTOOLS_CONVERT_FASTA { + ext.args = "-format fasta" + } + + withName: BAMTOOLS_CONVERT_FASTQ { + ext.args = "-format fastq" + } + + withName: BAMTOOLS_CONVERT_JSON { + ext.args = "-format json" + } + + withName: BAMTOOLS_CONVERT_PILEUP { + ext.args = "-format pileup" + } + + withName: BAMTOOLS_CONVERT_SAM { + ext.args = "-format sam" + } + + withName: BAMTOOLS_CONVERT_YAML { + ext.args = "-format yaml" + } + +} diff --git a/tests/modules/bamtools/convert/test.yml b/tests/modules/bamtools/convert/test.yml new file mode 100644 index 00000000..3922ece2 --- /dev/null +++ b/tests/modules/bamtools/convert/test.yml @@ -0,0 +1,90 @@ +- name: bamtools convert test_bamtools_convert_ext_error + command: nextflow run tests/modules/bamtools/convert -entry test_bamtools_convert_ext_error -c tests/config/nextflow.config + tags: + - bamtools + - bamtools/convert + exit_code: 1 + +- name: bamtools convert test_bamtools_convert_noext_error + command: nextflow run tests/modules/bamtools/convert -entry test_bamtools_convert_noext_error -c tests/config/nextflow.config + tags: + - bamtools + - bamtools/convert + exit_code: 1 + +- name: bamtools convert test_bamtools_convert_bed + command: nextflow run tests/modules/bamtools/convert -entry test_bamtools_convert_bed -c tests/config/nextflow.config + tags: + - bamtools + - bamtools/convert + files: + - path: output/bamtools/test.bed + md5sum: 4e34cc15bf31e700f5f3a9f8fffb6c81 + - path: output/bamtools/versions.yml + md5sum: eb7a144b8a97965d3482f6f96b8a8243 + +- name: bamtools convert test_bamtools_convert_fasta + command: nextflow run tests/modules/bamtools/convert -entry test_bamtools_convert_fasta -c tests/config/nextflow.config + tags: + - bamtools + - bamtools/convert + files: + - path: output/bamtools/test.fasta + md5sum: 52aeacf78571862b7e97c7d44ac8f827 + - path: output/bamtools/versions.yml + md5sum: 42d19a2b2b07f05edb82b34369dfd754 + +- name: bamtools convert test_bamtools_convert_fastq + command: nextflow run tests/modules/bamtools/convert -entry test_bamtools_convert_fastq -c tests/config/nextflow.config + tags: + - bamtools + - bamtools/convert + files: + - path: output/bamtools/test.fastq + md5sum: e591c48daad2c56638e5d6f21f1f71c5 + - path: output/bamtools/versions.yml + md5sum: 13f0bf8a3e1f8f527f96dabaa5c8051e + +- name: bamtools convert test_bamtools_convert_json + command: nextflow run tests/modules/bamtools/convert -entry test_bamtools_convert_json -c tests/config/nextflow.config + tags: + - bamtools + - bamtools/convert + files: + - path: output/bamtools/test.json + md5sum: 04afed696f9f14da85a460353645d1f5 + - path: output/bamtools/versions.yml + md5sum: 33d633dbd6209cb93c9b071f8c0ed3b3 + +- name: bamtools convert test_bamtools_convert_pileup + command: nextflow run tests/modules/bamtools/convert -entry test_bamtools_convert_pileup -c tests/config/nextflow.config + tags: + - bamtools + - bamtools/convert + files: + - path: output/bamtools/test.pileup + md5sum: e5a3cb4a3e1bf980a575fafce6a2826f + - path: output/bamtools/versions.yml + md5sum: fd3ad0edd1e085b1a002e0593d1d5814 + +- name: bamtools convert test_bamtools_convert_sam + command: nextflow run tests/modules/bamtools/convert -entry test_bamtools_convert_sam -c tests/config/nextflow.config + tags: + - bamtools + - bamtools/convert + files: + - path: output/bamtools/test.sam + md5sum: 61ab3d0de16a9da8b651f9c692e19d5e + - path: output/bamtools/versions.yml + md5sum: 4be470ce3cc0143ae5ae415b612a4965 + +- name: bamtools convert test_bamtools_convert_yaml + command: nextflow run tests/modules/bamtools/convert -entry test_bamtools_convert_yaml -c tests/config/nextflow.config + tags: + - bamtools + - bamtools/convert + files: + - path: output/bamtools/test.yaml + md5sum: 68b56f198da036fef33e150eb773dc3b + - path: output/bamtools/versions.yml + md5sum: 1116abc088c5edf11bee393961c18b3e