Merge pull request #171 from JoseEspinosa/mosdepth

Add mosdepth module
This commit is contained in:
Harshil Patel 2021-02-15 23:13:01 +00:00 committed by GitHub
commit 8eb3acc43f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 244 additions and 0 deletions

4
.github/filters.yml vendored
View file

@ -148,6 +148,10 @@ minimap2_align:
- software/minimap2/align/** - software/minimap2/align/**
- tests/software/minimap2/align/** - tests/software/minimap2/align/**
mosdepth:
- software/mosdepth/**
- tests/software/mosdepth/**
multiqc: multiqc:
- software/fastqc/** - software/fastqc/**
- software/multiqc/** - software/multiqc/**

View file

@ -0,0 +1,59 @@
/*
* -----------------------------------------------------
* 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.publish_by_id = args.publish_by_id ?: false
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_id) {
path_list.add(args.publish_id)
}
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"
}
}
}

48
software/mosdepth/main.nf Normal file
View file

@ -0,0 +1,48 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName } from './functions'
params.options = [:]
def options = initOptions(params.options)
process MOSDEPTH {
tag "$meta.id"
label 'process_medium'
publishDir "${params.outdir}",
mode: params.publish_dir_mode,
saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:getSoftwareName(task.process), publish_id:meta.id) }
conda (params.enable_conda ? 'bioconda::mosdepth=0.3.1' : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/mosdepth:0.3.1--ha7ba039_0"
} else {
container "quay.io/biocontainers/mosdepth:0.3.1--ha7ba039_0"
}
input:
tuple val(meta), path(bam), path(bai)
path bed
val window_size
output:
tuple val(meta), path('*.global.dist.txt') , emit: global_txt
tuple val(meta), path('*.region.dist.txt') , emit: regions_txt
tuple val(meta), path('*.summary.txt') , emit: summary_txt
tuple val(meta), path('*.per-base.bed.gz') , emit: per_base_bed
tuple val(meta), path('*.per-base.bed.gz.csi'), emit: per_base_csi
tuple val(meta), path('*.regions.bed.gz') , emit: regions_bed
tuple val(meta), path('*.regions.bed.gz.csi') , emit: regions_csi
path '*.version.txt' , emit: version
script:
def software = getSoftwareName(task.process)
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
def interval = window_size ? "--by ${window_size}" : "--by ${bed}"
"""
mosdepth \\
$interval \\
$options.args \\
$prefix \\
$bam
echo \$(mosdepth --version 2>&1) | sed 's/^.*mosdepth //; s/ .*\$//' > ${software}.version.txt
"""
}

View file

@ -0,0 +1,97 @@
name: mosdepth
description: Calculates genome-wide sequencing coverage.
keywords:
- mosdepth
- bam
- cram
- coverage
tools:
- mosdepth:
description: |
Fast BAM/CRAM depth calculation for WGS, exome, or targeted sequencing.
documentation: https://github.com/brentp/mosdepth
doi: 10.1093/bioinformatics/btx699
params:
- outdir:
type: string
description: |
The pipeline's output directory. By default, the module will
output files into `$params.outdir/<SOFTWARE>`
- publish_dir_mode:
type: string
description: |
Value for the Nextflow `publishDir` mode parameter.
Available: symlink, rellink, link, copy, copyNoFollow, move.
- enable_conda:
type: boolean
description: |
Run the module with Conda using the software specified
via the `conda` directive
- singularity_pull_docker_container:
type: boolean
description: |
Instead of directly downloading Singularity images for use with Singularity,
force the workflow to pull and convert Docker containers instead.
input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- bam:
type: file
description: Input BAM/CRAM file
pattern: "*.{bam,cram}"
- bai:
type: file
description: Index for BAM/CRAM file
pattern: "*.{bai,crai}"
- bed:
type: file
description: BED file with intersected intervals
pattern: "*.{bed}"
- window_size:
type: integer
description: Window size
pattern: "[0-9]+"
output:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- global_txt:
type: file
description: Text file with global cumulative coverage distribution
pattern: "*.{global.dist.txt}"
- regions_txt:
type: file
description: Text file with region cumulative coverage distribution
pattern: "*.{region.dist.txt}"
- summary_txt:
type: file
description: Text file with summary mean depths per chromosome and regions
pattern: "*.{summary.txt}"
- per_base_bed:
type: file
description: BED file with per-base coverage
pattern: "*.{per-base.bed.gz}"
- per_base_csi:
type: file
description: Index file for BED file with per-base coverage
pattern: "*.{per-base.bed.gz.csi}"
- regions_bed:
type: file
description: BED file with per-region coverage
pattern: "*.{regions.bed.gz}"
- regions_csi:
type: file
description: Index file for BED file with per-region coverage
pattern: "*.{regions.bed.gz.csi}"
- version:
type: file
description: File containing software version
pattern: "*.{version.txt}"
authors:
- "@joseespinosa"
- "@drpatelh"

View file

View file

@ -0,0 +1,17 @@
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
include { MOSDEPTH } from '../../../software/mosdepth/main.nf' addParams( options: [:] )
workflow test_mosdepth {
input = [ [ id:'test', single_end:true ],
[ file("${launchDir}/tests/data/bam/test.paired_end.sorted.bam", checkIfExists: true) ],
[ file("${launchDir}/tests/data/bam/test.paired_end.sorted.bam.bai", checkIfExists: true) ] ]
dummy = [ file("${launchDir}/tests/data/dummy/dummy_file.txt", checkIfExists: true) ]
window_size = 100
MOSDEPTH ( input, dummy, window_size )
}

View file

@ -0,0 +1,19 @@
- name: mosdepth
command: nextflow run ./tests/software/mosdepth -entry test_mosdepth -c tests/config/nextflow.config
tags:
- mosdepth
files:
- path: output/mosdepth/test.per-base.bed.gz
md5sum: 4965936f5a7502cff93286c0324e41ff
- path: output/mosdepth/test.regions.bed.gz
md5sum: 6997da219218fa57484572c3a2963dd6
- path: output/mosdepth/test.per-base.bed.gz.csi
md5sum: feed5da1defda07b6eaebcf497581115
- path: output/mosdepth/test.mosdepth.region.dist.txt
md5sum: f1f89c14bab380f44e95b09f676d0c52
- path: output/mosdepth/test.mosdepth.global.dist.txt
md5sum: 239d156c9008dc59c7f0138f6b0ba300
- path: output/mosdepth/test.regions.bed.gz.csi
md5sum: a1c982f3e2a97f529ad5780d32010c32
- path: output/mosdepth/test.mosdepth.summary.txt
md5sum: 5a92dee6e87136a65c7973260f229852