Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement bioformats2raw structure #50

Merged
merged 6 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/ome_zarr_models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions src/ome_zarr_models/v04/bioformats2raw.py
Original file line number Diff line number Diff line change
@@ -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 BioFormats2RawAttrs(Base):
"""
A bioformats2raw zarr group.
dstansby marked this conversation as resolved.
Show resolved Hide resolved
dstansby marked this conversation as resolved.
Show resolved Hide resolved
"""

bioformats2raw_layout: Literal[3] = Field(..., alias="bioformats2raw.layout")
plate: Plate | None = None
series: Any | None = None
30 changes: 30 additions & 0 deletions tests/v04/data/bioformats2raw_example.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
33 changes: 33 additions & 0 deletions tests/v04/test_bioformats2raw.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from pathlib import Path

from ome_zarr_models.v04.bioformats2raw import BioFormats2RawAttrs
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:
model = BioFormats2RawAttrs.model_validate_json(f.read())

assert model == BioFormats2RawAttrs(
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,
)