diff --git a/software/iqtree/functions.nf b/software/iqtree/functions.nf new file mode 100644 index 00000000..9d0137e3 --- /dev/null +++ b/software/iqtree/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/iqtree/main.nf b/software/iqtree/main.nf new file mode 100644 index 00000000..390cd4b3 --- /dev/null +++ b/software/iqtree/main.nf @@ -0,0 +1,44 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process IQTREE { + tag "$variant_alignment" + 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::iqtree=2.1.2" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/iqtree:2.1.2--h56fc30b_0" + } else { + container "quay.io/biocontainers/iqtree:2.1.2--h56fc30b_0" + } + + input: + path alignment + val constant_sites + + output: + path "*.treefile", emit: phylogeny + path "*.version.txt", emit: version + + script: + def software = getSoftwareName(task.process) + def fconst_args = constant_sites ? '-fconst $constant_sites' : '' + def memory = task.memory.toString().replaceAll(' ', '') + """ + iqtree \\ + $fconst_args \\ + $options.args \\ + -s $alignment \\ + -nt AUTO \\ + -ntmax $task.cpus \\ + -mem $memory \\ + + echo \$(iqtree -version 2>&1) | sed 's/^IQ-TREE multicore version \\([0-9\\.]*\\) .*\$/\\1/' > ${software}.version.txt + """ +} diff --git a/software/iqtree/meta.yml b/software/iqtree/meta.yml new file mode 100644 index 00000000..19f81b15 --- /dev/null +++ b/software/iqtree/meta.yml @@ -0,0 +1,34 @@ +name: iqtree +description: Produces a Newick format phylogeny from a multiple sequence alignment using the maxium likelihood algorithm. Capable of bacterial genome size alignments. +keywords: + - phylogeny + - newick + - maximum likelihood +tools: + - iqtree: + description: Efficient phylogenomic software by maximum likelihood. + homepage: http://www.iqtree.org + documentation: http://www.iqtree.org/doc + tool_dev_url: https://github.com/iqtree/iqtree2 + doi: doi.org/10.1093/molbev/msaa015 + 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: "*.{treefile}" + +authors: + - "@avantonder" + - "@aunderwo" diff --git a/tests/config/pytest_software.yml b/tests/config/pytest_software.yml index 774815bb..8b7a1587 100644 --- a/tests/config/pytest_software.yml +++ b/tests/config/pytest_software.yml @@ -277,6 +277,10 @@ homer/annotatepeaks: - software/homer/annotatepeaks/** - tests/software/homer/annotatepeaks/** +iqtree: + - software/iqtree/** + - tests/software/iqtree/** + ivar/consensus: - software/ivar/consensus/** - tests/software/ivar/consensus/** diff --git a/tests/software/iqtree/main.nf b/tests/software/iqtree/main.nf new file mode 100644 index 00000000..8191ea6a --- /dev/null +++ b/tests/software/iqtree/main.nf @@ -0,0 +1,12 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { IQTREE } from '../../../software/iqtree/main.nf' addParams( options: [:] ) + +workflow test_iqtree { + + input = [ file(params.test_data['sarscov2']['genome']['informative_sites_fas'], checkIfExists: true) ] + + IQTREE ( input, '' ) +} diff --git a/tests/software/iqtree/test.yml b/tests/software/iqtree/test.yml new file mode 100644 index 00000000..6c3fb407 --- /dev/null +++ b/tests/software/iqtree/test.yml @@ -0,0 +1,11 @@ +- name: iqtree + command: nextflow run ./tests/software/iqtree -entry test_iqtree -c tests/config/nextflow.config + tags: + - iqtree + files: + - path: output/iqtree/informative_sites.fas.treefile + contains: + - '(sample1:0.002' + - '(sample2:0.005' + - 'sample3:0.0005' + - 'sample4:0.001'