From bd3e0b36ddea2939ec8fd1b0fee3654fe032e6c5 Mon Sep 17 00:00:00 2001 From: Yehuda Warszawer <36595323+yw7@users.noreply.github.com> Date: Sat, 28 Sep 2024 14:10:01 +0300 Subject: [PATCH 1/3] Update BIDS path arguments in utilities Switched from specifying `-d` and `-u` to using the more flexible `-p "sub-*/anat/"` in various scripts for consistency and ease of use. This change consolidates path handling, making it easier to manage directories and improves the robustness of the BIDS-compatible utility scripts. --- scripts/prepare_datasets.sh | 4 ++-- totalspineseg/utils/augment.py | 2 +- totalspineseg/utils/average4d.py | 2 +- totalspineseg/utils/crop_image2seg.py | 2 +- totalspineseg/utils/extract_alternate.py | 2 +- totalspineseg/utils/extract_levels.py | 2 +- totalspineseg/utils/extract_soft.py | 2 +- totalspineseg/utils/fill_canal.py | 2 +- totalspineseg/utils/iterative_label.py | 2 +- totalspineseg/utils/largest_component.py | 2 +- totalspineseg/utils/map_labels.py | 3 +-- totalspineseg/utils/preview_jpg.py | 2 +- totalspineseg/utils/reorient_canonical.py | 2 +- totalspineseg/utils/resample.py | 2 +- totalspineseg/utils/transform_seg2image.py | 2 +- 15 files changed, 16 insertions(+), 17 deletions(-) diff --git a/scripts/prepare_datasets.sh b/scripts/prepare_datasets.sh index 533efb1..abafce6 100644 --- a/scripts/prepare_datasets.sh +++ b/scripts/prepare_datasets.sh @@ -75,8 +75,8 @@ for dsp in "$bids"/*; do echo "Working on $dsn" echo "Adding label-canal_seg and label-SC_seg to label-spine_dseg" - totalspineseg_map_labels -m 1:2 -s "$bids"/$dsn/derivatives/labels_iso -o "$bids"/$dsn/derivatives/labels_iso --update-segs-dir "$bids"/$dsn/derivatives/labels_iso --seg-suffix "_label-canal_seg" --output-seg-suffix "_label-spine_dseg" --update-seg-suffix "_label-spine_dseg" -d "sub-" -u "anat" -r -w $JOBS - totalspineseg_map_labels -m 1:1 -s "$bids"/$dsn/derivatives/labels_iso -o "$bids"/$dsn/derivatives/labels_iso --update-segs-dir "$bids"/$dsn/derivatives/labels_iso --seg-suffix "_label-SC_seg" --output-seg-suffix "_label-spine_dseg" --update-seg-suffix "_label-spine_dseg" -d "sub-" -u "anat" -r -w $JOBS + totalspineseg_map_labels -m 1:2 -s "$bids"/$dsn/derivatives/labels_iso -o "$bids"/$dsn/derivatives/labels_iso --update-segs-dir "$bids"/$dsn/derivatives/labels_iso --seg-suffix "_label-canal_seg" --output-seg-suffix "_label-spine_dseg" --update-seg-suffix "_label-spine_dseg" -p "sub-*/anat/" -r -w $JOBS + totalspineseg_map_labels -m 1:1 -s "$bids"/$dsn/derivatives/labels_iso -o "$bids"/$dsn/derivatives/labels_iso --update-segs-dir "$bids"/$dsn/derivatives/labels_iso --seg-suffix "_label-SC_seg" --output-seg-suffix "_label-spine_dseg" --update-seg-suffix "_label-spine_dseg" -p "sub-*/anat/" -r -w $JOBS echo "Copy images and labels into the nnUNet dataset folder" totalspineseg_cpdir "$bids"/$dsn "$nnUNet_raw"/$SRC_DATASET/imagesTr -p "sub-*/anat/sub-*.nii.gz" -f -t sub-:sub-${dsw} .nii.gz:_0000.nii.gz -r -w $JOBS diff --git a/totalspineseg/utils/augment.py b/totalspineseg/utils/augment.py index 37e02dc..e9c9174 100644 --- a/totalspineseg/utils/augment.py +++ b/totalspineseg/utils/augment.py @@ -27,7 +27,7 @@ def main(): Examples: augment -i images -s labels -o images -g labels --labels2image --seg-classes 1 2 11-50 63-100 For BIDS: - augment -i . -s derivatives/labels -o . -g derivatives/labels --image-suffix "" --output-image-suffix "" --seg-suffix "_seg" --output-seg-suffix "_seg" -d "sub-" -u "anat" --labels2image --seg-classes 1 2 11-50 63-100 + augment -i . -s derivatives/labels -o . -g derivatives/labels --image-suffix "" --output-image-suffix "" --seg-suffix "_seg" --output-seg-suffix "_seg" -p "sub-*/anat/" --labels2image --seg-classes 1 2 11-50 63-100 '''), formatter_class=argparse.RawTextHelpFormatter ) diff --git a/totalspineseg/utils/average4d.py b/totalspineseg/utils/average4d.py index c608693..af29004 100644 --- a/totalspineseg/utils/average4d.py +++ b/totalspineseg/utils/average4d.py @@ -21,7 +21,7 @@ def main(): Examples: average4d -i images -o images For BIDS: - average4d -i . -o . --image-suffix "" --output-image-suffix "" -d "sub-" -u "anat" + average4d -i . -o . --image-suffix "" --output-image-suffix "" -p "sub-*/anat/" '''), formatter_class=argparse.RawTextHelpFormatter ) diff --git a/totalspineseg/utils/crop_image2seg.py b/totalspineseg/utils/crop_image2seg.py index f82cbcf..a1ddfd0 100644 --- a/totalspineseg/utils/crop_image2seg.py +++ b/totalspineseg/utils/crop_image2seg.py @@ -23,7 +23,7 @@ def main(): Examples: crop_image2seg -i images -s labels -o images -m 50 For BIDS: - crop_image2seg -i . -s derivatives/labels -o . --image-suffix "" --output-image-suffix "" --seg-suffix "_seg" -d "sub-" -u "anat" -m 50 + crop_image2seg -i . -s derivatives/labels -o . --image-suffix "" --output-image-suffix "" --seg-suffix "_seg" -p "sub-*/anat/" -m 50 '''), formatter_class=argparse.RawTextHelpFormatter ) diff --git a/totalspineseg/utils/extract_alternate.py b/totalspineseg/utils/extract_alternate.py index 3c2e0cb..053c1da 100644 --- a/totalspineseg/utils/extract_alternate.py +++ b/totalspineseg/utils/extract_alternate.py @@ -25,7 +25,7 @@ def main(): Examples: extract_alternate -s labels -o levels --labels 60-100 -r For BIDS: - extract_alternate -s derivatives/labels -o derivatives/labels --seg-suffix "_seg" --output-seg-suffix "_levels" -d "sub-" -u "anat" --labels 60-100 -r + extract_alternate -s derivatives/labels -o derivatives/labels --seg-suffix "_seg" --output-seg-suffix "_levels" -p "sub-*/anat/" --labels 60-100 -r '''), formatter_class=argparse.RawTextHelpFormatter ) diff --git a/totalspineseg/utils/extract_levels.py b/totalspineseg/utils/extract_levels.py index 906ec50..3acd3cd 100644 --- a/totalspineseg/utils/extract_levels.py +++ b/totalspineseg/utils/extract_levels.py @@ -20,7 +20,7 @@ def main(): Examples: extract_levels -s labels -o levels --canal-labels 1 2 --disc-labels 60-64 70-81 90-94 100 -r For BIDS: - extract_levels -s derivatives/labels -o derivatives/labels --seg-suffix "_seg" --output-seg-suffix "_levels" -d "sub-" -u "anat" --canal-labels 1 2 --disc-labels 60-64 70-81 90-94 100 -r + extract_levels -s derivatives/labels -o derivatives/labels --seg-suffix "_seg" --output-seg-suffix "_levels" -p "sub-*/anat/" --canal-labels 1 2 --disc-labels 60-64 70-81 90-94 100 -r '''), formatter_class=argparse.RawTextHelpFormatter ) diff --git a/totalspineseg/utils/extract_soft.py b/totalspineseg/utils/extract_soft.py index ba1aed6..e26544d 100644 --- a/totalspineseg/utils/extract_soft.py +++ b/totalspineseg/utils/extract_soft.py @@ -24,7 +24,7 @@ def main(): Examples: extract_soft -n npzs -s labels -o canal_soft For BIDS: - extract_soft -n derivatives/labels -s derivatives/labels -o derivatives/labels --npz-suffix "" --seg-suffix "_seg" --output-seg-suffix "_cord" -d "sub-" -u "anat" + extract_soft -n derivatives/labels -s derivatives/labels -o derivatives/labels --npz-suffix "" --seg-suffix "_seg" --output-seg-suffix "_cord" -p "sub-*/anat/" '''), formatter_class=argparse.RawTextHelpFormatter ) diff --git a/totalspineseg/utils/fill_canal.py b/totalspineseg/utils/fill_canal.py index 280f2d2..4008b61 100644 --- a/totalspineseg/utils/fill_canal.py +++ b/totalspineseg/utils/fill_canal.py @@ -21,7 +21,7 @@ def main(): Examples: fill_canal -s labels -o labels_fixed For BIDS: - fill_canal -s derivatives/labels -o derivatives/labels --seg-suffix "_seg" --output-seg-suffix "_seg_fixed" -d "sub-" -u "anat" + fill_canal -s derivatives/labels -o derivatives/labels --seg-suffix "_seg" --output-seg-suffix "_seg_fixed" -p "sub-*/anat/" '''), formatter_class=argparse.RawTextHelpFormatter ) diff --git a/totalspineseg/utils/iterative_label.py b/totalspineseg/utils/iterative_label.py index a1c9cfe..7fd6444 100644 --- a/totalspineseg/utils/iterative_label.py +++ b/totalspineseg/utils/iterative_label.py @@ -25,7 +25,7 @@ def main(): iterative_label -s labels_init -o labels -l localizers --selected-disc-landmarks 2 5 --disc-labels 1-5 --disc-landmark-labels 2 3 4 5 --disc-landmark-output-labels 63 71 91 100 --canal-labels 7 8 --canal-output-label 2 --cord-labels 9 --cord-output-label 1 --loc-disc-labels 63-100 -r iterative_label -s labels_init -o labels -l localizers --selected-disc-landmarks 4 7 --disc-labels 1-7 --disc-landmark-labels 4 5 6 7 --disc-landmark-output-labels 63 71 91 100 --vertebrae-labels 9-14 --vertebrae-landmark-output-labels 13 21 41 50 --vertebrae-extra-labels 8 --canal-labels 15 16 --canal-output-label 2 --cord-labels 17 --cord-output-label 1 --sacrum-labels 14 --sacrum-output-label 50 --loc-disc-labels 63-100 -r For BIDS: - iterative_label -s derivatives/labels -o derivatives/labels --seg-suffix "_seg" --output-seg-suffix "_seg_seq" -d "sub-" -u "anat" --selected-disc-landmarks 2 5 3 4 --disc-labels 1-5 --disc-landmark-labels 2 3 4 5 --disc-landmark-output-labels 63 71 91 100 --canal-labels 7 8 --canal-output-label 2 --cord-labels 9 --cord-output-label 1 -r + iterative_label -s derivatives/labels -o derivatives/labels --seg-suffix "_seg" --output-seg-suffix "_seg_seq" -p "sub-*/anat/" --selected-disc-landmarks 2 5 3 4 --disc-labels 1-5 --disc-landmark-labels 2 3 4 5 --disc-landmark-output-labels 63 71 91 100 --canal-labels 7 8 --canal-output-label 2 --cord-labels 9 --cord-output-label 1 -r '''), formatter_class=argparse.RawTextHelpFormatter ) diff --git a/totalspineseg/utils/largest_component.py b/totalspineseg/utils/largest_component.py index 8dc46a3..ebf63a1 100644 --- a/totalspineseg/utils/largest_component.py +++ b/totalspineseg/utils/largest_component.py @@ -21,7 +21,7 @@ def main(): Examples: largest_component -s labels -o labels_largest For BIDS: - largest_component -s derivatives/labels -o derivatives/labels --seg-suffix "_seg" --output-seg-suffix "_seg_largest" -d "sub-" -u "anat" + largest_component -s derivatives/labels -o derivatives/labels --seg-suffix "_seg" --output-seg-suffix "_seg_largest" -p "sub-*/anat/" '''), formatter_class=argparse.RawTextHelpFormatter ) diff --git a/totalspineseg/utils/map_labels.py b/totalspineseg/utils/map_labels.py index be6e9a1..fb60f3c 100644 --- a/totalspineseg/utils/map_labels.py +++ b/totalspineseg/utils/map_labels.py @@ -20,9 +20,8 @@ def main(): Examples: map_labels -s labels -o labels_mapped -m map.json map_labels -s labels -o labels_mapped -m 92:1 93:2 - map_labels -s labels -o labels_mapped -m map.json -d sub- -s anat For BIDS: - map_labels -s derivatives/labels -o derivatives/labels -m map.json --seg-suffix "_seg" --output-seg-suffix "_seg_mapped" -d "sub-" -u "anat" + map_labels -s derivatives/labels -o derivatives/labels -m map.json --seg-suffix "_seg" --output-seg-suffix "_seg_mapped" -p "sub-*/anat/" '''), formatter_class=argparse.RawTextHelpFormatter ) diff --git a/totalspineseg/utils/preview_jpg.py b/totalspineseg/utils/preview_jpg.py index edda153..f49ad3b 100644 --- a/totalspineseg/utils/preview_jpg.py +++ b/totalspineseg/utils/preview_jpg.py @@ -26,7 +26,7 @@ def main(): Examples: preview_jpg -i images -s labels -o preview For BIDS: - preview_jpg -i . -s derivatives/labels -o derivatives/preview --seg-suffix "_seg" -d "sub-" -u "anat" + preview_jpg -i . -s derivatives/labels -o derivatives/preview --seg-suffix "_seg" -p "sub-*/anat/" '''), formatter_class=argparse.RawTextHelpFormatter ) diff --git a/totalspineseg/utils/reorient_canonical.py b/totalspineseg/utils/reorient_canonical.py index e3db83c..f4ac08f 100644 --- a/totalspineseg/utils/reorient_canonical.py +++ b/totalspineseg/utils/reorient_canonical.py @@ -21,7 +21,7 @@ def main(): Examples: reorient_canonical -i images -o images For BIDS: - reorient_canonical -i . -o . --image-suffix "" --output-image-suffix "" -d "sub-" -u "anat" + reorient_canonical -i . -o . --image-suffix "" --output-image-suffix "" -p "sub-*/anat/" '''), formatter_class=argparse.RawTextHelpFormatter ) diff --git a/totalspineseg/utils/resample.py b/totalspineseg/utils/resample.py index cc579d2..da7d065 100644 --- a/totalspineseg/utils/resample.py +++ b/totalspineseg/utils/resample.py @@ -23,7 +23,7 @@ def main(): Examples: resample -i images -o images For BIDS: - resample -i . -o . --image-suffix "" --output-image-suffix "" -d "sub-" -u "anat" -m 1 + resample -i . -o . --image-suffix "" --output-image-suffix "" -p "sub-*/anat/" -m 1 '''), formatter_class=argparse.RawTextHelpFormatter ) diff --git a/totalspineseg/utils/transform_seg2image.py b/totalspineseg/utils/transform_seg2image.py index f688a5c..425ff12 100644 --- a/totalspineseg/utils/transform_seg2image.py +++ b/totalspineseg/utils/transform_seg2image.py @@ -24,7 +24,7 @@ def main(): Examples: transform_seg2image -i images -s labels -o labels_transformed For BIDS: - transform_seg2image -i . -s derivatives/labels -o derivatives/labels --image-suffix "" --output-image-suffix "" --seg-suffix "_seg" --output-seg-suffix "_seg" -d "sub-" -u "anat" + transform_seg2image -i . -s derivatives/labels -o derivatives/labels --image-suffix "" --output-image-suffix "" --seg-suffix "_seg" --output-seg-suffix "_seg" -p "sub-*/anat/" '''), formatter_class=argparse.RawTextHelpFormatter ) From c635c2569720ead1cb6bc15a065cee95528b7df5 Mon Sep 17 00:00:00 2001 From: Yehuda Warszawer <36595323+yw7@users.noreply.github.com> Date: Sat, 28 Sep 2024 14:41:03 +0300 Subject: [PATCH 2/3] Remove Unused Arguments --subject-dir and --subject-subdir Removed arguments and related code handling subject directories and subdirectories across various utils scripts. This simplification reduces complexity and potential errors related to directory management, focusing operations directly on the specified paths. Fix #65 --- totalspineseg/utils/augment.py | 24 ---------------------- totalspineseg/utils/average4d.py | 24 ---------------------- totalspineseg/utils/crop_image2seg.py | 24 ---------------------- totalspineseg/utils/extract_alternate.py | 24 ---------------------- totalspineseg/utils/extract_levels.py | 24 ---------------------- totalspineseg/utils/extract_soft.py | 24 ---------------------- totalspineseg/utils/fill_canal.py | 24 ---------------------- totalspineseg/utils/iterative_label.py | 24 ---------------------- totalspineseg/utils/largest_component.py | 24 ---------------------- totalspineseg/utils/map_labels.py | 24 ---------------------- totalspineseg/utils/preview_jpg.py | 24 ---------------------- totalspineseg/utils/reorient_canonical.py | 24 ---------------------- totalspineseg/utils/resample.py | 24 ---------------------- totalspineseg/utils/transform_seg2image.py | 24 ---------------------- 14 files changed, 336 deletions(-) diff --git a/totalspineseg/utils/augment.py b/totalspineseg/utils/augment.py index e9c9174..f6cefd2 100644 --- a/totalspineseg/utils/augment.py +++ b/totalspineseg/utils/augment.py @@ -47,18 +47,6 @@ def main(): '--output-segs-dir', '-g', type=Path, required=True, help='The folder where output augmented segmentation will be saved with _a1, _a2 etc. suffixes (required).' ) - parser.add_argument( - '--subject-dir', '-d', type=str, default=None, nargs='?', const='', - help=' '.join(f''' - Is every subject has its oen direcrory. - If this argument will be provided without value it will look for any directory in the segmentation directory. - If value also provided it will be used as a prefix to subject directory, defaults to False (no subjet directory). - '''.split()), - ) - parser.add_argument( - '--subject-subdir', '-u', type=str, default='', - help='Subfolder inside subject folder containing masks, defaults to no subfolder.' - ) parser.add_argument( '--prefix', '-p', type=str, default='', help='File prefix to work on.' @@ -112,8 +100,6 @@ def main(): segs_path = args.segs_dir output_images_path = args.output_images_dir output_segs_path = args.output_segs_dir - subject_dir = args.subject_dir - subject_subdir = args.subject_subdir prefix = args.prefix image_suffix = args.image_suffix seg_suffix = args.seg_suffix @@ -134,8 +120,6 @@ def main(): segs_path = "{segs_path}" output_images_path = "{output_images_path}" output_segs_path = "{output_segs_path}" - subject_dir = "{subject_dir}" - subject_subdir = "{subject_subdir}" prefix = "{prefix}" image_suffix = "{image_suffix}" seg_suffix = "{seg_suffix}" @@ -154,8 +138,6 @@ def main(): segs_path=segs_path, output_images_path=output_images_path, output_segs_path=output_segs_path, - subject_dir=subject_dir, - subject_subdir=subject_subdir, prefix=prefix, image_suffix=image_suffix, seg_suffix=seg_suffix, @@ -174,8 +156,6 @@ def augment_mp( segs_path, output_images_path, output_segs_path, - subject_dir=None, - subject_subdir='', prefix='', image_suffix='_0000', seg_suffix='', @@ -197,10 +177,6 @@ def augment_mp( output_segs_path = Path(output_segs_path) glob_pattern = "" - if subject_dir is not None: - glob_pattern += f"{subject_dir}*/" - if len(subject_subdir) > 0: - glob_pattern += f"{subject_subdir}/" glob_pattern += f'{prefix}*{image_suffix}.nii.gz' # Process the NIfTI image and segmentation files diff --git a/totalspineseg/utils/average4d.py b/totalspineseg/utils/average4d.py index af29004..8f8988c 100644 --- a/totalspineseg/utils/average4d.py +++ b/totalspineseg/utils/average4d.py @@ -33,18 +33,6 @@ def main(): '--output-images-dir', '-o', type=Path, required=True, help='The folder where output images will be saved (required).' ) - parser.add_argument( - '--subject-dir', '-d', type=str, default=None, nargs='?', const='', - help=' '.join(f''' - Is every subject has its oen direcrory. - If this argument will be provided without value it will look for any directory in the segmentation directory. - If value also provided it will be used as a prefix to subject directory, defaults to False (no subjet directory). - '''.split()) - ) - parser.add_argument( - '--subject-subdir', '-u', type=str, default='', - help='Subfolder inside subject folder containing masks, defaults to no subfolder.' - ) parser.add_argument( '--prefix', '-p', type=str, default='', help='File prefix to work on.' @@ -76,8 +64,6 @@ def main(): # Get the command-line argument values images_path = args.images_dir output_images_path = args.output_images_dir - subject_dir = args.subject_dir - subject_subdir = args.subject_subdir prefix = args.prefix image_suffix = args.image_suffix output_image_suffix = args.output_image_suffix @@ -91,8 +77,6 @@ def main(): Running {Path(__file__).stem} with the following params: images_path = "{images_path}" output_images_path = "{output_images_path}" - subject_dir = "{subject_dir}" - subject_subdir = "{subject_subdir}" prefix = "{prefix}" image_suffix = "{image_suffix}" output_image_suffix = "{output_image_suffix}" @@ -104,8 +88,6 @@ def main(): average4d_mp( images_path=images_path, output_images_path=output_images_path, - subject_dir=subject_dir, - subject_subdir=subject_subdir, prefix=prefix, image_suffix=image_suffix, output_image_suffix=output_image_suffix, @@ -117,8 +99,6 @@ def main(): def average4d_mp( images_path, output_images_path, - subject_dir=None, - subject_subdir='', prefix='', image_suffix='_0000', output_image_suffix='_0000', @@ -133,10 +113,6 @@ def average4d_mp( output_images_path = Path(output_images_path) glob_pattern = "" - if subject_dir is not None: - glob_pattern += f"{subject_dir}*/" - if len(subject_subdir) > 0: - glob_pattern += f"{subject_subdir}/" glob_pattern += f'{prefix}*{image_suffix}.nii.gz' # Process the NIfTI image and segmentation files diff --git a/totalspineseg/utils/crop_image2seg.py b/totalspineseg/utils/crop_image2seg.py index a1ddfd0..5038102 100644 --- a/totalspineseg/utils/crop_image2seg.py +++ b/totalspineseg/utils/crop_image2seg.py @@ -39,18 +39,6 @@ def main(): '--output-images-dir', '-o', type=Path, required=True, help='The folder where output augmented images will be saved with _a1, _a2 etc. suffixes (required).' ) - parser.add_argument( - '--subject-dir', '-d', type=str, default=None, nargs='?', const='', - help=' '.join(f''' - Is every subject has its oen direcrory. - If this argument will be provided without value it will look for any directory in the segmentation directory. - If value also provided it will be used as a prefix to subject directory, defaults to False (no subjet directory). - '''.split()) - ) - parser.add_argument( - '--subject-subdir', '-u', type=str, default='', - help='Subfolder inside subject folder containing masks, defaults to no subfolder.' - ) parser.add_argument( '--prefix', '-p', type=str, default='', help='File prefix to work on.' @@ -91,8 +79,6 @@ def main(): images_path = args.images_dir segs_path = args.segs_dir output_images_path = args.output_images_dir - subject_dir = args.subject_dir - subject_subdir = args.subject_subdir prefix = args.prefix image_suffix = args.image_suffix seg_suffix = args.seg_suffix @@ -109,8 +95,6 @@ def main(): images_path = "{images_path}" segs_path = "{segs_path}" output_images_path = "{output_images_path}" - subject_dir = "{subject_dir}" - subject_subdir = "{subject_subdir}" prefix = "{prefix}" image_suffix = "{image_suffix}" seg_suffix = "{seg_suffix}" @@ -125,8 +109,6 @@ def main(): images_path=images_path, segs_path=segs_path, output_images_path=output_images_path, - subject_dir=subject_dir, - subject_subdir=subject_subdir, prefix=prefix, image_suffix=image_suffix, seg_suffix=seg_suffix, @@ -141,8 +123,6 @@ def crop_image2seg_mp( images_path, segs_path, output_images_path, - subject_dir=None, - subject_subdir='', prefix='', image_suffix='_0000', seg_suffix='', @@ -160,10 +140,6 @@ def crop_image2seg_mp( output_images_path = Path(output_images_path) glob_pattern = "" - if subject_dir is not None: - glob_pattern += f"{subject_dir}*/" - if len(subject_subdir) > 0: - glob_pattern += f"{subject_subdir}/" glob_pattern += f'{prefix}*{image_suffix}.nii.gz' # Process the NIfTI image and segmentation files diff --git a/totalspineseg/utils/extract_alternate.py b/totalspineseg/utils/extract_alternate.py index 053c1da..55ce6b3 100644 --- a/totalspineseg/utils/extract_alternate.py +++ b/totalspineseg/utils/extract_alternate.py @@ -38,18 +38,6 @@ def main(): '--output-segs-dir', '-o', type=Path, required=True, help='Folder to save output segmentations.' ) - parser.add_argument( - '--subject-dir', '-d', type=str, default=None, nargs='?', const='', - help=' '.join(f''' - Is every subject has its oen direcrory. - If this argument will be provided without value it will look for any directory in the segmentation directory. - If value also provided it will be used as a prefix to subject directory (for example "sub-"), defaults to False (no subjet directory). - '''.split()) - ) - parser.add_argument( - '--subject-subdir', '-u', type=str, default='', - help='Subfolder inside subject folder containing masks (for example "anat"), defaults to no subfolder.' - ) parser.add_argument( '--prefix', '-p', type=str, default='', help='File prefix to work on.' @@ -89,8 +77,6 @@ def main(): # Get arguments segs_path = args.segs_dir output_segs_path = args.output_segs_dir - subject_dir = args.subject_dir - subject_subdir = args.subject_subdir prefix = args.prefix seg_suffix = args.seg_suffix output_seg_suffix = args.output_seg_suffix @@ -106,8 +92,6 @@ def main(): Running {Path(__file__).stem} with the following params: segs_dir = "{segs_path}" output_segs_dir = "{output_segs_path}" - subject_dir = "{subject_dir}" - subject_subdir = "{subject_subdir}" prefix = "{prefix}" seg_suffix = "{seg_suffix}" output_seg_suffix = "{output_seg_suffix}" @@ -121,8 +105,6 @@ def main(): extract_alternate_mp( segs_path=segs_path, output_segs_path=output_segs_path, - subject_dir=subject_dir, - subject_subdir=subject_subdir, prefix=prefix, seg_suffix=seg_suffix, output_seg_suffix=output_seg_suffix, @@ -136,8 +118,6 @@ def main(): def extract_alternate_mp( segs_path, output_segs_path, - subject_dir=None, - subject_subdir='', prefix='', seg_suffix='', output_seg_suffix='', @@ -154,10 +134,6 @@ def extract_alternate_mp( output_segs_path = Path(output_segs_path) glob_pattern = "" - if subject_dir is not None: - glob_pattern += f"{subject_dir}*/" - if len(subject_subdir) > 0: - glob_pattern += f"{subject_subdir}/" glob_pattern += f'{prefix}*{seg_suffix}.nii.gz' # Process the NIfTI image and segmentation files diff --git a/totalspineseg/utils/extract_levels.py b/totalspineseg/utils/extract_levels.py index 3acd3cd..776b7f1 100644 --- a/totalspineseg/utils/extract_levels.py +++ b/totalspineseg/utils/extract_levels.py @@ -33,18 +33,6 @@ def main(): '--output-segs-dir', '-o', type=Path, required=True, help='Folder to save output segmentations.' ) - parser.add_argument( - '--subject-dir', '-d', type=str, default=None, nargs='?', const='', - help=' '.join(f''' - Is every subject has its oen direcrory. - If this argument will be provided without value it will look for any directory in the segmentation directory. - If value also provided it will be used as a prefix to subject directory (for example "sub-"), defaults to False (no subjet directory). - '''.split()) - ) - parser.add_argument( - '--subject-subdir', '-u', type=str, default='', - help='Subfolder inside subject folder containing masks (for example "anat"), defaults to no subfolder.' - ) parser.add_argument( '--prefix', '-p', type=str, default='', help='File prefix to work on.' @@ -88,8 +76,6 @@ def main(): # Get arguments segs_path = args.segs_dir output_segs_path = args.output_segs_dir - subject_dir = args.subject_dir - subject_subdir = args.subject_subdir prefix = args.prefix seg_suffix = args.seg_suffix output_seg_suffix = args.output_seg_suffix @@ -106,8 +92,6 @@ def main(): Running {Path(__file__).stem} with the following params: segs_dir = "{segs_path}" output_segs_dir = "{output_segs_path}" - subject_dir = "{subject_dir}" - subject_subdir = "{subject_subdir}" prefix = "{prefix}" seg_suffix = "{seg_suffix}" output_seg_suffix = "{output_seg_suffix}" @@ -122,8 +106,6 @@ def main(): extract_levels_mp( segs_path=segs_path, output_segs_path=output_segs_path, - subject_dir=subject_dir, - subject_subdir=subject_subdir, prefix=prefix, seg_suffix=seg_suffix, output_seg_suffix=output_seg_suffix, @@ -138,8 +120,6 @@ def main(): def extract_levels_mp( segs_path, output_segs_path, - subject_dir=None, - subject_subdir='', prefix='', seg_suffix='', output_seg_suffix='', @@ -157,10 +137,6 @@ def extract_levels_mp( output_segs_path = Path(output_segs_path) glob_pattern = "" - if subject_dir is not None: - glob_pattern += f"{subject_dir}*/" - if len(subject_subdir) > 0: - glob_pattern += f"{subject_subdir}/" glob_pattern += f'{prefix}*{seg_suffix}.nii.gz' # Process the NIfTI image and segmentation files diff --git a/totalspineseg/utils/extract_soft.py b/totalspineseg/utils/extract_soft.py index e26544d..8cb6509 100644 --- a/totalspineseg/utils/extract_soft.py +++ b/totalspineseg/utils/extract_soft.py @@ -40,18 +40,6 @@ def main(): '--output-segs-dir', '-o', type=Path, required=True, help='The folder where output soft segmentations will be saved (required).' ) - parser.add_argument( - '--subject-dir', '-d', type=str, default=None, nargs='?', const='', - help=' '.join(f''' - Is every subject has its oen direcrory. - If this argument will be provided without value it will look for any directory in the segmentation directory. - If value also provided it will be used as a prefix to subject directory, defaults to False (no subjet directory). - '''.split()) - ) - parser.add_argument( - '--subject-subdir', '-u', type=str, default='', - help='Subfolder inside subject folder containing masks, defaults to no subfolder.' - ) parser.add_argument( '--prefix', '-p', type=str, default='', help='File prefix to work on.' @@ -104,8 +92,6 @@ def main(): npzs_path = args.npzs_dir segs_path = args.segs_dir output_segs_path = args.output_segs_dir - subject_dir = args.subject_dir - subject_subdir = args.subject_subdir prefix = args.prefix npz_suffix = args.npz_suffix seg_suffix = args.seg_suffix @@ -125,8 +111,6 @@ def main(): npzs_path = "{npzs_path}" segs_path = "{segs_path}" output_segs_path = "{output_segs_path}" - subject_dir = "{subject_dir}" - subject_subdir = "{subject_subdir}" prefix = "{prefix}" npz_suffix = "{npz_suffix}" seg_suffix = "{seg_suffix}" @@ -144,8 +128,6 @@ def main(): npzs_path=npzs_path, segs_path=segs_path, output_segs_path=output_segs_path, - subject_dir=subject_dir, - subject_subdir=subject_subdir, prefix=prefix, npz_suffix=npz_suffix, seg_suffix=seg_suffix, @@ -163,8 +145,6 @@ def extract_soft_mp( npzs_path, segs_path, output_segs_path, - subject_dir=None, - subject_subdir='', prefix='', npz_suffix='', seg_suffix='', @@ -185,10 +165,6 @@ def extract_soft_mp( output_segs_path = Path(output_segs_path) glob_pattern = "" - if subject_dir is not None: - glob_pattern += f"{subject_dir}*/" - if len(subject_subdir) > 0: - glob_pattern += f"{subject_subdir}/" glob_pattern += f'{prefix}*{npz_suffix}.npz' # Process the NIfTI npz and segmentation files diff --git a/totalspineseg/utils/fill_canal.py b/totalspineseg/utils/fill_canal.py index 4008b61..3ae5e6c 100644 --- a/totalspineseg/utils/fill_canal.py +++ b/totalspineseg/utils/fill_canal.py @@ -34,18 +34,6 @@ def main(): '--output-segs-dir', '-o', type=Path, required=True, help='Folder to save output segmentations.' ) - parser.add_argument( - '--subject-dir', '-d', type=str, default=None, nargs='?', const='', - help=' '.join(f''' - Is every subject has its oen direcrory. - If this argument will be provided without value it will look for any directory in the segmentation directory. - If value also provided it will be used as a prefix to subject directory (for example "sub-"), defaults to False (no subjet directory). - '''.split()) - ) - parser.add_argument( - '--subject-subdir', '-u', type=str, default='', - help='Subfolder inside subject folder containing masks (for example "anat"), defaults to no subfolder.' - ) parser.add_argument( '--prefix', '-p', type=str, default='', help='File prefix to work on.' @@ -93,8 +81,6 @@ def main(): # Get arguments segs_path = args.segs_dir output_segs_path = args.output_segs_dir - subject_dir = args.subject_dir - subject_subdir = args.subject_subdir prefix = args.prefix seg_suffix = args.seg_suffix output_seg_suffix = args.output_seg_suffix @@ -112,8 +98,6 @@ def main(): Running {Path(__file__).stem} with the following params: segs_dir = "{segs_path}" output_segs_dir = "{output_segs_path}" - subject_dir = "{subject_dir}" - subject_subdir = "{subject_subdir}" prefix = "{prefix}" seg_suffix = "{seg_suffix}" output_seg_suffix = "{output_seg_suffix}" @@ -129,8 +113,6 @@ def main(): fill_canal_mp( segs_path=segs_path, output_segs_path=output_segs_path, - subject_dir=subject_dir, - subject_subdir=subject_subdir, prefix=prefix, seg_suffix=seg_suffix, output_seg_suffix=output_seg_suffix, @@ -146,8 +128,6 @@ def main(): def fill_canal_mp( segs_path, output_segs_path, - subject_dir=None, - subject_subdir='', prefix='', seg_suffix='', output_seg_suffix='', @@ -166,10 +146,6 @@ def fill_canal_mp( output_segs_path = Path(output_segs_path) glob_pattern = "" - if subject_dir is not None: - glob_pattern += f"{subject_dir}*/" - if len(subject_subdir) > 0: - glob_pattern += f"{subject_subdir}/" glob_pattern += f'{prefix}*{seg_suffix}.nii.gz' # Process the NIfTI image and segmentation files diff --git a/totalspineseg/utils/iterative_label.py b/totalspineseg/utils/iterative_label.py index 7fd6444..709d80d 100644 --- a/totalspineseg/utils/iterative_label.py +++ b/totalspineseg/utils/iterative_label.py @@ -46,18 +46,6 @@ def main(): Matching will based on the majority of the voxels of the first vertebra or disc in the localizer, that intersect with the input segmentation. '''.split()) ) - parser.add_argument( - '--subject-dir', '-d', type=str, default=None, nargs='?', const='', - help=' '.join(f''' - Is every subject has its oen direcrory. - If this argument will be provided without value it will look for any directory in the segmentation directory. - If value also provided it will be used as a prefix to subject directory (for example "sub-"), defaults to False (no subjet directory). - '''.split()) - ) - parser.add_argument( - '--subject-subdir', '-u', type=str, default='', - help='Subfolder inside subject folder containing masks (for example "anat"), defaults to no subfolder.' - ) parser.add_argument( '--prefix', '-p', type=str, default='', help='File prefix to work on.' @@ -183,8 +171,6 @@ def main(): segs_path = args.segs_dir output_segs_path = args.output_segs_dir locs_path = args.locs_dir - subject_dir = args.subject_dir - subject_subdir = args.subject_subdir prefix = args.prefix seg_suffix = args.seg_suffix output_seg_suffix = args.output_seg_suffix @@ -221,8 +207,6 @@ def main(): segs_dir = "{segs_path}" output_segs_dir = "{output_segs_path}" locs_dir = "{locs_path}" - subject_dir = "{subject_dir}" - subject_subdir = "{subject_subdir}" prefix = "{prefix}" seg_suffix = "{seg_suffix}" output_seg_suffix = "{output_seg_suffix}" @@ -263,8 +247,6 @@ def main(): segs_path=segs_path, output_segs_path=output_segs_path, locs_path=locs_path, - subject_dir=subject_dir, - subject_subdir=subject_subdir, prefix=prefix, seg_suffix=seg_suffix, output_seg_suffix=output_seg_suffix, @@ -299,8 +281,6 @@ def iterative_label_mp( segs_path, output_segs_path, locs_path=None, - subject_dir=None, - subject_subdir='', prefix='', seg_suffix='', output_seg_suffix='', @@ -338,10 +318,6 @@ def iterative_label_mp( locs_path = locs_path and Path(locs_path) glob_pattern = "" - if subject_dir is not None: - glob_pattern += f"{subject_dir}*/" - if len(subject_subdir) > 0: - glob_pattern += f"{subject_subdir}/" glob_pattern += f'{prefix}*{seg_suffix}.nii.gz' # Process the NIfTI image and segmentation files diff --git a/totalspineseg/utils/largest_component.py b/totalspineseg/utils/largest_component.py index ebf63a1..028351b 100644 --- a/totalspineseg/utils/largest_component.py +++ b/totalspineseg/utils/largest_component.py @@ -34,18 +34,6 @@ def main(): '--output-segs-dir', '-o', type=Path, required=True, help='Folder to save output segmentations.' ) - parser.add_argument( - '--subject-dir', '-d', type=str, default=None, nargs='?', const='', - help=' '.join(f''' - Is every subject has its oen direcrory. - If this argument will be provided without value it will look for any directory in the segmentation directory. - If value also provided it will be used as a prefix to subject directory (for example "sub-"), defaults to False (no subjet directory). - '''.split()), - ) - parser.add_argument( - '--subject-subdir', '-u', type=str, default='', - help='Subfolder inside subject folder containing masks (for example "anat"), defaults to no subfolder.' - ) parser.add_argument( '--prefix', '-p', type=str, default='', help='File prefix to work on.' @@ -85,8 +73,6 @@ def main(): # Get arguments segs_path = args.segs_dir output_segs_path = args.output_segs_dir - subject_dir = args.subject_dir - subject_subdir = args.subject_subdir prefix = args.prefix seg_suffix = args.seg_suffix output_seg_suffix = args.output_seg_suffix @@ -102,8 +88,6 @@ def main(): Running {Path(__file__).stem} with the following params: segs_dir = "{segs_path}" output_segs_dir = "{output_segs_path}" - subject_dir = "{subject_dir}" - subject_subdir = "{subject_subdir}" prefix = "{prefix}" seg_suffix = "{seg_suffix}" output_seg_suffix = "{output_seg_suffix}" @@ -117,8 +101,6 @@ def main(): largest_component_mp( segs_path=segs_path, output_segs_path=output_segs_path, - subject_dir=subject_dir, - subject_subdir=subject_subdir, prefix=prefix, seg_suffix=seg_suffix, output_seg_suffix=output_seg_suffix, @@ -132,8 +114,6 @@ def main(): def largest_component_mp( segs_path, output_segs_path, - subject_dir=None, - subject_subdir='', prefix='', seg_suffix='', output_seg_suffix='', @@ -150,10 +130,6 @@ def largest_component_mp( output_segs_path = Path(output_segs_path) glob_pattern = "" - if subject_dir is not None: - glob_pattern += f"{subject_dir}*/" - if len(subject_subdir) > 0: - glob_pattern += f"{subject_subdir}/" glob_pattern += f'{prefix}*{seg_suffix}.nii.gz' # Process the NIfTI image and segmentation files diff --git a/totalspineseg/utils/map_labels.py b/totalspineseg/utils/map_labels.py index fb60f3c..65af597 100644 --- a/totalspineseg/utils/map_labels.py +++ b/totalspineseg/utils/map_labels.py @@ -51,18 +51,6 @@ def main(): or provide a dict directly like 1:2 2:15 '''.split()), ) - parser.add_argument( - '--subject-dir', '-d', type=str, default=None, nargs='?', const='', - help=' '.join(f''' - Is every subject has its oen direcrory. - If this argument will be provided without value it will look for any directory in the segmentation directory. - If value also provided it will be used as a prefix to subject directory, defaults to False (no subjet directory). - '''.split()), - ) - parser.add_argument( - '--subject-subdir', '-u', type=str, default='', - help='Subfolder inside subject folder containing masks, defaults to no subfolder.' - ) parser.add_argument( '--prefix', '-p', type=str, default='', help='File prefix to work on.' @@ -109,8 +97,6 @@ def main(): update_segs_path = args.update_segs_dir update_from_segs_path = args.update_from_segs_dir map_list = args.map - subject_dir = args.subject_dir - subject_subdir = args.subject_subdir prefix = args.prefix seg_suffix = args.seg_suffix output_seg_suffix = args.output_seg_suffix @@ -130,8 +116,6 @@ def main(): update_segs_dir = "{update_segs_path}" update_from_segs_dir = "{update_from_segs_path}" map = {map_list} - subject_dir = "{subject_dir}" - subject_subdir = "{subject_subdir}" prefix = "{prefix}" seg_suffix = "{seg_suffix}" output_seg_suffix = "{output_seg_suffix}" @@ -160,8 +144,6 @@ def main(): update_segs_path=update_segs_path, update_from_segs_path=update_from_segs_path, map_dict=map_dict, - subject_dir=subject_dir, - subject_subdir=subject_subdir, prefix=prefix, seg_suffix=seg_suffix, output_seg_suffix=output_seg_suffix, @@ -179,8 +161,6 @@ def map_labels_mp( update_segs_path=None, update_from_segs_path=None, map_dict={}, - subject_dir=None, - subject_subdir='', prefix='', seg_suffix='', output_seg_suffix='', @@ -200,10 +180,6 @@ def map_labels_mp( update_from_segs_path = update_from_segs_path and Path(update_from_segs_path) glob_pattern = "" - if subject_dir is not None: - glob_pattern += f"{subject_dir}*/" - if len(subject_subdir) > 0: - glob_pattern += f"{subject_subdir}/" glob_pattern += f'{prefix}*{seg_suffix}.nii.gz' # Process the NIfTI image and segmentation files diff --git a/totalspineseg/utils/preview_jpg.py b/totalspineseg/utils/preview_jpg.py index f49ad3b..fa5e32d 100644 --- a/totalspineseg/utils/preview_jpg.py +++ b/totalspineseg/utils/preview_jpg.py @@ -42,18 +42,6 @@ def main(): '--segs-dir', '-s', type=Path, default=None, help='The folder where input NIfTI segmentation files are located.' ) - parser.add_argument( - '--subject-dir', '-d', type=str, default=None, nargs='?', const='', - help=' '.join(f''' - Is every subject has its oen direcrory. - If this argument will be provided without value it will look for any directory in the segmentation directory. - If value also provided it will be used as a prefix to subject directory, defaults to False (no subjet directory). - '''.split()) - ) - parser.add_argument( - '--subject-subdir', '-u', type=str, default='', - help='Subfolder inside subject folder containing masks, defaults to no subfolder.' - ) parser.add_argument( '--prefix', '-p', type=str, default='', help='File prefix to work on.' @@ -116,8 +104,6 @@ def main(): images_path = args.images_dir output_path = args.output_dir segs_path = args.segs_dir - subject_dir = args.subject_dir - subject_subdir = args.subject_subdir prefix = args.prefix image_suffix = args.image_suffix output_suffix = args.output_suffix @@ -143,8 +129,6 @@ def main(): images_path = "{images_path}" output_dir = "{output_path}" segs_path = "{segs_path}" - subject_dir = "{subject_dir}" - subject_subdir = "{subject_subdir}" prefix = "{prefix}" image_suffix = "{image_suffix}" output_suffix = "{output_suffix}" @@ -162,8 +146,6 @@ def main(): images_path=images_path, output_path=output_path, segs_path=segs_path, - subject_dir=subject_dir, - subject_subdir=subject_subdir, prefix=prefix, image_suffix=image_suffix, output_suffix=output_suffix, @@ -195,8 +177,6 @@ def preview_jpg_mp( images_path, output_path, segs_path=None, - subject_dir=None, - subject_subdir='', prefix='', image_suffix='_0000', output_suffix='', @@ -217,10 +197,6 @@ def preview_jpg_mp( segs_path = segs_path and Path(segs_path) glob_pattern = "" - if subject_dir is not None: - glob_pattern += f"{subject_dir}*/" - if len(subject_subdir) > 0: - glob_pattern += f"{subject_subdir}/" glob_pattern += f'{prefix}*{image_suffix}' # Process the NIfTI image and segmentation files diff --git a/totalspineseg/utils/reorient_canonical.py b/totalspineseg/utils/reorient_canonical.py index f4ac08f..35357d7 100644 --- a/totalspineseg/utils/reorient_canonical.py +++ b/totalspineseg/utils/reorient_canonical.py @@ -33,18 +33,6 @@ def main(): '--output-images-dir', '-o', type=Path, required=True, help='The folder where output images will be saved (required).' ) - parser.add_argument( - '--subject-dir', '-d', type=str, default=None, nargs='?', const='', - help=' '.join(f''' - Is every subject has its oen direcrory. - If this argument will be provided without value it will look for any directory in the segmentation directory. - If value also provided it will be used as a prefix to subject directory, defaults to False (no subjet directory). - '''.split()) - ) - parser.add_argument( - '--subject-subdir', '-u', type=str, default='', - help='Subfolder inside subject folder containing masks, defaults to no subfolder.' - ) parser.add_argument( '--prefix', '-p', type=str, default='', help='File prefix to work on.' @@ -76,8 +64,6 @@ def main(): # Get the command-line argument values images_path = args.images_dir output_images_path = args.output_images_dir - subject_dir = args.subject_dir - subject_subdir = args.subject_subdir prefix = args.prefix image_suffix = args.image_suffix output_image_suffix = args.output_image_suffix @@ -91,8 +77,6 @@ def main(): Running {Path(__file__).stem} with the following params: images_path = "{images_path}" output_images_path = "{output_images_path}" - subject_dir = "{subject_dir}" - subject_subdir = "{subject_subdir}" prefix = "{prefix}" image_suffix = "{image_suffix}" output_image_suffix = "{output_image_suffix}" @@ -104,8 +88,6 @@ def main(): reorient_canonical_mp( images_path=images_path, output_images_path=output_images_path, - subject_dir=subject_dir, - subject_subdir=subject_subdir, prefix=prefix, image_suffix=image_suffix, output_image_suffix=output_image_suffix, @@ -117,8 +99,6 @@ def main(): def reorient_canonical_mp( images_path, output_images_path, - subject_dir=None, - subject_subdir='', prefix='', image_suffix='_0000', output_image_suffix='_0000', @@ -133,10 +113,6 @@ def reorient_canonical_mp( output_images_path = Path(output_images_path) glob_pattern = "" - if subject_dir is not None: - glob_pattern += f"{subject_dir}*/" - if len(subject_subdir) > 0: - glob_pattern += f"{subject_subdir}/" glob_pattern += f'{prefix}*{image_suffix}.nii.gz' # Process the NIfTI image and segmentation files diff --git a/totalspineseg/utils/resample.py b/totalspineseg/utils/resample.py index da7d065..1b661b2 100644 --- a/totalspineseg/utils/resample.py +++ b/totalspineseg/utils/resample.py @@ -35,18 +35,6 @@ def main(): '--output-images-dir', '-o', type=Path, required=True, help='The folder where output augmented images will be saved with _a1, _a2 etc. suffixes (required).' ) - parser.add_argument( - '--subject-dir', '-d', type=str, default=None, nargs='?', const='', - help=' '.join(f''' - Is every subject has its oen direcrory. - If this argument will be provided without value it will look for any directory in the segmentation directory. - If value also provided it will be used as a prefix to subject directory, defaults to False (no subjet directory). - '''.split()) - ) - parser.add_argument( - '--subject-subdir', '-u', type=str, default='', - help='Subfolder inside subject folder containing masks, defaults to no subfolder.' - ) parser.add_argument( '--prefix', '-p', type=str, default='', help='File prefix to work on.' @@ -82,8 +70,6 @@ def main(): # Get the command-line argument values images_path = args.images_dir output_images_path = args.output_images_dir - subject_dir = args.subject_dir - subject_subdir = args.subject_subdir prefix = args.prefix image_suffix = args.image_suffix output_image_suffix = args.output_image_suffix @@ -98,8 +84,6 @@ def main(): Running {Path(__file__).stem} with the following params: images_path = "{images_path}" output_images_path = "{output_images_path}" - subject_dir = "{subject_dir}" - subject_subdir = "{subject_subdir}" prefix = "{prefix}" image_suffix = "{image_suffix}" output_image_suffix = "{output_image_suffix}" @@ -112,8 +96,6 @@ def main(): resample_mp( images_path=images_path, output_images_path=output_images_path, - subject_dir=subject_dir, - subject_subdir=subject_subdir, prefix=prefix, image_suffix=image_suffix, output_image_suffix=output_image_suffix, @@ -126,8 +108,6 @@ def main(): def resample_mp( images_path, output_images_path, - subject_dir=None, - subject_subdir='', prefix='', image_suffix='_0000', output_image_suffix='_0000', @@ -143,10 +123,6 @@ def resample_mp( output_images_path = Path(output_images_path) glob_pattern = "" - if subject_dir is not None: - glob_pattern += f"{subject_dir}*/" - if len(subject_subdir) > 0: - glob_pattern += f"{subject_subdir}/" glob_pattern += f'{prefix}*{image_suffix}.nii.gz' # Process the NIfTI image and segmentation files diff --git a/totalspineseg/utils/transform_seg2image.py b/totalspineseg/utils/transform_seg2image.py index 425ff12..6b59b87 100644 --- a/totalspineseg/utils/transform_seg2image.py +++ b/totalspineseg/utils/transform_seg2image.py @@ -40,18 +40,6 @@ def main(): '--output-segs-dir', '-o', type=Path, required=True, help='The folder where output augmented images will be saved (required).' ) - parser.add_argument( - '--subject-dir', '-d', type=str, default=None, nargs='?', const='', - help=' '.join(f''' - Is every subject has its oen direcrory. - If this argument will be provided without value it will look for any directory in the segmentation directory. - If value also provided it will be used as a prefix to subject directory, defaults to False (no subjet directory). - '''.split()) - ) - parser.add_argument( - '--subject-subdir', '-u', type=str, default='', - help='Subfolder inside subject folder containing masks, defaults to no subfolder.' - ) parser.add_argument( '--prefix', '-p', type=str, default='', help='File prefix to work on.' @@ -92,8 +80,6 @@ def main(): images_path = args.images_dir segs_path = args.segs_dir output_segs_path = args.output_segs_dir - subject_dir = args.subject_dir - subject_subdir = args.subject_subdir prefix = args.prefix image_suffix = args.image_suffix seg_suffix = args.seg_suffix @@ -110,8 +96,6 @@ def main(): images_path = "{images_path}" segs_path = "{segs_path}" output_segs_path = "{output_segs_path}" - subject_dir = "{subject_dir}" - subject_subdir = "{subject_subdir}" prefix = "{prefix}" image_suffix = "{image_suffix}" seg_suffix = "{seg_suffix}" @@ -126,8 +110,6 @@ def main(): images_path=images_path, segs_path=segs_path, output_segs_path=output_segs_path, - subject_dir=subject_dir, - subject_subdir=subject_subdir, prefix=prefix, image_suffix=image_suffix, seg_suffix=seg_suffix, @@ -142,8 +124,6 @@ def transform_seg2image_mp( images_path, segs_path, output_segs_path, - subject_dir=None, - subject_subdir='', prefix='', image_suffix='_0000', seg_suffix='', @@ -161,10 +141,6 @@ def transform_seg2image_mp( output_segs_path = Path(output_segs_path) glob_pattern = "" - if subject_dir is not None: - glob_pattern += f"{subject_dir}*/" - if len(subject_subdir) > 0: - glob_pattern += f"{subject_subdir}/" glob_pattern += f'{prefix}*{image_suffix}.nii.gz' # Process the NIfTI image and segmentation files From 6647823a3563e3d865fe304448b0301c4c4d57f3 Mon Sep 17 00:00:00 2001 From: Yehuda Warszawer <36595323+yw7@users.noreply.github.com> Date: Sat, 28 Sep 2024 14:44:35 +0300 Subject: [PATCH 3/3] Simplify glob pattern assignments in utils Refactor glob pattern assignments to use direct string formatting instead of concatenation across multiple utility functions. This improves code readability and maintainability without changing functionality. --- totalspineseg/utils/augment.py | 3 +-- totalspineseg/utils/average4d.py | 3 +-- totalspineseg/utils/crop_image2seg.py | 3 +-- totalspineseg/utils/extract_alternate.py | 3 +-- totalspineseg/utils/extract_levels.py | 3 +-- totalspineseg/utils/extract_soft.py | 3 +-- totalspineseg/utils/fill_canal.py | 3 +-- totalspineseg/utils/iterative_label.py | 3 +-- totalspineseg/utils/largest_component.py | 3 +-- totalspineseg/utils/map_labels.py | 3 +-- totalspineseg/utils/preview_jpg.py | 3 +-- totalspineseg/utils/reorient_canonical.py | 3 +-- totalspineseg/utils/resample.py | 3 +-- totalspineseg/utils/transform_seg2image.py | 3 +-- 14 files changed, 14 insertions(+), 28 deletions(-) diff --git a/totalspineseg/utils/augment.py b/totalspineseg/utils/augment.py index f6cefd2..030d565 100644 --- a/totalspineseg/utils/augment.py +++ b/totalspineseg/utils/augment.py @@ -176,8 +176,7 @@ def augment_mp( output_images_path = Path(output_images_path) output_segs_path = Path(output_segs_path) - glob_pattern = "" - glob_pattern += f'{prefix}*{image_suffix}.nii.gz' + glob_pattern = f'{prefix}*{image_suffix}.nii.gz' # Process the NIfTI image and segmentation files image_path_list = list(images_path.glob(glob_pattern)) diff --git a/totalspineseg/utils/average4d.py b/totalspineseg/utils/average4d.py index 8f8988c..b95dc7e 100644 --- a/totalspineseg/utils/average4d.py +++ b/totalspineseg/utils/average4d.py @@ -112,8 +112,7 @@ def average4d_mp( images_path = Path(images_path) output_images_path = Path(output_images_path) - glob_pattern = "" - glob_pattern += f'{prefix}*{image_suffix}.nii.gz' + glob_pattern = f'{prefix}*{image_suffix}.nii.gz' # Process the NIfTI image and segmentation files image_path_list = list(images_path.glob(glob_pattern)) diff --git a/totalspineseg/utils/crop_image2seg.py b/totalspineseg/utils/crop_image2seg.py index 5038102..14fe0b7 100644 --- a/totalspineseg/utils/crop_image2seg.py +++ b/totalspineseg/utils/crop_image2seg.py @@ -139,8 +139,7 @@ def crop_image2seg_mp( segs_path = Path(segs_path) output_images_path = Path(output_images_path) - glob_pattern = "" - glob_pattern += f'{prefix}*{image_suffix}.nii.gz' + glob_pattern = f'{prefix}*{image_suffix}.nii.gz' # Process the NIfTI image and segmentation files image_path_list = list(images_path.glob(glob_pattern)) diff --git a/totalspineseg/utils/extract_alternate.py b/totalspineseg/utils/extract_alternate.py index 55ce6b3..b139789 100644 --- a/totalspineseg/utils/extract_alternate.py +++ b/totalspineseg/utils/extract_alternate.py @@ -133,8 +133,7 @@ def extract_alternate_mp( segs_path = Path(segs_path) output_segs_path = Path(output_segs_path) - glob_pattern = "" - glob_pattern += f'{prefix}*{seg_suffix}.nii.gz' + glob_pattern = f'{prefix}*{seg_suffix}.nii.gz' # Process the NIfTI image and segmentation files seg_path_list = list(segs_path.glob(glob_pattern)) diff --git a/totalspineseg/utils/extract_levels.py b/totalspineseg/utils/extract_levels.py index 776b7f1..522b80a 100644 --- a/totalspineseg/utils/extract_levels.py +++ b/totalspineseg/utils/extract_levels.py @@ -136,8 +136,7 @@ def extract_levels_mp( segs_path = Path(segs_path) output_segs_path = Path(output_segs_path) - glob_pattern = "" - glob_pattern += f'{prefix}*{seg_suffix}.nii.gz' + glob_pattern = f'{prefix}*{seg_suffix}.nii.gz' # Process the NIfTI image and segmentation files seg_path_list = list(segs_path.glob(glob_pattern)) diff --git a/totalspineseg/utils/extract_soft.py b/totalspineseg/utils/extract_soft.py index 8cb6509..00946d7 100644 --- a/totalspineseg/utils/extract_soft.py +++ b/totalspineseg/utils/extract_soft.py @@ -164,8 +164,7 @@ def extract_soft_mp( segs_path = Path(segs_path) output_segs_path = Path(output_segs_path) - glob_pattern = "" - glob_pattern += f'{prefix}*{npz_suffix}.npz' + glob_pattern = f'{prefix}*{npz_suffix}.npz' # Process the NIfTI npz and segmentation files npz_path_list = list(npzs_path.glob(glob_pattern)) diff --git a/totalspineseg/utils/fill_canal.py b/totalspineseg/utils/fill_canal.py index 3ae5e6c..74f8437 100644 --- a/totalspineseg/utils/fill_canal.py +++ b/totalspineseg/utils/fill_canal.py @@ -145,8 +145,7 @@ def fill_canal_mp( segs_path = Path(segs_path) output_segs_path = Path(output_segs_path) - glob_pattern = "" - glob_pattern += f'{prefix}*{seg_suffix}.nii.gz' + glob_pattern = f'{prefix}*{seg_suffix}.nii.gz' # Process the NIfTI image and segmentation files seg_path_list = list(segs_path.glob(glob_pattern)) diff --git a/totalspineseg/utils/iterative_label.py b/totalspineseg/utils/iterative_label.py index 709d80d..2420ebf 100644 --- a/totalspineseg/utils/iterative_label.py +++ b/totalspineseg/utils/iterative_label.py @@ -317,8 +317,7 @@ def iterative_label_mp( output_segs_path = Path(output_segs_path) locs_path = locs_path and Path(locs_path) - glob_pattern = "" - glob_pattern += f'{prefix}*{seg_suffix}.nii.gz' + glob_pattern = f'{prefix}*{seg_suffix}.nii.gz' # Process the NIfTI image and segmentation files seg_path_list = list(segs_path.glob(glob_pattern)) diff --git a/totalspineseg/utils/largest_component.py b/totalspineseg/utils/largest_component.py index 028351b..6e4d5d7 100644 --- a/totalspineseg/utils/largest_component.py +++ b/totalspineseg/utils/largest_component.py @@ -129,8 +129,7 @@ def largest_component_mp( segs_path = Path(segs_path) output_segs_path = Path(output_segs_path) - glob_pattern = "" - glob_pattern += f'{prefix}*{seg_suffix}.nii.gz' + glob_pattern = f'{prefix}*{seg_suffix}.nii.gz' # Process the NIfTI image and segmentation files seg_path_list = list(segs_path.glob(glob_pattern)) diff --git a/totalspineseg/utils/map_labels.py b/totalspineseg/utils/map_labels.py index 65af597..37dffa1 100644 --- a/totalspineseg/utils/map_labels.py +++ b/totalspineseg/utils/map_labels.py @@ -179,8 +179,7 @@ def map_labels_mp( update_segs_path = update_segs_path and Path(update_segs_path) update_from_segs_path = update_from_segs_path and Path(update_from_segs_path) - glob_pattern = "" - glob_pattern += f'{prefix}*{seg_suffix}.nii.gz' + glob_pattern = f'{prefix}*{seg_suffix}.nii.gz' # Process the NIfTI image and segmentation files seg_path_list = list(segs_path.glob(glob_pattern)) diff --git a/totalspineseg/utils/preview_jpg.py b/totalspineseg/utils/preview_jpg.py index fa5e32d..2a59081 100644 --- a/totalspineseg/utils/preview_jpg.py +++ b/totalspineseg/utils/preview_jpg.py @@ -196,8 +196,7 @@ def preview_jpg_mp( output_path = Path(output_path) segs_path = segs_path and Path(segs_path) - glob_pattern = "" - glob_pattern += f'{prefix}*{image_suffix}' + glob_pattern = f'{prefix}*{image_suffix}' # Process the NIfTI image and segmentation files image_path_list = [_ for __ in [list(images_path.glob(f'{glob_pattern}.{e}')) for e in EXT] for _ in __] diff --git a/totalspineseg/utils/reorient_canonical.py b/totalspineseg/utils/reorient_canonical.py index 35357d7..f594315 100644 --- a/totalspineseg/utils/reorient_canonical.py +++ b/totalspineseg/utils/reorient_canonical.py @@ -112,8 +112,7 @@ def reorient_canonical_mp( images_path = Path(images_path) output_images_path = Path(output_images_path) - glob_pattern = "" - glob_pattern += f'{prefix}*{image_suffix}.nii.gz' + glob_pattern = f'{prefix}*{image_suffix}.nii.gz' # Process the NIfTI image and segmentation files image_path_list = list(images_path.glob(glob_pattern)) diff --git a/totalspineseg/utils/resample.py b/totalspineseg/utils/resample.py index 1b661b2..44f8837 100644 --- a/totalspineseg/utils/resample.py +++ b/totalspineseg/utils/resample.py @@ -122,8 +122,7 @@ def resample_mp( images_path = Path(images_path) output_images_path = Path(output_images_path) - glob_pattern = "" - glob_pattern += f'{prefix}*{image_suffix}.nii.gz' + glob_pattern = f'{prefix}*{image_suffix}.nii.gz' # Process the NIfTI image and segmentation files image_path_list = list(images_path.glob(glob_pattern)) diff --git a/totalspineseg/utils/transform_seg2image.py b/totalspineseg/utils/transform_seg2image.py index 6b59b87..9932b6f 100644 --- a/totalspineseg/utils/transform_seg2image.py +++ b/totalspineseg/utils/transform_seg2image.py @@ -140,8 +140,7 @@ def transform_seg2image_mp( segs_path = Path(segs_path) output_segs_path = Path(output_segs_path) - glob_pattern = "" - glob_pattern += f'{prefix}*{image_suffix}.nii.gz' + glob_pattern = f'{prefix}*{image_suffix}.nii.gz' # Process the NIfTI image and segmentation files image_path_list = list(images_path.glob(glob_pattern))