From 08b71fa85f69147f7c56552bfca08045ac43a137 Mon Sep 17 00:00:00 2001 From: "James A. Fellows Yates" Date: Wed, 3 Nov 2021 17:01:23 +0100 Subject: [PATCH] New module: `gunc run` (+ `gunc downloaddb`) (#880) * 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 GUNC download_db and run commands * Bump with version without zgrep * Apply suggestions from code review Co-authored-by: Robert A. Petit III * Harshil formatting * Apply suggestions from code review Co-authored-by: Robert A. Petit III Co-authored-by: Harshil Patel Co-authored-by: Maxime Borry Co-authored-by: Robert A. Petit III --- modules/gunc/downloaddb/functions.nf | 78 ++++++++++++++++++++++++++ modules/gunc/downloaddb/main.nf | 37 ++++++++++++ modules/gunc/downloaddb/meta.yml | 36 ++++++++++++ modules/gunc/run/functions.nf | 78 ++++++++++++++++++++++++++ modules/gunc/run/main.nf | 45 +++++++++++++++ modules/gunc/run/meta.yml | 53 +++++++++++++++++ tests/config/pytest_modules.yml | 8 +++ tests/modules/gunc/downloaddb/main.nf | 12 ++++ tests/modules/gunc/downloaddb/test.yml | 8 +++ tests/modules/gunc/run/main.nf | 17 ++++++ tests/modules/gunc/run/test.yml | 8 +++ 11 files changed, 380 insertions(+) create mode 100644 modules/gunc/downloaddb/functions.nf create mode 100644 modules/gunc/downloaddb/main.nf create mode 100644 modules/gunc/downloaddb/meta.yml create mode 100644 modules/gunc/run/functions.nf create mode 100644 modules/gunc/run/main.nf create mode 100644 modules/gunc/run/meta.yml create mode 100644 tests/modules/gunc/downloaddb/main.nf create mode 100644 tests/modules/gunc/downloaddb/test.yml create mode 100644 tests/modules/gunc/run/main.nf create mode 100644 tests/modules/gunc/run/test.yml diff --git a/modules/gunc/downloaddb/functions.nf b/modules/gunc/downloaddb/functions.nf new file mode 100644 index 00000000..85628ee0 --- /dev/null +++ b/modules/gunc/downloaddb/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/gunc/downloaddb/main.nf b/modules/gunc/downloaddb/main.nf new file mode 100644 index 00000000..af421608 --- /dev/null +++ b/modules/gunc/downloaddb/main.nf @@ -0,0 +1,37 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process GUNC_DOWNLOADDB { + tag '$db_name' + 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::gunc=1.0.5" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/gunc:1.0.5--pyhdfd78af_0" + } else { + container "quay.io/biocontainers/gunc:1.0.5--pyhdfd78af_0" + } + + input: + val db_name + + output: + path "*.dmnd" , emit: db + path "versions.yml" , emit: versions + + script: + """ + gunc download_db . -db $db_name $options.args + + cat <<-END_VERSIONS > versions.yml + ${getProcessName(task.process)}: + ${getSoftwareName(task.process)}: \$( gunc --version ) + END_VERSIONS + """ +} diff --git a/modules/gunc/downloaddb/meta.yml b/modules/gunc/downloaddb/meta.yml new file mode 100644 index 00000000..cb486da0 --- /dev/null +++ b/modules/gunc/downloaddb/meta.yml @@ -0,0 +1,36 @@ +name: gunc_downloaddb +description: Download database for GUNC detection of Chimerism and Contamination in Prokaryotic Genomes +keywords: + - download + - prokaryote + - assembly + - genome + - quality control + - chimeras +tools: + - gunc: + description: Python package for detection of chimerism and contamination in prokaryotic genomes. + homepage: https://grp-bork.embl-community.io/gunc/ + documentation: https://grp-bork.embl-community.io/gunc/ + tool_dev_url: https://github.com/grp-bork/gunc + doi: "10.1186/s13059-021-02393-0" + licence: ['GNU General Public v3 or later (GPL v3+)'] + +input: + - db_name: + type: string + description: "Which database to download. Options: progenomes or gtdb" + pattern: "progenomes|gtdb" + +output: + - versions: + type: file + description: File containing software versions + pattern: "versions.yml" + - db: + type: file + description: GUNC database file + pattern: "*.dmnd" + +authors: + - "@jfy133" diff --git a/modules/gunc/run/functions.nf b/modules/gunc/run/functions.nf new file mode 100644 index 00000000..85628ee0 --- /dev/null +++ b/modules/gunc/run/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/gunc/run/main.nf b/modules/gunc/run/main.nf new file mode 100644 index 00000000..f873a7df --- /dev/null +++ b/modules/gunc/run/main.nf @@ -0,0 +1,45 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process GUNC_RUN { + 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), meta:meta, publish_by_meta:['id']) } + + conda (params.enable_conda ? "bioconda::gunc=1.0.5" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/gunc:1.0.5--pyhdfd78af_0" + } else { + container "quay.io/biocontainers/gunc:1.0.5--pyhdfd78af_0" + } + + input: + tuple val(meta), path(fasta) + path(db) + + output: + tuple val(meta), path("*maxCSS_level.tsv") , emit: maxcss_level_tsv + tuple val(meta), path("*all_levels.tsv") , optional: true, emit: all_levels_tsv + path "versions.yml" , emit: versions + + script: + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + """ + gunc \\ + run \\ + --input_fasta $fasta \\ + --db_file $db \\ + --threads $task.cpus \\ + $options.args + + cat <<-END_VERSIONS > versions.yml + ${getProcessName(task.process)}: + ${getSoftwareName(task.process)}: \$( gunc --version ) + END_VERSIONS + """ +} diff --git a/modules/gunc/run/meta.yml b/modules/gunc/run/meta.yml new file mode 100644 index 00000000..1dd4a8ae --- /dev/null +++ b/modules/gunc/run/meta.yml @@ -0,0 +1,53 @@ +name: gunc_run +description: Detection of Chimerism and Contamination in Prokaryotic Genomes +keywords: + - prokaryote + - assembly + - genome + - quality control + - chimeras +tools: + - gunc: + description: Python package for detection of chimerism and contamination in prokaryotic genomes. + homepage: https://grp-bork.embl-community.io/gunc/ + documentation: https://grp-bork.embl-community.io/gunc/ + tool_dev_url: https://github.com/grp-bork/gunc + doi: "10.1186/s13059-021-02393-0" + licence: ['GNU General Public v3 or later (GPL v3+)'] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - fasta: + type: file + description: FASTA file containing contig (bins) + pattern: "*.fa" + - db: + type: file + description: GUNC database file + pattern: "*.dmnd" + +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" + - maxcss_levels_tsv: + type: file + description: Output file with scores for a taxonomic level with the highest CSS score + pattern: "*.tsv" + - all_levels_tsv: + type: file + description: Optional output file with results for each taxonomic level + pattern: "*.tsv" + +authors: + - "@jfy133" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 047f83ff..8d8f32f3 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -546,6 +546,14 @@ gubbins: - modules/gubbins/** - tests/modules/gubbins/** +gunc/downloaddb: + - modules/gunc/downloaddb/** + - tests/modules/gunc/downloaddb/** + +gunc/run: + - modules/gunc/run/** + - tests/modules/gunc/run/** + gunzip: - modules/gunzip/** - tests/modules/gunzip/** diff --git a/tests/modules/gunc/downloaddb/main.nf b/tests/modules/gunc/downloaddb/main.nf new file mode 100644 index 00000000..c0321279 --- /dev/null +++ b/tests/modules/gunc/downloaddb/main.nf @@ -0,0 +1,12 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { GUNC_DOWNLOADDB } from '../../../../modules/gunc/downloaddb/main.nf' addParams( options: [:] ) + +workflow test_gunc_downloaddb { + + input = 'progenomes' + + GUNC_DOWNLOADDB ( input ) +} diff --git a/tests/modules/gunc/downloaddb/test.yml b/tests/modules/gunc/downloaddb/test.yml new file mode 100644 index 00000000..d1aafae7 --- /dev/null +++ b/tests/modules/gunc/downloaddb/test.yml @@ -0,0 +1,8 @@ +- name: gunc downloaddb + command: nextflow run ./tests/modules/gunc/downloaddb -entry test_gunc_downloaddb -c tests/config/nextflow.config + tags: + - gunc + - gunc/downloaddb + files: + - path: output/gunc/gunc_db_progenomes2.1.dmnd + md5sum: 447c9330056b02f29f30fe81fe4af4eb diff --git a/tests/modules/gunc/run/main.nf b/tests/modules/gunc/run/main.nf new file mode 100644 index 00000000..a1a191dc --- /dev/null +++ b/tests/modules/gunc/run/main.nf @@ -0,0 +1,17 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { GUNC_RUN } from '../../../../modules/gunc/run/main.nf' addParams( options: [:] ) +include { GUNC_DOWNLOADDB } from '../../../../modules/gunc/downloaddb/main.nf' addParams( options: [:] ) + + +workflow test_gunc_run { + + input = [ [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['illumina']['contigs_fasta'], checkIfExists: true) ] + + GUNC_DOWNLOADDB('progenomes') + + GUNC_RUN ( input, GUNC_DOWNLOADDB.out.db ) +} diff --git a/tests/modules/gunc/run/test.yml b/tests/modules/gunc/run/test.yml new file mode 100644 index 00000000..d527f37e --- /dev/null +++ b/tests/modules/gunc/run/test.yml @@ -0,0 +1,8 @@ +- name: gunc run + command: nextflow run ./tests/modules/gunc/run -entry test_gunc_run -c tests/config/nextflow.config + tags: + - gunc + - gunc/run + files: + - path: output/gunc/GUNC.progenomes_2.1.maxCSS_level.tsv + md5sum: 0420c1a9f2c50fefaee9fab5d80a551a