Skip to content

Commit

Permalink
Merge branch 'nf-core:master' into backfill_software_licenses_meta
Browse files Browse the repository at this point in the history
  • Loading branch information
klkeys authored Oct 22, 2021
2 parents b4044f2 + 32f6191 commit e20047b
Show file tree
Hide file tree
Showing 17 changed files with 547 additions and 15 deletions.
78 changes: 78 additions & 0 deletions modules/genrich/functions.nf
Original file line number Diff line number Diff line change
@@ -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"
}
}
69 changes: 69 additions & 0 deletions modules/genrich/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Import generic module functions
include { initOptions; saveFiles; getSoftwareName; getProcessName } from './functions'

params.options = [:]
options = initOptions(params.options)

process GENRICH {
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), meta:meta, publish_by_meta:['id']) }

conda (params.enable_conda ? "bioconda::genrich=0.6.1" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/genrich:0.6.1--h5bf99c6_1"
} else {
container "quay.io/biocontainers/genrich:0.6.1--h5bf99c6_1"
}

input:
tuple val(meta), path(treatment_bam)
path control_bam
path blacklist_bed

output:
tuple val(meta), path("*narrowPeak") , emit: peaks
tuple val(meta), path("*pvalues.bedGraph"), optional:true, emit: bedgraph_pvalues
tuple val(meta), path("*pileup.bedGraph") , optional:true, emit: bedgraph_pileup
tuple val(meta), path("*intervals.bed") , optional:true, emit: bed_intervals
tuple val(meta), path("*duplicates.txt") , optional:true, emit: duplicates
path "versions.yml" , emit: versions

script:
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
def control = params.control_bam ? "-c $control_bam" : ''
def pvalues = params.pvalues ? "-f ${prefix}.pvalues.bedGraph" : ""
def pileup = params.pileup ? "-k ${prefix}.pileup.bedGraph" : ""
def bed = params.bed ? "-b ${prefix}.intervals.bed" : ""
def blacklist = params.blacklist_bed ? "-E $blacklist_bed" : ""
def duplicates = ""
if (params.save_duplicates) {
if (options.args.contains('-r')) {
duplicates = "-R ${prefix}.duplicates.txt"
} else {
log.info '[Genrich] Duplicates can only be saved if they are filtered, defaulting to -r option (Remove PCR duplicates).'
duplicates = "-r -R ${prefix}.duplicates.txt"
}
}
"""
Genrich \\
-t $treatment_bam \\
$options.args \\
$control \\
$blacklist \\
-o ${prefix}.narrowPeak \\
$pvalues \\
$pileup \\
$bed \\
$duplicates \\
$blacklist \\
$control
cat <<-END_VERSIONS > versions.yml
${getProcessName(task.process)}:
${getSoftwareName(task.process)}: \$(echo \$(Genrich --version 2>&1) | sed 's/^Genrich, version //; s/ .*\$//')
END_VERSIONS
"""
}
71 changes: 71 additions & 0 deletions modules/genrich/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
name: genrich
description: Peak-calling for ChIP-seq and ATAC-seq enrichment experiments
keywords:
- peak-calling
- ChIP-seq
- ATAC-seq
tools:
- genrich:
description: |
Genrich is a peak-caller for genomic enrichment assays (e.g. ChIP-seq, ATAC-seq).
It analyzes alignment files generated following the assay and produces a file
detailing peaks of significant enrichment.
homepage: https://github.com/jsh58/Genrich
documentation: https://github.com/jsh58/Genrich#readme
tool_dev_url: https://github.com/jsh58/Genrich
doi: ""
licence: ['MIT']

input:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- treatment_bam:
type: file
description: Coordinate sorted BAM/SAM file from treatment sample
pattern: "*.{bam,sam}"
- control_bam:
type: file
description: Coordinate sorted BAM/SAM file from control sample
pattern: "*.{bam,sam}"
- blacklist_bed:
type: file
description: Bed file containing genomic intervals to exclude from the analysis
pattern: "*.{bed}"

output:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. [ id:'test', single_end:false ]
- peaks:
type: file
description: Output file is in ENCODE narrowPeak format
pattern: "*.{narrowPeak}"
- bedgraph_pvalues:
type: file
description: bedGraph file containing p/q values
pattern: "*.{pvalues.bedGraph}"
- bedgraph_pileup:
type: file
description: bedGraph file containing pileups and p-values
pattern: "*.{pileup.bedGraph}"
- bed_intervals:
type: file
description: Bed file containing annotated intervals
pattern: "*.{intervals.bed}"
- duplicates:
type: file
description: Text output file containing intervals corresponding to PCR duplicates
pattern: "*.{intervals.txt}"
- version:
type: file
description: File containing software version
pattern: "*.{version.txt}"

authors:
- "@JoseEspinosa"

13 changes: 7 additions & 6 deletions modules/seacr/callpeak/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,30 @@ process SEACR_CALLPEAK {
mode: params.publish_dir_mode,
saveAs: { filename -> saveFiles(filename:filename, options:params.options, publish_dir:getSoftwareName(task.process), meta:meta, publish_by_meta:['id']) }

conda (params.enable_conda ? "bioconda::seacr=1.3 conda-forge::r-base=4.0.2 bioconda::bedtools=2.29.2" : null)
conda (params.enable_conda ? "bioconda::seacr=1.3 conda-forge::r-base=4.0.2 bioconda::bedtools=2.30.0" : null)
if (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container) {
container "https://depot.galaxyproject.org/singularity/mulled-v2-03bfeb32fe80910c231f630d4262b83677c8c0f4:5bb5ed4307a8187a7f34730b00431de93688fa59-0"
container "https://depot.galaxyproject.org/singularity/mulled-v2-03bfeb32fe80910c231f630d4262b83677c8c0f4:f4bb19b68e66de27e4c64306f951d5ff11919931-0"
} else {
container 'quay.io/biocontainers/mulled-v2-03bfeb32fe80910c231f630d4262b83677c8c0f4:5bb5ed4307a8187a7f34730b00431de93688fa59-0'
container 'quay.io/biocontainers/mulled-v2-03bfeb32fe80910c231f630d4262b83677c8c0f4:f4bb19b68e66de27e4c64306f951d5ff11919931-0'
}

input:
tuple val(meta), path(bedgraph), path(ctrlbedgraph)
val (threshold)

output:
tuple val(meta), path("*.bed"), emit: bed
path "versions.yml" , emit: versions

script:
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
def prefix = options.suffix ? "${meta.id}${options.suffix}" : "${meta.id}"
def function_switch = ctrlbedgraph ? "$ctrlbedgraph" : "$threshold"
"""
SEACR_1.3.sh \\
$bedgraph \\
$ctrlbedgraph \\
$function_switch \\
$options.args \\
$prefix
cat <<-END_VERSIONS > versions.yml
${getProcessName(task.process)}:
${getSoftwareName(task.process)}: \$(echo $VERSION)
Expand Down
5 changes: 5 additions & 0 deletions modules/seacr/callpeak/meta.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

name: seacr_callpeak
description: Call peaks using SEACR on sequenced reads in bedgraph format
keywords:
Expand Down Expand Up @@ -31,6 +32,10 @@ input:
type: file
description: |
Control (IgG) data bedgraph file to generate an empirical threshold for peak calling.
- threshold:
type: value
description: |
Threshold value used to call peaks if the ctrlbedgraph input is set to []. Set to 1 if using a control bedgraph
output:
- meta:
type: map
Expand Down
78 changes: 78 additions & 0 deletions modules/ucsc/liftover/functions.nf
Original file line number Diff line number Diff line change
@@ -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"
}
}
Loading

0 comments on commit e20047b

Please sign in to comment.