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 <drpatelh@users.noreply.github.com>

* Update tests/config/test_data.config

Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>

* Update main.nf

* Update tests/config/test_data.config

Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>

* Update test with new file name

Co-authored-by: Jose Espinosa-Carrasco <kadomu@gmail.com>
This commit is contained in:
Harshil Patel 2021-10-30 09:52:13 +01:00 committed by GitHub
parent bc8697b766
commit 9fb26ae462
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 267 additions and 0 deletions

78
modules/idr/functions.nf Normal file
View file

@ -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"
}
}

56
modules/idr/main.nf Normal file
View file

@ -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
"""
}

53
modules/idr/meta.yml Normal file
View file

@ -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"

View file

@ -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/**

View file

@ -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"

35
tests/modules/idr/main.nf Normal file
View file

@ -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', '' )
}

View file

@ -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