From 5a59e61052b5290f9516c5dafe104bc4d2cb827f Mon Sep 17 00:00:00 2001 From: Thanh Lee Date: Fri, 9 Apr 2021 13:10:32 +0100 Subject: [PATCH] new module: rasusa (#413) * new module: rasusa * Removed blank line in software/rasusa/main * updated code as per reviewcomments * removed blank line as failed for lint * updated as per review comments * Apply suggestions from code review Co-authored-by: Harshil Patel --- software/rasusa/functions.nf | 60 ++++++++++++++++++++++++++++++++ software/rasusa/main.nf | 43 +++++++++++++++++++++++ software/rasusa/meta.yml | 48 +++++++++++++++++++++++++ tests/config/pytest_software.yml | 4 +++ tests/software/rasusa/main.nf | 18 ++++++++++ tests/software/rasusa/test.yml | 9 +++++ 6 files changed, 182 insertions(+) create mode 100644 software/rasusa/functions.nf create mode 100644 software/rasusa/main.nf create mode 100644 software/rasusa/meta.yml create mode 100644 tests/software/rasusa/main.nf create mode 100644 tests/software/rasusa/test.yml diff --git a/software/rasusa/functions.nf b/software/rasusa/functions.nf new file mode 100644 index 00000000..f177f0c8 --- /dev/null +++ b/software/rasusa/functions.nf @@ -0,0 +1,60 @@ +/* + * ----------------------------------------------------- + * 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_id = args.publish_by_id ?: false + 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_id) { + path_list.add(args.publish_id) + } + 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/rasusa/main.nf b/software/rasusa/main.nf new file mode 100644 index 00000000..1b6be154 --- /dev/null +++ b/software/rasusa/main.nf @@ -0,0 +1,43 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process RASUSA { + 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), publish_id:meta.id) } + + conda (params.enable_conda ? "bioconda::rasusa=0.3.0" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/rasusa:0.3.0--h779adbc_1" + } else { + container "quay.io/biocontainers/rasusa:0.3.0--h779adbc_1" + } + + input: + tuple val(meta), path(reads) + val depth_cutoff + val genome_size + + output: + tuple val(meta), path('*.fastq.gz'), emit: reads + path '*.version.txt' , emit: version + + script: + def software = getSoftwareName(task.process) + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + def output = meta.single_end ? "--output ${prefix}.fastq.gz" : "--output ${prefix}_1.fastq.gz ${prefix}_2.fastq.gz" + """ + rasusa \\ + $options.args \\ + --coverage $depth_cutoff \\ + --genome-size $genome_size \\ + --input $reads \\ + $output + echo \$(rasusa --version 2>&1) | sed -e "s/rasusa //g" > ${software}.version.txt + """ +} diff --git a/software/rasusa/meta.yml b/software/rasusa/meta.yml new file mode 100644 index 00000000..35fd2718 --- /dev/null +++ b/software/rasusa/meta.yml @@ -0,0 +1,48 @@ +name: rasusa +description: Randomly subsample sequencing reads to a specified coverage +keywords: + - coverage + - depth + - subsampling +tools: + - rasusa: + description: Randomly subsample sequencing reads to a specified coverage + homepage: https://github.com/mbhall88/rasusa + documentation: https://github.com/mbhall88/rasusa/blob/master/README.md + tool_dev_url: https://github.com/mbhall88/rasusa + doi: "10.5281/zenodo.3731394" + licence: ['MIT'] + +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 + - depth_cutoff: + type: integer + description: Depth of coverage cutoff + - genome_size: + type: string + description: Genome size of the species + +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}" + - reads: + type: file + description: Reads with subsampled coverage + pattern: "*.fastq.gz" + +authors: + - "@thanhleviet" diff --git a/tests/config/pytest_software.yml b/tests/config/pytest_software.yml index c7105f8c..330f0430 100644 --- a/tests/config/pytest_software.yml +++ b/tests/config/pytest_software.yml @@ -386,6 +386,10 @@ quast: - software/quast/** - tests/software/quast/** +rasusa: + - software/rasusa/** + - tests/software/rasusa/** + rapidnj: - software/rapidnj/** - tests/software/rapidnj/** diff --git a/tests/software/rasusa/main.nf b/tests/software/rasusa/main.nf new file mode 100644 index 00000000..4a7c39f7 --- /dev/null +++ b/tests/software/rasusa/main.nf @@ -0,0 +1,18 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { RASUSA } from '../../../software/rasusa/main.nf' addParams( options: ['suffix':'_100X']) + +workflow test_rasusa { + 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) + ] + ] + + depth_cutoff = 100 + genome_size = "1000000b" + + RASUSA ( input, depth_cutoff, genome_size ) +} diff --git a/tests/software/rasusa/test.yml b/tests/software/rasusa/test.yml new file mode 100644 index 00000000..8df5bee9 --- /dev/null +++ b/tests/software/rasusa/test.yml @@ -0,0 +1,9 @@ +- name: rasusa test_rasusa + command: nextflow run tests/software/rasusa -entry test_rasusa -c tests/config/nextflow.config + tags: + - rasusa + files: + - path: output/rasusa/test_100X_1.fastq.gz + md5sum: b9d6f0bef1ef0c21576330d882a7edbb + - path: output/rasusa/test_100X_2.fastq.gz + md5sum: 479bc4cdce2511a9af219e6c39db8d30