From 0d8f5f0572aaed0f3d1af92a68b978ad573f8a1d Mon Sep 17 00:00:00 2001 From: phue Date: Thu, 18 Feb 2021 10:56:36 +0100 Subject: [PATCH] add bismark/genome_preparation + tests --- .github/filters.yml | 4 ++ .../bismark/genome_preparation/functions.nf | 59 +++++++++++++++++++ software/bismark/genome_preparation/main.nf | 37 ++++++++++++ software/bismark/genome_preparation/meta.yml | 57 ++++++++++++++++++ .../bismark/genome_preparation/main.nf | 10 ++++ .../bismark/genome_preparation/test.yml | 36 +++++++++++ 6 files changed, 203 insertions(+) create mode 100644 software/bismark/genome_preparation/functions.nf create mode 100644 software/bismark/genome_preparation/main.nf create mode 100644 software/bismark/genome_preparation/meta.yml create mode 100644 tests/software/bismark/genome_preparation/main.nf create mode 100644 tests/software/bismark/genome_preparation/test.yml diff --git a/.github/filters.yml b/.github/filters.yml index ccc38674..537d982f 100644 --- a/.github/filters.yml +++ b/.github/filters.yml @@ -54,6 +54,10 @@ bedtools_sort: - software/bedtools/sort/** - tests/software/bedtools/sort/** +bismark_genome_preparation: + - software/bismark/genome_preparation/** + - tests/software/bismark/genome_preparation/** + blast_makeblastdb: - software/blast/makeblastdb/** - tests/software/blast/makeblastdb/** diff --git a/software/bismark/genome_preparation/functions.nf b/software/bismark/genome_preparation/functions.nf new file mode 100644 index 00000000..d25eea86 --- /dev/null +++ b/software/bismark/genome_preparation/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/bismark/genome_preparation/main.nf b/software/bismark/genome_preparation/main.nf new file mode 100644 index 00000000..5a265508 --- /dev/null +++ b/software/bismark/genome_preparation/main.nf @@ -0,0 +1,37 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +def options = initOptions(params.options) + +process BISMARK_GENOME_PREPARATION { + 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::bismark==0.23.0" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/bismark:0.23.0--0" + } else { + container "quay.io/biocontainers/bismark:0.23.0--0" + } + + input: + path fasta, stageAs: "BismarkIndex/*" + + output: + path "BismarkIndex" , emit: index + path "*.version.txt", emit: version + + script: + def software = getSoftwareName(task.process) + """ + bismark_genome_preparation \\ + $options.args \\ + BismarkIndex + + echo \$(bismark -v 2>&1) | sed 's/^.*Bismark Version: v//; s/Copyright.*\$//' > ${software}.version.txt + """ +} diff --git a/software/bismark/genome_preparation/meta.yml b/software/bismark/genome_preparation/meta.yml new file mode 100644 index 00000000..4bd10db7 --- /dev/null +++ b/software/bismark/genome_preparation/meta.yml @@ -0,0 +1,57 @@ +name: bismark_genome_preparation +description: | + Converts a specified reference genome into two different bisulfite + converted versions and indexes them for alignments. +keywords: + - bismark + - 3-letter genome + - index + - methylation + - 5mC + - methylseq + - bisulphite + - fasta +tools: + - bismark: + description: | + Bismark is a tool to map bisulfite treated sequencing reads + and perform methylation calling in a quick and easy-to-use fashion. + homepage: https://github.com/FelixKrueger/Bismark + documentation: https://github.com/FelixKrueger/Bismark/tree/master/Docs + doi: 10.1093/bioinformatics/btr167 +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: dir + description: Bismark genome index directory + pattern: "BismarkIndex" + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" +authors: + - "@phue" diff --git a/tests/software/bismark/genome_preparation/main.nf b/tests/software/bismark/genome_preparation/main.nf new file mode 100644 index 00000000..9205196c --- /dev/null +++ b/tests/software/bismark/genome_preparation/main.nf @@ -0,0 +1,10 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { BISMARK_GENOME_PREPARATION } from '../../../../software/bismark/genome_preparation/main.nf' addParams( options: [:] ) + +workflow test_bismark_genome_preparation { + + BISMARK_GENOME_PREPARATION ( file("${launchDir}/tests/data/fasta/E_coli/NC_010473.fa", checkIfExists: true) ) +} diff --git a/tests/software/bismark/genome_preparation/test.yml b/tests/software/bismark/genome_preparation/test.yml new file mode 100644 index 00000000..a6f9539f --- /dev/null +++ b/tests/software/bismark/genome_preparation/test.yml @@ -0,0 +1,36 @@ +- name: Run bismark_genome_preparation test workflow + command: nextflow run ./tests/software/bismark/genome_preparation -entry test_bismark_genome_preparation -c tests/config/nextflow.config + tags: + - bismark + - bismark_genome_preparation + files: + - path: output/bismark/BismarkIndex/NC_010473.fa + md5sum: ad277e6b3da5dcf9fccfcd3a55fcec8e + - path: output/bismark/BismarkIndex/Bisulfite_Genome/CT_conversion/genome_mfa.CT_conversion.fa + md5sum: f878bc2c1d6d1404157ebf931e971f02 + - path: output/bismark/BismarkIndex/Bisulfite_Genome/CT_conversion/BS_CT.1.bt2 + md5sum: d865be3bfe02a3d5e277128fe7902b47 + - path: output/bismark/BismarkIndex/Bisulfite_Genome/CT_conversion/BS_CT.2.bt2 + md5sum: 486dfea5dde17f126cf498ead0e91421 + - path: output/bismark/BismarkIndex/Bisulfite_Genome/CT_conversion/BS_CT.3.bt2 + md5sum: cd201e81724f3099131aec16ef2cc53b + - path: output/bismark/BismarkIndex/Bisulfite_Genome/CT_conversion/BS_CT.4.bt2 + md5sum: 4c81a7364a80bf3151a5464108593497 + - path: output/bismark/BismarkIndex/Bisulfite_Genome/GA_conversion/genome_mfa.GA_conversion.fa + md5sum: 8cb16ceaf0543061151d8c1b7d1f85b4 + - path: output/bismark/BismarkIndex/Bisulfite_Genome/GA_conversion/BS_GA.1.bt2 + md5sum: fe77e5d17a7aa30c3a788bb90b396842 + - path: output/bismark/BismarkIndex/Bisulfite_Genome/GA_conversion/BS_GA.2.bt2 + md5sum: 3c6e4a48ad05f8af5f4015db7571d253 + - path: output/bismark/BismarkIndex/Bisulfite_Genome/GA_conversion/BS_GA.3.bt2 + md5sum: cd201e81724f3099131aec16ef2cc53b + - path: output/bismark/BismarkIndex/Bisulfite_Genome/GA_conversion/BS_GA.4.bt2 + md5sum: f651bcfb9713f6ee1ce648b7c244b50e + - path: output/bismark/BismarkIndex/Bisulfite_Genome/CT_conversion/BS_CT.rev.1.bt2 + md5sum: 2261afbed214da6f59f1bf648c20fb6b + - path: output/bismark/BismarkIndex/Bisulfite_Genome/CT_conversion/BS_CT.rev.2.bt2 + md5sum: 622991847ea56f3c4f8583bb23ceee7a + - path: output/bismark/BismarkIndex/Bisulfite_Genome/GA_conversion/BS_GA.rev.1.bt2 + md5sum: 32220350073a71a9cd69677f3aa4e577 + - path: output/bismark/BismarkIndex/Bisulfite_Genome/GA_conversion/BS_GA.rev.2.bt2 + md5sum: f7467830c4f33497c54c9e7e502a5def