{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Interoperability\n", "\n", "This notebook shows some way that you can import and export data from `spatialproteomics`." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "tags": [] }, "outputs": [], "source": [ "%reload_ext autoreload\n", "%autoreload 2\n", "\n", "import spatialproteomics as sp\n", "import pandas as pd\n", "import xarray as xr\n", "import os\n", "import shutil\n", "import anndata" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exporting Data\n", "\n", "Once you are happy with your analysis, you will likely want to export the results. The easiest way to do this is by using the `zarr` format, but `csv`, `anndata`, and `spatialdata` are also supported." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset> Size: 171kB\n", "Dimensions: (cells: 56, cells_2: 56, channels: 5, y: 101, x: 101,\n", " la_features: 2, labels: 4, la_props: 2,\n", " neighborhoods: 5, nh_props: 2, features: 6)\n", "Coordinates:\n", " * cells (cells) int64 448B 1 2 3 4 5 6 7 ... 51 52 53 54 55 56\n", " * cells_2 (cells_2) int64 448B 1 2 3 4 5 6 ... 51 52 53 54 55 56\n", " * channels (channels) <U11 220B 'DAPI' 'PAX5' 'CD3' 'CD4' 'CD8'\n", " * features (features) <U14 336B 'CD4_binarized' ... 'centroid-1'\n", " * la_features (la_features) object 16B 'labels_0' 'labels_1'\n", " * la_props (la_props) <U6 48B '_color' '_name'\n", " * labels (labels) int64 32B 1 2 3 4\n", " * neighborhoods (neighborhoods) int64 40B 1 2 3 4 5\n", " * nh_props (nh_props) <U6 48B '_color' '_name'\n", " * x (x) int64 808B 1600 1601 1602 1603 ... 1698 1699 1700\n", " * y (y) int64 808B 2100 2101 2102 2103 ... 2198 2199 2200\n", "Data variables:\n", " _adjacency_matrix (cells, cells_2) int64 25kB dask.array<chunksize=(56, 56), meta=np.ndarray>\n", " _image (channels, y, x) uint8 51kB dask.array<chunksize=(5, 101, 101), meta=np.ndarray>\n", " _intensity (cells, channels) float64 2kB dask.array<chunksize=(56, 5), meta=np.ndarray>\n", " _la_layers (cells, la_features) object 896B dask.array<chunksize=(56, 2), meta=np.ndarray>\n", " _la_properties (labels, la_props) object 64B dask.array<chunksize=(4, 2), meta=np.ndarray>\n", " _neighborhoods (cells, labels) float64 2kB dask.array<chunksize=(56, 4), meta=np.ndarray>\n", " _nh_properties (neighborhoods, nh_props) <U14 560B dask.array<chunksize=(5, 2), meta=np.ndarray>\n", " _obs (cells, features) float64 3kB dask.array<chunksize=(56, 6), meta=np.ndarray>\n", " _percentage_positive (cells, channels) float64 2kB dask.array<chunksize=(56, 5), meta=np.ndarray>\n", " _segmentation (y, x) int64 82kB dask.array<chunksize=(101, 101), meta=np.ndarray>
\n", " | CD4_binarized | \n", "CD8_binarized | \n", "_labels | \n", "_neighborhoods | \n", "centroid-0 | \n", "centroid-1 | \n", "
---|---|---|---|---|---|---|
1 | \n", "0.0 | \n", "0.0 | \n", "B | \n", "Neighborhood 1 | \n", "2103.768519 | \n", "1607.277778 | \n", "
2 | \n", "0.0 | \n", "1.0 | \n", "T_tox | \n", "Neighborhood 1 | \n", "2103.857143 | \n", "1630.741071 | \n", "
3 | \n", "1.0 | \n", "1.0 | \n", "T_h | \n", "Neighborhood 3 | \n", "2104.837037 | \n", "1668.733333 | \n", "
4 | \n", "0.0 | \n", "1.0 | \n", "T_tox | \n", "Neighborhood 3 | \n", "2101.750000 | \n", "1677.000000 | \n", "
5 | \n", "0.0 | \n", "1.0 | \n", "B | \n", "Neighborhood 3 | \n", "2104.416058 | \n", "1685.627737 | \n", "
<xarray.Dataset> Size: 9MB\n", "Dimensions: (channels: 3, y: 768, x: 1024, cells: 70, features: 2)\n", "Coordinates:\n", " * channels (channels) int64 24B 0 1 2\n", " * y (y) int64 6kB 0 1 2 3 4 5 6 7 ... 761 762 763 764 765 766 767\n", " * x (x) int64 8kB 0 1 2 3 4 5 6 ... 1018 1019 1020 1021 1022 1023\n", " * cells (cells) int64 560B 1 2 3 4 5 6 7 8 ... 64 65 66 67 68 69 70\n", " * features (features) <U10 80B 'centroid-0' 'centroid-1'\n", "Data variables:\n", " _image (channels, y, x) uint8 2MB dask.array<chunksize=(3, 768, 1024), meta=np.ndarray>\n", " _segmentation (y, x) int64 6MB 0 0 0 0 0 0 0 0 ... 69 69 69 69 69 69 69 69\n", " _obs (cells, features) float64 1kB 44.79 402.5 ... 736.5 890.5