Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
akhanf committed Dec 30, 2024
1 parent 5accc40 commit 5ae5a8d
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 132 deletions.
92 changes: 54 additions & 38 deletions hippunfold/resources/atlas-v2/Snakefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
hippunfold_dir = "/localscratch/hippunfold_khanlab"
hipp_dseg = "sub-maxprob_label-hipp_desc-manualsubfieldsunfoldaligned_dseg.nii.gz"
labellist = "labellist_withdg.txt"

hippunfold_dir='/localscratch/hippunfold_khanlab'
hipp_dseg='sub-maxprob_label-hipp_desc-manualsubfieldsunfoldaligned_dseg.nii.gz'
labellist='labellist_withdg.txt'

hemis=['L','R']
metrics=['thickness','curvature','gyrification']
surftypes=['midthickness','inner','outer']
hemis = ["L", "R"]
metrics = ["thickness", "curvature", "gyrification"]
surftypes = ["midthickness", "inner", "outer"]

hemi_to_structure = {"L": "CORTEX_LEFT", "R": "CORTEX_RIGHT"}
surf_to_secondary_type = {
Expand All @@ -15,76 +14,93 @@ surf_to_secondary_type = {
}



rule all:
input:
expand('hemi-{hemi}_label-{label}_dseg.label.gii',label=['hipp','dentate'],hemi=hemis),
expand('hemi-{hemi}_label-{label}_{metric}.shape.gii',label=['hipp'],hemi=hemis,metric=metrics),
expand('hemi-{hemi}_space-unfold_label-{label}_{surftype}.surf.gii',label=['hipp','dentate'],hemi=hemis,surftype=surftypes),

expand(
"hemi-{hemi}_label-{label}_dseg.label.gii",
label=["hipp", "dentate"],
hemi=hemis,
),
expand(
"hemi-{hemi}_label-{label}_{metric}.shape.gii",
label=["hipp"],
hemi=hemis,
metric=metrics,
),
expand(
"hemi-{hemi}_space-unfold_label-{label}_{surftype}.surf.gii",
label=["hipp", "dentate"],
hemi=hemis,
surftype=surftypes,
),


rule hipp_dseg:
input:
hipp_dseg
hipp_dseg,
output:
temp('hipp_dseg.nii.gz')
temp("hipp_dseg.nii.gz"),
shell:
'cp {input} {output}'
"cp {input} {output}"

rule dentate_dseg:

rule dentate_dseg:
input:
hipp_dseg
hipp_dseg,
params:
dg_label=6
dg_label=6,
output:
temp('dentate_dseg.nii.gz')
temp("dentate_dseg.nii.gz"),
shell:
'c3d {input} -scale 0 -shift {params.dg_label} -o {output}'
"c3d {input} -scale 0 -shift {params.dg_label} -o {output}"


rule surf_gifti:
input:
surf_gii=Path(hippunfold_dir) / 'hippunfold' / 'resources' / 'unfold_template_{label}' / 'tpl-avg_space-unfold_den-unfoldiso_{surftype}.surf.gii'
surf_gii=Path(hippunfold_dir)
/ "hippunfold"
/ "resources"
/ "unfold_template_{label}"
/ "tpl-avg_space-unfold_den-unfoldiso_{surftype}.surf.gii",
params:
structure_type=lambda wildcards: hemi_to_structure[wildcards.hemi],
secondary_type=lambda wildcards: surf_to_secondary_type[wildcards.surftype],
surface_type="FLAT",
output:
surf_gii='hemi-{hemi}_space-unfold_label-{label}_{surftype}.surf.gii'
surf_gii="hemi-{hemi}_space-unfold_label-{label}_{surftype}.surf.gii",
shell:
'cp {input} {output} && '
"cp {input} {output} && "
"wb_command -set-structure {output} {params.structure_type} -surface-type {params.surface_type}"
" -surface-secondary-type {params.secondary_type}"


rule label_gifti:
input:
dseg_nii='{label}_dseg.nii.gz',
dseg_nii="{label}_dseg.nii.gz",
lut=labellist,
surf_gii='hemi-{hemi}_space-unfold_label-{label}_midthickness.surf.gii'
surf_gii="hemi-{hemi}_space-unfold_label-{label}_midthickness.surf.gii",
params:
structure_type=lambda wildcards: hemi_to_structure[wildcards.hemi],
output:
label_gii='hemi-{hemi}_label-{label}_dseg.label.gii'
shadow: 'minimal'
label_gii="hemi-{hemi}_label-{label}_dseg.label.gii",
shadow:
"minimal"
shell:
'wb_command -volume-label-import {input.dseg_nii} {input.lut} label_vol.nii && '
'wb_command -volume-label-to-surface-mapping label_vol.nii {input.surf_gii} {output.label_gii} && '
"wb_command -volume-label-import {input.dseg_nii} {input.lut} label_vol.nii && "
"wb_command -volume-label-to-surface-mapping label_vol.nii {input.surf_gii} {output.label_gii} && "
"wb_command -set-structure {output} {params.structure_type}"



rule metric_gifti:
input:
metric_nii='{metric}.nii.gz',
surf_gii='hemi-{hemi}_space-unfold_label-{label}_inner.surf.gii' #existing metric niftis are on inner space
metric_nii="{metric}.nii.gz",
surf_gii="hemi-{hemi}_space-unfold_label-{label}_inner.surf.gii", #existing metric niftis are on inner space
params:
structure_type=lambda wildcards: hemi_to_structure[wildcards.hemi],
output:
metric_gii='hemi-{hemi}_label-{label}_{metric}.shape.gii'
shadow: 'minimal'
metric_gii="hemi-{hemi}_label-{label}_{metric}.shape.gii",
shadow:
"minimal"
shell:
'wb_command -volume-to-surface-mapping {input.metric_nii} {input.surf_gii} {output.metric_gii} -trilinear && '
"wb_command -volume-to-surface-mapping {input.metric_nii} {input.surf_gii} {output.metric_gii} -trilinear && "
"wb_command -set-structure {output} {params.structure_type}"


1 change: 1 addition & 0 deletions hippunfold/workflow/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ else:

include: "rules/shape_inject.smk"


rule all:
input:
get_final_output(),
Expand Down
5 changes: 4 additions & 1 deletion hippunfold/workflow/rules/gifti.smk
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ rule constrain_surf_to_bbox:
script:
"../scripts/constrain_surf_to_bbox.py"


# needed for if native_modality is corobl
rule cp_corobl_root:
input:
Expand Down Expand Up @@ -214,6 +215,7 @@ rule affine_gii_to_native:
shell:
"wb_command -surface-apply-affine {input.gii} {input.xfm} {output.gii}"


def get_cmd_cifti_metric(wildcards, input, output):
cmd = f"wb_command -cifti-create-dense-scalar {output}"
if "L" in config["hemi"]:
Expand Down Expand Up @@ -370,6 +372,7 @@ def get_gifti_metric_types(label):
types_list.append("myelin.shape")
return types_list


rule create_spec_file_hipp:
input:
metrics=lambda wildcards: expand(
Expand Down Expand Up @@ -413,7 +416,7 @@ rule create_spec_file_hipp:
**inputs.subj_wildcards
),
surfname=["midthickness"],
space=["{space}", "unfold","unfoldreg"],
space=["{space}", "unfold", "unfoldreg"],
allow_missing=True,
),
cifti_metrics=lambda wildcards: inputs[config["modality"]].expand(
Expand Down
Loading

0 comments on commit 5ae5a8d

Please sign in to comment.