From 04704c20349c0602947921af29631e2b408e66fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20H=C3=BCther?= Date: Sun, 21 Mar 2021 00:54:42 +0100 Subject: [PATCH] add bismark/methylation_extractor (#274) * add bismark/methylation_extractor * add tests for bismark/methylation_extractor * bismark/methylation_extractor: add genome_preparation to filters * Apply suggestions from code review Co-authored-by: Harshil Patel * remove params from meta.yml * pytest: remove md5sum checks for gzipped output gzip stores timestamps in the file header, so the checksum will be different each time Co-authored-by: Harshil Patel --- .../methylation_extractor/functions.nf | 59 +++++++++++++++++ .../bismark/methylation_extractor/main.nf | 48 ++++++++++++++ .../bismark/methylation_extractor/meta.yml | 66 +++++++++++++++++++ tests/config/pytest_software.yml | 9 +++ .../bismark/methylation_extractor/main.nf | 20 ++++++ .../bismark/methylation_extractor/test.yml | 18 +++++ 6 files changed, 220 insertions(+) create mode 100644 software/bismark/methylation_extractor/functions.nf create mode 100644 software/bismark/methylation_extractor/main.nf create mode 100644 software/bismark/methylation_extractor/meta.yml create mode 100644 tests/software/bismark/methylation_extractor/main.nf create mode 100644 tests/software/bismark/methylation_extractor/test.yml diff --git a/software/bismark/methylation_extractor/functions.nf b/software/bismark/methylation_extractor/functions.nf new file mode 100644 index 00000000..d25eea86 --- /dev/null +++ b/software/bismark/methylation_extractor/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/methylation_extractor/main.nf b/software/bismark/methylation_extractor/main.nf new file mode 100644 index 00000000..238b0220 --- /dev/null +++ b/software/bismark/methylation_extractor/main.nf @@ -0,0 +1,48 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process BISMARK_METHYLATION_EXTRACTOR { + tag "$meta.id" + 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:meta.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: + tuple val(meta), path(bam) + path index + + output: + tuple val(meta), path("*.bedGraph.gz") , emit: bedgraph + tuple val(meta), path("*.txt.gz") , emit: methylation_calls + tuple val(meta), path("*.cov.gz") , emit: coverage + tuple val(meta), path("*_splitting_report.txt"), emit: report + tuple val(meta), path("*.M-bias.txt") , emit: mbias + path "*.version.txt" , emit: version + + script: + def seqtype = meta.single_end ? '-s' : '-p' + def software = getSoftwareName(task.process) + """ + bismark_methylation_extractor \\ + --bedGraph \\ + --counts \\ + --gzip \\ + --report \\ + $seqtype \\ + $options.args \\ + $bam + + echo \$(bismark -v 2>&1) | sed 's/^.*Bismark Version: v//; s/Copyright.*\$//' > ${software}.version.txt + """ +} diff --git a/software/bismark/methylation_extractor/meta.yml b/software/bismark/methylation_extractor/meta.yml new file mode 100644 index 00000000..aeef7418 --- /dev/null +++ b/software/bismark/methylation_extractor/meta.yml @@ -0,0 +1,66 @@ +name: bismark_methylation_extractor +description: Extracts methylation information for individual cytosines from alignments. +keywords: + - bismark + - consensus + - map + - methylation + - 5mC + - methylseq + - bisulphite + - bam + - bedGraph +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 +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - bam: + type: file + description: BAM file containing read alignments + pattern: "*.{bam}" + - index: + type: dir + description: Bismark genome index directory + pattern: "BismarkIndex" +output: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. [ id:'test', single_end:false ] + - bedgraph: + type: file + description: Bismark output file containing coverage and methylation metrics + pattern: "*.{bedGraph.gz}" + - methylation_calls: + type: file + description: Bismark output file containing strand-specific methylation calls + pattern: "*.{txt.gz}" + - coverage: + type: file + description: Bismark output file containing coverage metrics + pattern: "*.{cov.gz}" + - report: + type: file + description: Bismark splitting reports + pattern: "*_{splitting_report.txt}" + - mbias: + type: file + description: Text file containing methylation bias information + pattern: "*.{M-bias.txt}" + - version: + type: file + description: File containing software version + pattern: "*.{version.txt}" +authors: + - "@phue" diff --git a/tests/config/pytest_software.yml b/tests/config/pytest_software.yml index 11fbbd98..a4dd79b9 100644 --- a/tests/config/pytest_software.yml +++ b/tests/config/pytest_software.yml @@ -66,6 +66,15 @@ bismark_genome_preparation: - software/bismark/genome_preparation/** - tests/software/bismark/genome_preparation/** +bismark_methylation_extractor: + - software/bismark/methylation_extractor/** + - software/bismark/genome_preparation/** + - tests/software/bismark/methylation_extractor/** + +blast_makeblastdb: + - software/blast/makeblastdb/** + - tests/software/blast/makeblastdb/** + blast_blastn: - software/blast/blastn/** - tests/software/blast/blastn/** diff --git a/tests/software/bismark/methylation_extractor/main.nf b/tests/software/bismark/methylation_extractor/main.nf new file mode 100644 index 00000000..01c51cad --- /dev/null +++ b/tests/software/bismark/methylation_extractor/main.nf @@ -0,0 +1,20 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { BISMARK_GENOME_PREPARATION } from '../../../../software/bismark/genome_preparation/main.nf' addParams( options: [:] ) +include { BISMARK_METHYLATION_EXTRACTOR } from '../../../../software/bismark/methylation_extractor/main.nf' addParams( options: [:] ) + +workflow test_bismark_methylation_extractor { + + def input = [] + input = [ [ id:'test', single_end:false ], // meta map + [ file("${launchDir}/tests/data/genomics/sarscov2/bam/test_methylated_paired_end.bam", checkIfExists: true) ] ] + + BISMARK_GENOME_PREPARATION ( file("${launchDir}/tests/data/genomics/sarscov2/fasta/test_genome.fasta", checkIfExists: true) ) + + BISMARK_METHYLATION_EXTRACTOR ( + input, + BISMARK_GENOME_PREPARATION.out.index + ) +} diff --git a/tests/software/bismark/methylation_extractor/test.yml b/tests/software/bismark/methylation_extractor/test.yml new file mode 100644 index 00000000..b351e7a2 --- /dev/null +++ b/tests/software/bismark/methylation_extractor/test.yml @@ -0,0 +1,18 @@ +- name: Run bismark methylation extractor test workflow + command: nextflow run ./tests/software/bismark/methylation_extractor -entry test_bismark_methylation_extractor -c tests/config/nextflow.config + tags: + - bismark + - bismark_methylation_extractor + files: + - path: output/bismark/CHG_OB_test_methylated_paired_end.txt.gz + - path: output/bismark/CHG_OT_test_methylated_paired_end.txt.gz + - path: output/bismark/CHH_OB_test_methylated_paired_end.txt.gz + - path: output/bismark/CHH_OT_test_methylated_paired_end.txt.gz + - path: output/bismark/CpG_OB_test_methylated_paired_end.txt.gz + - path: output/bismark/CpG_OT_test_methylated_paired_end.txt.gz + - path: output/bismark/test_methylated_paired_end.bedGraph.gz + - path: output/bismark/test_methylated_paired_end.bismark.cov.gz + - path: output/bismark/test_methylated_paired_end.M-bias.txt + md5sum: 0b100924d46b3c35115f1206f34c4a59 + - path: output/bismark/test_methylated_paired_end_splitting_report.txt + md5sum: 288d6f0110127e3a8c10391802118202