From e27553b989e1de428f9f0fa3dd8103590995a9a4 Mon Sep 17 00:00:00 2001 From: "James A. Fellows Yates" Date: Thu, 28 Oct 2021 12:10:21 +0200 Subject: [PATCH] Add module: `dedup` (#907) * 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 * Apply suggestions from code review Co-authored-by: Harshil Patel * 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 * fix: pigz formatting * Apply suggestions from code review Co-authored-by: Harshil Patel * Apply suggestions from code review * Add dedup (tests and version not working) * Fix dedup and tests Co-authored-by: Harshil Patel Co-authored-by: Maxime Borry --- modules/dedup/functions.nf | 78 +++++++++++++++++++++++++++++++++ modules/dedup/main.nf | 47 ++++++++++++++++++++ modules/dedup/meta.yml | 60 +++++++++++++++++++++++++ tests/config/pytest_modules.yml | 4 ++ tests/modules/dedup/main.nf | 13 ++++++ tests/modules/dedup/test.yml | 13 ++++++ 6 files changed, 215 insertions(+) create mode 100644 modules/dedup/functions.nf create mode 100644 modules/dedup/main.nf create mode 100644 modules/dedup/meta.yml create mode 100644 tests/modules/dedup/main.nf create mode 100644 tests/modules/dedup/test.yml diff --git a/modules/dedup/functions.nf b/modules/dedup/functions.nf new file mode 100644 index 00000000..85628ee0 --- /dev/null +++ b/modules/dedup/functions.nf @@ -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" + } +} diff --git a/modules/dedup/main.nf b/modules/dedup/main.nf new file mode 100644 index 00000000..62d720f6 --- /dev/null +++ b/modules/dedup/main.nf @@ -0,0 +1,47 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process DEDUP { + 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::dedup=0.12.8" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/dedup:0.12.8--hdfd78af_1" + } else { + container "quay.io/biocontainers/dedup:0.12.8--hdfd78af_1" + } + + input: + tuple val(meta), path(bam) + + output: + tuple val(meta), path("*_rmdup.bam"), emit: bam // _rmdup is hardcoded output from dedup + tuple val(meta), path("*.json") , emit: json + tuple val(meta), path("*.hist") , emit: hist + tuple val(meta), path("*log") , emit: log + path "versions.yml" , emit: versions + + script: + prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + + """ + dedup \\ + -Xmx${task.memory.toGiga()}g \\ + -i $bam \\ + -o . \\ + $options.args + + cat <<-END_VERSIONS > versions.yml + ${getProcessName(task.process)}: + ${getSoftwareName(task.process)}: \$( echo \$(dedup --version 2>&1) | tail -n 1 | sed 's/.* v//') + + END_VERSIONS + """ +} diff --git a/modules/dedup/meta.yml b/modules/dedup/meta.yml new file mode 100644 index 00000000..0ddd648f --- /dev/null +++ b/modules/dedup/meta.yml @@ -0,0 +1,60 @@ +name: dedup +description: DeDup is a tool for read deduplication in paired-end read merging (e.g. for ancient DNA experiments). +keywords: + - dedup + - deduplication + - pcr duplicates + - ancient DNA + - paired-end + - bam +tools: + - dedup: + description: DeDup is a tool for read deduplication in paired-end read merging (e.g. for ancient DNA experiments). + homepage: https://github.com/apeltzer/DeDup + documentation: https://dedup.readthedocs.io/en/latest/ + tool_dev_url: https://github.com/apeltzer/DeDup + doi: "10.1186/s13059-016-0918-z" + 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/SAM file + pattern: "*.{bam,sam}" + +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: Deduplicated BAM file + pattern: "*_rmdup.bam" + - json: + type: file + description: JSON file for MultiQC + pattern: "*.json" + - hist: + type: file + description: Histogram data of amount of deduplication + pattern: "*.hist" + - log: + type: file + description: Dedup log information + pattern: "*log" + + + +authors: + - "@jfy133" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 524027a4..8577b15f 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -294,6 +294,10 @@ damageprofiler: - modules/damageprofiler/** - tests/modules/damageprofiler/** +dedup: + - modules/dedup/** + - tests/modules/dedup/** + deeptools/computematrix: - modules/deeptools/computematrix/** - tests/modules/deeptools/computematrix/** diff --git a/tests/modules/dedup/main.nf b/tests/modules/dedup/main.nf new file mode 100644 index 00000000..37e8e5c2 --- /dev/null +++ b/tests/modules/dedup/main.nf @@ -0,0 +1,13 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { DEDUP } from '../../../modules/dedup/main.nf' addParams( options: [args: "-m"] ) + +workflow test_dedup { + + input = [ [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['illumina']['test_paired_end_bam'], checkIfExists: true) ] + + DEDUP ( input ) +} diff --git a/tests/modules/dedup/test.yml b/tests/modules/dedup/test.yml new file mode 100644 index 00000000..b35cfafd --- /dev/null +++ b/tests/modules/dedup/test.yml @@ -0,0 +1,13 @@ +- name: dedup test_dedup + command: nextflow run tests/modules/dedup -entry test_dedup -c tests/config/nextflow.config + tags: + - dedup + files: + - path: output/dedup/test.paired_end.dedup.json + md5sum: 2def0b54aba1fafa21b274f260de1b6f + - path: output/dedup/test.paired_end.hist + md5sum: df3492273a1db0d8152e35d9d5e38aa6 + - path: output/dedup/test.paired_end.log + md5sum: 4b8855bd63b2f4b37da4cfb17e61fb00 + - path: output/dedup/test.paired_end_rmdup.bam + md5sum: 8b0408fe3e258989095303a47e5b5061