Skip to content

Commit

Permalink
Merge pull request #149 from ThoumyreStanislas/correction_registratio…
Browse files Browse the repository at this point in the history
…n_tractogram

[MODULE] Migrate tests registraction tractogram
  • Loading branch information
arnaudbore committed May 21, 2024
2 parents 613f832 + e9a522d commit 2cc9b03
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 66 deletions.
7 changes: 7 additions & 0 deletions modules/nf-scil/registration/tractogram/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
name: "registration_tractogram"
channels:
- Docker
- Apptainer
dependencies:
- "Scilpy"
36 changes: 19 additions & 17 deletions modules/nf-scil/registration/tractogram/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ process REGISTRATION_TRACTOGRAM {
label 'process_single'

container "${ workflow.containerEngine == 'singularity' && !task.ext.singularity_pull_docker_container ?
'scil.usherbrooke.ca/containers/scilus_1.6.0.sif':
'scilus/scilus:1.6.0' }"
'https://scil.usherbrooke.ca/containers/scilus_2.0.2.sif':
'scilus/scilus:2.0.2' }"

input:
tuple val(meta), path(anat), path(transfo), path(tractograms_dir, stageAs: 'tractograms/'), path(ref) /* optional, value = [] */, path(deformation) /* optional, value = [] */
tuple val(meta), path(anat), path(transfo), path(tractogram), path(ref) /* optional, value = [] */, path(deformation) /* optional, value = [] */

output:
tuple val(meta), path("*__*.{trk,tck}"), emit: warped_tractogram
Expand All @@ -18,6 +18,7 @@ process REGISTRATION_TRACTOGRAM {

script:
def prefix = task.ext.prefix ?: "${meta.id}"
def suffix = task.ext.suffix ? "_${task.ext.suffix}" : ""
def reference = "$ref" ? "--reference $ref" : ""
def in_deformation = "$deformation" ? "--in_deformation $deformation" : ""

Expand All @@ -32,20 +33,19 @@ process REGISTRATION_TRACTOGRAM {
def no_empty = task.ext.no_empty ? "--no_empty" : ""

"""
for tractogram in ${tractograms_dir};
for tractogram in ${tractogram};
do \
bname=\${tractogram/${prefix}_/_}
ext=\${tractogram#*.}
bname=\$(basename \${bname} .\${ext})
bname=\$(basename \${tractogram} .\${ext})
scil_apply_transform_to_tractogram.py \$tractogram $anat $transfo tmp.trk\
scil_tractogram_apply_transform.py \$tractogram $anat $transfo tmp.trk\
$in_deformation\
$inverse\
$reverse_operation\
$force\
$reference
scil_remove_invalid_streamlines.py tmp.trk ${prefix}__\${bname}.\${ext}\
scil_tractogram_remove_invalid.py tmp.trk ${prefix}__\${bname}${suffix}.\${ext}\
$cut_invalid\
$remove_single_point\
$remove_overlapping_points\
Expand All @@ -54,30 +54,32 @@ process REGISTRATION_TRACTOGRAM {
-f
done
cat <<-END_VERSIONS > versions.yml
"${task.process}":
scilpy: 1.6.0
scilpy: 2.0.2
END_VERSIONS
"""

stub:
def prefix = task.ext.prefix ?: "${meta.id}"
def suffix = task.ext.suffix ? "_${task.ext.suffix}" : ""
"""
for tractogram in ${tractograms_dir};
scil_tractogram_apply_transform.py -h
scil_tractogram_remove_invalid.py -h
for tractogram in ${tractogram};
do \
bname=\${tractogram/${prefix}_/_}
ext=\${tractogram#*.}
bname=\$(basename \${bname} .\${ext})
bname=\$(basename \${tractogram} .\${ext})
touch ${prefix}__\${bname}.\${ext}
touch ${prefix}__\${bname}${suffix}.\${ext}
done
scil_apply_transform_to_tractogram.py -h
scil_remove_invalid_streamlines.py -h
cat <<-END_VERSIONS > versions.yml
"${task.process}":
scilpy: 1.6.0
scilpy: 2.0.2
END_VERSIONS
"""
}
16 changes: 13 additions & 3 deletions modules/nf-scil/registration/tractogram/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,21 @@ input:
description: ANTs affine transform
pattern: "*.mat"

- tractograms_dir:
type: directory
description: Path to directory containing tractograms to register
- tractogram:
type: file
description: Tractogram or list of tractograms to register
pattern: "*.{trk,tck}"

- ref:
type: file
description: Reference anatomy for tck/vtk/fib/dpy file support (.nii or .nii.gz) (optional)
pattern: "*.{tck,vtk,fib,dpy}"

- deformation:
type: file
description: Path to the file containing a deformation field (optional)
pattern: "*.{nii,nii.gz}"

output:
- meta:
type: map
Expand Down
88 changes: 88 additions & 0 deletions modules/nf-scil/registration/tractogram/tests/main.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@

nextflow_process {

name "Test Process REGISTRATION_TRACTOGRAM"
script "../main.nf"
process "REGISTRATION_TRACTOGRAM"
config "./nextflow.config"

tag "modules"
tag "modules_nfcore"
tag "registration"
tag "registration/tractogram"

tag "subworkflows"
tag "subworkflows/load_test_data"

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"
"""
}
}
}


test("registration - tractogram_bundles") {


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.nii.gz", checkIfExists: true),
file("\${test_data_directory}/affine.txt", checkIfExists: true),
file("\${test_data_directory}/fibercup_atlas/subj_1/*.trk", checkIfExists: true),
[],
[]
]
}
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() }
)
}

}

test("registration - tractogram") {

config "./nextflow_suffix.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.nii.gz", checkIfExists: true),
file("\${test_data_directory}/affine.txt", checkIfExists: true),
file("\${test_data_directory}/fibercup_atlas/subj_1/bundle_2.trk", checkIfExists: true),
[],
[]
]
}
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out).match() }
)
}

}
}
88 changes: 88 additions & 0 deletions modules/nf-scil/registration/tractogram/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"registration - tractogram_bundles": {
"content": [
{
"0": [
[
{
"id": "test",
"single_end": false
},
[
"test__bundle_0.trk:md5,6e14cc02b66d12d5dde0a0701918385a",
"test__bundle_1.trk:md5,ef5a759144ab7e8d2f5abf30a463a152",
"test__bundle_2.trk:md5,824bcbf796cbce3e1c93e39d1c98dcf9",
"test__bundle_3.trk:md5,8877161b9aebaa6b12a4d7a8f8410407",
"test__bundle_4.trk:md5,6c8658b946154896952ca89e88fcf29f",
"test__bundle_5.trk:md5,fa058f93d9bfe4bed2ff027e9acd5682",
"test__bundle_6.trk:md5,125e50561b4b0c5fd8ee23867c28bc51"
]
]
],
"1": [
"versions.yml:md5,609469c08e60062eed7528276deddf5e"
],
"versions": [
"versions.yml:md5,609469c08e60062eed7528276deddf5e"
],
"warped_tractogram": [
[
{
"id": "test",
"single_end": false
},
[
"test__bundle_0.trk:md5,6e14cc02b66d12d5dde0a0701918385a",
"test__bundle_1.trk:md5,ef5a759144ab7e8d2f5abf30a463a152",
"test__bundle_2.trk:md5,824bcbf796cbce3e1c93e39d1c98dcf9",
"test__bundle_3.trk:md5,8877161b9aebaa6b12a4d7a8f8410407",
"test__bundle_4.trk:md5,6c8658b946154896952ca89e88fcf29f",
"test__bundle_5.trk:md5,fa058f93d9bfe4bed2ff027e9acd5682",
"test__bundle_6.trk:md5,125e50561b4b0c5fd8ee23867c28bc51"
]
]
]
}
],
"meta": {
"nf-test": "0.8.4",
"nextflow": "23.10.1"
},
"timestamp": "2024-05-15T19:11:42.198039"
},
"registration - tractogram": {
"content": [
{
"0": [
[
{
"id": "test",
"single_end": false
},
"test__bundle_2_mni.trk:md5,824bcbf796cbce3e1c93e39d1c98dcf9"
]
],
"1": [
"versions.yml:md5,609469c08e60062eed7528276deddf5e"
],
"versions": [
"versions.yml:md5,609469c08e60062eed7528276deddf5e"
],
"warped_tractogram": [
[
{
"id": "test",
"single_end": false
},
"test__bundle_2_mni.trk:md5,824bcbf796cbce3e1c93e39d1c98dcf9"
]
]
}
],
"meta": {
"nf-test": "0.8.4",
"nextflow": "23.10.1"
},
"timestamp": "2024-05-15T19:11:52.03634"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
process {
withName: "REGISTRATION_TRACTOGRAM" {
publishDir = { "${params.outdir}/${task.process.tokenize(':')[-1].tokenize('_')[0].toLowerCase()}" }
ext.inverse = true
ext.force = true
ext.reverse_operation = true
ext.cut_invalid = true
ext.remove_single_point = true
ext.remove_overlapping_points = true
ext.threshold = 0.001
ext.no_empty = true
ext.suffix = 'mni'
}
}
2 changes: 2 additions & 0 deletions modules/nf-scil/registration/tractogram/tests/tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
registration/tractogram:
- "modules/nf-scil/registration/tractogram/**"
25 changes: 0 additions & 25 deletions tests/modules/nf-scil/registration/tractogram/main.nf

This file was deleted.

21 changes: 0 additions & 21 deletions tests/modules/nf-scil/registration/tractogram/test.yml

This file was deleted.

0 comments on commit 2cc9b03

Please sign in to comment.