From df1b0880e68fab05dcb77a11545499bc6eb9147b Mon Sep 17 00:00:00 2001 From: Ali Khan Date: Fri, 10 Sep 2021 14:14:45 -0400 Subject: [PATCH 1/3] fixes for cropseg -add missing wildcard constraints -add test case for single hemi --- hippunfold/tests/hippunfold_test.py | 6 ++++++ hippunfold/workflow/Snakefile | 1 + hippunfold/workflow/rules/preproc_cropseg.smk | 2 +- test_data/data_cropseg_1hemi/sub-001_hemi-L_dseg.nii.gz | 0 4 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 test_data/data_cropseg_1hemi/sub-001_hemi-L_dseg.nii.gz diff --git a/hippunfold/tests/hippunfold_test.py b/hippunfold/tests/hippunfold_test.py index 6129e9ff..d540d3ec 100644 --- a/hippunfold/tests/hippunfold_test.py +++ b/hippunfold/tests/hippunfold_test.py @@ -49,3 +49,9 @@ def test_dry_runs(script_runner): ret = script_runner.run('hippunfold', '-',output_dir,'participant','-np','--modality','cropseg','--path_cropseg','test_data/data_cropseg/sub-{subject}_hemi-{hemi}_dseg.nii.gz') assert ret.success + #cropseg with single hemi -- requires user to specify --hemi + with tempfile.TemporaryDirectory() as output_dir: + ret = script_runner.run('hippunfold', '-',output_dir,'participant','-np','--modality','cropseg','--path_cropseg','test_data/data_cropseg_1hemi/sub-{subject}_hemi-{hemi}_dseg.nii.gz','--hemi','L') + assert ret.success + + diff --git a/hippunfold/workflow/Snakefile b/hippunfold/workflow/Snakefile index 60da2dad..aa2cb7ff 100644 --- a/hippunfold/workflow/Snakefile +++ b/hippunfold/workflow/Snakefile @@ -43,6 +43,7 @@ wildcard_constraints: hemi='[a-zA-Z0-9]+', surfname='[a-zA-Z0-9]+', modality='[a-zA-Z0-9]+', + density='[a-zA-Z0-9]+', include: 'rules/common.smk' diff --git a/hippunfold/workflow/rules/preproc_cropseg.smk b/hippunfold/workflow/rules/preproc_cropseg.smk index 9bef6f8d..6c5d9744 100644 --- a/hippunfold/workflow/rules/preproc_cropseg.smk +++ b/hippunfold/workflow/rules/preproc_cropseg.smk @@ -1,7 +1,7 @@ rule import_cropseg: input: config['input_path']['cropseg'] output: - nii = bids(root='work',datatype='anat',**config['subj_wildcards'],suffix='dseg.nii.gz',desc='cropped',space='corobl',hemi='{hemi}'), + nii = bids(root='work',datatype='anat',**config['subj_wildcards'],suffix='dseg.nii.gz',desc='cropped',space='corobl',hemi='{hemi,L|R}'), group: 'subj' shell: 'cp {input} {output}' diff --git a/test_data/data_cropseg_1hemi/sub-001_hemi-L_dseg.nii.gz b/test_data/data_cropseg_1hemi/sub-001_hemi-L_dseg.nii.gz new file mode 100644 index 00000000..e69de29b From 50c25fcafc9ca1d7d4a6ba566763458d2cc4d41b Mon Sep 17 00:00:00 2001 From: Ali Khan Date: Fri, 10 Sep 2021 14:15:19 -0400 Subject: [PATCH 2/3] fix unrelated warning in equivol --- hippunfold/workflow/rules/autotop.smk | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hippunfold/workflow/rules/autotop.smk b/hippunfold/workflow/rules/autotop.smk index 01762cbe..cea3c8d3 100644 --- a/hippunfold/workflow/rules/autotop.smk +++ b/hippunfold/workflow/rules/autotop.smk @@ -46,8 +46,8 @@ rule prep_equivolume_coords: rule equivolume_coords: input: - outerbin = bids(root='work',datatype='seg_{modality}',dir='{dir}',desc='all',suffix='mask.nii.gz',space='corobl',hemi='{hemi,Lflip|R}', **config['subj_wildcards']), - innerbin = bids(root='work',datatype='seg_{modality}',dir='{dir}',desc='SRLM',suffix='mask.nii.gz',space='corobl',hemi='{hemi,Lflip|R}', **config['subj_wildcards']), + outerbin = bids(root='work',datatype='seg_{modality}',dir='{dir}',desc='all',suffix='mask.nii.gz',space='corobl',hemi='{hemi}', **config['subj_wildcards']), + innerbin = bids(root='work',datatype='seg_{modality}',dir='{dir}',desc='SRLM',suffix='mask.nii.gz',space='corobl',hemi='{hemi}', **config['subj_wildcards']), params: src_labels = lambda wildcards: config['laplace_labels'][wildcards.dir]['src'], output: From 888117833479664772587cc23947cbd491d95bfc Mon Sep 17 00:00:00 2001 From: Ali Khan Date: Fri, 10 Sep 2021 14:44:22 -0400 Subject: [PATCH 3/3] corrected example for cropseg --- docs/tutorials/specializedScans.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/tutorials/specializedScans.rst b/docs/tutorials/specializedScans.rst index b7841c85..b4142b51 100644 --- a/docs/tutorials/specializedScans.rst +++ b/docs/tutorials/specializedScans.rst @@ -1,6 +1,6 @@ Specialized scans ===================== -This tutorial will cover how HippUnfold can be applied to nonstandard data including ex-vivo scans, super high resolution data (eg. <0.3mm isotropic), non-MRI 3D imaging data, or scans where a corresponding whole-brain T1w image is not available. +This tutorial will cover how HippUnfold can be applied to non-standard data including ex-vivo scans, super-high resolution data (eg. <0.3mm isotropic), non-MRI 3D imaging data, or scans where a corresponding whole-brain T1w image is not available. We will show how the available flags can be adapted for these use-cases with several worked examples. @@ -13,16 +13,16 @@ This will require manual segmentation of hippocampal grey matter, SRLM, and neig Here is an example of what the input directory might look like:: - PATH_TO_EXVIVO_DIR/ + exvivo/ └── sub-001/ ├── sub-001_hemi-R_desc-hippo_T2w.nii.gz └── sub-001_hemi-R_desc-hippo_dseg.nii.gz This can be unfolded with the command:: - hippunfold PATH_TO_EXVIVO_DIR PATH_TO_OUTPUT_DIR participant --modality cropseg --hemi R --skip_inject_template_labels + hippunfold - PATH_TO_OUTPUT_DIR participant --modality cropseg --path_cropseg exvivo/sub-{subject}/sub-{subject}_hemi-{hemi}_desc-hippo_dseg.nii.gz --hemi R --skip_inject_template_labels -Explanation: ``--modality cropseg`` informs HippUnfold that the input manual segmentation should not be resampled and UNet does not need to be run. Output files will be named with ``space-corobl`` because HippUnfold is coded to effectively treat all files as already being in this space. We need the ``--hemi R`` to prevent HippUnfold looking for both hemispheres. Finally, because this segmentation was performed manually on very high resolution data, we can optionally consider skipping the template shape injection step with ``--skip_inject_template_labels``. Template shape injection can fix minor errors in segmentation from UNet or from an imperfect manual rater, at the cost of smoothing out some details of the hippocampus due to the fact that it uses deformable registration with inherent smoothness contraints. +Explanation: ``--modality cropseg`` informs HippUnfold that the input manual segmentation should not be resampled and UNet does not need to be run. Because of a limitation in bids parsing for the `hemi` entity, we need to use the generic path input, `--path_cropseg` in this case, making sure we use the `{subject}` and `{hemi}` wildcards in the filename. Output files will be named with ``space-corobl`` because HippUnfold is coded to effectively treat all files as already being in this space. We need the ``--hemi R`` to prevent HippUnfold looking for both hemispheres. Finally, because this segmentation was performed manually on very high resolution data, we can optionally consider skipping the template shape injection step with ``--skip_inject_template_labels``. Template shape injection can fix minor errors in segmentation from UNet or from an imperfect manual rater, at the cost of smoothing out some details of the hippocampus due to the fact that it uses deformable registration with inherent smoothness contraints. Note that because we are not resampling to the CITI168 template or using UNet, the T2w image in this example is effectively not being used at all. Instead, the provided manual segmentation makes up the basis for unfolding.