Skip to content
Draft
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
50 changes: 50 additions & 0 deletions lib/galaxy/datatypes/binary.py
Original file line number Diff line number Diff line change
Expand Up @@ -4864,3 +4864,53 @@ def set_meta(self, dataset: DatasetProtocol, overwrite: bool = True, **kwd) -> N
with open(dataset.get_file_name(), "rb") as handle:
header_bytes = handle.read(8)
dataset.metadata.version = struct.unpack("<i", header_bytes[4:8])[0]

class SpatialData(CompressedZarrZipArchive):
"""
Class for SpatialData file: https://spatialdata.scverse.org/

SpatialData: an open and universal framework for processing spatial omics data.
SpatialData aims at implementing a performant in-memory representation in Python
and an on-disk representation based on the Zarr and Parquet data formats
and following, when applicable, the OME-NGFF specification

The format stores multi-modal spatial omics datasets including:
- Images (2D/3D multi-scale)
- Labels (segmentation masks)
- Shapes (polygons, circles)
- Points (transcript locations, point clouds)
- Tables (annotations)
"""

file_ext = "spatialdata.zip"

def sniff(self, filename: str) -> bool:
"""
Check if the file is a valid SpatialData zarr archive.

SpatialData files are Zarr archives with specific structure containing
element directories like images/, labels/, shapes/, points/, or tables/.

>>> from galaxy.datatypes.sniff import get_test_fname
>>> fname = get_test_fname('spatialdata_example.spatialdata.zip')
>>> SpatialData().sniff(fname)
True
>>> fname = get_test_fname('test.zarr.zip')
>>> SpatialData().sniff(fname)
False
"""

try:
with zipfile.ZipFile(filename) as zf:
# Look for SpatialData-specific structure
# SpatialData has element directories like images/, labels/, shapes/, points/, tables/
spatialdata_elements = {'images', 'labels', 'shapes', 'points', 'tables'}
for file in zf.namelist():
parts = file.split('/')
if len(parts) > 0 and parts[0] in spatialdata_elements:
return True

return False
except Exception:
return False

Loading