diff --git a/modules/nf-neuro/tractogram/densitymap/environment.yml b/modules/nf-neuro/tractogram/densitymap/environment.yml new file mode 100644 index 0000000..d32f726 --- /dev/null +++ b/modules/nf-neuro/tractogram/densitymap/environment.yml @@ -0,0 +1,3 @@ +channels: [] +dependencies: [] +name: tractogram_densitymap diff --git a/modules/nf-neuro/tractogram/densitymap/main.nf b/modules/nf-neuro/tractogram/densitymap/main.nf new file mode 100644 index 0000000..964ab7a --- /dev/null +++ b/modules/nf-neuro/tractogram/densitymap/main.nf @@ -0,0 +1,46 @@ +process TRACTOGRAM_DENSITYMAP { + 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(tractogram) + + output: + tuple val(meta), path("*__*.nii.gz"), emit: density_map + path "versions.yml" , emit: versions + + when: + task.ext.when == null || task.ext.when + + script: + def args = task.ext.args ?: '' + def prefix = task.ext.prefix ?: "${meta.id}" + def binary = task.ext.is_binary ? "--binary" : "" + """ + bname=\$(basename ${tractogram} .trk) + scil_tractogram_compute_density_map.py $tractogram ${prefix}__\${bname}.nii.gz ${binary} + + 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 args = task.ext.args ?: '' + def prefix = task.ext.prefix ?: "${meta.id}" + """ + scil_tractogram_compute_density_map.py -h + + touch ${prefix}_AF_L.nii.gz + + 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-neuro/tractogram/densitymap/meta.yml b/modules/nf-neuro/tractogram/densitymap/meta.yml new file mode 100644 index 0000000..7f0ebee --- /dev/null +++ b/modules/nf-neuro/tractogram/densitymap/meta.yml @@ -0,0 +1,45 @@ +--- +name: "tractogram_densitymap" +description: Compute density maps from tractograms +keywords: + - Diffusion MRI + - Tractogram + - Density Map +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:'test', single_end:false ]` + + - tractogram: + type: file + description: Tractogram file for density map computation + pattern: "*.trk" + +output: + - meta: + type: map + description: | + Groovy Map containing sample information + e.g. `[ id:'test', single_end:false ]` + + - density_map: + type: file + description: Computed density map + pattern: "*.nii.gz" + + - versions: + type: file + description: File containing software versions + pattern: "versions.yml" + +authors: + - "@GuillaumeTh" +maintainers: + - "@GuillaumeTh" diff --git a/modules/nf-neuro/tractogram/densitymap/tests/main.nf.test b/modules/nf-neuro/tractogram/densitymap/tests/main.nf.test new file mode 100644 index 0000000..eac8bae --- /dev/null +++ b/modules/nf-neuro/tractogram/densitymap/tests/main.nf.test @@ -0,0 +1,75 @@ +nextflow_process { + + name "Test Process TRACTOGRAM_DENSITYMAP" + script "../main.nf" + process "TRACTOGRAM_DENSITYMAP" + + tag "modules" + tag "modules_nfcore" + tag "tractogram" + tag "tractogram/densitymap" + + tag "subworkflows" + tag "subworkflows/load_test_data" + + setup { + run("LOAD_TEST_DATA", alias: "LOAD_DATA") { + script "../../../../../subworkflows/nf-neuro/load_test_data/main.nf" + process { + """ + input[0] = Channel.from( [ "bundles.zip" ] ) + input[1] = "test.load-test-data" + """ + } + } + } + + test("densitymap - map") { + + 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}/bundle_all_1mm.trk") + ] + } + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + } + + test("densitymap - mask") { + + config "./nextflow_mask.config" + + 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}/bundle_all_1mm.trk") + ] + } + """ + } + } + + then { + assertAll( + { assert process.success }, + { assert snapshot(process.out).match() } + ) + } + } + +} diff --git a/modules/nf-neuro/tractogram/densitymap/tests/main.nf.test.snap b/modules/nf-neuro/tractogram/densitymap/tests/main.nf.test.snap new file mode 100644 index 0000000..5429afc --- /dev/null +++ b/modules/nf-neuro/tractogram/densitymap/tests/main.nf.test.snap @@ -0,0 +1,72 @@ +{ + "densitymap - map": { + "content": [ + { + "0": [ + [ + { + "id": "test", + "single_end": false + }, + "test__bundle_all_1mm.nii.gz:md5,a9cc8ba016a680ec8cbac940c45e5464" + ] + ], + "1": [ + "versions.yml:md5,7a2b58d5ff9231cb698c8ca1a279171f" + ], + "density_map": [ + [ + { + "id": "test", + "single_end": false + }, + "test__bundle_all_1mm.nii.gz:md5,a9cc8ba016a680ec8cbac940c45e5464" + ] + ], + "versions": [ + "versions.yml:md5,7a2b58d5ff9231cb698c8ca1a279171f" + ] + } + ], + "meta": { + "nf-test": "0.9.0", + "nextflow": "24.10.0" + }, + "timestamp": "2024-10-31T13:26:09.344942322" + }, + "densitymap - mask": { + "content": [ + { + "0": [ + [ + { + "id": "test", + "single_end": false + }, + "test__bundle_all_1mm.nii.gz:md5,5c682d295c593e132295e21e753a6f4f" + ] + ], + "1": [ + "versions.yml:md5,7a2b58d5ff9231cb698c8ca1a279171f" + ], + "density_map": [ + [ + { + "id": "test", + "single_end": false + }, + "test__bundle_all_1mm.nii.gz:md5,5c682d295c593e132295e21e753a6f4f" + ] + ], + "versions": [ + "versions.yml:md5,7a2b58d5ff9231cb698c8ca1a279171f" + ] + } + ], + "meta": { + "nf-test": "0.9.0", + "nextflow": "24.10.0" + }, + "timestamp": "2024-10-31T13:26:15.496099088" + } +} \ No newline at end of file diff --git a/modules/nf-neuro/tractogram/densitymap/tests/nextflow_mask.config b/modules/nf-neuro/tractogram/densitymap/tests/nextflow_mask.config new file mode 100644 index 0000000..0cdbe09 --- /dev/null +++ b/modules/nf-neuro/tractogram/densitymap/tests/nextflow_mask.config @@ -0,0 +1,6 @@ +process { + withName: "TRACTOGRAM_DENSITYMAP" { + publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" } + ext.is_binary = true + } +} diff --git a/modules/nf-neuro/tractogram/densitymap/tests/tags.yml b/modules/nf-neuro/tractogram/densitymap/tests/tags.yml new file mode 100644 index 0000000..34b3d41 --- /dev/null +++ b/modules/nf-neuro/tractogram/densitymap/tests/tags.yml @@ -0,0 +1,2 @@ +tractogram/densitymap: + - "modules/nf-neuro/tractogram/densitymap/**"