From fc4f3e8822865d85904c1e96e93868dae7247a81 Mon Sep 17 00:00:00 2001 From: "Robert A. Petit III" Date: Thu, 4 Nov 2021 01:49:30 -0600 Subject: [PATCH] add seqsero2 module (#1016) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add seqsero2 module * correct lint errors * Update modules/seqsero2/main.nf Co-authored-by: Sébastien Guizard * set output directory Co-authored-by: Sébastien Guizard --- modules/seqsero2/functions.nf | 78 +++++++++++++++++++++++++++++++++ modules/seqsero2/main.nf | 45 +++++++++++++++++++ modules/seqsero2/meta.yml | 52 ++++++++++++++++++++++ tests/config/pytest_modules.yml | 12 +++-- tests/modules/seqsero2/main.nf | 13 ++++++ tests/modules/seqsero2/test.yml | 11 +++++ 6 files changed, 207 insertions(+), 4 deletions(-) create mode 100644 modules/seqsero2/functions.nf create mode 100644 modules/seqsero2/main.nf create mode 100644 modules/seqsero2/meta.yml create mode 100644 tests/modules/seqsero2/main.nf create mode 100644 tests/modules/seqsero2/test.yml diff --git a/modules/seqsero2/functions.nf b/modules/seqsero2/functions.nf new file mode 100644 index 00000000..85628ee0 --- /dev/null +++ b/modules/seqsero2/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/seqsero2/main.nf b/modules/seqsero2/main.nf new file mode 100644 index 00000000..3748a6e4 --- /dev/null +++ b/modules/seqsero2/main.nf @@ -0,0 +1,45 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process SEQSERO2 { + 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::seqsero2=1.2.1" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/seqsero2:1.2.1--py_0" + } else { + container "quay.io/biocontainers/seqsero2:1.2.1--py_0" + } + + input: + tuple val(meta), path(seqs) + + output: + tuple val(meta), path("results/*_log.txt") , emit: log + tuple val(meta), path("results/*_result.tsv"), emit: tsv + tuple val(meta), path("results/*_result.txt"), emit: txt + path "versions.yml" , emit: versions + + script: + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + """ + SeqSero2_package.py \\ + $options.args \\ + -d results/ \\ + -n $prefix \\ + -p $task.cpus \\ + -i $seqs + + cat <<-END_VERSIONS > versions.yml + ${getProcessName(task.process)}: + ${getSoftwareName(task.process)}: \$( echo \$( SeqSero2_package.py --version 2>&1) | sed 's/^.*SeqSero2_package.py //' ) + END_VERSIONS + """ +} diff --git a/modules/seqsero2/meta.yml b/modules/seqsero2/meta.yml new file mode 100644 index 00000000..ceea80e3 --- /dev/null +++ b/modules/seqsero2/meta.yml @@ -0,0 +1,52 @@ +name: seqsero2 +description: Salmonella serotype prediction from reads and assemblies +keywords: + - fasta + - fastq + - salmonella + - sertotype +tools: + - seqsero2: + description: Salmonella serotype prediction from genome sequencing data + homepage: https://github.com/denglab/SeqSero2 + documentation: https://github.com/denglab/SeqSero2 + tool_dev_url: https://github.com/denglab/SeqSero2 + doi: "10.1128/AEM.01746-19" + licence: ['GPL v2'] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - seqs: + type: file + description: FASTQ or FASTA formated sequences + pattern: "*.{fq.gz,fastq.gz,fna.gz,fna,fasta.gz,fasta,fa.gz,fa}" + +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" + - log: + type: file + description: A log of serotype antigen results + pattern: "*_log.txt" + - tsv: + type: file + description: Tab-delimited summary of the SeqSero2 results + pattern: "*_result.tsv" + - txt: + type: file + description: Detailed summary of the SeqSero2 results + pattern: "*_result.txt" + +authors: + - "@rpetit3" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 8d8f32f3..008c98dc 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -446,14 +446,14 @@ gatk4/fastqtosam: - modules/gatk4/fastqtosam/** - tests/modules/gatk4/fastqtosam/** -gatk4/genomicsdbimport: - - modules/gatk4/genomicsdbimport/** - - tests/modules/gatk4/genomicsdbimport/** - gatk4/filtermutectcalls: - modules/gatk4/filtermutectcalls/** - tests/modules/gatk4/filtermutectcalls/** +gatk4/genomicsdbimport: + - modules/gatk4/genomicsdbimport/** + - tests/modules/gatk4/genomicsdbimport/** + gatk4/getpileupsummaries: - modules/gatk4/getpileupsummaries/** - tests/modules/gatk4/getpileupsummaries/** @@ -1083,6 +1083,10 @@ seqkit/split2: - modules/seqkit/split2/** - tests/modules/seqkit/split2/** +seqsero2: + - modules/seqsero2/** + - tests/modules/seqsero2/** + seqtk/mergepe: - modules/seqtk/mergepe/** - tests/modules/seqtk/mergepe/** diff --git a/tests/modules/seqsero2/main.nf b/tests/modules/seqsero2/main.nf new file mode 100644 index 00000000..04ee8e27 --- /dev/null +++ b/tests/modules/seqsero2/main.nf @@ -0,0 +1,13 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { SEQSERO2 } from '../../../modules/seqsero2/main.nf' addParams( options: [args: '-m k -t 4'] ) + +workflow test_seqsero2 { + + input = [ [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) ] + + SEQSERO2 ( input ) +} diff --git a/tests/modules/seqsero2/test.yml b/tests/modules/seqsero2/test.yml new file mode 100644 index 00000000..2aa49686 --- /dev/null +++ b/tests/modules/seqsero2/test.yml @@ -0,0 +1,11 @@ +- name: seqsero2 test_seqsero2 + command: nextflow run tests/modules/seqsero2 -entry test_seqsero2 -c tests/config/nextflow.config + tags: + - seqsero2 + files: + - path: output/seqsero2/results/SeqSero_log.txt + md5sum: d00242dfa734b5abb3622a6048f0b4fb + - path: output/seqsero2/results/SeqSero_result.tsv + contains: ['Sample', 'Predicted', 'Note'] + - path: output/seqsero2/results/SeqSero_result.txt + contains: ['Sample', 'Predicted', 'Note']