From 43e0721bc5e202d447f614141f5043d1f233b18f Mon Sep 17 00:00:00 2001 From: Anthony Gagnon Date: Tue, 10 Sep 2024 19:54:05 +0000 Subject: [PATCH] add bundle coloring module --- .../nf-scil/bundle/coloring/environment.yml | 8 +++ modules/nf-scil/bundle/coloring/main.nf | 53 +++++++++++++++++++ modules/nf-scil/bundle/coloring/meta.yml | 45 ++++++++++++++++ .../bundle/coloring/tests/main.nf.test | 46 ++++++++++++++++ .../bundle/coloring/tests/main.nf.test.snap | 53 +++++++++++++++++++ .../bundle/coloring/tests/nextflow.config | 14 +++++ .../nf-scil/bundle/coloring/tests/tags.yml | 2 + 7 files changed, 221 insertions(+) create mode 100644 modules/nf-scil/bundle/coloring/environment.yml create mode 100644 modules/nf-scil/bundle/coloring/main.nf create mode 100644 modules/nf-scil/bundle/coloring/meta.yml create mode 100644 modules/nf-scil/bundle/coloring/tests/main.nf.test create mode 100644 modules/nf-scil/bundle/coloring/tests/main.nf.test.snap create mode 100644 modules/nf-scil/bundle/coloring/tests/nextflow.config create mode 100644 modules/nf-scil/bundle/coloring/tests/tags.yml diff --git a/modules/nf-scil/bundle/coloring/environment.yml b/modules/nf-scil/bundle/coloring/environment.yml new file mode 100644 index 00000000..eca15051 --- /dev/null +++ b/modules/nf-scil/bundle/coloring/environment.yml @@ -0,0 +1,8 @@ +--- +# yaml-language-server: $schema=https://raw.githubusercontent.com/nf-core/modules/master/modules/environment-schema.json +name: "bundle_coloring" +channels: + - Docker + - Apptainer +dependencies: + - "scilpy" diff --git a/modules/nf-scil/bundle/coloring/main.nf b/modules/nf-scil/bundle/coloring/main.nf new file mode 100644 index 00000000..cd583f40 --- /dev/null +++ b/modules/nf-scil/bundle/coloring/main.nf @@ -0,0 +1,53 @@ +import groovy.json.JsonOutput + +process BUNDLE_COLORING { + tag "$meta.id" + label 'process_single' + + container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ? + 'https://scil.usherbrooke.ca/containers/scilus_2.0.2.sif': + 'scilus/scilus:2.0.2' }" + + input: + tuple val(meta), path(bundles) + + output: + tuple val(meta), path("*_colored.trk") , emit: bundles + path "versions.yml" , emit: versions + + when: + task.ext.when == null || task.ext.when + + script: + def prefix = task.ext.prefix ?: "${meta.id}" + def json_str = JsonOutput.toJson(task.ext.colors) + String bundles_list = bundles.join(", ").replace(',', '') + + """ + echo '$json_str' >> colors.json + scil_tractogram_assign_uniform_color.py --dict_colors colors.json \ + --out_suffix "_colored" $bundles_list + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + scilpy: \$(pip list --disable-pip-version-check --no-python-version-warning | grep scilpy | tr -s ' ' | cut -d' ' -f2) + END_VERSIONS + """ + + stub: + def prefix = task.ext.prefix ?: "${meta.id}" + + """ + for bundle in $bundles_list; do + bname=\$(basename \$bundle .\${ext}) + touch \${bname}_colored.trk + done + + scil_tractogram_assign_uniform_color.py -h + + cat <<-END_VERSIONS > versions.yml + "${task.process}": + scilpy: \$(pip list --disable-pip-version-check --no-python-version-warning | grep scilpy | tr -s ' ' | cut -d' ' -f2) + END_VERSIONS + """ +} diff --git a/modules/nf-scil/bundle/coloring/meta.yml b/modules/nf-scil/bundle/coloring/meta.yml new file mode 100644 index 00000000..d4e6f5b8 --- /dev/null +++ b/modules/nf-scil/bundle/coloring/meta.yml @@ -0,0 +1,45 @@ +--- +name: "bundle_coloring" +description: Assign color to bundles. +keywords: + - Bundles + - Coloring + - Tractometry +tools: + - "scilpy": + description: "The Sherbrooke Connectivity Imaging Lab (SCIL) Python dMRI processing toolbox." + homepage: "https://github.com/scilus/scilpy.git" + +input: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. `[ id:'sample1', single_end:false ]` + + - bundles: + type: file + description: Flatten list of trk files containing bundles to be colored. + pattern: "*.trk" + +output: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. `[ id:'sample1', single_end:false ]` + + - bundles: + type: file + description: Colored bundles file. + pattern: "*_colored.trk" + + - versions: + type: file + description: File containing software versions + pattern: "versions.yml" + +authors: + - "@gagnonanthony" +maintainers: + - "@gagnonanthony" diff --git a/modules/nf-scil/bundle/coloring/tests/main.nf.test b/modules/nf-scil/bundle/coloring/tests/main.nf.test new file mode 100644 index 00000000..18841ebf --- /dev/null +++ b/modules/nf-scil/bundle/coloring/tests/main.nf.test @@ -0,0 +1,46 @@ +nextflow_process { + + name "Test Process BUNDLE_COLORING" + script "../main.nf" + process "BUNDLE_COLORING" + config "./nextflow.config" + + tag "modules" + tag "modules_nfcore" + tag "bundle" + tag "bundle/coloring" + + tag "subworkflows/load_test_data" + + test("bundle - coloring") { + setup { + run("LOAD_TEST_DATA", alias: "LOAD_DATA") { + script "../../../../../subworkflows/nf-scil/load_test_data/main.nf" + process { + """ + input[0] = Channel.from( [ "bundles.zip" ] ) + input[1] = "test.load-test-data" + """ + } + } + } + when { + process { + """ + input[0] = LOAD_DATA.out.test_data_directory.map{ + test_data_directory -> [ + [ id:'test', single_end:false ], // meta map + file("\${test_data_directory}/fibercup_atlas/subj_1/*.trk", checkIfExists: true) + ] + } + """ + } + } + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + } +} diff --git a/modules/nf-scil/bundle/coloring/tests/main.nf.test.snap b/modules/nf-scil/bundle/coloring/tests/main.nf.test.snap new file mode 100644 index 00000000..7b674bf3 --- /dev/null +++ b/modules/nf-scil/bundle/coloring/tests/main.nf.test.snap @@ -0,0 +1,53 @@ +{ + "bundle - coloring": { + "content": [ + { + "0": [ + [ + { + "id": "test", + "single_end": false + }, + [ + "bundle_0_colored.trk:md5,28654c91d0f6c5e3f3a7f101f7fd482d", + "bundle_1_colored.trk:md5,3b58a00009f2bb24c4051dd88d53aeee", + "bundle_2_colored.trk:md5,21d955afc36acfd8b214e562b199f929", + "bundle_3_colored.trk:md5,5ce663fb79ad52f1b30fe462d5b48afe", + "bundle_4_colored.trk:md5,da36a33cbaa5e38801480b51ee2943b4", + "bundle_5_colored.trk:md5,0c2cd57e4372c2b71274cafc03d82490", + "bundle_6_colored.trk:md5,0614ea97e6f1fa44e40cef2c2c67a4b1" + ] + ] + ], + "1": [ + "versions.yml:md5,99caf95a695ad5ae4c7e8e879af86b5a" + ], + "bundles": [ + [ + { + "id": "test", + "single_end": false + }, + [ + "bundle_0_colored.trk:md5,28654c91d0f6c5e3f3a7f101f7fd482d", + "bundle_1_colored.trk:md5,3b58a00009f2bb24c4051dd88d53aeee", + "bundle_2_colored.trk:md5,21d955afc36acfd8b214e562b199f929", + "bundle_3_colored.trk:md5,5ce663fb79ad52f1b30fe462d5b48afe", + "bundle_4_colored.trk:md5,da36a33cbaa5e38801480b51ee2943b4", + "bundle_5_colored.trk:md5,0c2cd57e4372c2b71274cafc03d82490", + "bundle_6_colored.trk:md5,0614ea97e6f1fa44e40cef2c2c67a4b1" + ] + ] + ], + "versions": [ + "versions.yml:md5,99caf95a695ad5ae4c7e8e879af86b5a" + ] + } + ], + "meta": { + "nf-test": "0.9.0-rc1", + "nextflow": "24.04.3" + }, + "timestamp": "2024-09-10T15:52:32.023077" + } +} \ No newline at end of file diff --git a/modules/nf-scil/bundle/coloring/tests/nextflow.config b/modules/nf-scil/bundle/coloring/tests/nextflow.config new file mode 100644 index 00000000..abc7a82f --- /dev/null +++ b/modules/nf-scil/bundle/coloring/tests/nextflow.config @@ -0,0 +1,14 @@ +process { + publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" } + withName: "BUNDLE_COLORING" { + ext.colors = [ + "bundle_0":"0xd9bd09", + "bundle_1":"0xcc0000", + "bundle_2":"0xffdf0f", + "bundle_3":"0x0d6cbf", + "bundle_4":"0xbf0099", + "bundle_5":"0xf20505", + "bundle_6":"0x9ad909" + ] + } +} diff --git a/modules/nf-scil/bundle/coloring/tests/tags.yml b/modules/nf-scil/bundle/coloring/tests/tags.yml new file mode 100644 index 00000000..4d98ed8b --- /dev/null +++ b/modules/nf-scil/bundle/coloring/tests/tags.yml @@ -0,0 +1,2 @@ +bundle/coloring: + - "modules/nf-scil/bundle/coloring/**"