From 9f6990680a533e7ceef3b1fe776332f78cd14d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kre=C5=A1imir=20Be=C5=A1tak?= <86408271+kbestak@users.noreply.github.com> Date: Wed, 20 Mar 2024 13:13:32 +0100 Subject: [PATCH] Added contrast limited adaptive histogram equalization module (#5268) * clahe_module * removed todos * Fixed linting, excluded conda tests. * Added conda test skip to workflows/test.yml. --------- Co-authored-by: Florian Wuennemann --- .github/workflows/test.yml | 2 + modules/nf-core/molkartgarage/clahe/main.nf | 49 +++++++++++++++ modules/nf-core/molkartgarage/clahe/meta.yml | 52 ++++++++++++++++ .../molkartgarage/clahe/tests/main.nf.test | 60 +++++++++++++++++++ .../clahe/tests/main.nf.test.snap | 14 +++++ .../molkartgarage/clahe/tests/nextflow.config | 7 +++ .../molkartgarage/clahe/tests/tags.yml | 2 + 7 files changed, 186 insertions(+) create mode 100644 modules/nf-core/molkartgarage/clahe/main.nf create mode 100644 modules/nf-core/molkartgarage/clahe/meta.yml create mode 100644 modules/nf-core/molkartgarage/clahe/tests/main.nf.test create mode 100644 modules/nf-core/molkartgarage/clahe/tests/main.nf.test.snap create mode 100644 modules/nf-core/molkartgarage/clahe/tests/nextflow.config create mode 100644 modules/nf-core/molkartgarage/clahe/tests/tags.yml diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 544b2cf26b1..6bf82516a05 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -561,6 +561,8 @@ jobs: tags: merquryfk/merquryfk - profile: conda tags: merquryfk/ploidyplot + - profile: conda + tags: molkartgarage/clahe - profile: conda tags: quartonotebook - profile: conda diff --git a/modules/nf-core/molkartgarage/clahe/main.nf b/modules/nf-core/molkartgarage/clahe/main.nf new file mode 100644 index 00000000000..1d070aeebcf --- /dev/null +++ b/modules/nf-core/molkartgarage/clahe/main.nf @@ -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 + """ +} diff --git a/modules/nf-core/molkartgarage/clahe/meta.yml b/modules/nf-core/molkartgarage/clahe/meta.yml new file mode 100644 index 00000000000..9ca71304aa3 --- /dev/null +++ b/modules/nf-core/molkartgarage/clahe/meta.yml @@ -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" diff --git a/modules/nf-core/molkartgarage/clahe/tests/main.nf.test b/modules/nf-core/molkartgarage/clahe/tests/main.nf.test new file mode 100644 index 00000000000..15c67b7d7fa --- /dev/null +++ b/modules/nf-core/molkartgarage/clahe/tests/main.nf.test @@ -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 } + ) + } + + } + +} diff --git a/modules/nf-core/molkartgarage/clahe/tests/main.nf.test.snap b/modules/nf-core/molkartgarage/clahe/tests/main.nf.test.snap new file mode 100644 index 00000000000..349a0e9bfa6 --- /dev/null +++ b/modules/nf-core/molkartgarage/clahe/tests/main.nf.test.snap @@ -0,0 +1,14 @@ +{ + "versions": { + "content": [ + [ + "versions.yml:md5,ddf084b777e987eb83271f02e4e4cf2b" + ] + ], + "meta": { + "nf-test": "0.8.4", + "nextflow": "23.10.1" + }, + "timestamp": "2024-03-19T13:20:00.607838647" + } +} \ No newline at end of file diff --git a/modules/nf-core/molkartgarage/clahe/tests/nextflow.config b/modules/nf-core/molkartgarage/clahe/tests/nextflow.config new file mode 100644 index 00000000000..72dd3fcceec --- /dev/null +++ b/modules/nf-core/molkartgarage/clahe/tests/nextflow.config @@ -0,0 +1,7 @@ +process { + + withName: "MOLKARTGARAGE_CLAHE" { + ext.args = '--tile-size 368 --tile-size 48 --pixel-size 0.138 --cliplimit 0.01' + } + +} diff --git a/modules/nf-core/molkartgarage/clahe/tests/tags.yml b/modules/nf-core/molkartgarage/clahe/tests/tags.yml new file mode 100644 index 00000000000..b7bba012974 --- /dev/null +++ b/modules/nf-core/molkartgarage/clahe/tests/tags.yml @@ -0,0 +1,2 @@ +molkartgarage/clahe: + - "modules/nf-core/molkartgarage/clahe/**"