Skip to content

Commit

Permalink
Limit warnings raised by check_files_exist when running another round…
Browse files Browse the repository at this point in the history
… of corrections. (#39)

- the check_files_exist function now also checks for labels under the derivatives
- we are doing this because if labels exist under derivatives, we do not want raise warnings

Fixes: #38
  • Loading branch information
valosekj authored May 10, 2023
1 parent 919329d commit 33457d3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
8 changes: 4 additions & 4 deletions manual_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,14 +572,14 @@ def main():
'FILES_CENTERLINE': args.suffix_files_centerline # e.g., _centerline or _label-centerline
}

# Check for missing files before starting the whole process
if not args.add_seg_only:
utils.check_files_exist(dict_yml, utils.get_full_path(args.path_in), suffix_dict)

path_out = utils.get_full_path(args.path_out)
# check that output folder exists and has write permission
path_out_deriv = utils.check_output_folder(path_out, args.path_derivatives)

# Check for missing files before starting the whole process
if not args.add_seg_only:
utils.check_files_exist(dict_yml, utils.get_full_path(args.path_in), suffix_dict, path_out_deriv)

# Fetch parameters for FSLeyes
param_fsleyes = ParamFSLeyes(cm=args.fsleyes_cm, dr=args.fsleyes_dr, second_orthoview=args.fsleyes_second_orthoview)

Expand Down
19 changes: 16 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,13 @@ def get_full_path(path):
return os.path.abspath(os.path.expanduser(path))


def check_files_exist(dict_files, path_data, suffix_dict):
def check_files_exist(dict_files, path_data, suffix_dict, path_derivatives=None):
"""
Check if all files listed in the input dictionary exist
:param dict_files:
:param path_data: folder where BIDS dataset is located
:param suffix_dict: dictionary with label file suffixes
:param path_derivatives: folder where derivatives are located
:return:
"""
missing_files = []
Expand All @@ -216,8 +217,20 @@ def check_files_exist(dict_files, path_data, suffix_dict):
# Construct absolute path to the input label (segmentation, labeling etc.) file
# For example: '/Users/user/dataset/data_processed/sub-001/anat/sub-001_T2w_seg.nii.gz'
fname_label = add_suffix(fname, suffix_dict[task])
if not os.path.exists(fname_label):
missing_files_labels.append(fname_label)
# If path_derivatives exists, check also labels under the derivatives folder
# Note: we are doing this because if labels exist under derivatives, we do not want raise warnings
if path_derivatives is not None:
# Construct absolute path to the label under derivatives folder
fname_label_derivatives = os.path.join(path_derivatives, subject, ses, contrast,
add_suffix(filename, suffix_dict[task] + '-manual'))
# Check if there is no label (i.e., no file under path_data and no label under path_derivatives)
# If no label is in either directory, add the file to the list of missing files.
if not os.path.exists(fname_label) and not os.path.exists(fname_label_derivatives):
missing_files_labels.append(fname_label)
# No derivatives folder
else:
if not os.path.exists(fname_label):
missing_files_labels.append(fname_label)
if missing_files:
logging.warning("The following files are missing: \n{}".format(missing_files))
logging.warning("\nPlease check that the files listed in the yaml file and the input path are correct.\n")
Expand Down

0 comments on commit 33457d3

Please sign in to comment.