mirror of
https://github.com/MillironX/nf-core_modules.git
synced 2024-12-22 11:08:17 +00:00
Add bamutil/trimbam
(#1060)
* Specify more guidelines on input channels * Linting * Updates based on code review * Update README.md * Fix broken sentence * feat: add megahit module, currently decompressed output * Update main.nf * Update tests/modules/megahit/test.yml Co-authored-by: Maxime Borry <maxibor@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com> * feat: compress all outputs, remove md5sums due to gz stochasicity * fix: wrong conda channel for pigz * fix: broken singleend tests and update meta.yml * Missed one * Apply suggestions from code review Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com> * fix: pigz formatting * Apply suggestions from code review Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com> * Apply suggestions from code review * Add bamUtil trimBam * Update modules/bamutil/trimbam/main.nf Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com> * Update modules/bamutil/trimbam/main.nf * Changes after code-review * YAML lint Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com> Co-authored-by: Maxime Borry <maxibor@users.noreply.github.com>
This commit is contained in:
parent
eff515891d
commit
632587a7fc
6 changed files with 200 additions and 0 deletions
78
modules/bamutil/trimbam/functions.nf
Normal file
78
modules/bamutil/trimbam/functions.nf
Normal file
|
@ -0,0 +1,78 @@
|
|||
//
|
||||
// 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()
|
||||
}
|
||||
|
||||
//
|
||||
// Extract name of module from process name using $task.process
|
||||
//
|
||||
def getProcessName(task_process) {
|
||||
return task_process.tokenize(':')[-1]
|
||||
}
|
||||
|
||||
//
|
||||
// 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) {
|
||||
def ioptions = initOptions(args.options)
|
||||
def path_list = [ ioptions.publish_dir ?: args.publish_dir ]
|
||||
|
||||
// Do not publish versions.yml unless running from pytest workflow
|
||||
if (args.filename.equals('versions.yml') && !System.getenv("NF_CORE_MODULES_TEST")) {
|
||||
return null
|
||||
}
|
||||
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"
|
||||
}
|
||||
}
|
44
modules/bamutil/trimbam/main.nf
Normal file
44
modules/bamutil/trimbam/main.nf
Normal file
|
@ -0,0 +1,44 @@
|
|||
// Import generic module functions
|
||||
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'
|
||||
|
||||
params.options = [:]
|
||||
options = initOptions(params.options)
|
||||
|
||||
process BAMUTIL_TRIMBAM {
|
||||
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::bamutil=1.0.15" : null)
|
||||
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
|
||||
container "https://depot.galaxyproject.org/singularity/bamutil:1.0.15--h2e03b76_1"
|
||||
} else {
|
||||
container "quay.io/biocontainers/bamutil:1.0.15--h2e03b76_1"
|
||||
}
|
||||
|
||||
input:
|
||||
tuple val(meta), path(bam), val(trim_left), val(trim_right)
|
||||
|
||||
output:
|
||||
tuple val(meta), path("*.bam"), emit: bam
|
||||
path "versions.yml" , emit: versions
|
||||
|
||||
script:
|
||||
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
|
||||
"""
|
||||
bam \\
|
||||
trimBam \\
|
||||
$bam \\
|
||||
${prefix}.bam \\
|
||||
$options.args \\
|
||||
-L $trim_left \\
|
||||
-R $trim_right
|
||||
|
||||
cat <<-END_VERSIONS > versions.yml
|
||||
${getProcessName(task.process)}:
|
||||
${getSoftwareName(task.process)}: \$( echo \$( bam trimBam 2>&1 ) | sed 's/^Version: //;s/;.*//' )
|
||||
END_VERSIONS
|
||||
"""
|
||||
}
|
51
modules/bamutil/trimbam/meta.yml
Normal file
51
modules/bamutil/trimbam/meta.yml
Normal file
|
@ -0,0 +1,51 @@
|
|||
name: bamutil_trimbam
|
||||
description: trims the end of reads in a SAM/BAM file, changing read ends to ‘N’ and quality to ‘!’, or by soft clipping
|
||||
keywords:
|
||||
- bam
|
||||
- trim
|
||||
- clipping
|
||||
- bamUtil
|
||||
- trimBam
|
||||
tools:
|
||||
- bamutil:
|
||||
description: Programs that perform operations on SAM/BAM files, all built into a single executable, bam.
|
||||
homepage: https://genome.sph.umich.edu/wiki/BamUtil
|
||||
documentation: https://genome.sph.umich.edu/wiki/BamUtil:_trimBam
|
||||
tool_dev_url: https://github.com/statgen/bamUtil
|
||||
doi: "10.1101/gr.176552.114"
|
||||
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 file
|
||||
pattern: "*.bam"
|
||||
- trim_left:
|
||||
type: integer
|
||||
description: Number of bases to trim off the right-hand side of a read. Reverse strands are reversed before trimming.
|
||||
- trim_right:
|
||||
type: integer
|
||||
description: Number of bases to trim off the right-hand side of a read. Reverse strands are reversed before trimming.
|
||||
|
||||
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"
|
||||
- bam:
|
||||
type: file
|
||||
description: Trimmed but unsorted BAM file
|
||||
pattern: "*.bam"
|
||||
|
||||
authors:
|
||||
- "@jfy133"
|
|
@ -46,6 +46,10 @@ bamtools/split:
|
|||
- modules/bamtools/split/**
|
||||
- tests/modules/bamtools/split/**
|
||||
|
||||
bamutil/trimbam:
|
||||
- modules/bamutil/trimbam/**
|
||||
- tests/modules/bamutil/trimbam/**
|
||||
|
||||
bandage/image:
|
||||
- modules/bandage/image/**
|
||||
- tests/modules/bandage/image/**
|
||||
|
|
15
tests/modules/bamutil/trimbam/main.nf
Normal file
15
tests/modules/bamutil/trimbam/main.nf
Normal file
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env nextflow
|
||||
|
||||
nextflow.enable.dsl = 2
|
||||
|
||||
include { BAMUTIL_TRIMBAM } from '../../../../modules/bamutil/trimbam/main.nf' addParams( options: [:] )
|
||||
|
||||
workflow test_bamutil_trimbam {
|
||||
|
||||
input = [ [ id:'test', single_end:false ], // meta map
|
||||
file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true),
|
||||
2,
|
||||
2 ]
|
||||
|
||||
BAMUTIL_TRIMBAM ( input )
|
||||
}
|
8
tests/modules/bamutil/trimbam/test.yml
Normal file
8
tests/modules/bamutil/trimbam/test.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
- name: bamutil trimbam test_bamutil_trimbam
|
||||
command: nextflow run tests/modules/bamutil/trimbam -entry test_bamutil_trimbam -c tests/config/nextflow.config
|
||||
tags:
|
||||
- bamutil/trimbam
|
||||
- bamutil
|
||||
files:
|
||||
- path: output/bamutil/test.bam
|
||||
md5sum: 9ddd0ecca82f7f3433383f3d1308970e
|
Loading…
Reference in a new issue