From a95ee401d01736b1b681ff352e1f33b1ca55f8f9 Mon Sep 17 00:00:00 2001 From: Jordan DeKraker Date: Thu, 12 Dec 2024 16:26:41 -0500 Subject: [PATCH] removed segT*w --- .github/workflows/python-testing.yml | 10 +-- hippunfold/config/snakebids.yml | 16 +--- .../resources/label_lut/manual_dseg.tsv | 9 +++ .../resources/label_lut/subfields_dseg .tsv | 9 +++ hippunfold/workflow/Snakefile | 13 +-- hippunfold/workflow/rules/preproc_cropseg.smk | 18 +++-- hippunfold/workflow/rules/preproc_seg.smk | 79 ------------------- hippunfold/workflow/rules/shape_inject.smk | 25 ------ .../anat}/sub-001_hemi-L_dseg.nii.gz | 0 .../anat}/sub-001_hemi-R_dseg.nii.gz | 0 .../anat}/sub-001_hemi-L_dseg.nii.gz | 0 11 files changed, 36 insertions(+), 143 deletions(-) create mode 100644 hippunfold/resources/label_lut/manual_dseg.tsv create mode 100644 hippunfold/resources/label_lut/subfields_dseg .tsv delete mode 100644 hippunfold/workflow/rules/preproc_seg.smk rename test_data/data_cropseg/{ => sub-001/anat}/sub-001_hemi-L_dseg.nii.gz (100%) rename test_data/data_cropseg/{ => sub-001/anat}/sub-001_hemi-R_dseg.nii.gz (100%) rename test_data/data_cropseg_1hemi/{ => sub-001/anat}/sub-001_hemi-L_dseg.nii.gz (100%) diff --git a/.github/workflows/python-testing.yml b/.github/workflows/python-testing.yml index 7a51a32e..9a16ac45 100644 --- a/.github/workflows/python-testing.yml +++ b/.github/workflows/python-testing.yml @@ -94,17 +94,13 @@ jobs: run: | poetry run hippunfold test_data/bids_singleT2w_longitudinal test_out participant -np --modality T2w - - name: Test manual seg T2w bids - run: | - poetry run hippunfold test_data/bids_segT2w test_out participant -np --modality segT2w - - name: Test cropseg bids, with path override run: | - poetry run hippunfold . test_out participant -np --modality cropseg --path_cropseg test_data/data_cropseg/sub-{subject}_hemi-{hemi}_dseg.nii.gz + poetry run hippunfold test_data/data_cropseg test_out participant -np --modality cropseg --path_cropseg test_data/data_cropseg/sub-{subject}_hemi-{hemi}_dseg.nii.gz - - name: Test cropseg bids, with path override, left hemi + - name: Test cropseg bids, one hemisphere hemi run: | - poetry run hippunfold . test_out participant -np --modality cropseg --path_cropseg test_data/data_cropseg_1hemi/sub-{subject}_hemi-{hemi}_dseg.nii.gz --hemi L + poetry run hippunfold test_data/data_cropseg_1hemi test_out participant -np --modality cropseg --hemi L - name: Test T2w with T1w template registration run: | diff --git a/hippunfold/config/snakebids.yml b/hippunfold/config/snakebids.yml index fd4c6662..b94db2f6 100644 --- a/hippunfold/config/snakebids.yml +++ b/hippunfold/config/snakebids.yml @@ -67,18 +67,6 @@ pybids_inputs: - acquisition - run - seg: - filters: - suffix: 'dseg' - extension: '.nii.gz' - datatype: 'anat' - invalid_filters: 'allow' - wildcards: - - subject - - session - - acquisition - - run - cropseg: filters: suffix: 'dseg' @@ -100,14 +88,12 @@ pybids_inputs: parse_args: --modality: - help: 'Type of image to run hippunfold on. Modality prefixed with seg will import an existing (manual) hippocampal tissue segmentation from that space, instead of running neural network (default: %(default)s)' + help: 'Type of image to run hippunfold on. For manual segmentations, use cropseg and be sure to match the label scheme applied in the look up table (lut) online. For best performance, please also make sure the input is approximately aligned to the template space, with hemi-L|R in the name. (default: %(default)s)' required: True choices: - T1w - T2w - hippb500 - - segT1w - - segT2w - cropseg diff --git a/hippunfold/resources/label_lut/manual_dseg.tsv b/hippunfold/resources/label_lut/manual_dseg.tsv new file mode 100644 index 00000000..12413b53 --- /dev/null +++ b/hippunfold/resources/label_lut/manual_dseg.tsv @@ -0,0 +1,9 @@ +index name abbreviation +1 hippocampal grey matter GM +2 SRLM or 'dark band' SRLM +3 neocortex (entorhinal or parahippocampal) MTLC +4 pial surface Pial +5 hippocampal-amygdalar transition area HATA +6 indusium griseum IndGris +7 cysts Cyst +8 dentate gyrus DG \ No newline at end of file diff --git a/hippunfold/resources/label_lut/subfields_dseg .tsv b/hippunfold/resources/label_lut/subfields_dseg .tsv new file mode 100644 index 00000000..cafbd646 --- /dev/null +++ b/hippunfold/resources/label_lut/subfields_dseg .tsv @@ -0,0 +1,9 @@ +#No. Label R G B A +1 subiculum 41 43 252 0 +2 CA1 102 209 216 0 +3 CA2 0 179 60 0 +4 CA3 255 182 0 0 +5 CA4 255 43 23 0 +6 dentate_gyrus 245 236 0 0 +7 SRLM 119 54 155 0 +8 cysts 255 255 255 0 \ No newline at end of file diff --git a/hippunfold/workflow/Snakefile b/hippunfold/workflow/Snakefile index 46b4a248..07bffaf8 100644 --- a/hippunfold/workflow/Snakefile +++ b/hippunfold/workflow/Snakefile @@ -65,13 +65,6 @@ if config["skip_inject_template_labels"]: # TODO do we need this? config["autotop_labels"] = ["hipp"] -# add seg (if chosen) and the modality to the inputs -if config["modality"][:3] == "seg": # if modality is segT2w, then add seg - limit_to_list.add("seg") - limit_to_list.add(config["modality"][3:]) -else: - limit_to_list.add(config["modality"]) - # if atlas doesn't contain alignment features if not config["atlas"] == ["multihist7"]: config["no_unfolded_reg"] = True @@ -118,11 +111,7 @@ if "T1w" in limit_to_list: # include rules only as they are needed.. -if config["modality"] == "segT1w" or config["modality"] == "segT2w": - - include: "rules/preproc_seg.smk" - -elif config["modality"] == "cropseg": +if config["modality"] == "cropseg": include: "rules/preproc_cropseg.smk" diff --git a/hippunfold/workflow/rules/preproc_cropseg.smk b/hippunfold/workflow/rules/preproc_cropseg.smk index aface7f0..11ba4b73 100644 --- a/hippunfold/workflow/rules/preproc_cropseg.smk +++ b/hippunfold/workflow/rules/preproc_cropseg.smk @@ -1,7 +1,14 @@ -rule import_cropseg: +rule import_cropseg_to_corobl: input: in_img=partial(get_single_bids_input, component="cropseg"), + template_dir=Path(download_dir) / "template" / config["template"], + params: + std_to_cor=lambda wildcards: config["template_files"][config["template"]][ + "xfm_corobl" + ].format(**wildcards), + ref=lambda wildcards, input: Path(input.template_dir) + / config["template_files"][config["template"]]["crop_ref"].format(**wildcards), output: nii=bids( root=work, @@ -9,14 +16,15 @@ rule import_cropseg: **inputs.subj_wildcards, suffix="dseg.nii.gz", space="corobl", - hemi="{hemi,L|R}" + hemi="{hemi,L|R}", ), - group: - "subj" container: config["singularity"]["autotop"] + group: + "subj" shell: - "cp {input} {output}" + "ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS={threads} " + "antsApplyTransforms -d 3 --interpolation MultiLabel -i {input.in_img} -o {output.nii} -r {params.ref} -t {params.std_to_cor}" rule lr_flip_seg: diff --git a/hippunfold/workflow/rules/preproc_seg.smk b/hippunfold/workflow/rules/preproc_seg.smk deleted file mode 100644 index fbb221cb..00000000 --- a/hippunfold/workflow/rules/preproc_seg.smk +++ /dev/null @@ -1,79 +0,0 @@ -rule import_seg: - input: - in_img=partial(get_single_bids_input, component="seg"), - output: - bids(root=work, datatype="anat", **inputs.subj_wildcards, suffix="dseg.nii.gz"), - group: - "subj" - container: - config["singularity"]["autotop"] - shell: - "cp {input} {output}" - - -# now, transform to coronal oblique, xfm dependent on the space wildcard -rule warp_seg_to_corobl_crop: - input: - nii=bids( - root=work, datatype="anat", **inputs.subj_wildcards, suffix="dseg.nii.gz" - ), - xfm=bids( - root=work, - datatype="warps", - **inputs.subj_wildcards, - suffix="xfm.txt", - from_="{space}", - to="corobl", - desc="affine", - type_="itk" - ), - template_dir=Path(download_dir) / "template" / config["template"], - params: - ref=lambda wildcards, input: Path(input.template_dir) - / config["template_files"][config["template"]]["crop_ref"].format(**wildcards), - output: - nii=bids( - root=work, - datatype="anat", - **inputs.subj_wildcards, - suffix="dseg.nii.gz", - space="corobl", - hemi="{hemi,L|R}", - from_="{space}" - ), - container: - config["singularity"]["autotop"] - group: - "subj" - shell: - "ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS={threads} " - "antsApplyTransforms -d 3 --interpolation MultiLabel -i {input.nii} -o {output.nii} -r {params.ref} -t {input.xfm}" - - -rule lr_flip_seg: - input: - nii=bids( - root=work, - datatype="anat", - **inputs.subj_wildcards, - suffix="dseg.nii.gz", - space="corobl", - hemi="{hemi}", - from_="{space}" - ), - output: - nii=bids( - root=work, - datatype="anat", - **inputs.subj_wildcards, - suffix="dseg.nii.gz", - space="corobl", - hemi="{hemi,L}flip", - from_="{space}" - ), - container: - config["singularity"]["autotop"] - group: - "subj" - shell: - "c3d {input} -flip x -o {output}" diff --git a/hippunfold/workflow/rules/shape_inject.smk b/hippunfold/workflow/rules/shape_inject.smk index 2851fe7a..743dd25b 100644 --- a/hippunfold/workflow/rules/shape_inject.smk +++ b/hippunfold/workflow/rules/shape_inject.smk @@ -41,19 +41,6 @@ def get_input_for_shape_inject(wildcards): space="corobl", hemi="{hemi}", ).format(**wildcards) - elif get_modality_key(config["modality"]) == "seg": - modality_suffix = get_modality_suffix(config["modality"]) - seg = ( - bids( - root=work, - datatype="anat", - **inputs.subj_wildcards, - suffix="dseg.nii.gz", - space="corobl", - hemi="{hemi}", - from_="{modality_suffix}", - ).format(**wildcards, modality_suffix=modality_suffix), - ) else: seg = bids( root=work, @@ -77,18 +64,6 @@ def get_input_splitseg_for_shape_inject(wildcards): space="corobl", hemi="{hemi}", ).format(**wildcards) - - elif get_modality_key(config["modality"]) == "seg": - modality_suffix = get_modality_suffix(config["modality"]) - seg = bids( - root=work, - datatype="anat", - **inputs.subj_wildcards, - suffix="dsegsplit", - space="corobl", - hemi="{hemi}", - from_="{modality_suffix}", - ).format(**wildcards, modality_suffix=modality_suffix) else: seg = bids( root=work, diff --git a/test_data/data_cropseg/sub-001_hemi-L_dseg.nii.gz b/test_data/data_cropseg/sub-001/anat/sub-001_hemi-L_dseg.nii.gz similarity index 100% rename from test_data/data_cropseg/sub-001_hemi-L_dseg.nii.gz rename to test_data/data_cropseg/sub-001/anat/sub-001_hemi-L_dseg.nii.gz diff --git a/test_data/data_cropseg/sub-001_hemi-R_dseg.nii.gz b/test_data/data_cropseg/sub-001/anat/sub-001_hemi-R_dseg.nii.gz similarity index 100% rename from test_data/data_cropseg/sub-001_hemi-R_dseg.nii.gz rename to test_data/data_cropseg/sub-001/anat/sub-001_hemi-R_dseg.nii.gz diff --git a/test_data/data_cropseg_1hemi/sub-001_hemi-L_dseg.nii.gz b/test_data/data_cropseg_1hemi/sub-001/anat/sub-001_hemi-L_dseg.nii.gz similarity index 100% rename from test_data/data_cropseg_1hemi/sub-001_hemi-L_dseg.nii.gz rename to test_data/data_cropseg_1hemi/sub-001/anat/sub-001_hemi-L_dseg.nii.gz