Skip to content

Commit

Permalink
add template-based segmentation and marm templates
Browse files Browse the repository at this point in the history
note: this is just a copy of the marmunfold branch
  • Loading branch information
akhanf committed Feb 16, 2024
1 parent afe3237 commit d73576e
Show file tree
Hide file tree
Showing 4 changed files with 376 additions and 25 deletions.
72 changes: 64 additions & 8 deletions hippunfold/config/snakebids.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,40 @@ parse_args:
- segT1w
- segT2w
- cropseg



--template:
choices:
- 'CITI168'
- 'dHCP'
- 'MBMv2'
- 'MBMv3'
- 'CIVM'
default: 'CITI168'
help: 'Set the template to use for registration to coronal oblique (and optionally for template-based segmentation if --use-template-seg is enabled). CITI168 is for adult human data, dHCP is for neonatal human data, MBMv2 is for ex vivo marmoset data, MBMv3 is for in vivo marmoset data, and CIVM is for in vivo macaque data. (default: %(default)s)'




--inject_template:
choices:
- 'upenn'
- 'MBMv2'
- 'MBMv3'
- 'CIVM'
default: 'upenn'
help: 'Set the template to use for shape injection. (default: %(default)s)'

--use_template_seg:
help: 'Use template-based segmentation for hippocampal tissue *instead of* nnUnet and shape injection. This is only to be used if nnUnet models are not trained for the data you are using, e.g. for non-human primate data with the MBMv2 (ex vivo marmoset), MBMv3 (in vivomarmoset), or CIVM (in vivo macaque) template. (default: %(default)s)'
default: False
action: 'store_true'

--template_seg_smoothing_factor:
help: 'Scales the default smoothing sigma for gradient and warp in greedy registration for template-based segmentation. Using a value higher than 1 will use result in a smoother warp. (default: %(default)s)'
default: 2.0


--derivatives:
help: 'Path to the derivatives folder (e.g. for finding manual segs) (default: %(default)s) '
default: False
Expand Down Expand Up @@ -178,13 +211,7 @@ parse_args:
default: False
action: 'store_true'

--template:
choices:
- 'CITI168'
- 'dHCP'
default: 'CITI168'
help: 'Set the template to use for registration to coronal oblique. (default: %(default)s)'


--t1_reg_template:
help: 'Use T1w to register to template space, instead of the segmentation modality. Note: this was the default behavior prior to v1.0.0. (default: %(default)s)'
default: false
Expand Down Expand Up @@ -354,6 +381,33 @@ template_files:
crop_ref: tpl-dHCP_cohort-1_res-1_space-corobl_hemi-{hemi}_T2w.nii.gz
crop_refT1w: tpl-dHCP_cohort-1_res-1_space-corobl_hemi-{hemi}_T1w.nii.gz
Mask_crop: tpl-dHCP_cohort-1_res-1_space-corobl_hemi-{hemi}_desc-hipp_mask.nii.gz
MBMv2:
T1w: MBMv2/Template_sym_MTR_80um.nii.gz
T2w: MBMv2/Template_sym_T2_80um.nii.gz
xfm_corobl: MBMv2/tpl-MBMv2_from-native_to-corobl_type-itk_affine.txt
crop_ref: MBMv2/tpl-MBMv2_hemi-{hemi}_space-corobl_{modality}.nii.gz
Mask_crop: MBMv2/tpl-MBMv2_hemi-{hemi}_space-corobl_desc-hipp_mask.nii.gz
dseg: MBMv2/tpl-MBMv2_hemi-R_space-corobl_desc-tissuemanual_dseg.nii.gz
coords: MBMv2/tpl-MBMv2_dir-{dir}_hemi-R_space-corobl_label-{autotop}_desc-laplace_coords.nii.gz
MBMv3:
T1w: MBMv3/tpl-MBMv3_T1w.nii.gz
T2w: MBMv3/tpl-MBMv3_T2w.nii.gz
xfm_corobl: MBMv3/tpl-MBMv3_from-native_to-corobl_type-itk_affine.txt
crop_ref: MBMv3/tpl-MBMv3_hemi-{hemi}_space-corobl_{modality}.nii.gz
Mask_crop: MBMv3/tpl-MBMv3_hemi-{hemi}_space-corobl_desc-hipp_mask.nii.gz
dseg: MBMv3/tpl-MBMv3_hemi-R_space-corobl_desc-tissue_dseg.nii.gz
coords: MBMv3/tpl-MBMv3_dir-{dir}_hemi-R_space-corobl_label-{autotop}_desc-laplace_coords.nii.gz
CIVM:
T1w: CIVM/tpl-CIVM_T1w.nii.gz
xfm_corobl: CIVM/tpl-CIVM_from-native_to-corobl_type-itk_affine.txt
crop_ref: CIVM/tpl-CIVM_hemi-{hemi}_space-corobl_{modality}.nii.gz
Mask_crop: CIVM/tpl-CIVM_hemi-{hemi}_space-corobl_desc-hipp_mask.nii.gz
dseg: CIVM/tpl-CIVM_hemi-R_space-corobl_desc-tissue_dseg.nii.gz
coords: CIVM/tpl-CIVM_dir-{dir}_hemi-R_space-corobl_label-{autotop}_desc-laplace_coords.nii.gz
upenn:
T1w: upenn/tpl-upenn_desc-hipptissue_dseg.nii.gz
dseg: upenn/tpl-upenn_desc-hipptissue_dseg.nii.gz
coords: upenn/tpl-upenn_dir-{dir}_label-{autotop}_coords.nii.gz

atlas_files:
multihist7:
Expand Down Expand Up @@ -572,3 +626,5 @@ t1_reg_template: False
generate_myelin_map: False
no_unfolded_reg: False
root: results
use_template_seg: False
template_seg_smoothing_factor: 2
25 changes: 21 additions & 4 deletions hippunfold/workflow/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ elif "T1w" in config["modality"]:

# only generate hipp surface if skipping template injection
# i.e. drop dentate
if config["skip_inject_template_labels"]:
if config["skip_inject_template_labels"]: # TODO do we need this?
config["autotop_labels"] = ["hipp"]


Expand Down Expand Up @@ -144,9 +144,6 @@ include: "rules/autotop.smk"
include: "rules/warps.smk"


include: "rules/shape_inject.smk"


include: "rules/gifti.smk"


Expand All @@ -162,6 +159,26 @@ include: "rules/qc.smk"
include: "rules/myelin_map.smk"


if config["use_template_seg"]:
if (
"dseg" in config["template_files"][config["template"]]
and "coords" in config["template_files"][config["template"]]
):

include: "rules/templateseg.smk"

else:
print(
"use_template_seg is not possible, template dseg or coords do not exist for the chosen template"
)

include: "rules/shape_inject.smk"

else:

include: "rules/shape_inject.smk"


rule all:
input:
get_final_output(),
Expand Down
27 changes: 14 additions & 13 deletions hippunfold/workflow/rules/common.smk
Original file line number Diff line number Diff line change
Expand Up @@ -293,20 +293,21 @@ def get_final_qc():
)
)
if (config["modality"] == "T1w") or (config["modality"] == "T2w"):
qc.extend(
expand(
bids(
root=root,
datatype="qc",
desc="unetf3d",
suffix="dice.tsv",
hemi="{hemi}",
**config["subj_wildcards"],
),
hemi=config["hemi"],
allow_missing=True,
if not config["use_template_seg"]:
qc.extend(
expand(
bids(
root=root,
datatype="qc",
desc="unetf3d",
suffix="dice.tsv",
hemi="{hemi}",
**config["subj_wildcards"],
),
hemi=config["hemi"],
allow_missing=True,
)
)
)
return qc


Expand Down
Loading

0 comments on commit d73576e

Please sign in to comment.