From ec15bae344bcf5d34696f46361e9300b5577681c Mon Sep 17 00:00:00 2001 From: Thanh Lee Date: Sat, 10 Apr 2021 16:24:23 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=8F=8B=EF=B8=8F=E2=80=8D=E2=99=80?= =?UTF-8?q?=EF=B8=8F=20new=20submodule=20mash/sketch=F0=9F=95=BA=20(#426)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * new submodule mash/sketch * fixed submodule naming * OK, tag is diff to keyword * OK another round :rofl: * removed TODO comments * updated as per review comments :ok_man: * updated functions.nf :grin: * Update software/mash/sketch/main.nf * Update main.nf Removed blank line at the 12th Co-authored-by: Harshil Patel --- software/mash/sketch/functions.nf | 70 +++++++++++++++++++++++++++++ software/mash/sketch/main.nf | 40 +++++++++++++++++ software/mash/sketch/meta.yml | 40 +++++++++++++++++ tests/config/pytest_software.yml | 12 +++-- tests/software/mash/sketch/main.nf | 16 +++++++ tests/software/mash/sketch/test.yml | 9 ++++ 6 files changed, 183 insertions(+), 4 deletions(-) create mode 100644 software/mash/sketch/functions.nf create mode 100644 software/mash/sketch/main.nf create mode 100644 software/mash/sketch/meta.yml create mode 100644 tests/software/mash/sketch/main.nf create mode 100644 tests/software/mash/sketch/test.yml diff --git a/software/mash/sketch/functions.nf b/software/mash/sketch/functions.nf new file mode 100644 index 00000000..9d0137e3 --- /dev/null +++ b/software/mash/sketch/functions.nf @@ -0,0 +1,70 @@ +/* + * ----------------------------------------------------- + * 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/software/mash/sketch/main.nf b/software/mash/sketch/main.nf new file mode 100644 index 00000000..3cc7e199 --- /dev/null +++ b/software/mash/sketch/main.nf @@ -0,0 +1,40 @@ +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process MASH_SKETCH { + 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::mash=2.3" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/mash:2.3--he348c14_1" + } else { + container "quay.io/biocontainers/mash:2.3--he348c14_1" + } + + input: + tuple val(meta), path(reads) + + output: + tuple val(meta), path("*.msh") , emit: mash + tuple val(meta), path("*.mash_stats") , emit: stats + path "*.version.txt" , emit: version + + script: + def software = getSoftwareName(task.process) + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + """ + mash \\ + sketch \\ + $options.args \\ + -p $task.cpus \\ + -o ${prefix} \\ + -r $reads \\ + 2> ${prefix}.mash_stats + echo \$(mash --version 2>&1) > ${software}.version.txt + """ +} diff --git a/software/mash/sketch/meta.yml b/software/mash/sketch/meta.yml new file mode 100644 index 00000000..3c8c714e --- /dev/null +++ b/software/mash/sketch/meta.yml @@ -0,0 +1,40 @@ +name: mash_sketch +description: Creates vastly reduced representations of sequences using MinHash +keywords: + - mash/sketch +tools: + - mash: + description: Fast sequence distance estimator that uses MinHash + homepage: https://github.com/marbl/Mash + documentation: https://mash.readthedocs.io/en/latest/sketches.html + tool_dev_url: https://github.com/marbl/Mash + doi: "10.1186/s13059-016-0997-x" + licence: ['https://github.com/marbl/Mash/blob/master/LICENSE.txt'] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - reads: + type: file + description: List of input paired-end FastQ files + +output: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - version: + type: file + description: Sketch output + pattern: "*.{mash}" + - stats: + type: file + description: Sketch statistics + pattern: "*.{mash_stats}" + +authors: + - "@thanhleviet" diff --git a/tests/config/pytest_software.yml b/tests/config/pytest_software.yml index ede4f5a9..774815bb 100644 --- a/tests/config/pytest_software.yml +++ b/tests/config/pytest_software.yml @@ -301,6 +301,10 @@ kraken2/run: - software/kraken2/run/** - tests/software/kraken2/run/** +mash/sketch: + - software/mash/sketch/** + - tests/software/mash/sketch/** + methyldackel/extract: - software/methyldackel/extract/** - tests/software/methyldackel/extract/** @@ -386,14 +390,14 @@ quast: - software/quast/** - tests/software/quast/** -rasusa: - - software/rasusa/** - - tests/software/rasusa/** - rapidnj: - software/rapidnj/** - tests/software/rapidnj/** +rasusa: + - software/rasusa/** + - tests/software/rasusa/** + salmon/index: - software/salmon/index/** - tests/software/salmon/index/** diff --git a/tests/software/mash/sketch/main.nf b/tests/software/mash/sketch/main.nf new file mode 100644 index 00000000..45b57444 --- /dev/null +++ b/tests/software/mash/sketch/main.nf @@ -0,0 +1,16 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { MASH_SKETCH } from '../../../../software/mash/sketch/main.nf' addParams( options: [:] ) + +workflow test_mash_sketch { + + input = [ [ id:'test', single_end:false], // meta map + [ file(params.test_data['sarscov2']['illumina']['test_1_fastq_gz'], checkIfExists: true), + file(params.test_data['sarscov2']['illumina']['test_2_fastq_gz'], checkIfExists: true) + ] + ] + + MASH_SKETCH ( input ) +} diff --git a/tests/software/mash/sketch/test.yml b/tests/software/mash/sketch/test.yml new file mode 100644 index 00000000..11d2d86f --- /dev/null +++ b/tests/software/mash/sketch/test.yml @@ -0,0 +1,9 @@ +- name: mash sketch + command: nextflow run ./tests/software/mash/sketch -entry test_mash_sketch -c tests/config/nextflow.config + tags: + - mash/sketch + files: + - path: output/mash/test.msh + md5sum: d747145a43dad5f82342036f8f5d9133 + - path: output/mash/test.mash_stats + md5sum: 2a6f297d8e69a5e4160243bc6c89129c