diff --git a/model_server/clients/batch_runner.py b/model_server/clients/batch_runner.py index 6fd3dbd4c3e44de06b8315ba380958e24554e711..b9356ec8ca432ae5eb25856625fd529560bae704 100644 --- a/model_server/clients/batch_runner.py +++ b/model_server/clients/batch_runner.py @@ -144,7 +144,6 @@ class FileBatchRunnerClient(HttpClient): matching_files.append(f.name) return matching_files - files += _append_files_by_pattern(where_local, inp.get('pattern')) is_multiposition = inp.get('multiposition', False) where_remote = Path(self.remote_paths['input']) / inp['directory'] @@ -153,20 +152,27 @@ class FileBatchRunnerClient(HttpClient): for subdir in where_local.iterdir(): if not subdir.is_dir(): continue + if (sdp := inp.get('subdirectory_pattern')) is not None: + if sdp.upper() not in subdir.name.upper(): + continue matches = _append_files_by_pattern(subdir, inp.get('pattern')) files += [f'{subdir}/{f}' for f in matches] + else: + files += _append_files_by_pattern(where_local, inp.get('pattern')) - def _get_file_info(filename): + def _get_file_info(fpath_str): info = { - 'remote_path': (where_remote / filename).as_posix(), - 'local_path': where_local / filename, + 'remote_path': (where_remote / fpath_str).as_posix(), + 'local_path': where_local / fpath_str, 'is_multiposition': is_multiposition, } + filename = Path(fpath_str).name if (coord_regex := inp.get('coord_regex')) is not None: for coord_k, coord_v in re.search(coord_regex, filename).groupdict().items(): - if coord_k.lower() not in ['well', 'position', 'time']: - raise InvalidStackCoordinateKeyError(f'Cannot interpret coordinate {coord_k}') - info[f'coord_{coord_k.lower()}'] = int(coord_v) + if coord_k.lower() in ['well', 'position', 'time', 'date']: + info[f'coord_{coord_k.lower()}'] = int(coord_v) + else: + info[f'coord_{coord_k.lower()}'] = coord_v return info paths = paths + [_get_file_info(f) for f in files] if max_count is not None: