From 413a66be892717177c5812726d9daa3372bc9131 Mon Sep 17 00:00:00 2001 From: David Meunier Date: Mon, 25 Sep 2023 14:38:20 +0200 Subject: [PATCH 1/7] wmgm_mask --- macapype/pipelines/full_pipelines.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macapype/pipelines/full_pipelines.py b/macapype/pipelines/full_pipelines.py index 1eeb63d0a..5ffe0eb5a 100644 --- a/macapype/pipelines/full_pipelines.py +++ b/macapype/pipelines/full_pipelines.py @@ -3097,7 +3097,7 @@ def create_full_T1_ants_subpipes(params_template, params_template_aladin, "masked_debiased_T1", "cropped_brain_mask", "cropped_debiased_T1", "native_T1", "cropped_to_native_trans", - "wmgm_stl", "wmgm_nii", + "wmgm_stl", "wmgm_mask", 'stereo_native_T1', 'stereo_debiased_T1', 'stereo_brain_mask', 'stereo_segmented_brain_mask', 'stereo_prob_gm', 'stereo_prob_wm', From 0a70dffda172936585522e2efb63e60e68568c72 Mon Sep 17 00:00:00 2001 From: David Meunier Date: Thu, 4 Apr 2024 10:27:19 +0200 Subject: [PATCH 2/7] resample only if crop_aladin_pipe (not crop_T1) --- macapype/pipelines/prepare.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/macapype/pipelines/prepare.py b/macapype/pipelines/prepare.py index 67cf369b5..a0b586124 100644 --- a/macapype/pipelines/prepare.py +++ b/macapype/pipelines/prepare.py @@ -653,7 +653,8 @@ def create_short_preparation_pipe(params, params_template={}, outputnode, 'preproc_T2') # resample T1 to higher dimension - if "resample_T1_pad" in params.keys(): + if "resample_T1_pad" in params.keys() \ + and "crop_aladin_pipe" in params.keys(): resample_T1_pad = pe.Node( regutils.RegResample(), From ab0eebf86683c9592d30e81261d0e4f69cf6a606 Mon Sep 17 00:00:00 2001 From: David Meunier Date: Thu, 4 Apr 2024 13:52:39 +0200 Subject: [PATCH 3/7] print --- macapype/pipelines/prepare.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/macapype/pipelines/prepare.py b/macapype/pipelines/prepare.py index a0b586124..8c36fd99f 100644 --- a/macapype/pipelines/prepare.py +++ b/macapype/pipelines/prepare.py @@ -656,6 +656,9 @@ def create_short_preparation_pipe(params, params_template={}, if "resample_T1_pad" in params.keys() \ and "crop_aladin_pipe" in params.keys(): + print("entering resample_T1_pad \ + (with crop_aladin_pipe)") + resample_T1_pad = pe.Node( regutils.RegResample(), name="resample_T1_pad") @@ -666,7 +669,6 @@ def create_short_preparation_pipe(params, params_template={}, # T1 to pad if "avg_reorient_pipe" in params.keys(): - data_preparation_pipe.connect( av_T1, 'outputnode.std_img', resample_T1_pad, "flo_file") @@ -731,7 +733,6 @@ def create_short_preparation_pipe(params, params_template={}, # outputnode if "use_T2" in params.keys(): - data_preparation_pipe.connect( resample_T1_pad, 'out_file', outputnode, 'stereo_padded_T2') From 4fece28ba597d3f77569be72c114aec4d74ad3cc Mon Sep 17 00:00:00 2001 From: David Meunier Date: Thu, 4 Apr 2024 16:58:34 +0200 Subject: [PATCH 4/7] resample pad T1 and T2 if crop_T1 --- macapype/pipelines/prepare.py | 203 +++++++++++++++++++++------------- 1 file changed, 129 insertions(+), 74 deletions(-) diff --git a/macapype/pipelines/prepare.py b/macapype/pipelines/prepare.py index 8c36fd99f..3ef46d832 100644 --- a/macapype/pipelines/prepare.py +++ b/macapype/pipelines/prepare.py @@ -653,103 +653,158 @@ def create_short_preparation_pipe(params, params_template={}, outputnode, 'preproc_T2') # resample T1 to higher dimension - if "resample_T1_pad" in params.keys() \ - and "crop_aladin_pipe" in params.keys(): + if "resample_T1_pad" in params.keys(): + if "crop_T1" in params.keys(): + resample_T1_pad = 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"), + name="resample_T1_pad") - print("entering resample_T1_pad \ - (with crop_aladin_pipe)") + resample_T2_pad = NodeParams( + niu.Function( + input_names=["img_file", "pad_val", "const"], + output_names=["padded_img_file"], + function=pad_zero_mri), + params=parse_key(params, "resample_T2_pad"), + name="resample_T2_pad") - resample_T1_pad = pe.Node( - regutils.RegResample(), - name="resample_T1_pad") + # T1 to pad + if "avg_reorient_pipe" in params.keys(): + data_preparation_pipe.connect( + av_T1, 'outputnode.std_img', + resample_T1_pad, "img_file") - resample_T2_pad = pe.Node( - regutils.RegResample(), - name="resample_T2_pad") + else: + data_preparation_pipe.connect( + av_T1, 'avg_img', + resample_T1_pad, "img_file") - # T1 to pad - if "avg_reorient_pipe" in params.keys(): - data_preparation_pipe.connect( - av_T1, 'outputnode.std_img', - resample_T1_pad, "flo_file") + # T2 to pad + if "avg_reorient_pipe" in params.keys(): + data_preparation_pipe.connect( + av_T2, 'outputnode.std_img', + resample_T2_pad, "img_file") - else: - data_preparation_pipe.connect( - av_T1, 'avg_img', - resample_T1_pad, "flo_file") + else: + data_preparation_pipe.connect( + av_T2, 'avg_img', + resample_T2_pad, "img_file") - # T2 to pad - if 'aladin_T2_on_T1' in params.keys(): - data_preparation_pipe.connect( - align_T2_on_T1, "res_file", - resample_T2_pad, "flo_file") + # outputnode + if "use_T2" in params.keys(): + data_preparation_pipe.connect( + resample_T1_pad, 'padded_img_file', + outputnode, 'stereo_padded_T2') - else: - data_preparation_pipe.connect( - align_T2_on_T1, "out_file", - resample_T2_pad, "flo_file") + data_preparation_pipe.connect( + resample_T2_pad, 'padded_img_file', + outputnode, 'stereo_padded_T1') - if "padded_template_head" in params_template.keys(): - resample_T1_pad.inputs.ref_file = \ - params_template["padded_template_head"] + else: + data_preparation_pipe.connect( + resample_T1_pad, 'padded_img_file', + outputnode, 'stereo_padded_T1') - resample_T2_pad.inputs.ref_file = \ - params_template["padded_template_head"] + data_preparation_pipe.connect( + resample_T2_pad, 'padded_img_file', + outputnode, 'stereo_padded_T2') - elif "template_head" in params_template.keys(): - # 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"), - name="pad_template") + elif "crop_aladin_pipe" in params.keys(): - pad_template.inputs.img_file = params_template["template_head"] + resample_T1_pad = pe.Node( + regutils.RegResample(), + name="resample_T1_pad") - # resample_T1_pad - data_preparation_pipe.connect( - pad_template, 'padded_img_file', - resample_T1_pad, "ref_file") + resample_T2_pad = pe.Node( + regutils.RegResample(), + name="resample_T2_pad") - # resample_T2_pad - data_preparation_pipe.connect( - pad_template, 'padded_img_file', - resample_T2_pad, "ref_file") + # T1 to pad + if "avg_reorient_pipe" in params.keys(): + data_preparation_pipe.connect( + av_T1, 'outputnode.std_img', + resample_T1_pad, "flo_file") - else: - print("Error, template_head or padded_template_head should be \ - defined in template") - exit(-1) + else: + data_preparation_pipe.connect( + av_T1, 'avg_img', + resample_T1_pad, "flo_file") - data_preparation_pipe.connect( - crop_aladin_pipe, 'outputnode.native_to_stereo_trans', - resample_T1_pad, "trans_file") + # T2 to pad + if 'aladin_T2_on_T1' in params.keys(): + data_preparation_pipe.connect( + align_T2_on_T1, "res_file", + resample_T2_pad, "flo_file") - data_preparation_pipe.connect( - crop_aladin_pipe, 'outputnode.native_to_stereo_trans', - resample_T2_pad, "trans_file") + else: + data_preparation_pipe.connect( + align_T2_on_T1, "out_file", + resample_T2_pad, "flo_file") - # outputnode - if "use_T2" in params.keys(): - data_preparation_pipe.connect( - resample_T1_pad, 'out_file', - outputnode, 'stereo_padded_T2') + if "padded_template_head" in params_template.keys(): + resample_T1_pad.inputs.ref_file = \ + params_template["padded_template_head"] - data_preparation_pipe.connect( - resample_T2_pad, 'out_file', - outputnode, 'stereo_padded_T1') + resample_T2_pad.inputs.ref_file = \ + params_template["padded_template_head"] - else: + elif "template_head" in params_template.keys(): + # 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"), + name="pad_template") + + pad_template.inputs.img_file = params_template["template_head"] + + # resample_T1_pad + data_preparation_pipe.connect( + pad_template, 'padded_img_file', + resample_T1_pad, "ref_file") + + # resample_T2_pad + data_preparation_pipe.connect( + pad_template, 'padded_img_file', + resample_T2_pad, "ref_file") + + else: + print("Error, template_head or padded_template_head should be \ + defined in template") + exit(-1) data_preparation_pipe.connect( - resample_T1_pad, 'out_file', - outputnode, 'stereo_padded_T1') + crop_aladin_pipe, 'outputnode.native_to_stereo_trans', + resample_T1_pad, "trans_file") data_preparation_pipe.connect( - resample_T2_pad, 'out_file', - outputnode, 'stereo_padded_T2') + crop_aladin_pipe, 'outputnode.native_to_stereo_trans', + resample_T2_pad, "trans_file") + + # outputnode + if "use_T2" in params.keys(): + data_preparation_pipe.connect( + resample_T1_pad, 'out_file', + outputnode, 'stereo_padded_T2') + + data_preparation_pipe.connect( + resample_T2_pad, 'out_file', + outputnode, 'stereo_padded_T1') + + else: + + data_preparation_pipe.connect( + resample_T1_pad, 'out_file', + outputnode, 'stereo_padded_T1') + + data_preparation_pipe.connect( + resample_T2_pad, 'out_file', + outputnode, 'stereo_padded_T2') return data_preparation_pipe From 1b55460c9ff3cf94770d3c0a149db0c643c934af Mon Sep 17 00:00:00 2001 From: David Meunier Date: Fri, 5 Apr 2024 11:00:49 +0200 Subject: [PATCH 5/7] added params dogs and sheep, and corresponding species --- workflows/params_segment_dog_ants.json | 56 ++++++++++++++++++ workflows/params_segment_dog_spm.json | 60 +++++++++++++++++++ workflows/params_segment_sheep_ants.json | 73 ++++++++++++++++++++++++ workflows/segment_pnh.py | 3 +- 4 files changed, 191 insertions(+), 1 deletion(-) create mode 100755 workflows/params_segment_dog_ants.json create mode 100755 workflows/params_segment_dog_spm.json create mode 100755 workflows/params_segment_sheep_ants.json diff --git a/workflows/params_segment_dog_ants.json b/workflows/params_segment_dog_ants.json new file mode 100755 index 000000000..e387202e4 --- /dev/null +++ b/workflows/params_segment_dog_ants.json @@ -0,0 +1,56 @@ +{ + "general": + { + }, + "short_preparation_pipe": + { + "crop_aladin_pipe": + { + "reg_T1_on_template": + { + } + } + }, + "fast": + { + "args": "-l 3" + }, + "extract_pipe": + { + "atlas_brex": + { + "f": 0.62, + "reg": 1, + "msk": "b,0.5,0,0", + "wrp": "5,5,5", + "dil": 4, + "vox": 1 + } + }, + "brain_segment_pipe": + { + "reg": + { + "n": 2, + "m": "ref", + "dof": 12 + }, + "segment_atropos_pipe": + { + "use_priors":0.5, + "Atropos": + { + "dimension": 3 + }, + "tissue_dict": + { + "gm": 2, + "wm": 3, + "csf": 1 + } + }, + "export_5tt_pipe": + { + } + } +} diff --git a/workflows/params_segment_dog_spm.json b/workflows/params_segment_dog_spm.json new file mode 100755 index 000000000..83cb71ba4 --- /dev/null +++ b/workflows/params_segment_dog_spm.json @@ -0,0 +1,60 @@ +{ + "general": + { + }, + "short_preparation_pipe": + { + "aladin_T2_on_T1":{}, + "crop_aladin_pipe": + { + "reg_T1_on_template": + { + } + } + }, + "debias": + { + "s": 4 + }, + "reg": + { + "n": 2, + "m": "ref", + "dof": 12 + }, + "old_segment_pipe": + { + "segment": + { + "gm_output_type": [false, false, true], + "wm_output_type": [false, false, true], + "csf_output_type": [false, false, true] + }, + "threshold_gm": + { + "thresh": 0.5 + }, + "threshold_wm": + { + "thresh": 0.5 + }, + "threshold_csf": + { + "thresh": 0.5 + }, + "export_5tt_pipe": {} + }, + "mask_from_seg_pipe": + { + "dilate_mask": + { + "kernel_shape": "sphere", + "kernel_size": 2 + }, + "erode_mask": + { + "kernel_shape": "sphere", + "kernel_size": 2 + } + } +} diff --git a/workflows/params_segment_sheep_ants.json b/workflows/params_segment_sheep_ants.json new file mode 100755 index 000000000..046757657 --- /dev/null +++ b/workflows/params_segment_sheep_ants.json @@ -0,0 +1,73 @@ +{ + "general": + { + }, + "short_preparation_pipe": + { + "crop_T1": + { + "args": "error, specify in indiv" + }, + "resample_T1_pad": + { + "pad_val": 30 + } + }, + "N4debias": + { + "dimension": 3, + "bspline_fitting_distance": 200, + "n_iterations": [50, 50, 40, 30], + "convergence_threshold": 0.00000001, + "shrink_factor": 2, + "args": "-r 0 --verbose 1" + }, + "extract_pipe": + { + "atlas_brex": + { + "f": 0.5, + "reg": 1, + "msk": "b,0.5,0,0", + "wrp": "5,5,5", + "dil": 1 + } + }, + "debias": + { + "s": 2 + }, + "brain_segment_pipe": + { + "reg": + { + "n": 2, + "m": "ref", + "dof": 12 + }, + "segment_atropos_pipe": + { + "use_priors": 0.0, + "Atropos": + { + "dimension": 3 + }, + "tissue_dict": + { + "gm": 2, + "wm": 3, + "csf": 1 + } + }, + "export_5tt_pipe": + { + }, + "IsoSurface_brain_pipe": + { + "merge_brain_tissues": + { + "keep_indexes": [1,2,3] + } + } + } +} diff --git a/workflows/segment_pnh.py b/workflows/segment_pnh.py index 2111a80d7..6ecc0aabd 100644 --- a/workflows/segment_pnh.py +++ b/workflows/segment_pnh.py @@ -185,7 +185,8 @@ def create_main_workflow(data_dir, process_dir, soft, species, datatypes, if species in list(rep_species.keys()): species = rep_species[species] - list_species = ["macaque", "marmo", "baboon", "chimp"] + list_species = ["macaque", "marmo", "baboon", + "chimp", "sheep", "dog"] assert species in list_species, \ "Error, species {} should in the following list {}".format( From 2629fbcdc5dba68fbc7263bc0f7cbb1258debeb2 Mon Sep 17 00:00:00 2001 From: David Meunier Date: Fri, 5 Apr 2024 11:01:04 +0200 Subject: [PATCH 6/7] subs indoxed_mask --- macapype/utils/subs.json | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/macapype/utils/subs.json b/macapype/utils/subs.json index bb7f41d00..a263cfaac 100644 --- a/macapype/utils/subs.json +++ b/macapype/utils/subs.json @@ -1,24 +1,23 @@ { "T1w_roi_noise_corrected_debiased_BET_FLIRT-to_inia19-t1-brain": "space-inia19_desc-brain_T1w", - "T1w_roi_corrected_debiased_BET_FLIRT-to_Haiko89_Asymmetric.Template_n89_flirt_thresh_fillh_indexed_mask":"space-orig_desc-brain_dseg", + "T1w_roi_corrected_debiased_BET_FLIRT-to_Haiko89_Asymmetric.Template_n89_flirt_thresh_fillh_indexed_mask":"space-stereo_desc-brain_dseg", "BET_mask_": "", - "T1w_roi_restore_debiased_brain_SegmentationPosteriors02_thresh_5tt": "space-orig_desc-5tt_dseg", - "T1w_roi_corrected_restore_debiased_brain_SegmentationPosteriors02_thresh_5tt": "space-orig_desc-5tt_dseg", + "T1w_roi_restore_debiased_brain_SegmentationPosteriors02_thresh_5tt": "space-stereo_desc-5tt_dseg", + "T1w_roi_corrected_restore_debiased_brain_SegmentationPosteriors02_thresh_5tt": "space-stereo_desc-5tt_dseg", "T1w_flirt_res_restore_debiased_brain_Segmentation_1_merged_bin_5tt.nii.gz": "space-native_desc-5tt_dseg", - "T1w_roi_restore_brain_bin_bin": "space-orig_desc-brain_mask", - "T1w_roi_corrected_restore_brain_bin_bin": "space-orig_desc-brain_mask", + "T1w_roi_restore_brain_bin_bin": "space-stereo_desc-brain_mask", + "T1w_roi_corrected_restore_brain_bin_bin": "space-stereo_desc-brain_mask", - "T1w_roi_restore_debiased_brain.nii.gz": "space-orig_desc-preproc_desc-brain_T1w.nii.gz", - "T1w_roi_corrected_restore_debiased_brain.nii.gz": "space-orig_desc-preproc_desc-brain_T1w.nii.gz", + "T1w_roi_restore_debiased_brain.nii.gz": "space-stereo_desc-preproc_desc-brain_T1w.nii.gz", + "T1w_roi_corrected_restore_debiased_brain.nii.gz": "space-stereo_desc-preproc_desc-brain_T1w.nii.gz", - "T1w_roi_restore.nii.gz": "space-orig_desc-preproc_T1w.nii.gz", - "T1w_roi_corrected_restore.nii.gz": "space-orig_desc-preproc_T1w.nii.gz", + "T1w_roi_restore.nii.gz": "space-stereo_desc-preproc_T1w.nii.gz", + "T1w_roi_corrected_restore.nii.gz": "space-stereo_desc-preproc_T1w.nii.gz", "Segmentation_allineate": "space-template_desc-brain_dseg", - "indexed_mask": "space-orig_desc-brain_dseg", "FLAIR_flirt_flirt": "space-inia19_FLAIR", "T1w_":"", @@ -26,6 +25,7 @@ "PDw_":"", "_roi":"", "_ROI":"", + "indexed_mask": "", "_restore_debiased_brain":"", "_restore_debiased":"", "_restore_brain": "", From dc88f9495d15fb72004e4b55cfad0f208d8b6a08 Mon Sep 17 00:00:00 2001 From: David Meunier Date: Fri, 5 Apr 2024 13:38:32 +0200 Subject: [PATCH 7/7] indexed_mask_ --- macapype/utils/subs.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/macapype/utils/subs.json b/macapype/utils/subs.json index a263cfaac..27a672f8e 100644 --- a/macapype/utils/subs.json +++ b/macapype/utils/subs.json @@ -25,7 +25,7 @@ "PDw_":"", "_roi":"", "_ROI":"", - "indexed_mask": "", + "_indexed_mask": "", "_restore_debiased_brain":"", "_restore_debiased":"", "_restore_brain": "",