From 180b1cf36ba53901fae6cba0ce6acd9771eb8a2e Mon Sep 17 00:00:00 2001 From: phue Date: Wed, 17 Feb 2021 18:03:48 +0100 Subject: [PATCH] add bwameth/index module + test --- .github/filters.yml | 4 ++ software/bwameth/index/functions.nf | 59 +++++++++++++++++++++++++++ software/bwameth/index/main.nf | 35 ++++++++++++++++ software/bwameth/index/meta.yml | 53 ++++++++++++++++++++++++ tests/software/bwameth/index/main.nf | 10 +++++ tests/software/bwameth/index/test.yml | 18 ++++++++ 6 files changed, 179 insertions(+) create mode 100644 software/bwameth/index/functions.nf create mode 100644 software/bwameth/index/main.nf create mode 100644 software/bwameth/index/meta.yml create mode 100644 tests/software/bwameth/index/main.nf create mode 100644 tests/software/bwameth/index/test.yml diff --git a/.github/filters.yml b/.github/filters.yml index 695ac1b9..fe648c39 100644 --- a/.github/filters.yml +++ b/.github/filters.yml @@ -96,6 +96,10 @@ bwamem2_mem: - software/bwamem2/mem/** - tests/software/bwamem2/mem/** +bwameth_index: + - software/bwameth/index/** + - tests/software/bwameth/index/** + cat_fastq: - software/cat/fastq/** - tests/software/cat/fastq/** diff --git a/software/bwameth/index/functions.nf b/software/bwameth/index/functions.nf new file mode 100644 index 00000000..d25eea86 --- /dev/null +++ b/software/bwameth/index/functions.nf @@ -0,0 +1,59 @@ +/* + * ----------------------------------------------------- + * 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/bwameth/index/main.nf b/software/bwameth/index/main.nf new file mode 100644 index 00000000..cfa3e0ee --- /dev/null +++ b/software/bwameth/index/main.nf @@ -0,0 +1,35 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +def options = initOptions(params.options) + +process BWAMETH_INDEX { + tag "$fasta" + label 'process_high' + 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::bwameth=0.2.2" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/bwameth:0.20--py35_0" + } else { + container "quay.io/biocontainers/bwameth:0.20--py35_0" + } + + input: + path fasta + + output: + path "*.bwameth.c2t*", emit: index + path "*.version.txt" , emit: version + + script: + def software = getSoftwareName(task.process) + """ + bwameth.py index $fasta + + echo \$(bwameth.py --version 2>&1) | cut -f2 -d" " > ${software}.version.txt + """ +} diff --git a/software/bwameth/index/meta.yml b/software/bwameth/index/meta.yml new file mode 100644 index 00000000..68c2685b --- /dev/null +++ b/software/bwameth/index/meta.yml @@ -0,0 +1,53 @@ +name: bwameth_index +description: Performs indexing of c2t converted reference genome +keywords: + - bwameth + - 3-letter genome + - index + - methylseq + - bisulphite + - fasta +tools: + - bwameth: + description: | + Fast and accurate alignment of BS-Seq reads + using bwa-mem and a 3-letter genome. + homepage: https://github.com/brentp/bwa-meth + documentation: https://github.com/brentp/bwa-meth + arxiv: arXiv:1401.1129 +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 genome fasta file +output: + - index: + type: file + description: c2t converted genome BWA index files + pattern: "*.{bwameth.c2t.amb,bwameth.c2t.ann,bwameth.c2t.bwt,bwameth.c2t.pac,bwameth.c2t.sa}" + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" +authors: + - "@phue" diff --git a/tests/software/bwameth/index/main.nf b/tests/software/bwameth/index/main.nf new file mode 100644 index 00000000..ada96ebf --- /dev/null +++ b/tests/software/bwameth/index/main.nf @@ -0,0 +1,10 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { BWAMETH_INDEX } from '../../../../software/bwameth/index/main.nf' addParams( options: [:] ) + +workflow test_bwameth_index { + + BWAMETH_INDEX ( file("${launchDir}/tests/data/fasta/E_coli/NC_010473.fa", checkIfExists: true) ) +} diff --git a/tests/software/bwameth/index/test.yml b/tests/software/bwameth/index/test.yml new file mode 100644 index 00000000..14145fe5 --- /dev/null +++ b/tests/software/bwameth/index/test.yml @@ -0,0 +1,18 @@ +- name: Run bwameth index test workflow + command: nextflow run ./tests/software/bwameth/index -entry test_bwameth_index -c tests/config/nextflow.config + tags: + - bwameth + - bwameth_index + files: + - path: ./output/bwameth/NC_010473.fa.bwameth.c2t.pac + md5sum: 7586c6a3be45c4dea15376a5c7bb9bf0 + - path: ./output/bwameth/NC_010473.fa.bwameth.c2t.amb + md5sum: 87e019665cbb66bdee2bacccb26845c9 + - path: ./output/bwameth/NC_010473.fa.bwameth.c2t.ann + md5sum: a4659a63572b6998c67457bd8e95790d + - path: ./output/bwameth/NC_010473.fa.bwameth.c2t.bwt + md5sum: 582854008bcbe99d5b51290773a7db5f + - path: ./output/bwameth/NC_010473.fa.bwameth.c2t + md5sum: db670853725f4a31080c991e9df6b330 + - path: ./output/bwameth/NC_010473.fa.bwameth.c2t.sa + md5sum: 020db07e7e1544dc961c30c9936f3213