Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple atlases updating docs & coding style #205

Merged
merged 4 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/python-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ jobs:
- name: Test modality T1w with freesurfer atlas
run: |
poetry run hippunfold test_data/bids_T1w test_out participant -np --modality T1w --atlas freesurfer
- name: Test modality T1w with bigbrain and freesurfer atlas
run: |
poetry run hippunfold test_data/bids_T1w test_out participant -np --modality T1w --atlas bigbrain freesurfer





Expand Down
41 changes: 36 additions & 5 deletions docs/tutorials/outputs.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,22 +89,53 @@ equivalently, the scaling or distortion factor when unfolding:

sub-{subject}
└── surf
└── sub-001_hemi-R_space-T1w_den-0p5mm_{thickness,curvature,gyrification}.shape.gii
└── sub-001_hemi-{L,R}_space-T1w_den-0p5mm_label-hipp_{thickness,curvature,gyrification}.shape.gii
└── sub-001_hemi-{L,R}_space-T1w_den-0p5mm_label-dentate_{curvature,gyrification}.shape.gii

These metrics are shown in both folded and unfolded space in the images
below. Note that these results are from group-averaged data and so
individual subject maps may show considerably more variability.

![image](../images/metrics.png)


### surface labels

The subfield labels from unfolded atlases are also provided for each
subject, in `.label.gii` format. Analogous to the volume-based labels,
the name of the atlas (default: `bigbrain`) is in the file name.

sub-{subject}
└── surf
└── sub-001_hemi-{L,R}_space-T1w_den-0p5mm_label-hipp_atlas-bigbrain_subfields.label.gii


### cifti files

In addition to lateralized `.shape.gii` and `.label.gii` metrics and labels,
we also provide data mapped to hippocampi from hemispheres in a single
file using the corresponding CIFTI formats, `.dscalar.nii` and `.dlabel.nii`.
Note: since CIFTI does not support hippocampus
surfaces (yet), we make use of the `CORTEX_LEFT` and `CORTEX_RIGHT` labels for
the hippocampal surfaces.

sub-{subject}
└── surf
├── sub-001_space-T1w_den-0p5mm_label-{hipp,dentate}_{thickness,curvature,gyrification}.dscalar.nii
└── sub-001_space-T1w_den-0p5mm_label-hipp_atlas-bigbrain_subfields.dlabel.nii


### spec files

Finally, these files are packaged together for easy viewing in
Connectome Workbench, `wb_view`, in the following `.spec` files, for
each hemisphere separately, and combined:
each hemisphere and structure separately, and combined:

sub-{subject}
└── surf
├── sub-001_hemi-R_space-T1w_den-0p5mm_surfaces.spec
└── sub-001_space-T1w_den-0p5mm_surfaces.spec
├── sub-001_hemi-{L,R}_space-T1w_den-0p5mm_label-{hipp,dentate}_surfaces.spec
└── sub-001_space-T1w_den-0p5mm_label-{hipp,dentate}_surfaces.spec


### New: label-dentate

Expand All @@ -114,7 +145,7 @@ These are illustrated in the following image (orange represents the usual hippoc

![image](../images/dentate_cor.png)

Note that the dentate uses the same unfolding methods as the rest of the hippocampus, but with several caveats. Given its small size, its boundaries are not easily deliminated and so `inner`, `outer`, and `thickness` gifti surfaces are omitted. Furthermore, Laplace coordinates and therefore vertex spacing are not guaranteed to be topoligically equivalent as they are obtained through volumetric registration with the template shape injection step of this workflow.
Note that the dentate uses the same unfolding methods as the rest of the hippocampus, but with several caveats. Given its small size, its boundaries are not easily deliminated and so `inner`, `outer`, and `thickness` gifti surfaces are omitted. Furthermore, Laplace coordinates and therefore vertex spacing are not guaranteed to be topologically equivalent as they are obtained through volumetric registration with the template shape injection step of this workflow.

Corresponding `coords` and `warp` files are also generated.

Expand Down
9 changes: 4 additions & 5 deletions hippunfold/config/snakebids.yml
Original file line number Diff line number Diff line change
Expand Up @@ -283,27 +283,26 @@ surf_types:
dentate:
- midthickness

gifti_types:
gifti_metric_types:
hipp:
- gyrification.shape
- curvature.shape
- thickness.shape
- subfields.label
dentate:
- gyrification.shape
- curvature.shape

cifti_types:
cifti_metric_types:
hipp:
- gyrification.dscalar
- curvature.dscalar
- thickness.dscalar
- subfields.dlabel
dentate:
- gyrification.dscalar
- curvature.dscalar






#--- workflow specific configuration --
Expand Down
112 changes: 88 additions & 24 deletions hippunfold/workflow/rules/gifti.smk
Original file line number Diff line number Diff line change
Expand Up @@ -679,37 +679,101 @@ def get_cmd_spec_file(wildcards, input, output):
return " && ".join(cmds)


def concatenate_subfield_atlases(wildcards, types_list):
# only the subfields gii files have an atlas tag. This concatenates it on.
if type(types_list) == str:
types_list = list(types_list.split())
for ii in range(len(types_list)):
if "subfields" in types_list[ii]:
if "atlas" not in types_list[ii]:
orig = types_list[ii]
del types_list[ii]
for i in range(len(config["atlas"])):
types_list.append("atlas-" + config["atlas"][i] + "_" + orig)
return types_list


def get_cifti_types(wildcards):
types_list = config["cifti_types"][wildcards.label]
types_list = concatenate_subfield_atlases(wildcards, types_list)
def get_cifti_metric_types(label):
types_list = config["cifti_metric_types"][label]
if config["generate_myelin_map"]:
types_list.append("myelin.dscalar")
return types_list


def get_gifti_types(wildcards):
types_list = config["gifti_types"][wildcards.label]
types_list = concatenate_subfield_atlases(wildcards, types_list)
def get_gifti_metric_types(label):
types_list = config["gifti_metric_types"][label]
if config["generate_myelin_map"]:
types_list.append("myelin.shape")
return types_list


rule create_spec_file:
rule create_spec_file_hipp:
input:
metrics=lambda wildcards: expand(
bids(
root=root,
datatype="surf",
den="{density}",
suffix="{metric}.gii",
space="{space}",
hemi="{hemi}",
label="{label}",
**config["subj_wildcards"]
),
metric=get_gifti_metric_types(wildcards.label),
allow_missing=True,
),
subfields=lambda wildcards: expand(
bids(
root=root,
datatype="surf",
den="{density}",
suffix="subfields.label.gii",
space="{space}",
hemi="{hemi}",
label="{label}",
atlas="{atlas}",
**config["subj_wildcards"]
),
atlas=config["atlas"],
allow_missing=True,
),
surfs=expand(
bids(
root=root,
datatype="surf",
den="{density}",
suffix="{surfname}.surf.gii",
space="{space}",
hemi="{hemi}",
label="{label}",
**config["subj_wildcards"]
),
surfname=["midthickness"],
space=["{space}", "unfolded"],
allow_missing=True,
),
cifti=lambda wildcards: expand(
bids(
root=root,
datatype="surf",
den="{density}",
suffix="{cifti}.nii",
space="{space}",
label="{label}",
**config["subj_wildcards"]
),
cifti=get_cifti_metric_types(wildcards.label),
allow_missing=True,
),
params:
cmds=get_cmd_spec_file,
output:
spec_file=bids(
root=root,
datatype="surf",
den="{density}",
suffix="surfaces.spec",
hemi="{hemi,L|R}",
space="{space}",
label="{label,hipp}",
**config["subj_wildcards"]
),
container:
config["singularity"]["autotop"]
group:
"subj"
shell:
"{params.cmds}"


rule create_spec_file_dentate:
input:
metrics=lambda wildcards: expand(
bids(
Expand All @@ -722,7 +786,7 @@ rule create_spec_file:
label="{label}",
**config["subj_wildcards"]
),
metric=get_gifti_types(wildcards),
metric=get_gifti_metric_types(wildcards.label),
allow_missing=True,
),
surfs=expand(
Expand Down Expand Up @@ -750,7 +814,7 @@ rule create_spec_file:
label="{label}",
**config["subj_wildcards"]
),
cifti=get_cifti_types(wildcards),
cifti=get_cifti_metric_types(wildcards.label),
allow_missing=True,
),
params:
Expand All @@ -763,7 +827,7 @@ rule create_spec_file:
suffix="surfaces.spec",
hemi="{hemi,L|R}",
space="{space}",
label="{label}",
label="{label,dentate}",
**config["subj_wildcards"]
),
container:
Expand Down