From 01cc326c2326d17615857953d81c586e2a3e5c60 Mon Sep 17 00:00:00 2001 From: "James A. Fellows Yates" Date: Thu, 30 Sep 2021 12:54:16 +0200 Subject: [PATCH] add Amps (#768) * Specify more guidelines on input channels * Linting * Updates based on code review * Update README.md * Fix broken sentence * Start work, continue once on non-mobile internet * finished and working on conda * Update modules/amps/main.nf Co-authored-by: Jose Espinosa-Carrasco * Apply suggestions from code review Co-authored-by: Jose Espinosa-Carrasco Co-authored-by: Jose Espinosa-Carrasco --- modules/amps/functions.nf | 78 +++++++++++++++++++++++++++++++++ modules/amps/main.nf | 47 ++++++++++++++++++++ modules/amps/meta.yml | 66 ++++++++++++++++++++++++++++ tests/config/pytest_modules.yml | 4 ++ tests/modules/amps/main.nf | 32 ++++++++++++++ tests/modules/amps/test.yml | 11 +++++ 6 files changed, 238 insertions(+) create mode 100644 modules/amps/functions.nf create mode 100644 modules/amps/main.nf create mode 100644 modules/amps/meta.yml create mode 100644 tests/modules/amps/main.nf create mode 100644 tests/modules/amps/test.yml diff --git a/modules/amps/functions.nf b/modules/amps/functions.nf new file mode 100644 index 00000000..85628ee0 --- /dev/null +++ b/modules/amps/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/amps/main.nf b/modules/amps/main.nf new file mode 100644 index 00000000..676435f1 --- /dev/null +++ b/modules/amps/main.nf @@ -0,0 +1,47 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process AMPS { + 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:[:], publish_by_meta:[]) } + + conda (params.enable_conda ? "bioconda::hops=0.35" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/hops:0.35--hdfd78af_1" + } else { + container "quay.io/biocontainers/hops:0.35--hdfd78af_1" + } + + input: + path maltextract_results + path taxon_list + val filter + + output: + path "results/heatmap_overview_Wevid.json" , emit: json + path "results/heatmap_overview_Wevid.pdf" , emit: summary_pdf + path "results/heatmap_overview_Wevid.tsv" , emit: tsv + path "results/pdf_candidate_profiles/" , emit: candidate_pdfs + path "versions.yml" , emit: version + + script: + """ + postprocessing.AMPS.r \\ + -r $maltextract_results \\ + -n $taxon_list \\ + -m $filter \\ + -t $task.cpus \\ + -j \\ + $options.args + + cat <<-END_VERSIONS > versions.yml + ${getProcessName(task.process)}: + amps: \$(echo \$(hops --version 2>&1) | sed 's/HOPS version//') + END_VERSIONS + """ +} diff --git a/modules/amps/meta.yml b/modules/amps/meta.yml new file mode 100644 index 00000000..62844f6a --- /dev/null +++ b/modules/amps/meta.yml @@ -0,0 +1,66 @@ +name: amps +description: Post-processing script of the MaltExtract component of the HOPS package +keywords: + - malt + - MaltExtract + - HOPS + - amps + - alignment + - metagenomics + - ancient DNA + - aDNA + - palaeogenomics + - archaeogenomics + - microbiome + - authentication + - damage + - edit distance + - post Post-processing + - visualisation +tools: + - amps: + description: Post-processing script of the MaltExtract tool for ancient metagenomics + homepage: "https://github.com/rhuebler/HOPS" + documentation: "https://github.com/keyfm/amps" + tool_dev_url: "https://github.com/keyfm/amps" + doi: "10.1186/s13059-019-1903-0" + licence: ['GPL >=3'] + +input: + - maltextract_results: + type: directory + description: MaltExtract output directory + pattern: "results/" + - taxon_list: + type: file + description: List of target taxa to evaluate used in MaltExtract + pattern: "*.txt" + - filter: + type: string + description: The filter mode used in MaltExtract + pattern: "def_anc|default|scan|ancient|crawl" + +output: + - version: + type: file + description: File containing software version + pattern: "versions.yml" + - json: + type: file + description: Candidate summary heatmap in MultiQC compatible JSON format + pattern: "heatmap_overview_Wevid.json" + - summary_pdf: + type: file + description: Candidate summary heatmap in PDF format + pattern: "heatmap_overview_Wevid.pdf" + - tsv: + type: file + description: Candidate summary heatmap in TSV format + pattern: "heatmap_overview_Wevid.tsv" + - candidate_pdfs: + type: directory + description: Directory of per sample output PDFs organised by reference + pattern: "pdf_candidate_profiles/" + +authors: + - "@jfy133" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index ebe91db0..3dda1d94 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -14,6 +14,10 @@ allelecounter: - modules/allelecounter/** - tests/modules/allelecounter/** +amps: + - modules/amps/** + - tests/modules/amps/** + arriba: - modules/arriba/** - tests/modules/arriba/** diff --git a/tests/modules/amps/main.nf b/tests/modules/amps/main.nf new file mode 100644 index 00000000..7d7a40d1 --- /dev/null +++ b/tests/modules/amps/main.nf @@ -0,0 +1,32 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { UNZIP as UNZIP_MALT } from '../../../modules/unzip/main.nf' addParams( options: [:] ) +include { UNZIP as UNZIP_MALTEXTRACT } from '../../../modules/unzip/main.nf' addParams( options: [:] ) +include { MALT_BUILD } from '../../../modules/malt/build/main.nf' addParams( options: [:] ) +include { MALT_RUN } from '../../../modules/malt/run/main.nf' addParams( options: [:] ) +include { MALTEXTRACT } from '../../../modules/maltextract/main.nf' addParams( options: [args: "-f def_anc"] ) +include { AMPS } from '../../../modules/amps/main.nf' addParams( options: [:] ) + + +workflow test_amps { + + fastas = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) + gff = [] + seq_type = "DNA" + map_db = file("https://software-ab.informatik.uni-tuebingen.de/download/megan6/megan-nucl-Jan2021.db.zip", checkIfExists: true) + input = file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true) + mode = "BlastN" + taxon_list = file(params.test_data['sarscov2']['genome']['taxon_list_txt'], checkIfExists: true) + ncbi_dir = file(params.test_data['sarscov2']['genome']['ncbi_taxmap_zip'], checkIfExists: true) + filter = "def_anc" + + UNZIP_MALT ( map_db ) + UNZIP_MALTEXTRACT ( ncbi_dir ) + MALT_BUILD ( fastas, seq_type, gff, UNZIP_MALT.out.unzipped_archive ) + MALT_RUN ( input, mode, MALT_BUILD.out.index ) + MALTEXTRACT ( MALT_RUN.out.rma6, taxon_list, UNZIP_MALTEXTRACT.out.unzipped_archive) + + AMPS ( MALTEXTRACT.out.results, taxon_list, filter ) +} diff --git a/tests/modules/amps/test.yml b/tests/modules/amps/test.yml new file mode 100644 index 00000000..04691f18 --- /dev/null +++ b/tests/modules/amps/test.yml @@ -0,0 +1,11 @@ +- name: amps + command: nextflow run ./tests/modules/amps -entry test_amps -c tests/config/nextflow.config + tags: + - amps + files: + - path: output/amps/results/heatmap_overview_Wevid.json + md5sum: 82f484d02a9e3d0cc3d5bcdcc2965e44 + - path: output/amps/results/heatmap_overview_Wevid.pdf + - path: output/amps/results/heatmap_overview_Wevid.tsv + md5sum: 1a7d565a37ef4d6054f7ade63fbadc2f + - path: output/amps/results/pdf_candidate_profiles/Severe_acute_respiratory_syndrome_coronavirus_2/stp1_test_1.rma6_Severe_acute_respiratory_syndrome_coronavirus_2_summary.pdf