diff --git a/.github/filters.yml b/.github/filters.yml index b7b50b7c..c28e1dbc 100644 --- a/.github/filters.yml +++ b/.github/filters.yml @@ -54,6 +54,10 @@ bedtools_sort: - software/bedtools/sort/** - tests/software/bedtools/sort/** +blast_makeblastdb: + - software/blast/makeblastdb/** + - tests/software/blast/makeblastdb** + bowtie: - software/bowtie/build/** - tests/software/bowtie/build/** diff --git a/software/blast/makeblastdb/functions.nf b/software/blast/makeblastdb/functions.nf new file mode 100644 index 00000000..6f3b4b29 --- /dev/null +++ b/software/blast/makeblastdb/functions.nf @@ -0,0 +1,60 @@ + +/* + * ----------------------------------------------------- + * 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.publish_by_id = args.publish_by_id ?: false + 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_id) { + path_list.add(args.publish_id) + } + 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/blast/makeblastdb/main.nf b/software/blast/makeblastdb/main.nf new file mode 100644 index 00000000..c79b99da --- /dev/null +++ b/software/blast/makeblastdb/main.nf @@ -0,0 +1,38 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +def options = initOptions(params.options) + +process BLAST_MAKEBLASTDB { + 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), publish_id:'') } + + conda (params.enable_conda ? 'bioconda::blast=2.10.1' : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container 'https://depot.galaxyproject.org/singularity/blast:2.10.1--pl526he19e7b1_3' + } else { + container 'quay.io/biocontainers/blast:2.10.1--pl526he19e7b1_3' + } + + input: + path fasta + + output: + path 'blast_db' , emit: db + path '*.version.txt', emit: version + + script: + def software = getSoftwareName(task.process) + """ + makeblastdb \\ + -in $fasta \\ + $options.args + mkdir blast_db + mv ${fasta}* blast_db + echo \$(blastn -version 2>&1) | sed 's/^.*blastn: //; s/ .*\$//' > ${software}.version.txt + """ +} diff --git a/software/blast/makeblastdb/meta.yml b/software/blast/makeblastdb/meta.yml new file mode 100644 index 00000000..0629a49a --- /dev/null +++ b/software/blast/makeblastdb/meta.yml @@ -0,0 +1,51 @@ +name: blast_makeblastdb +description: Builds a BLAST database +keywords: + - fasta + - blast + - database +tools: + - blast: + description: | + BLAST finds regions of similarity between biological sequences. + homepage: https://blast.ncbi.nlm.nih.gov/Blast.cgi + documentation: https://blast.ncbi.nlm.nih.gov/Blast.cgi?CMD=Web&PAGE_TYPE=Blastdocs + doi: 10.1016/S0022-2836(05)80360-2 +params: + - outdir: + type: string + description: | + The pipeline's output directory. By default, the module will + output files into `$params.outdir/` + - publish_dir_mode: + type: string + description: | + Value for the Nextflow `publishDir` mode parameter. + Available: symlink, rellink, link, copy, copyNoFollow, move. + - enable_conda: + type: boolean + description: | + Run the module with Conda using the software specified + via the `conda` directive + - singularity_pull_docker_container: + type: boolean + description: | + Instead of directly downloading Singularity images for use with Singularity, + force the workflow to pull and convert Docker containers instead. +input: + - fasta: + type: file + description: Input fasta file + pattern: "*.{fa,fasta}" +output: + - db: + type: directory + description: Output directory containing blast database files + pattern: "*" + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" +authors: + - "@joseespinosa" + - "@drpatelh" diff --git a/tests/software/blast/makeblastdb/main.nf b/tests/software/blast/makeblastdb/main.nf new file mode 100644 index 00000000..92ce7608 --- /dev/null +++ b/tests/software/blast/makeblastdb/main.nf @@ -0,0 +1,12 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { BLAST_MAKEBLASTDB } from '../../../../software/blast/makeblastdb/main.nf' addParams( options: ['args': '-dbtype nucl'] ) + +workflow test_blast_makeblastdb { + def input = [] + input = [ file("${launchDir}/tests/data/fasta/E_coli/NC_010473.fa", checkIfExists: true) ] + + BLAST_MAKEBLASTDB( input ) +} diff --git a/tests/software/blast/makeblastdb/test.yml b/tests/software/blast/makeblastdb/test.yml new file mode 100644 index 00000000..ae39e6a3 --- /dev/null +++ b/tests/software/blast/makeblastdb/test.yml @@ -0,0 +1,20 @@ +- name: blast_makeblastdb + command: nextflow run ./tests/software/blast/makeblastdb -entry test_blast_makeblastdb -c tests/config/nextflow.config + tags: + - blast + - blast_makeblastdb + files: + - path: output/blast/blast_db/NC_010473.fa + md5sum: ad277e6b3da5dcf9fccfcd3a55fcec8e + - path: output/blast/blast_db/NC_010473.fa.ndb + md5sum: 5fc66e1a2b3b38966eb40ed15642ba3e + - path: output/blast/blast_db/NC_010473.fa.nhr + md5sum: 41702062ff7cce21e0649864013fad73 + - path: output/blast/blast_db/NC_010473.fa.nin + should_exist: true + - path: output/blast/blast_db/NC_010473.fa.not + md5sum: 1e53e9d08f1d23af0299cfa87478a7bb + - path: output/blast/blast_db/NC_010473.fa.nsq + md5sum: 8e2d0c3fc02a8c2c886bafb73bdd8a89 + - path: output/blast/blast_db/NC_010473.fa.ntf + md5sum: 1f6027d443e67a98ad0edc2d39971b0c