Skip to content

Commit

Permalink
added use_template_seg option, and MBMv2 files
Browse files Browse the repository at this point in the history
still a WIP

TODO: clean-up config and CLI for specifying templates -- right now
--template and --template_files is used to select the rigid/affine reg template, and
--inject_template and --inject_files is used to select the template shape injection or
registration-based segmentation template (for use_template_seg).. could
harmonize the structure for files, and keep separate flags..
  • Loading branch information
akhanf committed Sep 27, 2023
1 parent 3e84331 commit a5b793b
Show file tree
Hide file tree
Showing 17 changed files with 386 additions and 3 deletions.
6 changes: 6 additions & 0 deletions hippunfold/config/snakebids.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ parse_args:
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. This is only to be used if nnUnet models are not trained for the data you are using (e.g. for marmoset data with the MBMv2 template). (default: %(default)s)'
default: False
action: 'store_true'


--skip_inject_template_labels:
help: 'Set this flag to skip post-processing template injection into CNN segmentation. Note this will disable generation of DG surfaces. (default: %(default)s)'
Expand Down Expand Up @@ -580,3 +585,4 @@ t1_reg_template: False
generate_myelin_map: False
no_unfolded_reg: False
root: results
use_template_seg: False
38 changes: 38 additions & 0 deletions hippunfold/resources/tpl-MBMv2/Snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

configfile: 'config.yml'

rule all:
input:
coords=expand('tpl-{template}_dir-{dir}_hemi-{hemi}_space-corobl_label-{label}_desc-laplace_coords.nii.gz',
template='MBMv2',dir=['AP','PD','IO'],hemi='R',label=['hipp','dentate'])

ruleorder: laplace_dentate_AP > laplace_coords

rule laplace_coords:
input:
lbl=lambda wildcards: config['laplace_labels'][wildcards.label][wildcards.dir]['img'].format(**wildcards),
params:
gm_labels=lambda wildcards: config['laplace_labels'][wildcards.label][wildcards.dir]['gm'],
src_labels=lambda wildcards: config['laplace_labels'][wildcards.label][wildcards.dir]['src'],
sink_labels=lambda wildcards: config['laplace_labels'][wildcards.label][wildcards.dir]['sink'],
convergence_threshold=1e-5,
max_iters=10000,
output:
coords='tpl-{template}_dir-{dir}_hemi-{hemi}_space-corobl_label-{label}_desc-laplace_coords.nii.gz'
log:
'logs/tpl-{template}_dir-{dir}_hemi-{hemi}_space-corobl_label-{label}_desc-laplace_coords.txt'
script:
"../../workflow/scripts/laplace_coords.py"

rule laplace_dentate_AP:
""" we just mask this from the hipp label"""
input:
lbl=lambda wildcards: config['laplace_labels'][wildcards.label][wildcards.dir]['img'].format(**wildcards),
coords='tpl-{template}_dir-AP_hemi-{hemi}_space-corobl_label-hipp_desc-laplace_coords.nii.gz'
params:
gm_labels=lambda wildcards: config['laplace_labels'][wildcards.label][wildcards.dir]['gm'],
output:
coords='tpl-{template}_dir-{dir,AP}_hemi-{hemi}_space-corobl_label-{label,dentate}_desc-laplace_coords.nii.gz'
shell:
'c3d {input.lbl} -retain-labels {params.gm_labels} -binarize {input.coords} -multiply -o {output.coords}'

Binary file not shown.
Binary file not shown.
61 changes: 61 additions & 0 deletions hippunfold/resources/tpl-MBMv2/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
laplace_labels:
hipp:
AP:
img: 'tpl-{template}_hemi-{hemi}_space-corobl_desc-tissuemanual_dseg.nii.gz'
gm:
- 1
- 8
src:
- 5
sink:
- 6
PD:
img: 'tpl-{template}_hemi-{hemi}_space-corobl_desc-tissuemanual_dseg.nii.gz'
gm:
- 1
- 8
src:
- 3
sink:
- 8
IO:
img: 'tpl-{template}_hemi-{hemi}_space-corobl_desc-tissuemanual_dseg.nii.gz'
gm:
- 1
- 8
src:
- 2
- 4
- 7
sink:
- 0
dentate:
AP:
img: 'tpl-{template}_hemi-{hemi}_space-corobl_desc-tissuemanual_dseg.nii.gz'
gm:
- 8
src:
- 5
sink:
- 6
PD:
img: 'tpl-{template}_hemi-{hemi}_space-corobl_desc-tissueDGmanual_dseg.nii.gz'
gm:
- 8
src:
- 1
sink:
- 2
IO:
img: 'tpl-{template}_hemi-{hemi}_space-corobl_desc-tissuemanual_dseg.nii.gz'
gm:
- 8
src:
- 1
sink:
- 2
- 4
- 7
- 0


Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Insight Transform File V1.0
#Transform 0
Transform: MatrixOffsetTransformBase_double_3_3
Parameters: 1 0 0 0 0.6018150231520484 -0.7986355100472928 0 0.7986355100472928 0.6018150231520484 0 2.2613285618049965 -4.855523654670475
FixedParameters: 0 0 0
Binary file not shown.
Binary file not shown.
6 changes: 4 additions & 2 deletions hippunfold/workflow/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ include: "rules/autotop.smk"
include: "rules/warps.smk"


include: "rules/shape_inject.smk"


include: "rules/gifti.smk"
Expand All @@ -160,7 +159,10 @@ include: "rules/qc.smk"

include: "rules/myelin_map.smk"

include: "rules/templateseg.smk"
if config['use_template_seg']:
include: "rules/templateseg.smk"
else:
include: "rules/shape_inject.smk"

rule all:
input:
Expand Down
2 changes: 1 addition & 1 deletion hippunfold/workflow/rules/common.smk
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def get_final_qc():
allow_missing=True,
)
)
if (config["modality"] == "T1w") or (config["modality"] == "T2w"):
if (config["modality"] == "T1w") or (config["modality"] == "T2w") and not config['use_template_seg']:
qc.extend(
expand(
bids(
Expand Down
Loading

0 comments on commit a5b793b

Please sign in to comment.