From eb9178970f93f5638b24c1f5aa33e02233fb39ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20H=C3=BCther?= Date: Mon, 22 Mar 2021 14:58:54 +0100 Subject: [PATCH] add bismark/summary (#295) * add bismark/align module * bismark/align: add tests * bismark/align: update meta.yml * bismark/align: skip checksum for alignment logs they contain timestamps * bismark/align: restore correct checksum caused some mixup in the last commit * bismark/align: add genome_preparation to filters * Fix conda version pin * change options to be a global var * remove params from meta.yml * add bismark/summary * remove md5sum check for bismark_summary_report.html it contains a timestamp * fix tests * update meta.yml * remove mysterious index files --- software/bismark/summary/functions.nf | 59 +++++++++++++++++++++++++ software/bismark/summary/main.nf | 38 ++++++++++++++++ software/bismark/summary/meta.yml | 53 ++++++++++++++++++++++ tests/config/pytest_software.yml | 8 ++++ tests/software/bismark/summary/main.nf | 30 +++++++++++++ tests/software/bismark/summary/test.yml | 9 ++++ 6 files changed, 197 insertions(+) create mode 100644 software/bismark/summary/functions.nf create mode 100644 software/bismark/summary/main.nf create mode 100644 software/bismark/summary/meta.yml create mode 100644 tests/software/bismark/summary/main.nf create mode 100644 tests/software/bismark/summary/test.yml diff --git a/software/bismark/summary/functions.nf b/software/bismark/summary/functions.nf new file mode 100644 index 00000000..d25eea86 --- /dev/null +++ b/software/bismark/summary/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/summary/main.nf b/software/bismark/summary/main.nf new file mode 100644 index 00000000..d61ad2d7 --- /dev/null +++ b/software/bismark/summary/main.nf @@ -0,0 +1,38 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process BISMARK_SUMMARY { + label 'process_low' + 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(bam) + path(align_report) + path(dedup_report) + path(splitting_report) + path(mbias) + + output: + path("*{html,txt}") , emit: summary + path "*.version.txt", emit: version + + script: + def software = getSoftwareName(task.process) + """ + bismark2summary + + echo \$(bismark -v 2>&1) | sed 's/^.*Bismark Version: v//; s/Copyright.*\$//' > ${software}.version.txt + """ +} diff --git a/software/bismark/summary/meta.yml b/software/bismark/summary/meta.yml new file mode 100644 index 00000000..a88bf8f6 --- /dev/null +++ b/software/bismark/summary/meta.yml @@ -0,0 +1,53 @@ +name: bismark_summary +description: | + Uses Bismark report files of several samples in a run folder + to generate a graphical summary HTML report. +keywords: + - bismark + - qc + - methylation + - 5mC + - methylseq + - bisulphite + - report + - summary +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: + - bam: + type: file + description: Bismark alignment + pattern: "*.{bam}" + - align_report: + type: file + description: Bismark alignment reports + pattern: "*{report.txt}" + - dedup_report: + type: file + description: Bismark deduplication reports + pattern: "*.{deduplication_report.txt}" + - splitting_report: + type: file + description: Bismark splitting reports + pattern: "*{splitting_report.txt}" + - mbias: + type: file + description: Text file containing methylation bias information + pattern: "*.{txt}" +output: + - summary: + type: file + description: Bismark summary + pattern: "*.{html,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 995a0973..8c198be9 100644 --- a/tests/config/pytest_software.yml +++ b/tests/config/pytest_software.yml @@ -84,6 +84,14 @@ bismark_report: - software/bismark/report/** - tests/software/bismark/report/** +bismark_summary: + - software/bismark/genome_preparation/** + - software/bismark/align/** + - software/bismark/deduplicate/** + - software/bismark/methylation_extractor/** + - software/bismark/summary/** + - tests/software/bismark/summary/** + blast_makeblastdb: - software/blast/makeblastdb/** - tests/software/blast/makeblastdb/** diff --git a/tests/software/bismark/summary/main.nf b/tests/software/bismark/summary/main.nf new file mode 100644 index 00000000..d866a8a7 --- /dev/null +++ b/tests/software/bismark/summary/main.nf @@ -0,0 +1,30 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { BISMARK_GENOME_PREPARATION } from '../../../../software/bismark/genome_preparation/main.nf' addParams( options: [:] ) +include { BISMARK_ALIGN } from '../../../../software/bismark/align/main.nf' addParams( options: [:] ) +include { BISMARK_DEDUPLICATE } from '../../../../software/bismark/deduplicate/main.nf' addParams( options: [:] ) +include { BISMARK_METHYLATION_EXTRACTOR } from '../../../../software/bismark/methylation_extractor/main.nf' addParams( options: [:] ) +include { BISMARK_SUMMARY } from '../../../../software/bismark/summary/main.nf' addParams( options: [:] ) + +workflow test_bismark_summary { + + def input = [] + input = [ [ id:'test', single_end:false ], // meta map + [ file("${launchDir}/tests/data/genomics/sarscov2/fastq/test_methylated_1.fastq.gz", checkIfExists: true), + file("${launchDir}/tests/data/genomics/sarscov2/fastq/test_methylated_2.fastq.gz", checkIfExists: true) ] ] + + BISMARK_GENOME_PREPARATION ( file("${launchDir}/tests/data/genomics/sarscov2/fasta/test_genome.fasta", checkIfExists: true) ) + BISMARK_ALIGN ( input, BISMARK_GENOME_PREPARATION.out.index ) + BISMARK_DEDUPLICATE ( BISMARK_ALIGN.out.bam ) + BISMARK_METHYLATION_EXTRACTOR ( BISMARK_DEDUPLICATE.out.bam, BISMARK_GENOME_PREPARATION.out.index ) + + BISMARK_SUMMARY ( + BISMARK_ALIGN.out.bam.collect{ meta, bam -> bam }, + BISMARK_ALIGN.out.report.collect{ meta, report -> report }, + BISMARK_DEDUPLICATE.out.report.collect{ meta, bam -> bam }, + BISMARK_METHYLATION_EXTRACTOR.out.report.collect{ meta, report -> report }, + BISMARK_METHYLATION_EXTRACTOR.out.mbias.collect{ meta, mbias -> mbias } + ) +} diff --git a/tests/software/bismark/summary/test.yml b/tests/software/bismark/summary/test.yml new file mode 100644 index 00000000..0489dbff --- /dev/null +++ b/tests/software/bismark/summary/test.yml @@ -0,0 +1,9 @@ +- name: Run bismark summary test workflow + command: nextflow run ./tests/software/bismark/summary -entry test_bismark_summary -c tests/config/nextflow.config + tags: + - bismark + - bismark_summary + files: + - path: output/bismark/bismark_summary_report.html + - path: output/bismark/bismark_summary_report.txt + md5sum: 06fc717e81b3f8f0d6e279d572f407f6