Skip to content

Commit

Permalink
Fix alex comments
Browse files Browse the repository at this point in the history
  • Loading branch information
anroy1 committed Sep 13, 2024
1 parent acda670 commit bea6c73
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 174 deletions.
51 changes: 28 additions & 23 deletions subworkflows/nf-scil/registration/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,34 @@ include { REGISTRATION_ANATTODWI } from '../../../modules/nf-scil/registration/
include { REGISTRATION_ANTS } from '../../../modules/nf-scil/registration/ants/main'
include { REGISTRATION_EASYREG } from '../../../modules/nf-scil/registration/easyreg/main'

params.run_surgery = params.run_surgery?: false
params.run_surgery = false

workflow REGISTRATION {

// ** The subworkflow requires at least ch_image and ch_ref as inputs to ** //
// ** The subworkflow requires at least ch_image and ch_ref as inputs to ** //
// ** properly perform the registration. Supplying a ch_metric will select ** //
// ** the REGISTRATION_ANATTODWI module meanwhile NOT supplying a ch_metric ** //
// ** will select the REGISTRATION_ANTS (SyN or SyNQuick) module. ** //
// ** the REGISTRATION_ANATTODWI module meanwhile NOT supplying a ch_metric ** //
// ** will select the REGISTRATION_ANTS (SyN or SyNQuick) module. Alternatively, ** //
// ** NOT supplying ch_metric and activating run_surgery flag with select REGISTRATION_EASYREG ** //

take:
ch_image // channel: [ val(meta), [ image ] ]
ch_ref // channel: [ val(meta), [ ref ] ]
ch_metric // channel: [ val(meta), [ metric ] ], optional
ch_mask // channel: [ val(meta), [ mask ] ], optional
ch_segmentation // channel: [ val(meta), [ flo_segmentation ] ], optional
ch_ref_segmentation // channel: [ val(meta), [ ref_segmentation ] ], optional
ch_flo_segmentation // channel: [ val(meta), [ flo_segmentation ] ], optional


main:

image_warped = Channel.empty()
ref_warped = Channel.empty()
transfo_image = Channel.empty()
transfo_trk = Channel.empty()
out_segmentation = Channel.empty()
out_ref_segmentation = Channel.empty()

ch_versions = Channel.empty()

if ( ch_metric ) {
Expand All @@ -34,17 +43,14 @@ workflow REGISTRATION {

// ** Setting outputs ** //
image_warped = REGISTRATION_ANATTODWI.out.t1_warped
ref_warped = Channel.empty()
transfo_image = REGISTRATION_ANATTODWI.out.transfo_image
transfo_trk = REGISTRATION_ANATTODWI.out.transfo_trk
ref_segmentation = Channel.empty()
image_segmentation = Channel.empty()
}
else if ( params.run_surgery ) {
// ** Set up input channel ** //
ch_register = ch_ref.combine(ch_image, by: 0)
.combine(ch_ref_segmentation, by: 0)
.combine(ch_flo_segmentation, by: 0)
.combine(ch_segmentation, by: 0)

// ** Registration using Easyreg ** //
REGISTRATION_EASYREG ( ch_register )
Expand All @@ -53,15 +59,16 @@ workflow REGISTRATION {
// ** Setting outputs ** //
image_warped = REGISTRATION_EASYREG.out.flo_reg
transfo_image = REGISTRATION_EASYREG.out.fwd_field
.map{ it + [[]] }
.map{ it + [[]] }
transfo_trk = REGISTRATION_EASYREG.out.bak_field
.map{ [[]] + it }
ref_warped - REGISTRATON_EASYREG.out.ref_reg
.map{ [[]] + it }
ref_warped - REGISTRATION_EASYREG.out.ref_reg

// ** Setting optional outputs. If segmentations are not provided as inputs, ** //
// ** easyreg will outputs synthseg segmentations ** //
ref_segmentation = ch_ref_segmentation ? REGISTRATION_EASYREG.out.ref_seg : Channel.empty()
flo_segmentation = ch_ref_segmentation ? REGISTRATION_EASYREG.out.flo_seg : Channel.empty()
out_segmentation = ch_segmentation ? Channel.empty() : REGISTRATION_EASYREG.out.flo_seg
out_ref_segmentation = ch_ref_segmentation ? Channel.empty() : REGISTRATION_EASYREG.out.ref_seg


}
else {
Expand All @@ -83,20 +90,18 @@ workflow REGISTRATION {

// ** Setting outputs ** //
image_warped = REGISTRATION_ANTS.out.image
ref_warped = Channel.empty()
transfo_image = REGISTRATION_ANTS.out.transfo_image
transfo_trk = REGISTRATION_ANTS.out.transfo_trk
ref_segmentation = Channel.empty()
flo_segmentation = Channel.empty()
}

emit:
image_warped = image_warped // channel: [ val(meta), [ image ] ]
ref_warped = ref_warped // channel: [ val(meta), [ ref ] ]
transfo_image = transfo_image // channel: [ val(meta), [ warp, affine ] ]
transfo_trk = transfo_trk // channel: [ val(meta), [ inverseAffine, inverseWarp ] ]
ref_segmentation = ref_segmentation // channel: [ val(meta), [ ref_seg ] ]
flo_segmentation = flo_segmentation // channel: [ val(meta), [ flo_seg ] ]
image_warped = image_warped // channel: [ val(meta), [ image ] ]
ref_warped = ref_warped // channel: [ val(meta), [ ref ] ]
transfo_image = transfo_image // channel: [ val(meta), [ warp, affine ] ]
transfo_trk = transfo_trk // channel: [ val(meta), [ inverseAffine, inverseWarp ] ]
segmentation = out_segmentation // channel: [ val(meta), [ segmentation ] ]
ref_segmentation = out_ref_segmentation // channel: [ val(meta), [ ref_segmentation ] ]


versions = ch_versions // channel: [ versions.yml ]
}
17 changes: 9 additions & 8 deletions subworkflows/nf-scil/registration/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,22 @@ input:
REGISTRATION_ANTS, see the description section above for more details.
Structure: [ val(meta), path(mask) ]
pattern: "*.{nii,nii.gz}"
- ch_ref_segmentation:
- ch_segmentation:
type: file
description: |
The input channel containing the the SynthSeg v2 (non-robust) segmentation + parcellation of the reference image.
The input channel containing the the SynthSeg v2 (non-robust) segmentation + parcellation of the moving (floating in Easyreg naming convention) image.
If it des not exist, Easyreg will create it. If it already exists (e.g., from a previous EasyReg run),
then EasyReg will read it from disk (which is faster than segmenting).
pattern: "*.{nii,nii.gz}"
- ch_flo_segmentation:
- ch_ref_segmentation:
type: file
description: |
The input channel containing the the SynthSeg v2 (non-robust) segmentation + parcellation of the floating image.
The input channel containing the the SynthSeg v2 (non-robust) segmentation + parcellation of the fixed (reference in Easyreg naming convention) image.
If it des not exist, Easyreg will create it. If it already exists (e.g., from a previous EasyReg run),
then EasyReg will read it from disk (which is faster than segmenting).
pattern: "*.{nii,nii.gz}"


output:
- image_warped:
type: file
Expand Down Expand Up @@ -97,15 +98,15 @@ output:
be used to register tractograms or bundle in the subject's anatomical space.
Structure: [ val(meta), [ path(inverseAffine), path(inverseWarp) ]
pattern: "*.{nii,nii.gz,mat}"
- ref_segmentation:
- out_segmentation:
type: file
description: |
Channel containing the file with the SynthSeg v2 (non-robust) segmentation + parcellation of the reference image.
Channel containing the file with the SynthSeg v2 (non-robust) segmentation + parcellation of the moving (floating in Easyreg naming convention) image.
pattern: "*.{nii,nii.gz}"
- flo_segmentation:
- out_ref_segmentation:
type: file
description: |
Channel containing the file with the SynthSeg v2 (non-robust) segmentation + parcellation of the floating image.
Channel containing the file with the SynthSeg v2 (non-robust) segmentation + parcellation of the fixed (reference in Easyreg naming convention) image.
pattern: "*.{nii,nii.gz}"
- versions:
type: file
Expand Down
24 changes: 21 additions & 3 deletions subworkflows/nf-scil/registration/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ nextflow_workflow {
then {
assertAll(
{ assert workflow.success},
{ assert snapshot(workflow.out).match()}
{ assert snapshot(
niftiMD5SUM(workflow.out.image_warped.get(0).get(1)),
workflow.out.transfo_image,
workflow.out.transfo_trk,
workflow.out.versions
).match()}
)
}
}
Expand Down Expand Up @@ -89,7 +94,12 @@ nextflow_workflow {
then {
assertAll(
{ assert workflow.success},
{ assert snapshot(workflow.out).match()}
{ assert snapshot(
niftiMD5SUM(workflow.out.image_warped.get(0).get(1)),
workflow.out.transfo_image,
workflow.out.transfo_trk,
workflow.out.versions
).match()}
)
}
}
Expand Down Expand Up @@ -120,7 +130,15 @@ nextflow_workflow {
then {
assertAll(
{ assert workflow.success},
{ assert snapshot(workflow.out).match()}
{ assert snapshot(
niftiMD5SUM(workflow.out.image_warped.get(0).get(1)),
niftiMD5SUM(workflow.out.ref_warped.get(0).get(1)),
workflow.out.transfo_image,
workflow.out.transfo_trk,
niftiMD5SUM(workflow.out.segmentation.get(0).get(1)),
niftiMD5SUM(workflow.out.ref_segmentation.get(0).get(1)),
workflow.out.versions
).match()}
)
}
}
Expand Down
Loading

0 comments on commit bea6c73

Please sign in to comment.