Skip to content

Commit

Permalink
Added contrast limited adaptive histogram equalization module (nf-cor…
Browse files Browse the repository at this point in the history
…e#5268)

* clahe_module

* removed todos

* Fixed linting, excluded conda tests.

* Added conda test skip to workflows/test.yml.

---------

Co-authored-by: Florian Wuennemann <[email protected]>
  • Loading branch information
kbestak and FloWuenne authored Mar 20, 2024
1 parent 6920a61 commit 7b29d1b
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,8 @@ jobs:
tags: merquryfk/merquryfk
- profile: conda
tags: merquryfk/ploidyplot
- profile: conda
tags: molkartgarage/clahe
- profile: conda
tags: quartonotebook
- profile: conda
Expand Down
49 changes: 49 additions & 0 deletions modules/nf-core/molkartgarage/clahe/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
process MOLKARTGARAGE_CLAHE {
tag "$meta.id"
label 'process_medium'

container "ghcr.io/schapirolabor/molkart-local:v0.1.1"

input:
tuple val(meta), path(image)

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

when:
task.ext.when == null || task.ext.when

script:
// Exit if running this module with -profile conda / -profile mamba
if (workflow.profile.tokenize(',').intersect(['conda', 'mamba']).size() >= 1) {
error "Molkartgarage/clahe module does not support Conda. Please use Docker / Singularity / Podman instead."
}
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
"""
python /local/scripts/molkart_clahe.py \
--input ${image} \
--output ${prefix}.tiff \
$args
cat <<-END_VERSIONS > versions.yml
"${task.process}":
molkart_clahe: \$(python /local/scripts/molkart_clahe.py --version)
scikit-image: 0.19.2
END_VERSIONS
"""

stub:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
"""
touch ${prefix}.tiff
cat <<-END_VERSIONS > versions.yml
"${task.process}":
molkart_clahe: \$(python3 /local/scripts/molkart_clahe.py --version)
scikit-image: 0.19.2
END_VERSIONS
"""
}
52 changes: 52 additions & 0 deletions modules/nf-core/molkartgarage/clahe/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/meta-schema.json
name: "molkartgarage_clahe"
description: Contrast-limited adjusted histogram equalization (CLAHE) on single-channel tif images.
keywords:
- clahe
- image_processing
- imaging
- correction
tools:
- "molkartgarage":
description: "One-stop-shop for scripts and tools for processing data for molkart and spatial omics pipelines."
homepage: https://github.com/SchapiroLabor/molkart-local/tree/main
documentation: https://github.com/SchapiroLabor/molkart-local/tree/main
tool_dev_url: https://github.com/SchapiroLabor/molkart-local/blob/main/scripts/molkart_clahe.py
licence: ["MIT"]

input:
# Only when we have meta
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'sample1']`
- image:
type: file
description: Single-channel tiff file to be corrected.
pattern: "*.{tif,tiff}"

output:
#Only when we have meta
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'sample1']`
- versions:
type: file
description: File containing software versions
pattern: "versions.yml"

- img_clahe:
type: file
description: CLAHE corrected tiff file.
pattern: "*.{tiff}"

authors:
- "@kbestak"
maintainers:
- "@kbestak"
60 changes: 60 additions & 0 deletions modules/nf-core/molkartgarage/clahe/tests/main.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// test with: nf-core modules test molkartgarage/clahe
nextflow_process {

name "Test Process MOLKARTGARAGE_CLAHE"
script "../main.nf"
config "./nextflow.config"
process "MOLKARTGARAGE_CLAHE"

tag "modules"
tag "modules_nfcore"
tag "molkartgarage"
tag "molkartgarage/clahe"

test("clahe - tiff") {

when {
process {
"""
input[0] = [
[ id:'test' ], // meta map
file(params.test_data['imaging']['tiff']['mouse_heart_wga'], checkIfExists: true)
]
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert process.out.img_clahe }, // uuid in metadata changes so md5sums are not the same
{ assert snapshot(process.out.versions).match("versions") }
)
}

}

test("clahe - stub") {

options "-stub"

when {
process {
"""
input[0] = [
[ id:'test' ], // meta map
file(params.test_data['imaging']['tiff']['mouse_heart_wga'], checkIfExists: true)
]
"""
}
}

then {
assertAll(
{ assert process.success }
)
}

}

}
14 changes: 14 additions & 0 deletions modules/nf-core/molkartgarage/clahe/tests/main.nf.test.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions modules/nf-core/molkartgarage/clahe/tests/nextflow.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
process {

withName: "MOLKARTGARAGE_CLAHE" {
ext.args = '--tile-size 368 --tile-size 48 --pixel-size 0.138 --cliplimit 0.01'
}

}
2 changes: 2 additions & 0 deletions modules/nf-core/molkartgarage/clahe/tests/tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
molkartgarage/clahe:
- "modules/nf-core/molkartgarage/clahe/**"

0 comments on commit 7b29d1b

Please sign in to comment.