diff --git a/software/minimap2/index/functions.nf b/software/minimap2/index/functions.nf new file mode 100644 index 00000000..9d0137e3 --- /dev/null +++ b/software/minimap2/index/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/minimap2/index/main.nf b/software/minimap2/index/main.nf new file mode 100644 index 00000000..43c9c255 --- /dev/null +++ b/software/minimap2/index/main.nf @@ -0,0 +1,32 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +def options = initOptions(params.options) + +process MINIMAP2_INDEX { + 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:['']) } + + conda (params.enable_conda ? "bioconda::minimap2=2.17" : null) + container "quay.io/biocontainers/minimap2:2.17--hed695b0_3" + + input: + path(fasta) + + output: + path("*.mmi") , emit: index + path "*.version.txt" ,emit: version + + script: + """ + minimap2 \\ + -t $task.cpus \\ + -d ${fasta}.mmi \\ + $fasta + ps + minimap2 --version &> minimap2.version.txt + """ +} diff --git a/software/minimap2/index/meta.yml b/software/minimap2/index/meta.yml new file mode 100644 index 00000000..8273e239 --- /dev/null +++ b/software/minimap2/index/meta.yml @@ -0,0 +1,28 @@ +name: minimap2_index +description: Provides fasta index required by minimap2 alignment. +keywords: + - index + - fasta + - reference +tools: + - minimap2: + description: | + A versatile pairwise aligner for genomic and spliced nucleotide sequences. + homepage: https://github.com/lh3/minimap2 + documentation: https://github.com/lh3/minimap2#uguide +input: + - fasta: + type: file + description: | + Reference database in FASTA format. +output: + - mmi: + type: file + description: Minimap2 fasta index. + pattern: "*.mmi" + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" +authors: + - "@yuukiiwa" diff --git a/tests/config/pytest_software.yml b/tests/config/pytest_software.yml index 9e3df76b..e75f8774 100644 --- a/tests/config/pytest_software.yml +++ b/tests/config/pytest_software.yml @@ -358,6 +358,10 @@ minimap2/align: - software/minimap2/align/** - tests/software/minimap2/align/** +minimap2/index: + - software/minimap2/index/** + - tests/software/minimap2/index/** + mosdepth: - software/mosdepth/** - tests/software/mosdepth/** diff --git a/tests/software/minimap2/index/main.nf b/tests/software/minimap2/index/main.nf new file mode 100644 index 00000000..6949f587 --- /dev/null +++ b/tests/software/minimap2/index/main.nf @@ -0,0 +1,12 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { MINIMAP2_INDEX } from '../../../../software/minimap2/index/main.nf' addParams( options: [:] ) + +workflow test_minimap2_index { + + fasta = file(params.test_data['sarscov2']['genome']['genome_fasta'], checkIfExists: true) + + MINIMAP2_INDEX ( fasta ) +} diff --git a/tests/software/minimap2/index/test.yml b/tests/software/minimap2/index/test.yml new file mode 100644 index 00000000..c455b94f --- /dev/null +++ b/tests/software/minimap2/index/test.yml @@ -0,0 +1,8 @@ +- name: minimap2 index + command: nextflow run ./tests/software/minimap2/index -entry test_minimap2_index -c tests/config/nextflow.config + tags: + - minimap2 + - minimap2/index + files: + - path: ./output/minimap2/genome.fasta.mmi + md5sum: 72e450f12dc691e763c697463bdb1571