Skip to content

Commit

Permalink
Merge branch 'dev-v2.0.0' into simpleLflip
Browse files Browse the repository at this point in the history
  • Loading branch information
jordandekraker authored Dec 19, 2024
2 parents 69933e5 + ca08e47 commit 2525dfc
Show file tree
Hide file tree
Showing 13 changed files with 1,792 additions and 320 deletions.
39 changes: 32 additions & 7 deletions hippunfold/config/snakebids.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,12 @@ parse_args:
default: False
action: store_true

--native_surf:
help: 'Use native surf workflow to generate isosurfaces in native space, and use wb_command tools to resample. Note: this currently disables unfolded registration if applied (until it is implemented).'
default: False
action: store_true


--generate_myelin_map:
help: 'Generate myelin map using T1w divided by T2w, and map to surface with ribbon approach. Requires both T1w and T2w images to be present. (default: %(default)s)'
default: False
Expand Down Expand Up @@ -278,6 +284,7 @@ parse_args:
- synthseg_v0.2
- neonateT1w_v2


--enable-bids-validation:
help: |
Enable validation of BIDS dataset. BIDS validation would be performed
Expand All @@ -294,7 +301,6 @@ parse_args:
version: "1.5.2-pre.2"



# --- surface specific configuration --

autotop_labels:
Expand All @@ -308,6 +314,8 @@ surf_types:
- outer
dentate:
- midthickness
# - inner
# - outer

gifti_metric_types:
hipp:
Expand All @@ -327,7 +335,14 @@ cifti_metric_types:
- gyrification.dscalar
- curvature.dscalar


# params for detecting and removing outlier vertices
outlier_opts:
outlierSmoothDist:
unfoldiso: 15
0p5mm: 7
1mm: 3
2mm: 1
vertexOutlierThreshold: 3



Expand Down Expand Up @@ -364,6 +379,7 @@ template_available_hemis:
- R
- L


template_files:
CITI168:
T1w: T1w_head_700um.nii.gz
Expand Down Expand Up @@ -418,13 +434,15 @@ template_files:
dseg: tpl-ABAv3_hemi-{hemi}_space-corobl_desc-tissuemanual_dseg.nii.gz
coords: tpl-ABAv3_dir-{dir}_hemi-{hemi}_space-corobl_label-{autotop}_desc-laplace_coords.nii.gz
bigbrain:
T1w: tpl-bigbrain_100um_T1w.nii.gz
T1w: tpl-bigbrain_1mm_merker.nii.gz
T2w: tpl-bigbrain_1mm_merker.nii.gz
xfm_corobl: tpl-bigbrain_from-native_to-corobl_type-itk_affine.txt
crop_ref: tpl-bigbrain_hemi-{hemi}_space-corobl_desc-tissuemanual_40um_dseg.nii.gz
Mask_crop: tpl-bigbrain_hemi-{hemi}_space-corobl_desc-tissuemanual_40um_dseg.nii.gz
dseg: tpl-bigbrain_hemi-{hemi}_space-corobl_desc-tissuemanual_40um_dseg.nii.gz
crop_ref: tpl-bigbrain_hemi-{hemi}_space-corobl_100um_merker.nii.gz
Mask_crop: tpl-bigbrain_hemi-{hemi}_space-corobl_desc-tissuemanual_100um_dseg.nii.gz
dseg: tpl-bigbrain_hemi-{hemi}_space-corobl_desc-tissuemanual_100um_dseg.nii.gz
coords: tpl-bigbrain_dir-{dir}_hemi-{hemi}_space-corobl_label-{autotop}_desc-laplace_coords.nii.gz


atlas_files:
multihist7:
label_nii: sub-maxprob_label-hipp_desc-manualsubfieldsunfoldaligned_dseg.nii.gz
Expand Down Expand Up @@ -582,6 +600,11 @@ unfold_vol_ref:
- '2.5'
orient: RPI

unfold_crop_epsilon_fractions:
- 0
- 0
- 1 #in unfolded space voxels


# space for uniform unfolded grid:
# currently only used for interpolating hipp subfields on surface
Expand Down Expand Up @@ -638,7 +661,8 @@ laplace_labels:
- 7
sink:
- 0

gm_noDG:
- 1

output_spaces:
- native
Expand Down Expand Up @@ -666,3 +690,4 @@ no_unfolded_reg: False
root: results
use_template_seg: False
template_seg_smoothing_factor: 2
native_surf: False
8 changes: 7 additions & 1 deletion hippunfold/workflow/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ if config["skip_inject_template_labels"]: # TODO do we need this?
limit_to_list.add(config["modality"])

# if atlas doesn't contain alignment features
if not config["atlas"] == ["multihist7"]:
if not config["atlas"] == ["multihist7"] or config["native_surf"]:
config["no_unfolded_reg"] = True


inputs = snakebids.generate_inputs(
bids_dir=config["bids_dir"],
pybids_inputs=config["pybids_inputs"],
Expand Down Expand Up @@ -147,6 +148,11 @@ include: "rules/qc.smk"
include: "rules/myelin_map.smk"


if config["native_surf"]:

include: "rules/native_surf.smk"


if config["use_template_seg"]:
if (
"dseg" in config["template_files"][config["template"]]
Expand Down
51 changes: 6 additions & 45 deletions hippunfold/workflow/rules/common.smk
Original file line number Diff line number Diff line change
Expand Up @@ -40,55 +40,17 @@ def get_modality_suffix(modality):


def get_final_spec():
if len(config["hemi"]) == 2:
specs = inputs[config["modality"]].expand(
bids(
root=root,
datatype="surf",
den="{density}",
space="{space}",
label="{autotop}",
suffix="surfaces.spec",
**inputs.subj_wildcards,
),
density=config["output_density"],
space=ref_spaces,
autotop=config["autotop_labels"],
allow_missing=True,
)
else:
specs = inputs[config["modality"]].expand(
bids(
root=root,
datatype="surf",
den="{density}",
space="{space}",
hemi="{hemi}",
label="{autotop}",
suffix="surfaces.spec",
**inputs.subj_wildcards,
),
density=config["output_density"],
space=ref_spaces,
hemi=config["hemi"],
autotop=config["autotop_labels"],
allow_missing=True,
)
return specs


def get_final_surf():
gii = []
gii.extend(
specs = []
specs.extend(
inputs[config["modality"]].expand(
bids(
root=root,
datatype="surf",
den="{density}",
suffix="{surfname}.surf.gii",
space="{space}",
hemi="{hemi}",
label="{autotop}",
suffix="surfaces.spec",
**inputs.subj_wildcards,
),
density=config["output_density"],
Expand All @@ -99,16 +61,16 @@ def get_final_surf():
allow_missing=True,
)
)
gii.extend(
specs.extend(
inputs[config["modality"]].expand(
bids(
root=root,
datatype="surf",
den="{density}",
suffix="{surfname}.surf.gii",
space="{space}",
hemi="{hemi}",
label="{autotop}",
suffix="surfaces.spec",
**inputs.subj_wildcards,
),
density=config["output_density"],
Expand All @@ -119,7 +81,7 @@ def get_final_surf():
allow_missing=True,
)
)
return gii
return specs


def get_final_subfields():
Expand Down Expand Up @@ -373,7 +335,6 @@ def get_final_qc():
def get_final_subj_output():
subj_output = []
subj_output.extend(get_final_spec())
subj_output.extend(get_final_surf())
subj_output.extend(get_final_subfields())
subj_output.extend(get_final_coords())
subj_output.extend(get_final_transforms())
Expand Down
30 changes: 20 additions & 10 deletions hippunfold/workflow/rules/gifti.smk
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ rule warp_gii_unfold2corobl1:
datatype="surf",
den="{density}",
suffix="{surfname}.surf.gii",
desc="nonancorrect",
desc="nobadcorrect",
space="corobl",
unfoldreg="none",
hemi="{hemi}",
Expand All @@ -198,21 +198,26 @@ rule warp_gii_unfold2corobl1:
" -surface-secondary-type {params.secondary_type}"


# previous rule seems to be where nan vertices emerge, so we'll correct them here immediately after
rule correct_nan_vertices1:
# previous rule seems to be where bad vertices emerge, so we'll correct them here immediately after
rule correct_bad_vertices1:
input:
gii=bids(
root=work,
datatype="surf",
den="{density}",
suffix="{surfname}.surf.gii",
desc="nonancorrect",
desc="nobadcorrect",
space="corobl",
unfoldreg="none",
hemi="{hemi}",
label="hipp",
**inputs.subj_wildcards
),
params:
dist=lambda wildcards: config["outlier_opts"]["outlierSmoothDist"][
wildcards.density
],
threshold=config["outlier_opts"]["vertexOutlierThreshold"],
output:
gii=bids(
root=work,
Expand All @@ -230,7 +235,7 @@ rule correct_nan_vertices1:
container:
config["singularity"]["autotop"]
script:
"../scripts/fillnanvertices.py"
"../scripts/fillbadvertices.py"


# morphological features, calculated in native space:
Expand Down Expand Up @@ -730,7 +735,7 @@ rule warp_gii_unfold2corobl2:
datatype="surf",
den="{density}",
suffix="{surfname}.surf.gii",
desc="nonancorrect",
desc="nobadcorrect",
space="corobl",
hemi="{hemi}",
label="{autotop}",
Expand All @@ -746,20 +751,25 @@ rule warp_gii_unfold2corobl2:
" -surface-secondary-type {params.secondary_type}"


# previous rule seems to be where nan vertices emerge, so we'll correct them here immediately after
rule correct_nan_vertices2:
# previous rule seems to be where bad vertices emerge, so we'll correct them here immediately after
rule correct_bad_vertices2:
input:
gii=bids(
root=work,
datatype="surf",
den="{density}",
suffix="{surfname}.surf.gii",
desc="nonancorrect",
desc="nobadcorrect",
space="corobl",
hemi="{hemi}",
label="{autotop}",
**inputs.subj_wildcards
),
params:
dist=lambda wildcards: config["outlier_opts"]["outlierSmoothDist"][
wildcards.density
],
threshold=config["outlier_opts"]["vertexOutlierThreshold"],
output:
gii=bids(
root=work,
Expand All @@ -776,7 +786,7 @@ rule correct_nan_vertices2:
container:
config["singularity"]["autotop"]
script:
"../scripts/fillnanvertices.py"
"../scripts/fillbadvertices.py"


# needed for if native_modality is corobl
Expand Down
Loading

0 comments on commit 2525dfc

Please sign in to comment.