I/O
SpatialOmics uses format tokens to select the read/write backend. Pass the token as the first argument to read or write!.
Format tokens
SpatialOmics.SpatialDataZarr — Type
SpatialDataZarr()Format token for the native SpatialData OME-Zarr on-disk format.
Pass to read or write! to select this backend:
ds = read(SpatialDataZarr(), "/path/to/experiment.zarr")
write!(ds, "/path/to/output.zarr", SpatialDataZarr())read auto-detects whether the Zarr store was written by Python's SpatialData library or by this package and dispatches accordingly.
See also
SpatialOmics.CosMx — Type
CosMx(; morphology_dir=nothing)Format token for loading a CosMx SMI raw flat-file export.
Pass to read to load a CosMx export directory. If morphology_dir points to a Morphology2D tile directory, tissue images are stitched and included as a SpatialImage; otherwise only transcripts and cell boundaries are loaded.
ds = read(CosMx(), "/path/to/cosmx_export/")
ds = read(CosMx(morphology_dir="/path/to/Morphology2D"), "/path/to/cosmx_export/")Each field-of-view (FOV) is registered as a separate CoordinateSystem; use coord_systems(ds) and transform(ds, fov_cs, "global") to navigate between spaces.
See also
Reading
Base.read is extended for spatial format tokens:
# SpatialData OME-Zarr (auto-detects Julia vs Python-written stores)
ds = read(SpatialDataZarr(), "/path/to/experiment.zarr")
# CosMx SMI raw flat-file export
ds = read(CosMx(), "/path/to/cosmx_export/")
# CosMx with tissue images
ds = read(CosMx(morphology_dir="/path/to/Morphology2D"), "/path/to/export/")Writing
SpatialOmics.write! — Function
write!(ds, path, SpatialDataZarr()) → dsWrite ds to the SpatialData OME-Zarr format at path and update the dataset's backing store to point at the new location.
Unlike the non-mutating write, write! marks the backing store as permanent (non-owned) so the directory is not deleted when ds is garbage collected. Use this as the canonical "save" operation.
See also
Base.write (without !) is also defined and writes to disk without updating the dataset's backing store location. Prefer write! for persistent saves.