Interactivity with napari¶
Spatialproteomics has a variety of functions to ensure interoperability with existing tools. For example, we can export the spatialproteomics object into spatialdata, and the use napari for interactive visualizations.
[2]:
import spatialproteomics as sp
import xarray as xr
from napari_spatialdata import Interactive
import numpy as np
[3]:
# loading in a data set and performing some formatting for convenience
ds = xr.open_zarr("../../data/LN_11_1.zarr")
ds
[3]:
<xarray.Dataset> Size: 7GB Dimensions: (cells: 16871, cells_2: 16871, channels: 56, y: 3000, x: 3000, la_features: 4, labels: 18, la_props: 2, neighborhoods: 6, nh_props: 2, features: 22) Coordinates: * cells (cells) int64 135kB 1 2 3 4 5 ... 16868 16869 16870 16871 * cells_2 (cells_2) int64 135kB 1 2 3 4 ... 16868 16869 16870 16871 * channels (channels) <U11 2kB 'DAPI' 'Helios' ... 'CD79a' 'Ki-67' * features (features) object 176B 'BCL-2_binarized' ... 'inter_la... * la_features (la_features) object 32B 'labels_0' ... 'labels_3' * la_props (la_props) <U6 48B '_color' '_name' * labels (labels) int64 144B 1 2 3 4 5 6 7 ... 13 14 15 16 17 18 * neighborhoods (neighborhoods) int64 48B 1 2 3 4 5 6 * nh_props (nh_props) <U6 48B '_color' '_name' * x (x) int64 24kB 0 1 2 3 4 5 ... 2995 2996 2997 2998 2999 * y (y) int64 24kB 0 1 2 3 4 5 ... 2995 2996 2997 2998 2999 Data variables: _adjacency_matrix (cells, cells_2) int64 2GB dask.array<chunksize=(528, 528), meta=np.ndarray> _image (channels, y, x) float64 4GB dask.array<chunksize=(4, 375, 375), meta=np.ndarray> _image_raw (channels, y, x) uint8 504MB dask.array<chunksize=(7, 375, 750), meta=np.ndarray> _intensity (cells, channels) float64 8MB dask.array<chunksize=(4218, 14), meta=np.ndarray> _la_layers (cells, la_features) object 540kB dask.array<chunksize=(8436, 4), meta=np.ndarray> _la_properties (labels, la_props) object 288B dask.array<chunksize=(18, 2), meta=np.ndarray> _neighborhoods (cells, labels) float64 2MB dask.array<chunksize=(4218, 9), meta=np.ndarray> _nh_properties (neighborhoods, nh_props) <U14 672B dask.array<chunksize=(6, 2), meta=np.ndarray> _obs (cells, features) float64 3MB dask.array<chunksize=(4218, 11), meta=np.ndarray> _segmentation (y, x) int64 72MB dask.array<chunksize=(375, 375), meta=np.ndarray>
[4]:
# turning the spatialproteomics object into a spatialdata object
sd_obj = ds.tl.convert_to_spatialdata()
sd_obj
INFO Transposing `data` of type: <class 'dask.array.core.Array'> to ('c', 'y', 'x').
INFO Transposing `data` of type: <class 'dask.array.core.Array'> to ('y', 'x').
[4]:
SpatialData object
├── Images
│ └── 'image': DataArray[cyx] (56, 3000, 3000)
├── Labels
│ └── 'segmentation': DataArray[yx] (3000, 3000)
└── Tables
└── 'table': AnnData (16871, 56)
with coordinate systems:
▸ 'global', with elements:
image (Images), segmentation (Labels)
[ ]:
interactive = Interactive(sd_obj)
interactive.run()
Running this code in a python script will open napari
, which you can then use to interactively look at your data. You can look at different markers, visualize cell types, neighborhoods, and many more. Below are some examples of what you can visualize with napari
.
Markers¶

Segmentation¶

Cell Type Labels¶

Binarization¶

Neighborhoods¶

Features¶
