From 59efa7ebfdb8221d6d5b5c40ea06baf8a826eb89 Mon Sep 17 00:00:00 2001 From: Peter Swain <pswain@Home-iMac.local> Date: Wed, 22 May 2024 16:09:19 +0100 Subject: [PATCH] change(omero): get_images -> get_position_ids More docs added too. --- src/aliby/io/dataset.py | 4 ++-- src/aliby/io/omero.py | 45 +++++++++++++++++++++-------------------- src/aliby/pipeline.py | 2 +- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/src/aliby/io/dataset.py b/src/aliby/io/dataset.py index 28ba59d1..0ec31852 100644 --- a/src/aliby/io/dataset.py +++ b/src/aliby/io/dataset.py @@ -146,13 +146,13 @@ class DatasetLocalOME(DatasetLocalABC): def __init__(self, dpath: t.Union[str, Path], *args, **kwargs): super().__init__(dpath) assert len( - self.get_images() + self.get_position_ids() ), f"No valid files found. Formats are {self._valid_suffixes}" @property def date(self): """Get the date from the metadata of the first position.""" - return ImageLocalOME(list(self.get_images().values())[0]).date + return ImageLocalOME(list(self.get_position_ids().values())[0]).date def get_images(self): """Return a dictionary with the names of the image files.""" diff --git a/src/aliby/io/omero.py b/src/aliby/io/omero.py index d4c11a41..b1af704c 100644 --- a/src/aliby/io/omero.py +++ b/src/aliby/io/omero.py @@ -83,20 +83,21 @@ class BridgeOmero: def ome_class(self): """Initialise Omero Object Wrapper for instances when applicable.""" if not hasattr(self, "_ome_class"): - assert ( - self.conn.isConnected() and self.ome_id is not None - ), "No Blitz connection or valid omero id" - ome_type = [ - valid_name - for valid_name in ("Dataset", "Image") - if re.match( - f".*{ valid_name }.*", - self.__class__.__name__, - re.IGNORECASE, - ) - ][0] - self._ome_class = self.conn.getObject(ome_type, self.ome_id) - assert self._ome_class, f"{ome_type} {self.ome_id} not found." + if self.conn.isConnected() and self.ome_id is not None: + ome_type = [ + valid_name + for valid_name in ("Dataset", "Image") + if re.match( + f".*{ valid_name }.*", + self.__class__.__name__, + re.IGNORECASE, + ) + ][0] + # load data + self._ome_class = self.conn.getObject(ome_type, self.ome_id) + assert self._ome_class, f"{ome_type} {self.ome_id} not found." + else: + raise Exception("No Blitz connection or valid omero id.") return self._ome_class def create_gate(self) -> bool: @@ -181,17 +182,17 @@ class Dataset(BridgeOmero): @property def name(self): - """Get name.""" + """Get name of experiment.""" return self.ome_class.getName() @property def date(self): - """Get date.""" + """Get date of experiment.""" return self.ome_class.getDate() @property def unique_name(self): - """Create unique name.""" + """Get full name of experiment including its date.""" return "_".join( ( str(self.ome_id), @@ -200,7 +201,7 @@ class Dataset(BridgeOmero): ) ) - def get_images(self): + def get_position_ids(self): """Get dict of image names and IDs from OMERO.""" return { im.getName(): im.getId() for im in self.ome_class.listChildren() @@ -215,7 +216,7 @@ class Dataset(BridgeOmero): @property def files(self): - """Get files from OMERO.""" + """Get a dict of FileAnnotationWrappers, typically for log files.""" if not hasattr(self, "_files"): self._files = { x.getFileName(): x @@ -232,10 +233,10 @@ class Dataset(BridgeOmero): @property def tags(self): - """Get tags from OMERO.""" - if self._tags is None: + """Get a dict of TagAnnotationWrapper from OMERO for each position.""" + if not hasattr(self, "_tags"): self._tags = { - x.getname(): x + x.getId(): x for x in self.ome_class.listAnnotations() if isinstance(x, omero.gateway.TagAnnotationWrapper) } diff --git a/src/aliby/pipeline.py b/src/aliby/pipeline.py index 0608c66f..73966332 100644 --- a/src/aliby/pipeline.py +++ b/src/aliby/pipeline.py @@ -239,7 +239,7 @@ class Pipeline(ProcessABC): ) # get log files, either locally or via OMERO with dispatcher as conn: - position_ids = conn.get_images() + position_ids = conn.get_position_ids() directory = self.store or root_dir / conn.unique_name if not directory.exists(): directory.mkdir(parents=True) -- GitLab