From 9fb26ae46248c33ad858d79a36beb07912c85a89 Mon Sep 17 00:00:00 2001 From: Harshil Patel Date: Sat, 30 Oct 2021 09:52:13 +0100 Subject: [PATCH] Add IDR module (#908) * Add IDR module * Add meta and implement main todos * Modifying idr tests * Update tests/config/test_data.config Co-authored-by: Harshil Patel * Update tests/config/test_data.config Co-authored-by: Harshil Patel * Update main.nf * Update tests/config/test_data.config Co-authored-by: Harshil Patel * Update test with new file name Co-authored-by: Jose Espinosa-Carrasco --- modules/idr/functions.nf | 78 +++++++++++++++++++++++++++++++++ modules/idr/main.nf | 56 +++++++++++++++++++++++ modules/idr/meta.yml | 53 ++++++++++++++++++++++ tests/config/pytest_modules.yml | 4 ++ tests/config/test_data.config | 6 +++ tests/modules/idr/main.nf | 35 +++++++++++++++ tests/modules/idr/test.yml | 35 +++++++++++++++ 7 files changed, 267 insertions(+) create mode 100644 modules/idr/functions.nf create mode 100644 modules/idr/main.nf create mode 100644 modules/idr/meta.yml create mode 100644 tests/modules/idr/main.nf create mode 100644 tests/modules/idr/test.yml diff --git a/modules/idr/functions.nf b/modules/idr/functions.nf new file mode 100644 index 00000000..85628ee0 --- /dev/null +++ b/modules/idr/functions.nf @@ -0,0 +1,78 @@ +// +// 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() +} + +// +// Extract name of module from process name using $task.process +// +def getProcessName(task_process) { + return task_process.tokenize(':')[-1] +} + +// +// 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_meta = args.publish_by_meta ?: [] + 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) { + def ioptions = initOptions(args.options) + def path_list = [ ioptions.publish_dir ?: args.publish_dir ] + + // Do not publish versions.yml unless running from pytest workflow + if (args.filename.equals('versions.yml') && !System.getenv("NF_CORE_MODULES_TEST")) { + return null + } + if (ioptions.publish_by_meta) { + def key_list = ioptions.publish_by_meta instanceof List ? ioptions.publish_by_meta : args.publish_by_meta + for (key in key_list) { + if (args.meta && key instanceof String) { + def path = key + if (args.meta.containsKey(key)) { + path = args.meta[key] instanceof Boolean ? "${key}_${args.meta[key]}".toString() : args.meta[key] + } + path = path instanceof String ? path : '' + path_list.add(path) + } + } + } + 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/modules/idr/main.nf b/modules/idr/main.nf new file mode 100644 index 00000000..006826ac --- /dev/null +++ b/modules/idr/main.nf @@ -0,0 +1,56 @@ +// Import generic module functions +include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions' + +params.options = [:] +options = initOptions(params.options) + +process IDR { + tag "$prefix" + label 'process_low' + publishDir "${params.outdir}", + mode: params.publish_dir_mode, + saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:getSoftwareName(task.process), meta:[:], publish_by_meta:[]) } + + conda (params.enable_conda ? "bioconda::idr=2.0.4.2" : null) + if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) { + container "https://depot.galaxyproject.org/singularity/idr:2.0.4.2--py39hcbe4a3b_5" + } else { + container "quay.io/biocontainers/idr:2.0.4.2--py38h9af456f_5" + } + + input: + path peaks + val peak_type + val prefix + + output: + path "*idrValues.txt", emit: idr + path "*log.txt" , emit: log + path "*.png" , emit: png + path "versions.yml" , emit: versions + + script: + if (peaks.toList().size < 2) { + log.error "[ERROR] idr needs at least two replicates only one provided." + } + def peak_types = ['narrowPeak', 'broadPeak', 'bed'] + if (!peak_types.contains(peak_type)) { + log.error "[ERROR] Invalid option: '${peak_type}'. Valid options for 'peak_type': ${peak_types.join(', ')}." + } + def idr_vals = prefix ? "${prefix}.idrValues.txt" : "idrValues.txt" + def log_file = prefix ? "${prefix}.log.txt" : "log.txt" + """ + idr \\ + --samples $peaks \\ + --input-file-type $peak_type \\ + --output-file $idr_vals \\ + --log-output-file $log_file \\ + --plot \\ + $options.args + + cat <<-END_VERSIONS > versions.yml + ${getProcessName(task.process)}: + ${getSoftwareName(task.process)}: \$(echo \$(idr --version 2>&1) | sed 's/^.*IDR //; s/ .*\$//') + END_VERSIONS + """ +} diff --git a/modules/idr/meta.yml b/modules/idr/meta.yml new file mode 100644 index 00000000..c89e72a4 --- /dev/null +++ b/modules/idr/meta.yml @@ -0,0 +1,53 @@ +name: idr +description: | + Measures reproducibility of ChIP-seq, ATAC-seq peaks using IDR (Irreproducible + Discovery Rate) +keywords: + - IDR + - peaks + - ChIP-seq + - ATAC-seq +tools: + - idr: + description: | + The IDR (Irreproducible Discovery Rate) framework is a unified approach + to measure the reproducibility of findings identified from replicate + experiments and provide highly stable thresholds based on reproducibility. + homepage: None + documentation: None + tool_dev_url: https://github.com/kundajelab/idr + doi: "" + licence: ['GPL v2'] +input: + - peaks: + type: tuple of two files + description: BED, narrowPeak or broadPeak files of replicates + pattern: "*" + - peak_type: + type: value + description: Type of peak file + pattern: "{narrowPeak,broadPeak,bed}" + - prefix: + type: value + description: Prefix for output files +output: + - versions: + type: file + description: File containing software versions + pattern: "versions.yml" + - idr: + type: file + description: Text file containing IDR values + pattern: "*.{txt}" + - log: + type: file + description: Log file + pattern: "*.{txt}" + - png: + type: file + description: Plot generated by idr + pattern: "*{.png}" + +authors: + - "@drpatelh" + - "@joseespinosa" diff --git a/tests/config/pytest_modules.yml b/tests/config/pytest_modules.yml index db10b55b..ea999b6a 100644 --- a/tests/config/pytest_modules.yml +++ b/tests/config/pytest_modules.yml @@ -597,6 +597,10 @@ homer/makeucscfile: - modules/homer/makeucscfile/** - tests/modules/homer/makeucscfile/** +idr: + - modules/idr/** + - tests/modules/idr/** + iqtree: - modules/iqtree/** - tests/modules/iqtree/** diff --git a/tests/config/test_data.config b/tests/config/test_data.config index d0489e03..12252542 100644 --- a/tests/config/test_data.config +++ b/tests/config/test_data.config @@ -202,6 +202,12 @@ params { test2_genome_vcf_gz_tbi = "${test_data_dir}/genomics/homo_sapiens/illumina/gvcf/test2.genome.vcf.gz.tbi" test2_genome_vcf_idx = "${test_data_dir}/genomics/homo_sapiens/illumina/gvcf/test2.genome.vcf.idx" + test_broadpeak = "${test_data_dir}/genomics/homo_sapiens/illumina/broadpeak/test.broadPeak" + test2_broadpeak = "${test_data_dir}/genomics/homo_sapiens/illumina/broadpeak/test2.broadPeak" + + test_narrowpeak = "${test_data_dir}/genomics/homo_sapiens/illumina/narrowpeak/test.narrowPeak" + test2_narrowpeak = "${test_data_dir}/genomics/homo_sapiens/illumina/narrowpeak/test2.narrowPeak" + test_10x_1_fastq_gz = "${test_data_dir}/genomics/homo_sapiens/illumina/10xgenomics/test.10x_1.fastq.gz" test_10x_2_fastq_gz = "${test_data_dir}/genomics/homo_sapiens/illumina/10xgenomics/test.10x_2.fastq.gz" diff --git a/tests/modules/idr/main.nf b/tests/modules/idr/main.nf new file mode 100644 index 00000000..aa141a57 --- /dev/null +++ b/tests/modules/idr/main.nf @@ -0,0 +1,35 @@ +#!/usr/bin/env nextflow + +nextflow.enable.dsl = 2 + +include { IDR } from '../../../modules/idr/main.nf' addParams( options: [:] ) + +workflow test_idr_narrowpeak { + + input = [ + file(params.test_data['homo_sapiens']['illumina']['test_narrowpeak'], checkIfExists: true), + file(params.test_data['homo_sapiens']['illumina']['test2_narrowpeak'], checkIfExists: true) + ] + + IDR ( input, 'narrowPeak', 'test' ) +} + +workflow test_idr_broadpeak { + + input = [ + file(params.test_data['homo_sapiens']['illumina']['test_broadpeak'], checkIfExists: true), + file(params.test_data['homo_sapiens']['illumina']['test2_broadpeak'], checkIfExists: true) + ] + + IDR ( input, 'broadPeak', 'test' ) +} + +workflow test_idr_noprefix { + + input = [ + file(params.test_data['homo_sapiens']['illumina']['test_narrowpeak'], checkIfExists: true), + file(params.test_data['homo_sapiens']['illumina']['test2_narrowpeak'], checkIfExists: true) + ] + + IDR ( input, 'narrowPeak', '' ) +} diff --git a/tests/modules/idr/test.yml b/tests/modules/idr/test.yml new file mode 100644 index 00000000..35ee4bc9 --- /dev/null +++ b/tests/modules/idr/test.yml @@ -0,0 +1,35 @@ +- name: idr test_idr_narrowpeak + command: nextflow run tests/modules/idr -entry test_idr_narrowpeak -c tests/config/nextflow.config + tags: + - idr + files: + - path: output/idr/test.idrValues.txt + md5sum: 09be837cc6abbc3eb5958b74802eea55 + - path: output/idr/test.idrValues.txt.png + md5sum: 4a7143ccc0ccadb37c2317bf626e6d96 + - path: output/idr/test.log.txt + md5sum: 6443507ac66b9d3b64bc56b78328083e + +- name: idr test_idr_broadpeak + command: nextflow run tests/modules/idr -entry test_idr_broadpeak -c tests/config/nextflow.config + tags: + - idr + files: + - path: output/idr/test.idrValues.txt + md5sum: 387441c716815e4caec3e70a2cc11a4a + - path: output/idr/test.idrValues.txt.png + md5sum: 7204083ca5b920b4215a5991c12cb4e7 + - path: output/idr/test.log.txt + md5sum: e6917133112b5cec135c182ffac19237 + +- name: idr test_idr_noprefix + command: nextflow run tests/modules/idr -entry test_idr_noprefix -c tests/config/nextflow.config + tags: + - idr + files: + - path: output/idr/idrValues.txt + md5sum: 09be837cc6abbc3eb5958b74802eea55 + - path: output/idr/idrValues.txt.png + md5sum: 4a7143ccc0ccadb37c2317bf626e6d96 + - path: output/idr/log.txt + md5sum: 6443507ac66b9d3b64bc56b78328083e