From 0ba88fb8699ab1d94ca748ca1c5a903cbbc30602 Mon Sep 17 00:00:00 2001 From: "Robert A. Petit III" Date: Tue, 5 Oct 2021 15:08:47 -0600 Subject: [PATCH] add roary module (#776) * add module roary * Update meta.yml * Update meta.yml * Update meta.yml * Update meta.yml * Update main.nf * Update meta.yml * Apply suggestions from code review Co-authored-by: Harshil Patel --- modules/roary/functions.nf | 78 +++++++++++++++++++++++++++++++++ modules/roary/main.nf | 43 ++++++++++++++++++ modules/roary/meta.yml | 47 ++++++++++++++++++++ tests/config/pytest_modules.yml | 4 ++ tests/modules/roary/main.nf | 16 +++++++ tests/modules/roary/test.yml | 39 +++++++++++++++++ 6 files changed, 227 insertions(+) create mode 100644 modules/roary/functions.nf create mode 100644 modules/roary/main.nf create mode 100644 modules/roary/meta.yml create mode 100644 tests/modules/roary/main.nf create mode 100644 tests/modules/roary/test.yml diff --git a/modules/roary/functions.nf b/modules/roary/functions.nf new file mode 100644 index 00000000..85628ee0 --- /dev/null +++ b/modules/roary/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/roary/main.nf b/modules/roary/main.nf new file mode 100644 index 00000000..9dc948fb --- /dev/null +++ b/modules/roary/main.nf @@ -0,0 +1,43 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process ROARY { + 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::roary=3.13.0" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/roary:3.13.0--pl526h516909a_0" + } else { + container "quay.io/biocontainers/roary:3.13.0--pl526h516909a_0" + } + + input: + tuple val(meta), path(gff) + + output: + tuple val(meta), path("results/*") , emit: results + tuple val(meta), path("results/*.aln"), optional: true, emit: aln + path "versions.yml" , emit: versions + + script: + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + """ + roary \\ + $options.args \\ + -p $task.cpus \\ + -f results/ \\ + $gff + + cat <<-END_VERSIONS > versions.yml + ${getProcessName(task.process)}: + ${getSoftwareName(task.process)}: \$( roary --version ) + END_VERSIONS + """ +} diff --git a/modules/roary/meta.yml b/modules/roary/meta.yml new file mode 100644 index 00000000..4cf42bdf --- /dev/null +++ b/modules/roary/meta.yml @@ -0,0 +1,47 @@ +name: roary +description: Calculate pan-genome from annotated bacterial assemblies in GFF3 format +keywords: + - gff + - pan-genome + - alignment +tools: + - roary: + description: Rapid large-scale prokaryote pan genome analysis + homepage: http://sanger-pathogens.github.io/Roary/ + documentation: http://sanger-pathogens.github.io/Roary/ + tool_dev_url: https://github.com/sanger-pathogens/Roary/ + doi: "http://dx.doi.org/10.1093/bioinformatics/btv421" + licence: ['GPL v3'] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - gff: + type: file + description: A set of GFF3 formatted files + pattern: "*.{gff}" + +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" + - results: + type: directory + description: Directory containing Roary result files + pattern: "*/*" + - aln: + type: file + description: Core-genome alignment produced by Roary (Optional) + pattern: "*.{aln}" + +authors: + - "@rpetit3" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 8de7f7e2..19c17f40 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -811,6 +811,10 @@ raxmlng: - modules/raxmlng/** - tests/modules/raxmlng/** +roary: + - modules/roary/** + - tests/modules/roary/** + rsem/calculateexpression: - modules/rsem/calculateexpression/** - tests/modules/rsem/calculateexpression/** diff --git a/tests/modules/roary/main.nf b/tests/modules/roary/main.nf new file mode 100644 index 00000000..a4a96d6e --- /dev/null +++ b/tests/modules/roary/main.nf @@ -0,0 +1,16 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { ROARY } from '../../../modules/roary/main.nf' addParams( options: [:] ) + +workflow test_roary { + + input = [ [ id:'test', single_end:false ], // meta map + [ file("https://github.com/bactopia/bactopia-tests/raw/main/data/reference/gff/GCF_000292685.gff", checkIfExists: true), + file("https://github.com/bactopia/bactopia-tests/raw/main/data/reference/gff/GCF_000298385.gff", checkIfExists: true), + file("https://github.com/bactopia/bactopia-tests/raw/main/data/reference/gff/GCF_002849995.gff", checkIfExists: true) ] + ] + + ROARY ( input ) +} diff --git a/tests/modules/roary/test.yml b/tests/modules/roary/test.yml new file mode 100644 index 00000000..c8e8c33d --- /dev/null +++ b/tests/modules/roary/test.yml @@ -0,0 +1,39 @@ +- name: roary test_roary + command: nextflow run tests/modules/roary -entry test_roary -c tests/config/nextflow.config + tags: + - roary + files: + - path: output/roary/results/accessory.header.embl + contains: ['ID Genome standard; DNA; PRO; 1234 BP.'] + - path: output/roary/results/accessory.tab + contains: ['FT'] + - path: output/roary/results/accessory_binary_genes.fa + md5sum: 0baeea4947bf17a2bf29d43a44f0278f + - path: output/roary/results/accessory_binary_genes.fa.newick + md5sum: b1f8c76ab231bd38b850c1f8d3c1584b + - path: output/roary/results/accessory_graph.dot + contains: ['/* list of nodes */'] + - path: output/roary/results/blast_identity_frequency.Rtab + md5sum: 829baa25c3fad94b1af207265452a692 + - path: output/roary/results/clustered_proteins + contains: ['JKHLNHAL_00087'] + - path: output/roary/results/core_accessory.header.embl + contains: ['ID Genome standard; DNA; PRO; 1234 BP.'] + - path: output/roary/results/core_accessory.tab + contains: ['FT /taxa="GCF_000292685 GCF_000298385 GCF_002849995"'] + - path: output/roary/results/core_accessory_graph.dot + contains: ['/* list of nodes */'] + - path: output/roary/results/gene_presence_absence.Rtab + contains: ['Gene'] + - path: output/roary/results/gene_presence_absence.csv + contains: ['"Gene","Non-unique Gene name","Annotation","No. isolates","No. sequences"'] + - path: output/roary/results/number_of_conserved_genes.Rtab + contains: ['279'] + - path: output/roary/results/number_of_genes_in_pan_genome.Rtab + contains: ['279'] + - path: output/roary/results/number_of_new_genes.Rtab + contains: ['279'] + - path: output/roary/results/number_of_unique_genes.Rtab + contains: ['279'] + - path: output/roary/results/summary_statistics.txt + md5sum: 3921b5445df6a7ed59408119b8860a58