From 2ed9b6ae28a267819dc3323e624a0d22f8aca0f2 Mon Sep 17 00:00:00 2001 From: Anthony Underwood Date: Wed, 14 Apr 2021 08:38:59 +0100 Subject: [PATCH] Raxmlng (#443) * new raxml module * new raxml module * pass in args for bootstrap and add test for support file * remove unnecessary tag * ensure tags meet guidleines * Apply suggestions from code review * Update to latest functions file Co-authored-by: avantonder Co-authored-by: Harshil Patel --- software/raxmlng/functions.nf | 70 ++++++++++++++++++++++++++++++++ software/raxmlng/main.nf | 43 ++++++++++++++++++++ software/raxmlng/meta.yml | 38 +++++++++++++++++ tests/config/pytest_software.yml | 4 ++ tests/software/raxmlng/main.nf | 28 +++++++++++++ tests/software/raxmlng/test.yml | 31 ++++++++++++++ 6 files changed, 214 insertions(+) create mode 100644 software/raxmlng/functions.nf create mode 100644 software/raxmlng/main.nf create mode 100644 software/raxmlng/meta.yml create mode 100644 tests/software/raxmlng/main.nf create mode 100644 tests/software/raxmlng/test.yml diff --git a/software/raxmlng/functions.nf b/software/raxmlng/functions.nf new file mode 100644 index 00000000..9d0137e3 --- /dev/null +++ b/software/raxmlng/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/raxmlng/main.nf b/software/raxmlng/main.nf new file mode 100644 index 00000000..58f59287 --- /dev/null +++ b/software/raxmlng/main.nf @@ -0,0 +1,43 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process RAXMLNG { + 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:[:], publish_by_meta:[]) } + + conda (params.enable_conda ? "bioconda::raxml-ng=1.0.2" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/raxml-ng:1.0.2--h7447c1b_0" + } else { + container "quay.io/biocontainers/raxml-ng:1.0.2--h7447c1b_0" + } + + input: + path alignment + + output: + path "*.raxml.bestTree", emit: phylogeny + path "*.raxml.support" , optional:true, emit: phylogeny_bootstrapped + path "*.version.txt" , emit: version + + script: + def software = getSoftwareName(task.process) + + if (options.args.contains('--bs-trees')) { + options.args = "--all ${options.args}" + } + """ + raxml-ng \\ + $options.args \\ + --msa $alignment \\ + --threads $task.cpus \\ + --prefix output + + echo \$(raxml-ng --version 2>&1) | sed 's/^.*RAxML-NG v. //; s/released.*\$//' > ${software}.version.txt + """ +} diff --git a/software/raxmlng/meta.yml b/software/raxmlng/meta.yml new file mode 100644 index 00000000..1df98148 --- /dev/null +++ b/software/raxmlng/meta.yml @@ -0,0 +1,38 @@ +name: raxmlng +description: RAxML-NG is a phylogenetic tree inference tool which uses maximum-likelihood (ML) optimality criterion. +keywords: + - phylogeny + - newick + - maximum likelihood +tools: + - raxmlng: + description: RAxML-NG is a phylogenetic tree inference tool which uses maximum-likelihood (ML) optimality criterion. + homepage: https://github.com/amkozlov/raxml-ng + documentation: https://github.com/amkozlov/raxml-ng/wiki + tool_dev_url: https://github.com/amkozlov/raxml-ng + doi: doi.org/10.1093/bioinformatics/btz305 + licence: ['GPL v2-or-later'] + +input: + - alignment: + type: file + description: A FASTA format multiple sequence alignment file + pattern: "*.{fasta,fas,fa,mfa}" + +output: + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" + - phylogeny: + type: file + description: A phylogeny in Newick format + pattern: "*.{raxml.bestTree}" + - phylogeny_bootstrapped: + type: file + description: A phylogeny in Newick format with bootstrap values + pattern: "*.{raxml.support}" + +authors: + - "@avantonder" + - "@aunderwo" diff --git a/tests/config/pytest_software.yml b/tests/config/pytest_software.yml index 85381054..147f54ab 100644 --- a/tests/config/pytest_software.yml +++ b/tests/config/pytest_software.yml @@ -427,6 +427,10 @@ rasusa: - software/rasusa/** - tests/software/rasusa/** +raxmlng: + - software/raxmlng/** + - tests/software/raxmlng/** + rseqc/bamstat: - software/rseqc/bamstat/** - tests/software/rseqc/bamstat/** diff --git a/tests/software/raxmlng/main.nf b/tests/software/raxmlng/main.nf new file mode 100644 index 00000000..2e6aeb34 --- /dev/null +++ b/tests/software/raxmlng/main.nf @@ -0,0 +1,28 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { RAXMLNG as RAXMLNG_NO_BOOTSTRAP } from '../../../software/raxmlng/main.nf' addParams( options: [args:'--model GTR+G'] ) +include { RAXMLNG as RAXMLNG_BOOTSTRAP } from '../../../software/raxmlng/main.nf' addParams( options: [args:'--model GTR+G --bs-trees 1000'] ) + +/* + * Test without bootstrapping + */ + +workflow test_raxmlng_no_bootstrap { + + input = [ file(params.test_data['sarscov2']['genome']['informative_sites_fas'], checkIfExists: true) ] + + RAXMLNG_NO_BOOTSTRAP ( input ) +} + +/* + * Test with bootstrapping + */ + +workflow test_raxmlng_bootstrap { + + input = [ file(params.test_data['sarscov2']['genome']['informative_sites_fas'], checkIfExists: true) ] + + RAXMLNG_BOOTSTRAP ( input ) +} diff --git a/tests/software/raxmlng/test.yml b/tests/software/raxmlng/test.yml new file mode 100644 index 00000000..996f3760 --- /dev/null +++ b/tests/software/raxmlng/test.yml @@ -0,0 +1,31 @@ +- name: raxmlng no_bootstrap + command: nextflow run ./tests/software/raxmlng -entry test_raxmlng_no_bootstrap -c tests/config/nextflow.config + tags: + - raxmlng + files: + - path: output/raxmlng/output.raxml.bestTree + contains: + - 'sample1:0.359' + - 'sample2:1.50' + - 'sample3:0.000001' + - 'sample4:0.111' + +- name: raxmlng bootstrap + command: nextflow run ./tests/software/raxmlng -entry test_raxmlng_bootstrap -c tests/config/nextflow.config + tags: + - raxmlng + files: + - path: output/raxmlng/output.raxml.bestTree + contains: + - 'sample1:0.359' + - 'sample2:1.50' + - 'sample3:0.000001' + - 'sample4:0.111' + - path: output/raxmlng/output.raxml.support + contains: + - 'sample1:0.359' + - 'sample2:1.50' + - 'sample3:0.000001' + - 'sample4:0.111' + contains_regex: + - '\)[89]\d:'