From 6e92a6a0807eb76438f7a14bdc044f3e8f6ae659 Mon Sep 17 00:00:00 2001 From: JoseEspinosa Date: Mon, 15 Feb 2021 14:33:44 +0100 Subject: [PATCH] Adding mosdepth module --- .github/filters.yml | 4 ++ software/mosdepth/functions.nf | 59 +++++++++++++++++++ software/mosdepth/main.nf | 48 ++++++++++++++++ software/mosdepth/meta.yml | 97 ++++++++++++++++++++++++++++++++ tests/data/dummy/dummy_file.txt | 0 tests/software/mosdepth/main.nf | 17 ++++++ tests/software/mosdepth/test.yml | 19 +++++++ 7 files changed, 244 insertions(+) create mode 100644 software/mosdepth/functions.nf create mode 100644 software/mosdepth/main.nf create mode 100644 software/mosdepth/meta.yml create mode 100644 tests/data/dummy/dummy_file.txt create mode 100644 tests/software/mosdepth/main.nf create mode 100644 tests/software/mosdepth/test.yml diff --git a/.github/filters.yml b/.github/filters.yml index 5a1ed42e..4069d500 100644 --- a/.github/filters.yml +++ b/.github/filters.yml @@ -140,6 +140,10 @@ minimap2_align: - software/minimap2/align/** - tests/software/minimap2/align/** +mosdepth: + - software/mosdepth/** + - tests/software/mosdepth/** + multiqc: - software/fastqc/** - software/multiqc/** diff --git a/software/mosdepth/functions.nf b/software/mosdepth/functions.nf new file mode 100644 index 00000000..d25eea86 --- /dev/null +++ b/software/mosdepth/functions.nf @@ -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" + } + } +} diff --git a/software/mosdepth/main.nf b/software/mosdepth/main.nf new file mode 100644 index 00000000..43409bbe --- /dev/null +++ b/software/mosdepth/main.nf @@ -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=ha7ba039_0' : 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 + """ +} diff --git a/software/mosdepth/meta.yml b/software/mosdepth/meta.yml new file mode 100644 index 00000000..7a822894 --- /dev/null +++ b/software/mosdepth/meta.yml @@ -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/` + - 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" diff --git a/tests/data/dummy/dummy_file.txt b/tests/data/dummy/dummy_file.txt new file mode 100644 index 00000000..e69de29b diff --git a/tests/software/mosdepth/main.nf b/tests/software/mosdepth/main.nf new file mode 100644 index 00000000..5001fa78 --- /dev/null +++ b/tests/software/mosdepth/main.nf @@ -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 ) +} diff --git a/tests/software/mosdepth/test.yml b/tests/software/mosdepth/test.yml new file mode 100644 index 00000000..26b83e0a --- /dev/null +++ b/tests/software/mosdepth/test.yml @@ -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