From c3908a8fba0d36c20193b6d65f6c263350988a9c Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 23 Nov 2024 09:38:15 +0100 Subject: [PATCH 1/6] Implement bioformats2raw structure --- src/ome_zarr_models/v04/__init__.py | 3 ++- src/ome_zarr_models/v04/bioformats2raw.py | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 src/ome_zarr_models/v04/bioformats2raw.py diff --git a/src/ome_zarr_models/v04/__init__.py b/src/ome_zarr_models/v04/__init__.py index 0312410..30d34f5 100644 --- a/src/ome_zarr_models/v04/__init__.py +++ b/src/ome_zarr_models/v04/__init__.py @@ -1,4 +1,5 @@ +from ome_zarr_models.v04.bioformats2raw import BioFormats2Raw from ome_zarr_models.v04.hcs import HCS from ome_zarr_models.v04.image import Image -__all__ = ["HCS", "Image"] +__all__ = ["HCS", "Image", "BioFormats2Raw"] diff --git a/src/ome_zarr_models/v04/bioformats2raw.py b/src/ome_zarr_models/v04/bioformats2raw.py new file mode 100644 index 0000000..cc0f341 --- /dev/null +++ b/src/ome_zarr_models/v04/bioformats2raw.py @@ -0,0 +1,16 @@ +from typing import Any, Literal + +from pydantic import Field + +from ome_zarr_models.base import Base +from ome_zarr_models.v04.plate import Plate + + +class BioFormats2Raw(Base): + """ + A bioformats2raw zarr group. + """ + + bioformats2raw_layout = Field(Literal["3"], alias="bioformats2raw.layout") + plate: Plate | None = None + series: Any | None = None From a879b31f376e4f0cb27989bc6b8c59373245ca6a Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 23 Nov 2024 09:49:13 +0100 Subject: [PATCH 2/6] Add basic test --- src/ome_zarr_models/v04/bioformats2raw.py | 2 +- tests/v04/data/bioformats2raw_example.json | 30 ++++++++++++++++++++++ tests/v04/test_bioformats2raw.py | 18 +++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/v04/data/bioformats2raw_example.json create mode 100644 tests/v04/test_bioformats2raw.py diff --git a/src/ome_zarr_models/v04/bioformats2raw.py b/src/ome_zarr_models/v04/bioformats2raw.py index cc0f341..7029079 100644 --- a/src/ome_zarr_models/v04/bioformats2raw.py +++ b/src/ome_zarr_models/v04/bioformats2raw.py @@ -11,6 +11,6 @@ class BioFormats2Raw(Base): A bioformats2raw zarr group. """ - bioformats2raw_layout = Field(Literal["3"], alias="bioformats2raw.layout") + bioformats2raw_layout: Literal[3] = Field(..., alias="bioformats2raw.layout") plate: Plate | None = None series: Any | None = None diff --git a/tests/v04/data/bioformats2raw_example.json b/tests/v04/data/bioformats2raw_example.json new file mode 100644 index 0000000..33fb6b6 --- /dev/null +++ b/tests/v04/data/bioformats2raw_example.json @@ -0,0 +1,30 @@ +{ + "bioformats2raw.layout": 3, + "plate": { + "columns": [ + { + "name": "1" + } + ], + "name": "Plate Name 0", + "wells": [ + { + "path": "A/1", + "rowIndex": 0, + "columnIndex": 0 + } + ], + "field_count": 1, + "rows": [ + { + "name": "A" + } + ], + "acquisitions": [ + { + "id": 0 + } + ], + "version": "0.4" + } +} diff --git a/tests/v04/test_bioformats2raw.py b/tests/v04/test_bioformats2raw.py new file mode 100644 index 0000000..d5829b6 --- /dev/null +++ b/tests/v04/test_bioformats2raw.py @@ -0,0 +1,18 @@ +import json +from pathlib import Path + +from ome_zarr_models.v04.bioformats2raw import BioFormats2Raw +from ome_zarr_models.v04.plate import ( + AcquisitionInPlate, + ColumnInPlate, + Plate, + RowInPlate, + WellInPlate, +) + + +def test_bioformats2raw_exmaple_json(): + with open(Path(__file__).parent / "data" / "bioformats2raw_example.json") as f: + data = json.load(f) + + assert BioFormats2Raw(**data["bioformats"]) From b9fad79910d995893ea27eeaf8ebba0fa82bc53f Mon Sep 17 00:00:00 2001 From: David Stansby Date: Sat, 23 Nov 2024 10:09:49 +0100 Subject: [PATCH 3/6] Add test --- src/ome_zarr_models/base.py | 6 ++++++ tests/v04/test_bioformats2raw.py | 21 ++++++++++++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/ome_zarr_models/base.py b/src/ome_zarr_models/base.py index ece70b3..599a86e 100644 --- a/src/ome_zarr_models/base.py +++ b/src/ome_zarr_models/base.py @@ -13,3 +13,9 @@ class Config: validate_assignment = True extra = "allow" + # This allows fields with aliases to be populated by either + # their alias or class attribute name + # + # We use this so we can handle (at least) the "bioformats2raw.version" + # key - attributes in Python can't contain a "." + populate_by_name = True diff --git a/tests/v04/test_bioformats2raw.py b/tests/v04/test_bioformats2raw.py index d5829b6..fb5205a 100644 --- a/tests/v04/test_bioformats2raw.py +++ b/tests/v04/test_bioformats2raw.py @@ -1,4 +1,3 @@ -import json from pathlib import Path from ome_zarr_models.v04.bioformats2raw import BioFormats2Raw @@ -13,6 +12,22 @@ def test_bioformats2raw_exmaple_json(): with open(Path(__file__).parent / "data" / "bioformats2raw_example.json") as f: - data = json.load(f) + model = BioFormats2Raw.model_validate_json(f.read()) - assert BioFormats2Raw(**data["bioformats"]) + assert model == BioFormats2Raw( + bioformats2raw_layout=3, + plate=Plate( + acquisitions=[ + AcquisitionInPlate( + id=0, maximumfieldcount=None, name=None, description=None + ) + ], + columns=[ColumnInPlate(name="1")], + field_count=1, + name="Plate Name 0", + rows=[RowInPlate(name="A")], + version="0.4", + wells=[WellInPlate(path="A/1", rowIndex=0, columnIndex=0)], + ), + series=None, + ) From e30aaf8f0986bb27af6e59266d656debd2f106a8 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 26 Nov 2024 08:48:26 +0000 Subject: [PATCH 4/6] Rename bioformats2raw class --- src/ome_zarr_models/v04/__init__.py | 4 ++-- src/ome_zarr_models/v04/bioformats2raw.py | 2 +- tests/v04/test_bioformats2raw.py | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ome_zarr_models/v04/__init__.py b/src/ome_zarr_models/v04/__init__.py index 30d34f5..b6e39ea 100644 --- a/src/ome_zarr_models/v04/__init__.py +++ b/src/ome_zarr_models/v04/__init__.py @@ -1,5 +1,5 @@ -from ome_zarr_models.v04.bioformats2raw import BioFormats2Raw +from ome_zarr_models.v04.bioformats2raw import BioFormats2RawAttrs from ome_zarr_models.v04.hcs import HCS from ome_zarr_models.v04.image import Image -__all__ = ["HCS", "Image", "BioFormats2Raw"] +__all__ = ["HCS", "Image", "BioFormats2RawAttrs"] diff --git a/src/ome_zarr_models/v04/bioformats2raw.py b/src/ome_zarr_models/v04/bioformats2raw.py index 7029079..6c26210 100644 --- a/src/ome_zarr_models/v04/bioformats2raw.py +++ b/src/ome_zarr_models/v04/bioformats2raw.py @@ -6,7 +6,7 @@ from ome_zarr_models.v04.plate import Plate -class BioFormats2Raw(Base): +class BioFormats2RawAttrs(Base): """ A bioformats2raw zarr group. """ diff --git a/tests/v04/test_bioformats2raw.py b/tests/v04/test_bioformats2raw.py index fb5205a..f488e71 100644 --- a/tests/v04/test_bioformats2raw.py +++ b/tests/v04/test_bioformats2raw.py @@ -1,6 +1,6 @@ from pathlib import Path -from ome_zarr_models.v04.bioformats2raw import BioFormats2Raw +from ome_zarr_models.v04.bioformats2raw import BioFormats2RawAttrs from ome_zarr_models.v04.plate import ( AcquisitionInPlate, ColumnInPlate, @@ -12,9 +12,9 @@ def test_bioformats2raw_exmaple_json(): with open(Path(__file__).parent / "data" / "bioformats2raw_example.json") as f: - model = BioFormats2Raw.model_validate_json(f.read()) + model = BioFormats2RawAttrs.model_validate_json(f.read()) - assert model == BioFormats2Raw( + assert model == BioFormats2RawAttrs( bioformats2raw_layout=3, plate=Plate( acquisitions=[ From 4e4cc42e09bb41ada18a0a470a7fbd5ae922eced Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 26 Nov 2024 08:48:55 +0000 Subject: [PATCH 5/6] Don't import to top level namespace --- src/ome_zarr_models/v04/__init__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ome_zarr_models/v04/__init__.py b/src/ome_zarr_models/v04/__init__.py index b6e39ea..0312410 100644 --- a/src/ome_zarr_models/v04/__init__.py +++ b/src/ome_zarr_models/v04/__init__.py @@ -1,5 +1,4 @@ -from ome_zarr_models.v04.bioformats2raw import BioFormats2RawAttrs from ome_zarr_models.v04.hcs import HCS from ome_zarr_models.v04.image import Image -__all__ = ["HCS", "Image", "BioFormats2RawAttrs"] +__all__ = ["HCS", "Image"] From a9ca4013d12ca9bbd18a5d6ea821c5c6c5989662 Mon Sep 17 00:00:00 2001 From: David Stansby Date: Tue, 26 Nov 2024 08:55:35 +0000 Subject: [PATCH 6/6] Update src/ome_zarr_models/v04/bioformats2raw.py Co-authored-by: Davis Bennett --- src/ome_zarr_models/v04/bioformats2raw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ome_zarr_models/v04/bioformats2raw.py b/src/ome_zarr_models/v04/bioformats2raw.py index 6c26210..6c9c0d8 100644 --- a/src/ome_zarr_models/v04/bioformats2raw.py +++ b/src/ome_zarr_models/v04/bioformats2raw.py @@ -8,7 +8,7 @@ class BioFormats2RawAttrs(Base): """ - A bioformats2raw zarr group. + A model of the attributes contained in a bioformats2raw zarr group. """ bioformats2raw_layout: Literal[3] = Field(..., alias="bioformats2raw.layout")