From 22eaefe5833453918842d706884e52a888414a2e Mon Sep 17 00:00:00 2001 From: Gisela Gabernet Date: Wed, 24 Mar 2021 13:25:39 +0100 Subject: [PATCH] Add module kallisto/index (#357) * add kallisto index module * update kallisto module * add kallisto module tests * update kallisto index test.yml * update test data paths * fix version * fix kallisto index test yml * remove TODOs * Update software/kallisto/index/main.nf Co-authored-by: Harshil Patel * Update software/kallisto/index/main.nf Co-authored-by: Harshil Patel * output folder instead Co-authored-by: Harshil Patel --- software/kallisto/index/functions.nf | 60 ++++++++++++++++++++++++++ software/kallisto/index/main.nf | 39 +++++++++++++++++ software/kallisto/index/meta.yml | 31 +++++++++++++ tests/config/pytest_software.yml | 4 ++ tests/software/kallisto/index/main.nf | 13 ++++++ tests/software/kallisto/index/test.yml | 8 ++++ 6 files changed, 155 insertions(+) create mode 100644 software/kallisto/index/functions.nf create mode 100644 software/kallisto/index/main.nf create mode 100644 software/kallisto/index/meta.yml create mode 100644 tests/software/kallisto/index/main.nf create mode 100644 tests/software/kallisto/index/test.yml diff --git a/software/kallisto/index/functions.nf b/software/kallisto/index/functions.nf new file mode 100644 index 00000000..f177f0c8 --- /dev/null +++ b/software/kallisto/index/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.args3 = args.args3 ?: '' + 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/kallisto/index/main.nf b/software/kallisto/index/main.nf new file mode 100644 index 00000000..bf3f2415 --- /dev/null +++ b/software/kallisto/index/main.nf @@ -0,0 +1,39 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process KALLISTO_INDEX { + 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::kallisto=0.46.2" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/kallisto:0.46.2--h4f7b962_1" + } else { + container "quay.io/biocontainers/kallisto:0.46.2--h4f7b962_1" + } + + input: + path fasta + + output: + path "kallisto" , emit: idx + path "*.version.txt", emit: version + + script: + def software = getSoftwareName(task.process) + """ + kallisto \\ + index \\ + $options.args \\ + -i kallisto \\ + $fasta + + echo \$(kallisto 2>&1) | sed 's/^kallisto //; s/Usage.*\$//' > ${software}.version.txt + """ +} diff --git a/software/kallisto/index/meta.yml b/software/kallisto/index/meta.yml new file mode 100644 index 00000000..24b44b0b --- /dev/null +++ b/software/kallisto/index/meta.yml @@ -0,0 +1,31 @@ +name: kallisto_index +description: write your description here +keywords: + - sort +tools: + - kallisto: + description: Quantifying abundances of transcripts from bulk and single-cell RNA-Seq data, or more generally of target sequences using high-throughput sequencing reads. + homepage: https://pachterlab.github.io/kallisto/ + documentation: https://pachterlab.github.io/kallisto/manual + tool_dev_url: https://github.com/pachterlab/kallisto + doi: "" + licence: ['BSD_2_clause'] + +input: + - fasta: + type: file + description: genome fasta file + pattern: "*.{fasta}" + +output: + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" + - idx: + type: index + description: Kallisto genome index + pattern: "*.idx" + +authors: + - "@ggabernet" diff --git a/tests/config/pytest_software.yml b/tests/config/pytest_software.yml index 78fabf1e..2c21467e 100755 --- a/tests/config/pytest_software.yml +++ b/tests/config/pytest_software.yml @@ -250,6 +250,10 @@ ivar_variants: - software/ivar/variants/** - tests/software/ivar/variants/** +kallisto_index: + - software/kallisto/index/** + - tests/software/kallisto/index/** + kraken2_run: - software/kraken2/run/** - tests/software/kraken2/run/** diff --git a/tests/software/kallisto/index/main.nf b/tests/software/kallisto/index/main.nf new file mode 100644 index 00000000..90a8f657 --- /dev/null +++ b/tests/software/kallisto/index/main.nf @@ -0,0 +1,13 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { KALLISTO_INDEX } from '../../../../software/kallisto/index/main.nf' addParams( options: [:] ) + +workflow test_kallisto_index { + + def input = [] + input = file("${launchDir}/tests/data/genomics/sarscov2/genome/genome.fasta", checkIfExists: true) + + KALLISTO_INDEX ( input ) +} diff --git a/tests/software/kallisto/index/test.yml b/tests/software/kallisto/index/test.yml new file mode 100644 index 00000000..afbe1d7d --- /dev/null +++ b/tests/software/kallisto/index/test.yml @@ -0,0 +1,8 @@ +- name: kallisto index test_kallisto_index + command: nextflow run tests/software/kallisto/index -entry test_kallisto_index -c tests/config/nextflow.config + tags: + - kallisto + - kallisto_index + files: + - path: output/kallisto/kallisto + md5sum: bf8a58d329dddc96f0c32f7823bc0310