{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Interactivity\n", "\n", "*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 visualiztations." ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": [ "%reload_ext autoreload\n", "%autoreload 2\n", "\n", "import spatialproteomics as sp\n", "import xarray as xr\n", "from napari_spatialdata import Interactive\n", "import spatialdata\n", "from spatialdata import SpatialData\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/opt/conda/lib/python3.10/site-packages/xarray/backends/plugins.py:159: RuntimeWarning: 'scipy' fails while guessing\n", " warnings.warn(f\"{engine!r} fails while guessing\", RuntimeWarning)\n" ] }, { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
<xarray.Dataset>\n",
       "Dimensions:        (cells: 12560, channels: 56, y: 3000, x: 3000, features: 4,\n",
       "                    labels: 8, props: 2)\n",
       "Coordinates:\n",
       "  * cells          (cells) int64 1 2 3 4 5 6 ... 12556 12557 12558 12559 12560\n",
       "  * channels       (channels) <U11 'DAPI' 'Helios' 'CD10' ... 'CD79a' 'Ki-67'\n",
       "  * features       (features) <U10 'centroid-0' 'centroid-1' ... '_original_'\n",
       "  * labels         (labels) int64 1 2 3 4 5 6 7 8\n",
       "  * props          (props) <U6 '_color' '_name'\n",
       "  * x              (x) int64 0 1 2 3 4 5 6 ... 2994 2995 2996 2997 2998 2999\n",
       "  * y              (y) int64 0 1 2 3 4 5 6 ... 2994 2995 2996 2997 2998 2999\n",
       "Data variables:\n",
       "    _arcsinh_mean  (cells, channels) float64 3.111 0.0 1.391 ... 1.324 0.4174\n",
       "    _arcsinh_sum   (cells, channels) float64 8.346 0.0 6.564 ... 6.625 5.224\n",
       "    _image         (channels, y, x) uint8 4 4 4 4 5 4 4 3 4 ... 2 2 2 2 2 2 2 2\n",
       "    _obs           (cells, features) float64 613.3 768.4 4.0 ... 8.0 7.0\n",
       "    _raw_mean      (cells, channels) float64 56.02 0.0 9.426 ... 8.727 2.148\n",
       "    _raw_sum       (cells, channels) float64 1.053e+04 0.0 ... 1.885e+03 464.0\n",
       "    _segmentation  (y, x) int64 0 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0 0 0 0\n",
       "    _properties    (labels, props) object 'C3' ... 'B (PAX5)'
" ], "text/plain": [ "\n", "Dimensions: (cells: 12560, channels: 56, y: 3000, x: 3000, features: 4,\n", " labels: 8, props: 2)\n", "Coordinates:\n", " * cells (cells) int64 1 2 3 4 5 6 ... 12556 12557 12558 12559 12560\n", " * channels (channels) \u001b[0m to \u001b[1m(\u001b[0m\u001b[32m'c'\u001b[0m, \u001b[32m'y'\u001b[0m, \u001b[32m'x'\u001b[0m\u001b[1m)\u001b[0m. \n", "\u001b[34mINFO \u001b[0m Transposing `data` of type: \u001b[1m<\u001b[0m\u001b[1;95mclass\u001b[0m\u001b[39m \u001b[0m\u001b[32m'dask.array.core.Array'\u001b[0m\u001b[1m>\u001b[0m to \u001b[1m(\u001b[0m\u001b[32m'y'\u001b[0m, \u001b[32m'x'\u001b[0m\u001b[1m)\u001b[0m. \n" ] }, { "data": { "text/plain": [ "SpatialData object\n", "├── Images\n", "│ └── 'image': DataArray[cyx] (56, 3000, 3000)\n", "├── Labels\n", "│ └── 'segmentation': DataArray[yx] (3000, 3000)\n", "└── Tables\n", " └── 'table': AnnData (12560, 56)\n", "with coordinate systems:\n", " ▸ 'global', with elements:\n", " image (Images), segmentation (Labels)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# turning the spatialproteomics object into a spatialdata object\n", "sd_obj = ds.tl.convert_to_spatialdata(expression_matrix_key='_arcsinh_mean')\n", "sd_obj" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "interactive = Interactive(sd_obj)\n", "interactive.run()" ] } ], "metadata": { "kernelspec": { "display_name": "tmp_env", "language": "python", "name": "tmp_env" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.8" } }, "nbformat": 4, "nbformat_minor": 4 }