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
This commit is contained in:
James A. Fellows Yates 2021-09-15 10:31:49 +02:00 committed by GitHub
parent 6ff995e93d
commit c485109d9b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 172 additions and 1 deletions

View file

@ -7,4 +7,3 @@ bump-versions:
rseqc/inferexperiment: False
rseqc/innerdistance: False
sortmerna: False
malt/build: False

View file

@ -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"
}
}
}

View file

@ -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
"""
}

View file

@ -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"

View file

@ -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/**

View file

@ -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 )
}

View file

@ -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