Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle KeyErrors more gracefully if user marks FILES_REG as a qc_fail.yml #72

Merged
merged 4 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions manual_correction.py
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,10 @@ def main():
# Perform manual corrections
for task, files in dict_yml.items():
if task.startswith('FILES'):
# Check if task is in suffix_dict.keys(), if not, skip it
if task not in suffix_dict.keys():
logging.warning("WARNING: {} is not a valid task. Skipping it.".format(task))
continue
valosekj marked this conversation as resolved.
Show resolved Hide resolved
# Get the list of segmentation files to add to derivatives, excluding the manually corrected files in -config.
# TODO: probably extend also for other tasks (such as FILES_GMSEG)
if args.add_seg_only and task == 'FILES_SEG':
Expand Down
10 changes: 8 additions & 2 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,13 @@ def check_files_exist(dict_yml, path_img, path_label, suffix_dict):
"""
missing_files = []
missing_files_labels = []
missing_suffixes = set()
for task, files in dict_yml.items():
if task.startswith('FILES') and files:
# Check if task is in suffix_dict.keys(), if not, skip it
if task not in suffix_dict.keys():
logging.warning("WARNING: {} is not a valid task. Skipping it.".format(task))
continue
# Do no check if key is empty or if regex is used
if files is not None and '*' not in files[0]:
for file in files:
Expand All @@ -223,14 +228,15 @@ def check_files_exist(dict_yml, path_img, path_label, suffix_dict):
fname_label = add_suffix(os.path.join(path_label, subject, ses, contrast, filename), suffix_dict[task])
if not os.path.exists(fname_label):
missing_files_labels.append(fname_label)
missing_suffixes.add(suffix_dict[task])
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")
if missing_files_labels:
logging.warning("If you are creating label(s) from scratch, ignore the following message.")
logging.warning("\nThe following label files are missing: \n{}".format(missing_files_labels))
logging.warning("\nPlease check that the used suffix '{}' is correct. "
"If not, you can provide custom suffix using '-suffix-files-' flags.\n".format(suffix_dict[task]))
valosekj marked this conversation as resolved.
Show resolved Hide resolved
"If not, you can provide custom suffix using '-suffix-files-' flags.\n".format(sorted(missing_suffixes)))


def check_output_folder(path_bids):
Expand Down Expand Up @@ -323,4 +329,4 @@ def track_corrections(files_dict, config_path, file_path, task):

return files_dict


Loading