From 3332573d07acdc18d18eac3bfaf8f6f2afd57206 Mon Sep 17 00:00:00 2001 From: Christopher Rhodes <christopher.rhodes@embl.de> Date: Wed, 11 Dec 2024 15:35:31 +0100 Subject: [PATCH] Option to parse coordinates from filename --- model_server/clients/batch_runner.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/model_server/clients/batch_runner.py b/model_server/clients/batch_runner.py index 91fac94a..6492726e 100644 --- a/model_server/clients/batch_runner.py +++ b/model_server/clients/batch_runner.py @@ -1,6 +1,7 @@ from collections import OrderedDict import json from pathlib import Path +import re import shutil import pandas as pd @@ -142,11 +143,17 @@ class FileBatchRunnerClient(HttpClient): where_remote = Path(self.remote_paths['input']) / inp['directory'] def _get_file_info(filename): - return { + info = { 'remote_path': (where_remote / filename).as_posix(), 'local_path': where_local / filename, 'is_multiposition': is_multiposition, } + 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) + return info paths = paths + [_get_file_info(f) for f in files] if max_count is not None: df = pd.DataFrame(paths).head(min(max_count, len(paths))) @@ -269,4 +276,7 @@ class WatchPathVerificationError(Error): pass class TasksRemainingError(Error): + pass + +class InvalidStackCoordinateKeyError(Error): pass \ No newline at end of file -- GitLab