Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New module to burn voxels #27

Merged
merged 7 commits into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modules/nf-neuro/image/burnvoxels/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
channels: []
dependencies: []
name: image_burnvoxels
80 changes: 80 additions & 0 deletions modules/nf-neuro/image/burnvoxels/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
process IMAGE_BURNVOXELS {
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(masks), path(anat)

output:
tuple val(meta), path("*__all.nii.gz"), emit: all_masks_burned
tuple val(meta), path("*__*_*.nii.gz"), emit: each_mask_burned
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}"
String masks_list = masks.join(", ").replace(',', '')
Integer nb_masks = masks.size()
"""
# Normalize the anatomy between 0 and 300
scil_volume_math.py convert ${anat} anat_f32.nii.gz --data_type float32 -f
scil_volume_math.py normalize_max anat_f32.nii.gz anat_normalize.nii.gz -f
mrcalc 300 anat_normalize.nii.gz -multiply anat_normalize_300.nii.gz -force

# Set the step value for be applied to each bundle
mkdir masks_burned/
cnt=25
nb_masks=${nb_masks}
step=\$(echo 300 \${nb_masks} | awk '{print \$1 / (\$2 - 1)}')

for m in ${masks_list};
do
mname=\${m%%.*}
mname=\${mname##*__}
scil_volume_math.py convert \${m} masks_burned/tmp_\${mname}_f32.nii.gz --data_type float32 -f
mrcalc \${cnt} masks_burned/tmp_\${mname}_f32.nii.gz -multiply masks_burned/mask_\${mname}_\${cnt}.nii.gz -force
ImageMath 3 ${prefix}__\${mname}_\${cnt}.nii.gz addtozero masks_burned/mask_\${mname}_\${cnt}.nii.gz anat_normalize_300.nii.gz
rm masks_burned/tmp_\${mname}_f32.nii.gz
cnt=\$(echo \$cnt \${step} | awk '{print \$1 + \$2}');
done

echo $nb_masks
if [ \$nb_masks -eq 1 ]; then
mv masks_burned/mask_*.nii.gz mask_all_masks.nii.gz
else
scil_volume_math.py addition masks_burned/mask_*.nii.gz mask_all_masks.nii.gz -f
fi

ImageMath 3 ${prefix}__all.nii.gz addtozero mask_all_masks.nii.gz anat_normalize_300.nii.gz

cat <<-END_VERSIONS > versions.yml
"${task.process}":
ants: \$(antsRegistration --version | grep Version | cut -d" " -f3)
mrtrix \$(mrcalc -version | grep mrcalc | cut -d" " -f3)
scilpy: \$(pip list --disable-pip-version-check --no-python-version-warning | grep scilpy | tr -s ' ' | cut -d' ' -f2)
GuillaumeTh marked this conversation as resolved.
Show resolved Hide resolved
END_VERSIONS
"""

stub:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
"""
touch ${prefix}__all.nii.gz
touch ${prefix}__AF_L_25.nii.gz
touch ${prefix}__AF_L_125.nii.gz

cat <<-END_VERSIONS > versions.yml
"${task.process}":
ants: \$(antsRegistration --version | grep Version | cut -d" " -f3)
mrtrix \$(mrcalc -version | grep mrcalc | cut -d" " -f3)
scilpy: \$(pip list --disable-pip-version-check --no-python-version-warning | grep scilpy | tr -s ' ' | cut -d' ' -f2)
END_VERSIONS
"""
}
72 changes: 72 additions & 0 deletions modules/nf-neuro/image/burnvoxels/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
name: "image_burnvoxels"
description: |
1. **Burning Voxels**: The module takes binary masks and "burns" or imprints their voxels onto an anatomical image.
This means that the areas defined by the masks are marked or labeled on the anatomical image.

2. **Output Images**: The module generates multiple output images:
- One image with all masks burned onto the anatomical image.
- Separate images for each mask burned onto the anatomical image. If there are N masks, there will be N images.

3. **Label Values**: The burned voxels are assigned label values:
- The minimum label value is 25.
- Subsequent label values are incremented by a dynamically determined step based on the number of masks.

In summary, this module processes an anatomical image by applying binary masks to it, generating multiple labeled images as output.
keywords:
- Image Processing
- Voxel Burning
- Mask Application
tools:
GuillaumeTh marked this conversation as resolved.
Show resolved Hide resolved
- "ANTs":
description: "Advanced Normalization Tools (ANTs) for image processing."
homepage: "http://stnava.github.io/ANTs/"
- "mrtrix":
arnaudbore marked this conversation as resolved.
Show resolved Hide resolved
description: "MRtrix3 is a software package for various types of diffusion imaging data, including diffusion-weighted, diffusion-tensor, and q-ball imaging."
homepage: "https://www.mrtrix.org/"
- "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 ]`

- masks:
type: list
description: List of binary masks to be burned onto the anatomical image.
pattern: "*.nii.gz"

- anat:
type: file
description: Anatomical image to burn the masks onto.
pattern: "*.nii.gz"

output:
- meta:
type: map
description: |
Groovy Map containing sample information
e.g. `[ id:'sample1', single_end:false ]`

- all_masks_burned:
type: file
description: Anatomical image with all masks burned onto it.
pattern: "*.nii.gz"

- each_mask_burned:
type: list
description: Anatomical image with each mask burned onto it.
pattern: "*.nii.gz"

- versions:
type: file
description: File containing software versions
pattern: "versions.yml"

authors:
- "@GuillaumeTh"
maintainers:
- "@GuillaumeTh"
50 changes: 50 additions & 0 deletions modules/nf-neuro/image/burnvoxels/tests/main.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
nextflow_process {

name "Test Process IMAGE_BURNVOXELS"
script "../main.nf"
process "IMAGE_BURNVOXELS"

tag "modules"
tag "modules_nfcore"
tag "image"
tag "image/burnvoxels"

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( [ "tractometry.zip" ] )
input[1] = "test.load-test-data"
"""
}
}
}

test("burnvoxels - two masks") {

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}/IFGWM.nii.gz"), file("\${test_data_directory}/IFGWM_labels_map.nii.gz")],
file("\${test_data_directory}/mni_masked.nii.gz")
]
}
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() }
)
}
}
}
61 changes: 61 additions & 0 deletions modules/nf-neuro/image/burnvoxels/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"burnvoxels - two masks": {
"content": [
{
"0": [
[
{
"id": "test",
"single_end": false
},
"test__all.nii.gz:md5,7e8fe36daf0dfba28a5701c55e98a0ab"
]
],
"1": [
[
{
"id": "test",
"single_end": false
},
[
"test__IFGWM_25.nii.gz:md5,d9654356d7f9c2b0eda5f69e8e71b9c4",
"test__IFGWM_labels_map_325.nii.gz:md5,1169f8f2dba2ef2addaea6afd0ee82c2"
]
]
],
"2": [
"versions.yml:md5,950062f43518f49bd79589bb79b16191"
],
"all_masks_burned": [
[
{
"id": "test",
"single_end": false
},
"test__all.nii.gz:md5,7e8fe36daf0dfba28a5701c55e98a0ab"
]
],
"each_mask_burned": [
[
{
"id": "test",
"single_end": false
},
[
"test__IFGWM_25.nii.gz:md5,d9654356d7f9c2b0eda5f69e8e71b9c4",
"test__IFGWM_labels_map_325.nii.gz:md5,1169f8f2dba2ef2addaea6afd0ee82c2"
]
]
],
"versions": [
"versions.yml:md5,950062f43518f49bd79589bb79b16191"
]
}
],
"meta": {
"nf-test": "0.9.0",
"nextflow": "24.10.0"
},
"timestamp": "2024-10-30T15:22:58.330309703"
}
}
2 changes: 2 additions & 0 deletions modules/nf-neuro/image/burnvoxels/tests/tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
image/burnvoxels:
- "modules/nf-neuro/image/burnvoxels/**"