From 12ae7b0bffd6b4928e80996dbb18486c01a072c7 Mon Sep 17 00:00:00 2001 From: JoseEspinosa Date: Tue, 9 Feb 2021 16:58:36 +0100 Subject: [PATCH 1/3] Adding blast blastn module --- .github/filters.yml | 4 ++ software/blast/blastn/functions.nf | 60 +++++++++++++++++++++++++++ software/blast/blastn/main.nf | 42 +++++++++++++++++++ software/blast/blastn/meta.yml | 61 ++++++++++++++++++++++++++++ tests/software/blast/blastn/main.nf | 15 +++++++ tests/software/blast/blastn/test.yml | 22 ++++++++++ 6 files changed, 204 insertions(+) create mode 100644 software/blast/blastn/functions.nf create mode 100644 software/blast/blastn/main.nf create mode 100644 software/blast/blastn/meta.yml create mode 100644 tests/software/blast/blastn/main.nf create mode 100644 tests/software/blast/blastn/test.yml diff --git a/.github/filters.yml b/.github/filters.yml index c28e1dbc..51fbfa76 100644 --- a/.github/filters.yml +++ b/.github/filters.yml @@ -58,6 +58,10 @@ blast_makeblastdb: - software/blast/makeblastdb/** - tests/software/blast/makeblastdb** +blast_makeblastdb: + - software/blast/blastn/** + - tests/software/blast/blastn** + bowtie: - software/bowtie/build/** - tests/software/bowtie/build/** diff --git a/software/blast/blastn/functions.nf b/software/blast/blastn/functions.nf new file mode 100644 index 00000000..6f3b4b29 --- /dev/null +++ b/software/blast/blastn/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/blastn/main.nf b/software/blast/blastn/main.nf new file mode 100644 index 00000000..ec02f609 --- /dev/null +++ b/software/blast/blastn/main.nf @@ -0,0 +1,42 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +def options = initOptions(params.options) + +process BLAST_BLASTN { + 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), publish_id:meta.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: + tuple val(meta), path(fasta) + path db + + output: + tuple val(meta), path('*.blastn.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 "*.ndb" | sed 's/.ndb//'` + blastn \\ + -num_threads $task.cpus \\ + -db \$DB \\ + -query $fasta \\ + $options.args \\ + -out ${prefix}.blastn.txt + echo \$(blastn -version 2>&1) | sed 's/^.*blastn: //; s/ .*\$//' > ${software}.version.txt + """ +} diff --git a/software/blast/blastn/meta.yml b/software/blast/blastn/meta.yml new file mode 100644 index 00000000..41dd872d --- /dev/null +++ b/software/blast/blastn/meta.yml @@ -0,0 +1,61 @@ +name: blast_blastn +description: Queries a BLAST DNA database +keywords: + - fasta + - blast + - blastn + - DNA sequence +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: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - fasta: + type: file + description: Input fasta file containing queries sequences + pattern: "*.{fa,fasta}" + - db: + type: directory + description: Directory containing blast database + pattern: "*" +output: + - txt: + type: file + description: File containing blastn hits + pattern: "*.{blastn.txt}" + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" +authors: + - "@joseespinosa" + - "@drpatelh" diff --git a/tests/software/blast/blastn/main.nf b/tests/software/blast/blastn/main.nf new file mode 100644 index 00000000..f2f4d6c4 --- /dev/null +++ b/tests/software/blast/blastn/main.nf @@ -0,0 +1,15 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { BLAST_MAKEBLASTDB } from '../../../../software/blast/makeblastdb/main.nf' addParams( options: ['args': '-dbtype nucl'] ) +include { BLAST_BLASTN } from '../../../../software/blast/blastn/main.nf' addParams( options: [:] ) + +workflow test_blast_blastn { + + def input = [] + input = [ file("${launchDir}/tests/data/fasta/E_coli/NC_010473.fa", checkIfExists: true) ] + + BLAST_MAKEBLASTDB (input) + BLAST_BLASTN ([ [id:'test'], input ], BLAST_MAKEBLASTDB.out.db) +} diff --git a/tests/software/blast/blastn/test.yml b/tests/software/blast/blastn/test.yml new file mode 100644 index 00000000..e14cd8a5 --- /dev/null +++ b/tests/software/blast/blastn/test.yml @@ -0,0 +1,22 @@ +- name: blast_blastn + command: nextflow run ./tests/software/blast/blastn -entry test_blast_blastn -c tests/config/nextflow.config + tags: + - blast + - blast_blastn + 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 + - path: output/blast/test.blastn.txt + should_exist: true From 9a11e90892086eef424c6691f9989a58a167ec5c Mon Sep 17 00:00:00 2001 From: JoseEspinosa Date: Tue, 9 Feb 2021 17:07:23 +0100 Subject: [PATCH 2/3] Fixing tests --- .github/filters.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/filters.yml b/.github/filters.yml index 51fbfa76..a3d567ec 100644 --- a/.github/filters.yml +++ b/.github/filters.yml @@ -58,7 +58,7 @@ blast_makeblastdb: - software/blast/makeblastdb/** - tests/software/blast/makeblastdb** -blast_makeblastdb: +blast_blastn: - software/blast/blastn/** - tests/software/blast/blastn** From 1e9b88b33c8b6b108f7c7bfa79daa808bcca93b4 Mon Sep 17 00:00:00 2001 From: JoseEspinosa Date: Tue, 9 Feb 2021 18:16:16 +0100 Subject: [PATCH 3/3] Fixing trailing slashes in .github/filters.yml --- .github/filters.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/filters.yml b/.github/filters.yml index a3d567ec..83216113 100644 --- a/.github/filters.yml +++ b/.github/filters.yml @@ -4,27 +4,27 @@ bandage_image: bcftools_bgzip: - software/bcftools/bgzip/** - - tests/software/bcftools/bgzip** + - tests/software/bcftools/bgzip/** bcftools_consensus: - software/bcftools/consensus/** - - tests/software/bcftools/consensus** + - tests/software/bcftools/consensus/** bcftools_filter: - software/bcftools/filter/** - - tests/software/bcftools/filter** + - tests/software/bcftools/filter/** bcftools_isec: - software/bcftools/isec/** - - tests/software/bcftools/isec** + - tests/software/bcftools/isec/** bcftools_stats: - software/bcftools/stats/** - - tests/software/bcftools/stats** + - tests/software/bcftools/stats/** bcftools_tabix: - software/bcftools/tabix/** - - tests/software/bcftools/tabix** + - tests/software/bcftools/tabix/** bedtools_complement: - software/bedtools/complement/** @@ -56,11 +56,11 @@ bedtools_sort: blast_makeblastdb: - software/blast/makeblastdb/** - - tests/software/blast/makeblastdb** + - tests/software/blast/makeblastdb/** blast_blastn: - software/blast/blastn/** - - tests/software/blast/blastn** + - tests/software/blast/blastn/** bowtie: - software/bowtie/build/**