From ca53f7525b20bc021f37a8f841ba979fdd6aef49 Mon Sep 17 00:00:00 2001 From: Stephen Ficklin Date: Thu, 23 Sep 2021 01:13:04 -0700 Subject: [PATCH] Diamond (#710) * Added diamond * minor tweaks & yml fix * Fixed spacing issues due to failing lint * Update modules/diamond/blastp/main.nf Co-authored-by: Harshil Patel * Update modules/diamond/blastp/main.nf Co-authored-by: Harshil Patel * Update modules/diamond/blastp/main.nf Co-authored-by: Harshil Patel * Update modules/diamond/blastp/main.nf Co-authored-by: Harshil Patel * Update modules/diamond/blastp/main.nf Co-authored-by: Harshil Patel * Update modules/diamond/blastx/main.nf Co-authored-by: Harshil Patel * Update modules/diamond/blastx/main.nf Co-authored-by: Harshil Patel * Update modules/diamond/blastx/main.nf Co-authored-by: Harshil Patel * Update modules/diamond/blastx/main.nf Co-authored-by: Harshil Patel * Update modules/diamond/makedb/main.nf Co-authored-by: Harshil Patel * Update modules/diamond/makedb/main.nf Co-authored-by: Harshil Patel * Update tests/modules/diamond/blastp/main.nf Co-authored-by: Harshil Patel * Update tests/modules/diamond/blastx/main.nf Co-authored-by: Harshil Patel * Update tests/modules/diamond/blastx/main.nf Co-authored-by: Harshil Patel * Update tests/modules/diamond/blastp/main.nf Co-authored-by: Harshil Patel * Update modules/diamond/blastp/meta.yml Co-authored-by: Harshil Patel Co-authored-by: Harshil Patel --- modules/diamond/blastp/functions.nf | 68 +++++++++++++++++++++++++++ modules/diamond/blastp/main.nf | 47 ++++++++++++++++++ modules/diamond/blastp/meta.yml | 43 +++++++++++++++++ modules/diamond/blastx/functions.nf | 68 +++++++++++++++++++++++++++ modules/diamond/blastx/main.nf | 47 ++++++++++++++++++ modules/diamond/blastx/meta.yml | 43 +++++++++++++++++ modules/diamond/makedb/functions.nf | 68 +++++++++++++++++++++++++++ modules/diamond/makedb/main.nf | 42 +++++++++++++++++ modules/diamond/makedb/meta.yml | 34 ++++++++++++++ tests/config/pytest_modules.yml | 12 +++++ tests/modules/diamond/blastp/main.nf | 15 ++++++ tests/modules/diamond/blastp/test.yml | 8 ++++ tests/modules/diamond/blastx/main.nf | 15 ++++++ tests/modules/diamond/blastx/test.yml | 8 ++++ tests/modules/diamond/makedb/main.nf | 12 +++++ tests/modules/diamond/makedb/test.yml | 8 ++++ 16 files changed, 538 insertions(+) create mode 100644 modules/diamond/blastp/functions.nf create mode 100644 modules/diamond/blastp/main.nf create mode 100644 modules/diamond/blastp/meta.yml create mode 100644 modules/diamond/blastx/functions.nf create mode 100644 modules/diamond/blastx/main.nf create mode 100644 modules/diamond/blastx/meta.yml create mode 100644 modules/diamond/makedb/functions.nf create mode 100644 modules/diamond/makedb/main.nf create mode 100644 modules/diamond/makedb/meta.yml create mode 100644 tests/modules/diamond/blastp/main.nf create mode 100644 tests/modules/diamond/blastp/test.yml create mode 100644 tests/modules/diamond/blastx/main.nf create mode 100644 tests/modules/diamond/blastx/test.yml create mode 100644 tests/modules/diamond/makedb/main.nf create mode 100644 tests/modules/diamond/makedb/test.yml diff --git a/modules/diamond/blastp/functions.nf b/modules/diamond/blastp/functions.nf new file mode 100644 index 00000000..da9da093 --- /dev/null +++ b/modules/diamond/blastp/functions.nf @@ -0,0 +1,68 @@ +// +// 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/modules/diamond/blastp/main.nf b/modules/diamond/blastp/main.nf new file mode 100644 index 00000000..88ace780 --- /dev/null +++ b/modules/diamond/blastp/main.nf @@ -0,0 +1,47 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process DIAMOND_BLASTP { + 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']) } + + // Dimaond is limited to v2.0.9 because there is not a + // singularity version higher than this at the current time. + conda (params.enable_conda ? "bioconda::diamond=2.0.9" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container 'https://depot.galaxyproject.org/singularity/diamond:2.0.9--hdcc8f71_0' + } else { + container "quay.io/biocontainers/diamond:2.0.9--hdcc8f71_0" + } + + input: + tuple val(meta), path(fasta) + path db + + output: + tuple val(meta), path('*.txt'), emit: txt + path '*.version.txt' , emit: version + + script: + def software = getSoftwareName(task.process) + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + """ + DB=`find -L ./ -name "*.dmnd" | sed 's/.dmnd//'` + + diamond \\ + blastp \\ + --threads $task.cpus \\ + --db \$DB \\ + --query $fasta \\ + $options.args \\ + --out ${prefix}.txt + + echo \$(diamond --version 2>&1) | tail -n 1 | sed 's/^diamond version //' > ${software}.version.txt + """ +} diff --git a/modules/diamond/blastp/meta.yml b/modules/diamond/blastp/meta.yml new file mode 100644 index 00000000..b6e82f95 --- /dev/null +++ b/modules/diamond/blastp/meta.yml @@ -0,0 +1,43 @@ +name: diamond_blastp +description: Queries a DIAMOND database using blastp mode +keywords: + - fasta + - diamond + - blastp + - DNA sequence +tools: + - diamond: + description: Accelerated BLAST compatible local sequence aligner + homepage: https://github.com/bbuchfink/diamond + documentation: https://github.com/bbuchfink/diamond/wiki + tool_dev_url: https://github.com/bbuchfink/diamond + doi: "doi:10.1038/s41592-021-01101-x" + licence: ['GPL v3.0'] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - fasta: + type: file + description: Input fasta file containing query sequences + pattern: "*.{fa,fasta}" + - db: + type: directory + description: Directory containing the protein blast database + pattern: "*" + +output: + - txt: + type: file + description: File containing blastp hits + pattern: "*.{blastp.txt}" + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" + +authors: + - "@spficklin" diff --git a/modules/diamond/blastx/functions.nf b/modules/diamond/blastx/functions.nf new file mode 100644 index 00000000..da9da093 --- /dev/null +++ b/modules/diamond/blastx/functions.nf @@ -0,0 +1,68 @@ +// +// 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/modules/diamond/blastx/main.nf b/modules/diamond/blastx/main.nf new file mode 100644 index 00000000..cd9e4838 --- /dev/null +++ b/modules/diamond/blastx/main.nf @@ -0,0 +1,47 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process DIAMOND_BLASTX { + 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']) } + + // Dimaond is limited to v2.0.9 because there is not a + // singularity version higher than this at the current time. + conda (params.enable_conda ? "bioconda::diamond=2.0.9" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container 'https://depot.galaxyproject.org/singularity/diamond:2.0.9--hdcc8f71_0' + } else { + container "quay.io/biocontainers/diamond:2.0.9--hdcc8f71_0" + } + + input: + tuple val(meta), path(fasta) + path db + + output: + tuple val(meta), path('*.txt'), emit: txt + path '*.version.txt' , emit: version + + script: + def software = getSoftwareName(task.process) + def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}" + """ + DB=`find -L ./ -name "*.dmnd" | sed 's/.dmnd//'` + + diamond \\ + blastx \\ + --threads $task.cpus \\ + --db \$DB \\ + --query $fasta \\ + $options.args \\ + --out ${prefix}.txt + + echo \$(diamond --version 2>&1) | tail -n 1 | sed 's/^diamond version //' > ${software}.version.txt + """ +} diff --git a/modules/diamond/blastx/meta.yml b/modules/diamond/blastx/meta.yml new file mode 100644 index 00000000..d9670bed --- /dev/null +++ b/modules/diamond/blastx/meta.yml @@ -0,0 +1,43 @@ +name: diamond_blastx +description: Queries a DIAMOND database using blastx mode +keywords: + - fasta + - diamond + - blastx + - DNA sequence +tools: + - diamond: + description: Accelerated BLAST compatible local sequence aligner + homepage: https://github.com/bbuchfink/diamond + documentation: https://github.com/bbuchfink/diamond/wiki + tool_dev_url: https://github.com/bbuchfink/diamond + doi: "doi:10.1038/s41592-021-01101-x" + licence: ['GPL v3.0'] + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - fasta: + type: file + description: Input fasta file containing query sequences + pattern: "*.{fa,fasta}" + - db: + type: directory + description: Directory containing the nucelotide blast database + pattern: "*" + +output: + - txt: + type: file + description: File containing blastx hits + pattern: "*.{blastx.txt}" + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" + +authors: + - "@spficklin" diff --git a/modules/diamond/makedb/functions.nf b/modules/diamond/makedb/functions.nf new file mode 100644 index 00000000..da9da093 --- /dev/null +++ b/modules/diamond/makedb/functions.nf @@ -0,0 +1,68 @@ +// +// 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/modules/diamond/makedb/main.nf b/modules/diamond/makedb/main.nf new file mode 100644 index 00000000..3537d0aa --- /dev/null +++ b/modules/diamond/makedb/main.nf @@ -0,0 +1,42 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process DIAMOND_MAKEDB { + tag "$fasta" + 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:[]) } + + // Dimaond is limited to v2.0.9 because there is not a + // singularity version higher than this at the current time. + conda (params.enable_conda ? 'bioconda::diamond=2.0.9' : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container 'https://depot.galaxyproject.org/singularity/diamond:2.0.9--hdcc8f71_0' + } else { + container 'quay.io/biocontainers/diamond:2.0.9--hdcc8f71_0' + } + + input: + path fasta + + output: + path "${fasta}.dmnd", emit: db + path '*.version.txt', emit: version + + script: + def software = getSoftwareName(task.process) + """ + diamond \\ + makedb \\ + --threads $task.cpus \\ + --in $fasta \\ + -d $fasta \\ + $options.args + + echo \$(diamond --version 2>&1) | tail -n 1 | sed 's/^diamond version //' > ${software}.version.txt + """ +} diff --git a/modules/diamond/makedb/meta.yml b/modules/diamond/makedb/meta.yml new file mode 100644 index 00000000..edb63fab --- /dev/null +++ b/modules/diamond/makedb/meta.yml @@ -0,0 +1,34 @@ +name: diamond_makedb +description: Builds a DIAMOND database +keywords: + - fasta + - diamond + - index + - database +tools: + - diamond: + description: Accelerated BLAST compatible local sequence aligner + homepage: https://github.com/bbuchfink/diamond + documentation: https://github.com/bbuchfink/diamond/wiki + tool_dev_url: https://github.com/bbuchfink/diamond + doi: "doi:10.1038/s41592-021-01101-x" + licence: ['GPL v3.0'] + +input: + - fasta: + type: file + description: Input fasta file + pattern: "*.{fa,fasta}" + +output: + - db: + type: file + description: File of the indexed DIAMOND database + pattern: "*.{dmnd}" + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" + +authors: + - "@spficklin" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index 5307d684..74673511 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -286,6 +286,18 @@ delly/call: - modules/delly/call/** - tests/modules/delly/call/** +diamond/blastx: + - modules/diamond/blastx/** + - tests/modules/diamond/blastx/** + +diamond/blastp: + - modules/diamond/blastp/** + - tests/modules/diamond/blastp/** + +diamond/makedb: + - modules/diamond/makedb/** + - tests/modules/diamond/makedb/** + dragonflye: - modules/dragonflye/** - tests/modules/dragonflye/** diff --git a/tests/modules/diamond/blastp/main.nf b/tests/modules/diamond/blastp/main.nf new file mode 100644 index 00000000..ab131a86 --- /dev/null +++ b/tests/modules/diamond/blastp/main.nf @@ -0,0 +1,15 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { DIAMOND_MAKEDB } from '../../../../modules/diamond/makedb/main.nf' addParams( options: [:] ) +include { DIAMOND_BLASTP } from '../../../../modules/diamond/blastp/main.nf' addParams( options: [ suffix: '.diamond_blastp' ] ) + +workflow test_diamond_blastp { + + db = [ file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) ] + fasta = [ file(params.test_data['sarscov2']['genome']['transcriptome_fasta'], checkIfExists: true) ] + + DIAMOND_MAKEDB ( db ) + DIAMOND_BLASTP ( [ [id:'test'], fasta ], DIAMOND_MAKEDB.out.db ) +} diff --git a/tests/modules/diamond/blastp/test.yml b/tests/modules/diamond/blastp/test.yml new file mode 100644 index 00000000..ae62ea51 --- /dev/null +++ b/tests/modules/diamond/blastp/test.yml @@ -0,0 +1,8 @@ +- name: diamond blastp + command: nextflow run ./tests/modules/diamond/blastp -entry test_diamond_blastp -c tests/config/nextflow.config + tags: + - diamond + - diamond/blastp + files: + - path: ./output/diamond/test.diamond_blastp.txt + md5sum: 3ca7f6290c1d8741c573370e6f8b4db0 diff --git a/tests/modules/diamond/blastx/main.nf b/tests/modules/diamond/blastx/main.nf new file mode 100644 index 00000000..c0e437d7 --- /dev/null +++ b/tests/modules/diamond/blastx/main.nf @@ -0,0 +1,15 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { DIAMOND_MAKEDB } from '../../../../modules/diamond/makedb/main.nf' addParams( options: [:] ) +include { DIAMOND_BLASTX } from '../../../../modules/diamond/blastx/main.nf' addParams( options: [ suffix: '.diamond_blastx' ] ) + +workflow test_diamond_blastx { + + db = [ file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) ] + fasta = [ file(params.test_data['sarscov2']['genome']['transcriptome_fasta'], checkIfExists: true) ] + + DIAMOND_MAKEDB ( db ) + DIAMOND_BLASTX ( [ [id:'test'], fasta ], DIAMOND_MAKEDB.out.db ) +} diff --git a/tests/modules/diamond/blastx/test.yml b/tests/modules/diamond/blastx/test.yml new file mode 100644 index 00000000..91a6eb4f --- /dev/null +++ b/tests/modules/diamond/blastx/test.yml @@ -0,0 +1,8 @@ +- name: diamond blastx + command: nextflow run ./tests/modules/diamond/blastx -entry test_diamond_blastx -c tests/config/nextflow.config + tags: + - diamond + - diamond/blastx + files: + - path: ./output/diamond/test.diamond_blastx.txt + md5sum: d41d8cd98f00b204e9800998ecf8427e diff --git a/tests/modules/diamond/makedb/main.nf b/tests/modules/diamond/makedb/main.nf new file mode 100644 index 00000000..bcd7691e --- /dev/null +++ b/tests/modules/diamond/makedb/main.nf @@ -0,0 +1,12 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { DIAMOND_MAKEDB } from '../../../../modules/diamond/makedb/main.nf' addParams( options: [:] ) + +workflow test_diamond_makedb { + + input = [ file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) ] + + DIAMOND_MAKEDB ( input ) +} diff --git a/tests/modules/diamond/makedb/test.yml b/tests/modules/diamond/makedb/test.yml new file mode 100644 index 00000000..335b571f --- /dev/null +++ b/tests/modules/diamond/makedb/test.yml @@ -0,0 +1,8 @@ +- name: diamond makedb test_diamond_makedb + command: nextflow run ./tests/modules/diamond/makedb -entry test_diamond_makedb -c tests/config/nextflow.config + tags: + - diamond + - diamond/makedb + files: + - path: output/diamond/genome.fasta.dmnd + md5sum: 2447fb376394c20d43ea3aad2aa5d15d