diff --git a/manual_correction.py b/manual_correction.py index 4f71819..d41aeac 100644 --- a/manual_correction.py +++ b/manual_correction.py @@ -756,6 +756,13 @@ 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 + # Note that this check is done after the task.startswith('FILES') check because the manual-correction + # script should ignore keys that start with CORR (CORR keys are used to track the manual correction + # progress) + if task not in suffix_dict.keys(): + logging.warning("WARNING: {} is not a valid task. Skipping it.".format(task)) + continue # 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': diff --git a/tests/test_utils.py b/tests/test_utils.py index dd60564..af26390 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -167,7 +167,7 @@ def test_check_files_exist_missing_file(tmp_path, caplog): assert any('Please check that the files listed in the yaml file and the input path are correct' in rec.message for rec in caplog.records) assert any('BIDS/sub-001/ses-01/anat/sub-001_ses-01_T1w_seg.nii.gz' in rec.message for rec in caplog.records) assert any('BIDS/sub-002/ses-01/anat/sub-001_ses-01_T2star_gmseg.nii.gz' in rec.message for rec in caplog.records) - assert any("Please check that the used suffix '_gmseg' is correct" in rec.message for rec in caplog.records) + assert any("Please check that the used suffix ['_gmseg', '_seg'] is correct" in rec.message for rec in caplog.records) def test_track_corrections(tmp_path): diff --git a/utils.py b/utils.py index 0f1552b..66dd9e7 100644 --- a/utils.py +++ b/utils.py @@ -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: @@ -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])) + logging.warning("\nPlease check that the used suffix {} is correct. " + "If not, you can provide custom suffix using '-suffix-files-' flags.\n".format(sorted(missing_suffixes))) def check_output_folder(path_bids): @@ -323,4 +329,4 @@ def track_corrections(files_dict, config_path, file_path, task): return files_dict - \ No newline at end of file +