Skip to content

Commit

Permalink
Merge pull request #66 from neuropoly/remove-unused-arguments
Browse files Browse the repository at this point in the history
Remove unused arguments
  • Loading branch information
yw7 authored Oct 2, 2024
2 parents 6c98d77 + 80a3e5a commit 68bef13
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 381 deletions.
4 changes: 2 additions & 2 deletions scripts/prepare_datasets.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 2 additions & 27 deletions totalspineseg/utils/augment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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.'
Expand Down Expand Up @@ -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
Expand All @@ -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}"
Expand All @@ -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,
Expand All @@ -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='',
Expand All @@ -196,12 +176,7 @@ def augment_mp(
output_images_path = Path(output_images_path)
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'
glob_pattern = f'{prefix}*{image_suffix}.nii.gz'

# Process the NIfTI image and segmentation files
image_path_list = list(images_path.glob(glob_pattern))
Expand Down
29 changes: 2 additions & 27 deletions totalspineseg/utils/average4d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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.'
Expand Down Expand Up @@ -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
Expand All @@ -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}"
Expand All @@ -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,
Expand All @@ -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',
Expand All @@ -132,12 +112,7 @@ def average4d_mp(
images_path = Path(images_path)
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'
glob_pattern = f'{prefix}*{image_suffix}.nii.gz'

# Process the NIfTI image and segmentation files
image_path_list = list(images_path.glob(glob_pattern))
Expand Down
29 changes: 2 additions & 27 deletions totalspineseg/utils/crop_image2seg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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.'
Expand Down Expand Up @@ -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
Expand All @@ -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}"
Expand All @@ -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,
Expand All @@ -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='',
Expand All @@ -159,12 +139,7 @@ def crop_image2seg_mp(
segs_path = Path(segs_path)
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'
glob_pattern = f'{prefix}*{image_suffix}.nii.gz'

# Process the NIfTI image and segmentation files
image_path_list = list(images_path.glob(glob_pattern))
Expand Down
29 changes: 2 additions & 27 deletions totalspineseg/utils/extract_alternate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand All @@ -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.'
Expand Down Expand Up @@ -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
Expand All @@ -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}"
Expand All @@ -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,
Expand All @@ -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='',
Expand All @@ -153,12 +133,7 @@ def extract_alternate_mp(
segs_path = Path(segs_path)
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'
glob_pattern = f'{prefix}*{seg_suffix}.nii.gz'

# Process the NIfTI image and segmentation files
seg_path_list = list(segs_path.glob(glob_pattern))
Expand Down
Loading

0 comments on commit 68bef13

Please sign in to comment.