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

Stereo spm #234

Merged
merged 6 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
104 changes: 103 additions & 1 deletion macapype/pipelines/full_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@

def create_full_spm_subpipes(
params_template, params_template_aladin,
params_template_stereo,
params={}, name='full_spm_subpipes',
pad=False, space='template'):
""" Description: SPM based segmentation pipeline from T1w and T2w images
Expand Down Expand Up @@ -130,7 +131,11 @@ def create_full_spm_subpipes(
niu.IdentityInterface(fields=['brain_mask', 'segmented_brain_mask',
'debiased_T1', 'debiased_brain',
"wmgm_stl",
'prob_wm', 'prob_gm', 'prob_csf']),
'prob_wm', 'prob_gm', 'prob_csf',
'stereo_native_T1', 'stereo_debiased_T1',
'stereo_brain_mask',
'stereo_segmented_brain_mask',
"native_to_stereo_trans"]),
name='outputnode')
# preprocessing
if 'long_single_preparation_pipe' in params.keys():
Expand Down Expand Up @@ -234,6 +239,27 @@ def create_full_spm_subpipes(
seg_pipe.connect(pad_debiased_T1, "padded_img_file",
outputnode, "debiased_T1")

print("Padding debiased_T2 in native space")
pad_debiased_T2 = pe.Node(
niu.Function(
input_names=['cropped_img_file', 'orig_img_file',
'indiv_crop'],
output_names=['padded_img_file'],
function=padding_cropped_img),
name="pad_debiased_T2")

seg_pipe.connect(debias, 't2_debiased_file',
pad_debiased_T2, "cropped_img_file")

seg_pipe.connect(data_preparation_pipe, "outputnode.native_T2",
pad_debiased_T2, "orig_img_file")

seg_pipe.connect(inputnode, "indiv_params",
pad_debiased_T2, "indiv_crop")

seg_pipe.connect(pad_debiased_T2, "padded_img_file",
outputnode, "debiased_T2")

print("Padding debiased_brain in native space")
pad_debiased_brain = pe.Node(
niu.Function(
Expand Down Expand Up @@ -381,6 +407,64 @@ def create_full_spm_subpipes(
seg_pipe.connect(debias, 't1_debiased_file',
outputnode, "debiased_T1")

if "native_to_stereo_pipe" in params.keys():

native_to_stereo_pipe = create_native_to_stereo_pipe(
"native_to_stereo_pipe",
params=parse_key(params, "native_to_stereo_pipe"))

seg_pipe.connect(native_to_stereo_pipe,
'outputnode.native_to_stereo_trans',
outputnode, 'native_to_stereo_trans')

# full head version
seg_pipe.connect(data_preparation_pipe, "outputnode.native_T1",
native_to_stereo_pipe, 'inputnode.native_T1')

native_to_stereo_pipe.inputs.inputnode.stereo_T1 = \
params_template_stereo["template_head"]

seg_pipe.connect(native_to_stereo_pipe,
"outputnode.stereo_native_T1",
outputnode, "stereo_native_T1")

if pad:

# apply transfo to list
apply_stereo_mask = pe.Node(RegResample(inter_val="NN"),
name='apply_stereo_mask')

seg_pipe.connect(pad_mask, 'out_file',
apply_stereo_mask, "flo_file")
seg_pipe.connect(native_to_stereo_pipe,
'outputnode.native_to_stereo_trans',
apply_stereo_mask, "trans_file")

seg_pipe.connect(native_to_stereo_pipe,
'outputnode.padded_stereo_T1',
apply_stereo_mask, "ref_file")

seg_pipe.connect(apply_stereo_mask, "out_file",
outputnode, "stereo_brain_mask")

# apply transfo to list
apply_stereo_debiased_T1 = pe.Node(RegResample(),
name='apply_stereo_debiased_T1')

seg_pipe.connect(pad_debiased_T1, 'out_file',
apply_stereo_debiased_T1, "flo_file")

seg_pipe.connect(native_to_stereo_pipe,
'outputnode.native_to_stereo_trans',
apply_stereo_debiased_T1, "trans_file")

seg_pipe.connect(native_to_stereo_pipe,
'outputnode.padded_stereo_T1',
apply_stereo_debiased_T1, "ref_file")

seg_pipe.connect(apply_stereo_debiased_T1, "out_file",
outputnode, "stereo_debiased_T1")

# Iterative registration to the INIA19 template
reg = NodeParams(IterREGBET(),
params=parse_key(params, "reg"),
Expand Down Expand Up @@ -755,11 +839,29 @@ def create_full_spm_subpipes(
seg_pipe.connect(pad_seg_mask, "padded_img_file",
outputnode, "segmented_brain_mask")

if "native_to_stereo_pipe" in params:

# apply transfo to seg_mask
apply_stereo_seg_mask = pe.Node(RegResample(inter_val="NN"),
name='apply_stereo_seg_mask')

seg_pipe.connect(pad_seg_mask, 'out_file',
apply_stereo_seg_mask, "flo_file")
seg_pipe.connect(native_to_stereo_pipe,
'outputnode.native_to_stereo_trans',
apply_stereo_seg_mask, "trans_file")
seg_pipe.connect(native_to_stereo_pipe,
'outputnode.padded_stereo_T1',
apply_stereo_seg_mask, "ref_file")

seg_pipe.connect(apply_stereo_seg_mask, "out_file",
outputnode, "stereo_segmented_brain_mask")
else:
seg_pipe.connect(mask_from_seg_pipe,
'merge_indexed_mask.indexed_mask',
outputnode, 'segmented_brain_mask')

# LEGACY
if space == 'template':

# not mandatory
Expand Down
119 changes: 87 additions & 32 deletions macapype/pipelines/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,42 @@ def rename_all_derivatives(params, main_workflow, segment_pnh_pipe,
rename_prob_csf, 'out_file',
datasink, '@prob_csf')

if "mask_from_seg_pipe" in params.keys():

# rename segmented_brain_mask
rename_segmented_brain_mask = pe.Node(
niu.Rename(),
name="rename_segmented_brain_mask")
rename_segmented_brain_mask.inputs.format_string = \
pref_deriv + "_space-{}_desc-brain_dseg".format(space)
rename_segmented_brain_mask.inputs.parse_string = parse_str
rename_segmented_brain_mask.inputs.keep_ext = True

main_workflow.connect(
segment_pnh_pipe, 'outputnode.segmented_brain_mask',
rename_segmented_brain_mask, 'in_file')

main_workflow.connect(
rename_segmented_brain_mask, 'out_file',
datasink, '@segmented_brain_mask')

print("Renaming wmgm_stl file")

rename_wmgm_stl = pe.Node(niu.Rename(),
name="rename_wmgm_stl")
rename_wmgm_stl.inputs.format_string = \
pref_deriv + "_space-{}_desc-wmgm_mask".format(space)
rename_wmgm_stl.inputs.parse_string = parse_str
rename_wmgm_stl.inputs.keep_ext = True

main_workflow.connect(
segment_pnh_pipe, 'outputnode.wmgm_stl',
rename_wmgm_stl, 'in_file')

main_workflow.connect(
rename_wmgm_stl, 'out_file',
datasink, '@wmgm_stl')

if "native_to_stereo_pipe" in params.keys():

# rename stereo_native_T1
Expand Down Expand Up @@ -368,6 +404,41 @@ def rename_all_derivatives(params, main_workflow, segment_pnh_pipe,
rename_stereo_debiased_T1, 'out_file',
datasink, '@stereo_debiased_T1')

elif "debias" in params.keys():
# rename stereo_brain_mask
rename_stereo_brain_mask = pe.Node(
niu.Rename(),
name="rename_stereo_brain_mask")
rename_stereo_brain_mask.inputs.format_string = \
pref_deriv + "_space-stereo_desc-brain_mask"
rename_stereo_brain_mask.inputs.parse_string = parse_str
rename_stereo_brain_mask.inputs.keep_ext = True

main_workflow.connect(
segment_pnh_pipe, 'outputnode.stereo_brain_mask',
rename_stereo_brain_mask, 'in_file')

main_workflow.connect(
rename_stereo_brain_mask, 'out_file',
datasink, '@stereo_brain_mask')

# rename stereo_debiased_T1
rename_stereo_debiased_T1 = pe.Node(
niu.Rename(),
name="rename_stereo_debiased_T1")
rename_stereo_debiased_T1.inputs.format_string = \
pref_deriv + "_space-stereo_desc-debiased_T1w"
rename_stereo_debiased_T1.inputs.parse_string = parse_str
rename_stereo_debiased_T1.inputs.keep_ext = True

main_workflow.connect(
segment_pnh_pipe, 'outputnode.stereo_debiased_T1',
rename_stereo_debiased_T1, 'in_file')

main_workflow.connect(
rename_stereo_debiased_T1, 'out_file',
datasink, '@stereo_debiased_T1')

if "brain_segment_pipe" in params.keys():

# rename stereo_segmented_brain_mask
Expand Down Expand Up @@ -440,38 +511,22 @@ def rename_all_derivatives(params, main_workflow, segment_pnh_pipe,
rename_stereo_prob_csf, 'out_file',
datasink, '@stereo_prob_csf')

if "mask_from_seg_pipe" in params.keys():

# rename segmented_brain_mask
rename_segmented_brain_mask = pe.Node(
niu.Rename(),
name="rename_segmented_brain_mask")
rename_segmented_brain_mask.inputs.format_string = \
pref_deriv + "_space-{}_desc-brain_dseg".format(space)
rename_segmented_brain_mask.inputs.parse_string = parse_str
rename_segmented_brain_mask.inputs.keep_ext = True

main_workflow.connect(
segment_pnh_pipe, 'outputnode.segmented_brain_mask',
rename_segmented_brain_mask, 'in_file')

main_workflow.connect(
rename_segmented_brain_mask, 'out_file',
datasink, '@segmented_brain_mask')

print("Renaming wmgm_stl file")
elif "mask_from_seg_pipe" in params:
# rename stereo_segmented_brain_mask
rename_stereo_segmented_brain_mask = pe.Node(
niu.Rename(),
name="rename_stereo_segmented_brain_mask")

rename_wmgm_stl = pe.Node(niu.Rename(),
name="rename_wmgm_stl")
rename_wmgm_stl.inputs.format_string = \
pref_deriv + "_space-{}_desc-wmgm_mask".format(space)
rename_wmgm_stl.inputs.parse_string = parse_str
rename_wmgm_stl.inputs.keep_ext = True
rename_stereo_segmented_brain_mask.inputs.format_string =\
pref_deriv + "_space-stereo_desc-brain_dseg"
rename_stereo_segmented_brain_mask.inputs.parse_string = \
parse_str
rename_stereo_segmented_brain_mask.inputs.keep_ext = True

main_workflow.connect(
segment_pnh_pipe, 'outputnode.wmgm_stl',
rename_wmgm_stl, 'in_file')
main_workflow.connect(
segment_pnh_pipe, 'outputnode.stereo_segmented_brain_mask',
rename_stereo_segmented_brain_mask, 'in_file')

main_workflow.connect(
rename_wmgm_stl, 'out_file',
datasink, '@wmgm_stl')
main_workflow.connect(
rename_stereo_segmented_brain_mask, 'out_file',
datasink, '@stereo_segmented_brain_mask')
3 changes: 2 additions & 1 deletion macapype/pipelines/tests/test_full_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ def test_create_full_spm_subpipes_all_default_params():
# running workflow
segment_pnh = create_full_spm_subpipes(
params=params, params_template=params_template,
params_template_aladin=params_template, space=space,
params_template_aladin=params_template,
params_template_stereo=params_template, space=space,
name="test_create_full_ants_subpipes_all_default_params")

segment_pnh.base_dir = data_path
Expand Down
16 changes: 16 additions & 0 deletions workflows/params_segment_macaque_spm.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@
"kernel_size": 2
}
},
"native_to_stereo_pipe":
{
"pad_template_T1":
{
"pad_val": 20
},
"reg_T1_on_template":
{
"nac_flag": true,
"rig_only_flag":true,
"nosym_flag": true,
"ln_val" : 12,
"lp_val": 10,
"smoo_r_val" : 1.0
}
},
"regex_subs":
{
"FLAIR_flirt": "preproc-coreg_FLAIR"
Expand Down
1 change: 1 addition & 0 deletions workflows/segment_pnh.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ def create_main_workflow(data_dir, process_dir, soft, species, subjects,
segment_pnh_pipe = create_full_spm_subpipes(
params_template=params_template,
params_template_aladin=params_template_aladin,
params_template_stereo=params_template_stereo,
params=params, pad=pad, space=space)

elif "ants" in ssoft:
Expand Down
Loading