From c485109d9b79228e926bed1a860c457bcf269c65 Mon Sep 17 00:00:00 2001 From: "James A. Fellows Yates" Date: Wed, 15 Sep 2021 10:31:49 +0200 Subject: [PATCH] Add module: bamaligncleaner (#676) * Specify more guidelines on input channels * Linting * Updates based on code review * Update README.md * Fix broken sentence * Add bamAlignCleaner module * Add container tags * Update modules/bamaligncleaner/main.nf --- .nf-core.yml | 1 - modules/bamaligncleaner/functions.nf | 68 ++++++++++++++++++++++++++ modules/bamaligncleaner/main.nf | 40 +++++++++++++++ modules/bamaligncleaner/meta.yml | 40 +++++++++++++++ tests/config/pytest_modules.yml | 4 ++ tests/modules/bamaligncleaner/main.nf | 13 +++++ tests/modules/bamaligncleaner/test.yml | 7 +++ 7 files changed, 172 insertions(+), 1 deletion(-) create mode 100644 modules/bamaligncleaner/functions.nf create mode 100644 modules/bamaligncleaner/main.nf create mode 100644 modules/bamaligncleaner/meta.yml create mode 100644 tests/modules/bamaligncleaner/main.nf create mode 100644 tests/modules/bamaligncleaner/test.yml diff --git a/.nf-core.yml b/.nf-core.yml index 4f3bae33..72971af8 100644 --- a/.nf-core.yml +++ b/.nf-core.yml @@ -7,4 +7,3 @@ bump-versions: rseqc/inferexperiment: False rseqc/innerdistance: False sortmerna: False - malt/build: False diff --git a/modules/bamaligncleaner/functions.nf b/modules/bamaligncleaner/functions.nf new file mode 100644 index 00000000..da9da093 --- /dev/null +++ b/modules/bamaligncleaner/functions.nf @@ -0,0 +1,68 @@ +// +// Utility functions used in nf-core DSL2 module files +// + +// +// Extract name of software tool from process name using $task.process +// +def getSoftwareName(task_process) { + return task_process.tokenize(':')[-1].tokenize('_')[0].toLowerCase() +} + +// +// Function to initialise default values and to generate a Groovy Map of available options for nf-core modules +// +def initOptions(Map args) { + def Map options = [:] + options.args = args.args ?: '' + options.args2 = args.args2 ?: '' + options.args3 = args.args3 ?: '' + options.publish_by_meta = args.publish_by_meta ?: [] + options.publish_dir = args.publish_dir ?: '' + options.publish_files = args.publish_files + options.suffix = args.suffix ?: '' + return options +} + +// +// Tidy up and join elements of a list to return a path string +// +def getPathFromList(path_list) { + def paths = path_list.findAll { item -> !item?.trim().isEmpty() } // Remove empty entries + paths = paths.collect { it.trim().replaceAll("^[/]+|[/]+\$", "") } // Trim whitespace and trailing slashes + return paths.join('/') +} + +// +// Function to save/publish module results +// +def saveFiles(Map args) { + if (!args.filename.endsWith('.version.txt')) { + def ioptions = initOptions(args.options) + def path_list = [ ioptions.publish_dir ?: args.publish_dir ] + if (ioptions.publish_by_meta) { + def key_list = ioptions.publish_by_meta instanceof List ? ioptions.publish_by_meta : args.publish_by_meta + for (key in key_list) { + if (args.meta && key instanceof String) { + def path = key + if (args.meta.containsKey(key)) { + path = args.meta[key] instanceof Boolean ? "${key}_${args.meta[key]}".toString() : args.meta[key] + } + path = path instanceof String ? path : '' + path_list.add(path) + } + } + } + if (ioptions.publish_files instanceof Map) { + for (ext in ioptions.publish_files) { + if (args.filename.endsWith(ext.key)) { + def ext_list = path_list.collect() + ext_list.add(ext.value) + return "${getPathFromList(ext_list)}/$args.filename" + } + } + } else if (ioptions.publish_files == null) { + return "${getPathFromList(path_list)}/$args.filename" + } + } +} diff --git a/modules/bamaligncleaner/main.nf b/modules/bamaligncleaner/main.nf new file mode 100644 index 00000000..8ce73ee4 --- /dev/null +++ b/modules/bamaligncleaner/main.nf @@ -0,0 +1,40 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process BAMALIGNCLEANER { + tag "$meta.id" + label 'process_low' + publishDir "${params.outdir}", + mode: params.publish_dir_mode, + saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:getSoftwareName(task.process), meta:meta, publish_by_meta:['id']) } + + conda (params.enable_conda ? "bioconda::bamaligncleaner=0.2.1" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/bamaligncleaner:0.2.1--pyhdfd78af_0" + } else { + container "quay.io/biocontainers/bamaligncleaner:0.2.1--pyhdfd78af_0" + } + + input: + tuple val(meta), path(bam) + + output: + tuple val(meta), path("*.bam"), emit: bam + path "*.version.txt" , emit: version + + script: + def software = getSoftwareName(task.process) + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + + """ + bamAlignCleaner \\ + $options.args \\ + -o ${prefix}.bam \\ + ${bam} + + echo \$(bamAlignCleaner --version) | sed 's/.*version //' > ${software}.version.txt + """ +} diff --git a/modules/bamaligncleaner/meta.yml b/modules/bamaligncleaner/meta.yml new file mode 100644 index 00000000..8afdd44b --- /dev/null +++ b/modules/bamaligncleaner/meta.yml @@ -0,0 +1,40 @@ +name: bamaligncleaner +description: removes unused references from header of sorted BAM/CRAM files. +keywords: + - bam +tools: + - bamaligncleaner: + description: Removes unaligned references in aligned BAM alignment file + homepage: https://github.com/maxibor/bamAlignCleaner + documentation: https://github.com/maxibor/bamAlignCleaner + tool_dev_url: https://github.com/maxibor/bamAlignCleaner + licence: ['GPL v3'] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - bam: + type: file + description: BAM/CRAM file + pattern: "*.{bam,cram}" + +output: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" + - bam: + type: file + description: Sorted BAM/CRAM file + pattern: "*.{bam,cram}" + +authors: + - "@jfy133" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 23417eef..6d1f5dac 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -22,6 +22,10 @@ artic/minion: - modules/artic/minion/** - tests/modules/artic/minion/** +bamaligncleaner: + - modules/bamaligncleaner/** + - tests/modules/bamaligncleaner/** + bandage/image: - modules/bandage/image/** - tests/modules/bandage/image/** diff --git a/tests/modules/bamaligncleaner/main.nf b/tests/modules/bamaligncleaner/main.nf new file mode 100644 index 00000000..94ee005f --- /dev/null +++ b/tests/modules/bamaligncleaner/main.nf @@ -0,0 +1,13 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { BAMALIGNCLEANER } from '../../../modules/bamaligncleaner/main.nf' addParams( options: [:] ) + +workflow test_bamaligncleaner { + + input = [ [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['illumina']['test_single_end_sorted_bam'], checkIfExists: true) ] + + BAMALIGNCLEANER ( input ) +} diff --git a/tests/modules/bamaligncleaner/test.yml b/tests/modules/bamaligncleaner/test.yml new file mode 100644 index 00000000..568925b0 --- /dev/null +++ b/tests/modules/bamaligncleaner/test.yml @@ -0,0 +1,7 @@ +- name: bamaligncleaner + command: nextflow run ./tests/modules/bamaligncleaner -entry test_bamaligncleaner -c tests/config/nextflow.config + tags: + - bamaligncleaner + files: + - path: output/bamaligncleaner/test.bam + md5sum: 173cdb4c2713b77c528cac36ca2610fb