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 1 commit
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
78 changes: 78 additions & 0 deletions modules/nf-neuro/image/burnvoxels/main.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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%%_binary_mask.nii.gz}
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)
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)
scilpy: \$(pip list --disable-pip-version-check --no-python-version-warning | grep scilpy | tr -s ' ' | cut -d' ' -f2)
END_VERSIONS
"""
}
57 changes: 57 additions & 0 deletions modules/nf-neuro/image/burnvoxels/meta.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: "image_burnvoxels"
description: Burn voxels from masks into an anatomical image.
GuillaumeTh marked this conversation as resolved.
Show resolved Hide resolved
keywords:
- Image Processing
- Voxel Burning
- Mask Application
tools:
GuillaumeTh marked this conversation as resolved.
Show resolved Hide resolved
- "scilpy":
description: "The Sherbrooke Connectivity Imaging Lab (SCIL) Python dMRI processing toolbox."
homepage: "https://github.com/scilus/scilpy.git"
- "ANTs":
description: "Advanced Normalization Tools (ANTs) for image processing."
homepage: "http://stnava.github.io/ANTs/"

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 - one mask") {
GuillaumeTh marked this conversation as resolved.
Show resolved Hide resolved

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 - one mask": {
"content": [
{
"0": [
[
{
"id": "test",
"single_end": false
},
"test__all.nii.gz:md5,7e8fe36daf0dfba28a5701c55e98a0ab"
]
],
"1": [
[
{
"id": "test",
"single_end": false
},
[
"test__IFGWM.nii.gz_25.nii.gz:md5,d9654356d7f9c2b0eda5f69e8e71b9c4",
"test__IFGWM_labels_map.nii.gz_325.nii.gz:md5,1169f8f2dba2ef2addaea6afd0ee82c2"
GuillaumeTh marked this conversation as resolved.
Show resolved Hide resolved
]
]
],
"2": [
"versions.yml:md5,1a0b41002228884620a8f86332c19ad9"
],
"all_masks_burned": [
[
{
"id": "test",
"single_end": false
},
"test__all.nii.gz:md5,7e8fe36daf0dfba28a5701c55e98a0ab"
]
],
"each_mask_burned": [
[
{
"id": "test",
"single_end": false
},
[
"test__IFGWM.nii.gz_25.nii.gz:md5,d9654356d7f9c2b0eda5f69e8e71b9c4",
"test__IFGWM_labels_map.nii.gz_325.nii.gz:md5,1169f8f2dba2ef2addaea6afd0ee82c2"
]
]
],
"versions": [
"versions.yml:md5,1a0b41002228884620a8f86332c19ad9"
]
}
],
"meta": {
"nf-test": "0.9.0",
"nextflow": "24.10.0"
},
"timestamp": "2024-10-29T19:38:30.486863739"
}
}
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/**"