Skip to content

Commit

Permalink
Atlasbrex t2 (#261)
Browse files Browse the repository at this point in the history
use_T2 in atlas_brex and brain_segment_pipe
add an option for nonlin_reg
pad_template with ANTS PadImage
  • Loading branch information
davidmeunier79 authored Jun 17, 2024
1 parent 95d5d84 commit 2b0893b
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 71 deletions.
Binary file added macapype/pipelines/.prepare.py.kate-swp
Binary file not shown.
18 changes: 16 additions & 2 deletions macapype/pipelines/extract_brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,27 @@ def create_extract_pipe(params_template, params={},
"indiv_params"]),
name='inputnode')

# smooth before brex
if "smooth" in params.keys():

smooth = NodeParams(fsl.utils.Smooth(),
params=parse_key(params, "smooth"),
name='smooth')

extract_pipe.connect(inputnode, 'restore_T1',
smooth, 'in_file')
# atlas_brex
atlas_brex = NodeParams(AtlasBREX(),
params=parse_key(params, "atlas_brex"),
name='atlas_brex')

extract_pipe.connect(inputnode, 'restore_T1',
atlas_brex, 't1_restored_file')
if "smooth" in params.keys():
extract_pipe.connect(smooth, 'smoothed_file',
atlas_brex, 't1_restored_file')
else:

extract_pipe.connect(inputnode, 'restore_T1',
atlas_brex, 't1_restored_file')

atlas_brex.inputs.NMT_file = params_template["template_head"]
atlas_brex.inputs.NMT_SS_file = params_template["template_brain"]
Expand Down
204 changes: 149 additions & 55 deletions macapype/pipelines/full_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,8 +540,9 @@ def create_brain_segment_from_mask_pipe(

reg.inputs.refb_file = params_template["template_brain"]

reg.inputs.refw_file = params_template["template_head"]
reg.inputs.k = True
if "nonlin_reg" in params["reg"]:
reg.inputs.refw_file = params_template["template_head"]
reg.inputs.k = True

brain_segment_pipe.connect(
inputnode, 'debiased_T1',
Expand Down Expand Up @@ -1120,28 +1121,55 @@ def create_full_ants_subpipes(
seg_pipe.connect(inputnode, "indiv_params",
extract_pipe, "inputnode.indiv_params")

if "correct_bias_pipe" in params:
seg_pipe.connect(
correct_bias_pipe, "outputnode.debiased_T1",
extract_pipe, "inputnode.restore_T1")
if "use_T2" in params["extract_pipe"]:

elif "N4debias" in params.keys():
# brain extraction
seg_pipe.connect(
N4debias_T1, "output_image",
extract_pipe, "inputnode.restore_T1")
if "correct_bias_pipe" in params:
seg_pipe.connect(
correct_bias_pipe, "outputnode.debiased_T2",
extract_pipe, "inputnode.restore_T1")

elif "fast" in params.keys():
elif "N4debias" in params.keys():
# brain extraction
seg_pipe.connect(
N4debias_T2, "output_image",
extract_pipe, "inputnode.restore_T1")

elif "fast" in params.keys():

# brain extraction
seg_pipe.connect(
fast_T2, ("restored_image", show_files),
extract_pipe, "inputnode.restore_T1")
else:

seg_pipe.connect(
data_preparation_pipe, 'outputnode.preproc_T2',
extract_pipe, "inputnode.restore_T1")

# brain extraction
seg_pipe.connect(
fast_T1, ("restored_image", show_files),
extract_pipe, "inputnode.restore_T1")
else:

seg_pipe.connect(
data_preparation_pipe, 'outputnode.preproc_T1',
extract_pipe, "inputnode.restore_T1")
if "correct_bias_pipe" in params:
seg_pipe.connect(
correct_bias_pipe, "outputnode.debiased_T1",
extract_pipe, "inputnode.restore_T1")

elif "N4debias" in params.keys():
# brain extraction
seg_pipe.connect(
N4debias_T1, "output_image",
extract_pipe, "inputnode.restore_T1")

elif "fast" in params.keys():

# brain extraction
seg_pipe.connect(
fast_T1, ("restored_image", show_files),
extract_pipe, "inputnode.restore_T1")
else:

seg_pipe.connect(
data_preparation_pipe, 'outputnode.preproc_T1',
extract_pipe, "inputnode.restore_T1")

# outputnode
seg_pipe.connect(
Expand Down Expand Up @@ -1418,65 +1446,131 @@ def create_full_ants_subpipes(
seg_pipe.connect(inputnode, 'indiv_params',
brain_segment_pipe, 'inputnode.indiv_params')

if "masked_correct_bias_pipe" in params.keys():
seg_pipe.connect(
masked_correct_bias_pipe, 'outputnode.mask_debiased_T1',
brain_segment_pipe, 'inputnode.masked_debiased_T1')
if 'use_T2' in params['brain_segment_pipe'].keys():

if "correct_bias_pipe" in params.keys():
# using T2
if "masked_correct_bias_pipe" in params.keys():
seg_pipe.connect(
correct_bias_pipe, "outputnode.debiased_T1",
brain_segment_pipe, 'inputnode.debiased_T1')
masked_correct_bias_pipe, 'outputnode.mask_debiased_T2',
brain_segment_pipe, 'inputnode.masked_debiased_T1')

elif "N4debias" in params.keys():
if "correct_bias_pipe" in params.keys():
seg_pipe.connect(
correct_bias_pipe, "outputnode.debiased_T2",
brain_segment_pipe, 'inputnode.debiased_T1')

elif "N4debias" in params.keys():
seg_pipe.connect(
N4debias_T2, "output_image",
brain_segment_pipe, 'inputnode.debiased_T1')

elif "fast" in params.keys():
seg_pipe.connect(
fast_T2, ("restored_image", show_files),
brain_segment_pipe, 'inputnode.debiased_T1')

else:
seg_pipe.connect(
data_preparation_pipe, 'outputnode.preproc_T2',
brain_segment_pipe, 'inputnode.debiased_T1')

elif "debias" in params.keys():
seg_pipe.connect(
N4debias_T1, "output_image",
brain_segment_pipe, 'inputnode.debiased_T1')
debias, 't2_debiased_brain_file',
brain_segment_pipe, 'inputnode.masked_debiased_T1')

elif "fast" in params.keys():
seg_pipe.connect(
fast_T1, ("restored_image", show_files),
debias, 't2_debiased_file',
brain_segment_pipe, 'inputnode.debiased_T1')

else:
seg_pipe.connect(
data_preparation_pipe, 'outputnode.preproc_T1',
brain_segment_pipe, 'inputnode.debiased_T1')

elif "debias" in params.keys():
seg_pipe.connect(
debias, 't1_debiased_brain_file',
brain_segment_pipe, 'inputnode.masked_debiased_T1')
if "correct_bias_pipe" in params.keys():
seg_pipe.connect(
correct_bias_pipe, "outputnode.debiased_T2",
brain_segment_pipe, 'inputnode.debiased_T1')

seg_pipe.connect(
debias, 't1_debiased_file',
brain_segment_pipe, 'inputnode.debiased_T1')
elif "N4debias" in params.keys():
seg_pipe.connect(
N4debias_T2, "output_image",
brain_segment_pipe, 'inputnode.debiased_T1')

elif "fast" in params.keys():
seg_pipe.connect(
fast_T2, ("restored_image", show_files),
brain_segment_pipe, 'inputnode.debiased_T1')

else:
seg_pipe.connect(
data_preparation_pipe, 'outputnode.preproc_T2',
brain_segment_pipe, 'inputnode.debiased_T1')

seg_pipe.connect(
restore_mask_T2, 'out_file',
brain_segment_pipe, 'inputnode.masked_debiased_T1')

else:

if "correct_bias_pipe" in params.keys():
# using T1
if "masked_correct_bias_pipe" in params.keys():
seg_pipe.connect(
correct_bias_pipe, "outputnode.debiased_T1",
brain_segment_pipe, 'inputnode.debiased_T1')
masked_correct_bias_pipe, 'outputnode.mask_debiased_T1',
brain_segment_pipe, 'inputnode.masked_debiased_T1')

elif "N4debias" in params.keys():
if "correct_bias_pipe" in params.keys():
seg_pipe.connect(
correct_bias_pipe, "outputnode.debiased_T1",
brain_segment_pipe, 'inputnode.debiased_T1')

elif "N4debias" in params.keys():
seg_pipe.connect(
N4debias_T1, "output_image",
brain_segment_pipe, 'inputnode.debiased_T1')

elif "fast" in params.keys():
seg_pipe.connect(
fast_T1, ("restored_image", show_files),
brain_segment_pipe, 'inputnode.debiased_T1')

else:
seg_pipe.connect(
data_preparation_pipe, 'outputnode.preproc_T1',
brain_segment_pipe, 'inputnode.debiased_T1')

elif "debias" in params.keys():
seg_pipe.connect(
N4debias_T1, "output_image",
brain_segment_pipe, 'inputnode.debiased_T1')
debias, 't1_debiased_brain_file',
brain_segment_pipe, 'inputnode.masked_debiased_T1')

elif "fast" in params.keys():
seg_pipe.connect(
fast_T1, ("restored_image", show_files),
debias, 't1_debiased_file',
brain_segment_pipe, 'inputnode.debiased_T1')

else:
seg_pipe.connect(
data_preparation_pipe, 'outputnode.preproc_T1',
brain_segment_pipe, 'inputnode.debiased_T1')

seg_pipe.connect(
restore_mask_T1, 'out_file',
brain_segment_pipe, 'inputnode.masked_debiased_T1')
if "correct_bias_pipe" in params.keys():
seg_pipe.connect(
correct_bias_pipe, "outputnode.debiased_T1",
brain_segment_pipe, 'inputnode.debiased_T1')

elif "N4debias" in params.keys():
seg_pipe.connect(
N4debias_T1, "output_image",
brain_segment_pipe, 'inputnode.debiased_T1')

elif "fast" in params.keys():
seg_pipe.connect(
fast_T1, ("restored_image", show_files),
brain_segment_pipe, 'inputnode.debiased_T1')

else:
seg_pipe.connect(
data_preparation_pipe, 'outputnode.preproc_T1',
brain_segment_pipe, 'inputnode.debiased_T1')

seg_pipe.connect(
restore_mask_T1, 'out_file',
brain_segment_pipe, 'inputnode.masked_debiased_T1')

# outputnode
seg_pipe.connect(brain_segment_pipe, 'outputnode.segmented_file',
Expand Down
19 changes: 6 additions & 13 deletions macapype/pipelines/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ def create_short_preparation_pipe(params, params_template={},
outputnode, 'preproc_T2')

# resample T1 to higher dimension
if "resample_T1_pad" in params.keys():
if "pad_template" in params.keys():

resample_T1_pad = pe.Node(
regutils.RegResample(),
Expand Down Expand Up @@ -740,29 +740,22 @@ def create_short_preparation_pipe(params, params_template={},
params_template["padded_template_head"]

elif "template_head" in params_template.keys():
if "pad_val" in params["resample_T1_pad"].keys():
pad_val = params["resample_T1_pad"]["pad_val"]
print("Found pad_val {}".format(pad_val))

# padding versio of the template
pad_template = NodeParams(
niu.Function(
input_names=["img_file", "pad_val", "const"],
output_names=["padded_img_file"],
function=pad_zero_mri),
params=parse_key(params, "resample_T1_pad"),
ImageMath(),
params=parse_key(params, "pad_template"),
name="pad_template")

pad_template.inputs.img_file = params_template["template_head"]
pad_template.inputs.op1 = params_template["template_head"]

# resample_T1_pad
data_preparation_pipe.connect(
pad_template, 'padded_img_file',
pad_template, 'output_image',
resample_T1_pad, "ref_file")

# resample_T2_pad
data_preparation_pipe.connect(
pad_template, 'padded_img_file',
pad_template, 'output_image',
resample_T2_pad, "ref_file")

else:
Expand Down
2 changes: 1 addition & 1 deletion macapype/pipelines/rename.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def rename_all_brain_derivatives(params, main_workflow, segment_pnh_pipe,
rename_inv_trans, 'out_file',
datasink, '@stereo_to_native_trans')

if "resample_T1_pad" in params["short_preparation_pipe"].keys():
if "pad_template" in params["short_preparation_pipe"].keys():

rename_stereo_padded_T1 = pe.Node(
niu.Rename(),
Expand Down

0 comments on commit 2b0893b

Please sign in to comment.