diff --git a/software/nextclade/functions.nf b/software/nextclade/functions.nf new file mode 100755 index 00000000..9d0137e3 --- /dev/null +++ b/software/nextclade/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/nextclade/main.nf b/software/nextclade/main.nf new file mode 100755 index 00000000..49161732 --- /dev/null +++ b/software/nextclade/main.nf @@ -0,0 +1,55 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process NEXTCLADE { + 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::nextclade_js=0.14.2" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/nextclade_js:0.14.2--h9ee0642_0" + } else { + container "quay.io/biocontainers/nextclade_js:0.14.2--h9ee0642_0" + } + + input: + tuple val(meta), path(fasta) + val output_format + + output: + tuple val(meta), path("${prefix}.csv") , optional:true, emit: csv + tuple val(meta), path("${prefix}.json") , optional:true, emit: json + tuple val(meta), path("${prefix}.tree.json") , optional:true, emit: json_tree + tuple val(meta), path("${prefix}.tsv") , optional:true, emit: tsv + tuple val(meta), path("${prefix}.clades.tsv"), optional:true, emit: tsv_clades + path "*.version.txt" , emit: version + + script: + def software = getSoftwareName(task.process) + prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + def format = output_format + if (!(format in ['json', 'csv', 'tsv', 'tree', 'tsv-clades-only'])) { + format = 'json' + } + def extension = format + if (format in ['tsv-clades-only']) { + extension = '.clades.tsv' + } else if (format in ['tree']) { + extension = 'tree.json' + } + """ + nextclade \\ + $options.args \\ + --jobs $task.cpus \\ + --input-fasta $fasta \\ + --output-${format} ${prefix}.${extension} + + echo \$(nextclade --version 2>&1) > ${software}.version.txt + """ +} diff --git a/software/nextclade/meta.yml b/software/nextclade/meta.yml new file mode 100755 index 00000000..8e0eabd7 --- /dev/null +++ b/software/nextclade/meta.yml @@ -0,0 +1,64 @@ +name: nextclade +description: SARS-CoV-2 genome clade assignment, mutation calling, and sequence quality checks (Javascript implementation) +keywords: + - nextclade + - variant + - consensus +tools: + - nextclade: + description: SARS-CoV-2 genome clade assignment, mutation calling, and sequence quality checks (Javascript implementation) + homepage: https://clades.nextstrain.org + documentation: None + tool_dev_url: https://github.com/nextstrain/nextclade + doi: "" + licence: ['MIT'] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - fasta: + type: file + description: FASTA file containing one or more consensus sequences + pattern: "*.{fasta,fa}" + - output_format: + type: string + description: | + String for output format supported by nextclade + i.e one of 'json', 'csv', 'tsv', 'tree', 'tsv-clades-only' + +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}" + - csv: + type: file + description: CSV file containing nextclade results + pattern: "*.{csv}" + - json: + type: file + description: JSON file containing nextclade results + pattern: "*.{json}" + - json_tree: + type: file + description: Auspice JSON V2 containing nextclade results + pattern: "*.{tree.json}" + - tsv: + type: file + description: TSV file containing nextclade results + pattern: "*.{tsv}" + - tsv_clades: + type: file + description: TSV file containing nextclade results for clades only + pattern: "*.{clades.tsv}" + +authors: + - "@drpatelh" diff --git a/software/pangolin/main.nf b/software/pangolin/main.nf index facc7406..c78bef20 100644 --- a/software/pangolin/main.nf +++ b/software/pangolin/main.nf @@ -11,11 +11,11 @@ process PANGOLIN { 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::pangolin=2.3.8' : null) + conda (params.enable_conda ? 'bioconda::pangolin=2.4.2' : null) if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { - container 'https://depot.galaxyproject.org/singularity/pangolin:2.3.8--py_0' + container 'https://depot.galaxyproject.org/singularity/pangolin:2.4.2--pyhdfd78af_0' } else { - container 'quay.io/biocontainers/pangolin:2.3.8--py_0' + container 'quay.io/biocontainers/pangolin:2.4.2--pyhdfd78af_0' } input: diff --git a/tests/config/pytest_software.yml b/tests/config/pytest_software.yml index 016f6659..6fecac34 100644 --- a/tests/config/pytest_software.yml +++ b/tests/config/pytest_software.yml @@ -411,6 +411,10 @@ nanoplot: - software/nanoplot/** - tests/software/nanoplot/** +nextclade: + - software/nextclade/** + - tests/software/nextclade/** + optitype: - software/optitype/** - tests/software/optitype/** diff --git a/tests/software/nextclade/main.nf b/tests/software/nextclade/main.nf new file mode 100755 index 00000000..c86c9ce7 --- /dev/null +++ b/tests/software/nextclade/main.nf @@ -0,0 +1,33 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { NEXTCLADE } from '../../../software/nextclade/main.nf' addParams( options: [:] ) + +workflow test_nextclade_json { + input = [ [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) + ] + NEXTCLADE ( input, 'json' ) +} + +workflow test_nextclade_csv { + input = [ [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) + ] + NEXTCLADE ( input, 'csv' ) +} + +workflow test_nextclade_tsv { + input = [ [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) + ] + NEXTCLADE ( input, 'tsv' ) +} + +workflow test_nextclade_tree { + input = [ [ id:'test', single_end:false ], // meta map + file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) + ] + NEXTCLADE ( input, 'tree' ) +} diff --git a/tests/software/nextclade/test.yml b/tests/software/nextclade/test.yml new file mode 100755 index 00000000..2544f233 --- /dev/null +++ b/tests/software/nextclade/test.yml @@ -0,0 +1,31 @@ +- name: nextclade test_nextclade_json + command: nextflow run tests/software/nextclade -entry test_nextclade_json -c tests/config/nextflow.config + tags: + - nextclade + files: + - path: output/nextclade/test.json + md5sum: cab92830c5cb66076e7d6c054ea98362 + +- name: nextclade test_nextclade_csv + command: nextflow run tests/software/nextclade -entry test_nextclade_csv -c tests/config/nextflow.config + tags: + - nextclade + files: + - path: output/nextclade/test.csv + md5sum: 4f7096df9be51f99a0d62a38653b29cf + +- name: nextclade test_nextclade_tsv + command: nextflow run tests/software/nextclade -entry test_nextclade_tsv -c tests/config/nextflow.config + tags: + - nextclade + files: + - path: output/nextclade/test.tsv + md5sum: fe07dc4ffcd81742ca9bef93f88e8836 + +- name: nextclade test_nextclade_tree + command: nextflow run tests/software/nextclade -entry test_nextclade_tree -c tests/config/nextflow.config + tags: + - nextclade + files: + - path: output/nextclade/test.tree.json + md5sum: 508a6ea19daf98fd8ae9f2d470f8c3cd diff --git a/tests/software/pangolin/test.yml b/tests/software/pangolin/test.yml index ea7a0b71..8ff2816f 100644 --- a/tests/software/pangolin/test.yml +++ b/tests/software/pangolin/test.yml @@ -4,4 +4,4 @@ - pangolin files: - path: ./output/pangolin/test.pangolin.csv - md5sum: c8b1720f98c9e032908f61bbc05a0fe2 + md5sum: 57f6e1df5caa2515b0f1cefedeed6770