Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ data
# data folder
data/
tests/data
uv.lock
.asv/
.venv
.uv.lock
5 changes: 3 additions & 2 deletions src/spatialdata_io/readers/macsima.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"B": "bleach", # v1
"AntigenCycle": "stain", # v0
"S": "stain", # v1
"AF": "autofluorescence", # v1
}


Expand Down Expand Up @@ -499,7 +500,7 @@ def _parse_v0_ome_metadata(ome: OME) -> dict[str, Any]:

# Harmonize imagetype across versions
if metadata["imagetype"]:
metadata["imagetype"] = IMAGETYPE_DICT[metadata["imagetype"]]
metadata["imagetype"] = IMAGETYPE_DICT.get(metadata["imagetype"], metadata["imagetype"])

return metadata

Expand Down Expand Up @@ -579,7 +580,7 @@ def _parse_v1_ome_metadata(ome: OME) -> dict[str, Any]:

# Harmonize imagetype across versions
if metadata["imagetype"]:
metadata["imagetype"] = IMAGETYPE_DICT[metadata["imagetype"]]
metadata["imagetype"] = IMAGETYPE_DICT.get(metadata["imagetype"], metadata["imagetype"])

return metadata

Expand Down
40 changes: 40 additions & 0 deletions tests/test_macsima.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,26 @@ def test_parse_v0_ome_metadata_bleach_cycle_appends_background() -> None:
assert md["name"] == "CD4_background"


def test_parse_v0_ome_metadata_handles_unknown_imagetypes() -> None:
ome = OME(
structured_annotations=StructuredAnnotations(
map_annotations=[
MapAnnotation(
value={
"MICS cycle type": "NOT A VALID TYPE",
}
)
]
),
screens=[Screen(reagents=[Reagent(name="CD4__RPA-T4")])],
)

md = _parse_v0_ome_metadata(ome)

# Unknown types should just be passed through
assert md["imagetype"] == "NOT A VALID TYPE"


def test_parse_v1_ome_metadata_basic_extraction_and_conversions() -> None:
ome = OME(
structured_annotations=StructuredAnnotations(
Expand Down Expand Up @@ -605,6 +625,26 @@ def test_parse_v1_ome_metadata_invalid_numerics_become_none() -> None:
assert md["roi"] is None


def test_parse_v1_ome_metadata_handles_unknown_imagetypes() -> None:
ome = OME(
structured_annotations=StructuredAnnotations(
map_annotations=[
MapAnnotation(
value={
"ScanType": "NOT A VALID TYPE",
}
)
]
),
screens=[Screen(reagents=[Reagent(name="CD4__RPA-T4")])],
)

md = _parse_v1_ome_metadata(ome)

# Unknown types should just be passed through
assert md["imagetype"] == "NOT A VALID TYPE"


def make_ome_with_version(version_value: str, extra_ma: dict[str, Any] | None = None) -> OME:
base = {"SoftwareVersion": version_value}
if extra_ma:
Expand Down
Loading