From 7e45cbf4d1e48023cb40a2e047854fb57e1c9832 Mon Sep 17 00:00:00 2001 From: Maxime Borry Date: Thu, 16 Sep 2021 15:05:49 +0200 Subject: [PATCH] Add PyDamage filter (#713) * add pydamage module * remove TODOs * split module by subcommands * update version parsing * remove forgotten TODOs * update module names * remove old holistic module * Update modules/pydamage/analyze/main.nf Co-authored-by: James A. Fellows Yates * add keywords * update resource requirement * Update modules/pydamage/filter/main.nf Co-authored-by: James A. Fellows Yates * Update modules/pydamage/filter/meta.yml Co-authored-by: James A. Fellows Yates Co-authored-by: James A. Fellows Yates --- modules/pydamage/filter/functions.nf | 68 ++++++++++++++++++++++++++ modules/pydamage/filter/main.nf | 40 +++++++++++++++ modules/pydamage/filter/meta.yml | 51 +++++++++++++++++++ tests/config/pytest_modules.yml | 4 ++ tests/modules/pydamage/filter/main.nf | 16 ++++++ tests/modules/pydamage/filter/test.yml | 10 ++++ 6 files changed, 189 insertions(+) create mode 100644 modules/pydamage/filter/functions.nf create mode 100644 modules/pydamage/filter/main.nf create mode 100644 modules/pydamage/filter/meta.yml create mode 100644 tests/modules/pydamage/filter/main.nf create mode 100644 tests/modules/pydamage/filter/test.yml diff --git a/modules/pydamage/filter/functions.nf b/modules/pydamage/filter/functions.nf new file mode 100644 index 00000000..da9da093 --- /dev/null +++ b/modules/pydamage/filter/functions.nf @@ -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" + } + } +} diff --git a/modules/pydamage/filter/main.nf b/modules/pydamage/filter/main.nf new file mode 100644 index 00000000..0010a7e0 --- /dev/null +++ b/modules/pydamage/filter/main.nf @@ -0,0 +1,40 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process PYDAMAGE_FILTER { + 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::pydamage=0.62" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/pydamage:0.62--pyhdfd78af_0" + } else { + container "quay.io/biocontainers/pydamage:0.62--pyhdfd78af_0" + } + + input: + tuple val(meta), path(csv) + + output: + tuple val(meta), path("pydamage_results/pydamage_filtered_results.csv"), emit: csv + path "*.version.txt" , emit: version + + script: + def software = getSoftwareName(task.process) + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + """ + + pydamage \\ + filter \\ + $options.args \\ + $csv + + echo \$(pydamage --version 2>&1) | sed -e 's/pydamage, version //g' > ${software}.version.txt + """ +} diff --git a/modules/pydamage/filter/meta.yml b/modules/pydamage/filter/meta.yml new file mode 100644 index 00000000..0870636b --- /dev/null +++ b/modules/pydamage/filter/meta.yml @@ -0,0 +1,51 @@ +name: pydamage_filter +description: Damage parameter estimation for ancient DNA +keywords: + - ancient DNA + - aDNA + - de novo assembly + - filtering + - damage + - deamination + - miscoding lesions + - C to T + - palaeogenomics + - archaeogenomics + - palaeogenetics + - archaeogenetics +tools: + - pydamage: + description: Damage parameter estimation for ancient DNA + homepage: https://github.com/maxibor/pydamage + documentation: https://pydamage.readthedocs.io/ + tool_dev_url: https://github.com/maxibor/pydamage + licence: ['GPL v3'] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - csv: + type: file + description: csv file from pydamage analyze + pattern: "*.csv" + +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}" + - csv: + type: file + description: PyDamage filtered results as csv file + pattern: "*.csv" + +authors: + - "@maxibor" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 1e33a9d9..fdcbbf94 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -707,6 +707,10 @@ pydamage/analyze: - modules/pydamage/analyze/** - tests/modules/pydamage/analyze/** +pydamage/filter: + - modules/pydamage/filter/** + - tests/modules/pydamage/filter/** + qcat: - modules/qcat/** - tests/modules/qcat/** diff --git a/tests/modules/pydamage/filter/main.nf b/tests/modules/pydamage/filter/main.nf new file mode 100644 index 00000000..03e90408 --- /dev/null +++ b/tests/modules/pydamage/filter/main.nf @@ -0,0 +1,16 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { PYDAMAGE_ANALYZE } from '../../../../modules/pydamage/analyze/main.nf' addParams( options: [:] ) +include { PYDAMAGE_FILTER } from '../../../../modules/pydamage/filter/main.nf' addParams( options: [:] ) + +workflow test_pydamage { + + input = [ [ id:'test', single_end:false ], // meta map + file(params.test_data['homo_sapiens']['illumina']['test_paired_end_sorted_bam'], checkIfExists: true), + file(params.test_data['homo_sapiens']['illumina']['test_paired_end_sorted_bam_bai'], checkIfExists: true) ] + + PYDAMAGE_ANALYZE ( input ) + PYDAMAGE_FILTER (PYDAMAGE_ANALYZE.out.csv) +} diff --git a/tests/modules/pydamage/filter/test.yml b/tests/modules/pydamage/filter/test.yml new file mode 100644 index 00000000..e131d505 --- /dev/null +++ b/tests/modules/pydamage/filter/test.yml @@ -0,0 +1,10 @@ +- name: test_pydamage_filter + command: nextflow run tests/modules/pydamage/filter -entry test_pydamage -c tests/config/nextflow.config + tags: + - pydamage + - pydamage/filter + files: + - path: output/pydamage/pydamage_results/pydamage_filtered_results.csv + md5sum: 9f297233cf4932d7d7e52cc72d4727dc + - path: output/pydamage/pydamage_results/pydamage_results.csv + md5sum: 6847e0d5aa6dba85bbd2dd509772b7a0