napari-spatialdata 0.2.2__tar.gz → 0.2.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/PKG-INFO +1 -1
- napari-spatialdata-0.2.3/examples/spatialdata_visium.py +12 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata/_interactive.py +60 -1
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata/_utils.py +5 -1
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata/_version.py +2 -2
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata.egg-info/PKG-INFO +1 -1
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata.egg-info/SOURCES.txt +1 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/.github/workflows/test_and_deploy.yml +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/.gitignore +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/.mypy.ini +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/.napari/DESCRIPTION.md +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/.pre-commit-config.yaml +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/.readthedocs.yaml +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/CHANGELOG.md +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/LICENSE +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/MANIFEST.in +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/README.md +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/docs/Makefile +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/docs/_static/.gitkeep +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/docs/_templates/.gitkeep +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/docs/_templates/autosummary/class.rst +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/docs/api.md +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/docs/changelog.md +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/docs/conf.py +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/docs/contributing.md +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/docs/extensions/typed_returns.py +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/docs/index.md +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/docs/make.bat +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/docs/notebooks/mibitof_analysis.ipynb +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/docs/notebooks/nanostring_analysis.ipynb +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/docs/notebooks/spatialdata.ipynb +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/docs/references.bib +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/docs/references.md +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/docs/template_usage.md +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/examples/README.md +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/examples/spatialdata_mibitof.py +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/examples/spatialdata_nanostring.py +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/pyproject.toml +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/setup.cfg +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata/__init__.py +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata/_categoricals_utils.py +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata/_constants/__init__.py +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata/_constants/_constants.py +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata/_constants/_pkg_constants.py +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata/_constants/_utils.py +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata/_model.py +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata/_scatterwidgets.py +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata/_view.py +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata/_widgets.py +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata/napari.yaml +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata.egg-info/dependency_links.txt +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata.egg-info/entry_points.txt +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata.egg-info/requires.txt +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata.egg-info/top_level.txt +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/tests/__init__.py +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/tests/conftest.py +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/tests/test_interactive.py +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/tests/test_scatterwidgets.py +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/tests/test_spatialdata.py +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/tests/test_utils.py +0 -0
- {napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/tox.ini +0 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# In this script, we are reading the Visium dataset into a SpatialData object and visualising
|
|
2
|
+
# it with the Interactive class from napari_spatialdata.
|
|
3
|
+
|
|
4
|
+
# The dataset can be downloaded from https://spatialdata.scverse.org/en/latest/tutorials/notebooks/datasets/README.html
|
|
5
|
+
|
|
6
|
+
from napari_spatialdata import Interactive
|
|
7
|
+
from spatialdata import SpatialData
|
|
8
|
+
|
|
9
|
+
if __name__ == "__main__":
|
|
10
|
+
sdata = SpatialData.read("../data/visium/data.zarr") # Change this path!
|
|
11
|
+
i = Interactive(sdata)
|
|
12
|
+
i.run()
|
{napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata/_interactive.py
RENAMED
|
@@ -2,6 +2,7 @@ from typing import Any, Iterable, Union
|
|
|
2
2
|
|
|
3
3
|
import napari
|
|
4
4
|
import numpy as np
|
|
5
|
+
import shapely
|
|
5
6
|
from anndata import AnnData
|
|
6
7
|
from loguru import logger
|
|
7
8
|
from multiscale_spatial_image import MultiscaleSpatialImage
|
|
@@ -9,7 +10,7 @@ from napari.viewer import Viewer
|
|
|
9
10
|
from qtpy.QtWidgets import QLabel, QListWidget, QListWidgetItem, QVBoxLayout, QWidget
|
|
10
11
|
from spatialdata import SpatialData
|
|
11
12
|
|
|
12
|
-
from napari_spatialdata._utils import NDArrayA, _get_transform
|
|
13
|
+
from napari_spatialdata._utils import NDArrayA, _get_transform, _swap_coordinates
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
class ElementWidget(QListWidget):
|
|
@@ -71,9 +72,66 @@ class SdataWidget(QWidget):
|
|
|
71
72
|
self._add_image(text)
|
|
72
73
|
elif self.elements_widget._elements[text] == "points":
|
|
73
74
|
self._add_points(text)
|
|
75
|
+
elif self.elements_widget._elements[text] == "shapes":
|
|
76
|
+
self._add_shapes(text)
|
|
77
|
+
|
|
78
|
+
def _add_circles(self, key: str) -> None:
|
|
79
|
+
circles = []
|
|
80
|
+
df = self._sdata.shapes[key]
|
|
81
|
+
affine = _get_transform(self._sdata.shapes[key], self.coordinate_system_widget._system)
|
|
82
|
+
|
|
83
|
+
for i in range(0, len(df)):
|
|
84
|
+
circles.append([df.geometry[i].coords[0], [df.radius[i], df.radius[i]]])
|
|
85
|
+
|
|
86
|
+
circles = _swap_coordinates(circles)
|
|
87
|
+
|
|
88
|
+
self._viewer.add_shapes(
|
|
89
|
+
circles,
|
|
90
|
+
name=key,
|
|
91
|
+
affine=affine,
|
|
92
|
+
shape_type="ellipse",
|
|
93
|
+
metadata={
|
|
94
|
+
"adata": self._sdata.table[
|
|
95
|
+
self._sdata.table.obs[self._sdata.table.uns["spatialdata_attrs"]["region_key"]] == key
|
|
96
|
+
],
|
|
97
|
+
"shapes_key": self._sdata.table.uns["spatialdata_attrs"]["region_key"],
|
|
98
|
+
},
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
def _add_polygons(self, key: str) -> None:
|
|
102
|
+
polygons = []
|
|
103
|
+
df = self._sdata.shapes[key]
|
|
104
|
+
affine = _get_transform(self._sdata.shapes[key], self.coordinate_system_widget._system)
|
|
105
|
+
|
|
106
|
+
for i in range(0, len(df)):
|
|
107
|
+
polygons.append(list(df.geometry[i].exterior.coords))
|
|
108
|
+
|
|
109
|
+
polygons = _swap_coordinates(polygons)
|
|
110
|
+
|
|
111
|
+
self._viewer.add_shapes(
|
|
112
|
+
polygons,
|
|
113
|
+
name=key,
|
|
114
|
+
affine=affine,
|
|
115
|
+
shape_type="polygon",
|
|
116
|
+
metadata={
|
|
117
|
+
"adata": self._sdata.table[
|
|
118
|
+
self._sdata.table.obs[self._sdata.table.uns["spatialdata_attrs"]["region_key"]] == key
|
|
119
|
+
],
|
|
120
|
+
"shapes_key": self._sdata.table.uns["spatialdata_attrs"]["region_key"],
|
|
121
|
+
},
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
def _add_shapes(self, key: str) -> None:
|
|
125
|
+
if type(self._sdata.shapes[key].iloc[0][0]) == shapely.geometry.point.Point:
|
|
126
|
+
self._add_circles(key)
|
|
127
|
+
elif type(self._sdata.shapes[key].iloc[0][0]) == shapely.geometry.polygon.Polygon:
|
|
128
|
+
self._add_polygons(key)
|
|
129
|
+
else:
|
|
130
|
+
raise TypeError("Incorrect data type passed for shapes (should be Shapely Point or Polygon).")
|
|
74
131
|
|
|
75
132
|
def _add_label(self, key: str) -> None:
|
|
76
133
|
affine = _get_transform(self._sdata.labels[key], self.coordinate_system_widget._system)
|
|
134
|
+
|
|
77
135
|
self._viewer.add_labels(
|
|
78
136
|
self._sdata.labels[key],
|
|
79
137
|
name=key,
|
|
@@ -89,6 +147,7 @@ class SdataWidget(QWidget):
|
|
|
89
147
|
def _add_image(self, key: str) -> None:
|
|
90
148
|
img = self._sdata.images[key]
|
|
91
149
|
affine = _get_transform(self._sdata.images[key], self.coordinate_system_widget._system)
|
|
150
|
+
|
|
92
151
|
if isinstance(img, MultiscaleSpatialImage):
|
|
93
152
|
img = img["scale0"][key]
|
|
94
153
|
# TODO: type check
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
3
|
from functools import wraps
|
|
4
|
-
from typing import TYPE_CHECKING, Any, Callable, Optional, Sequence, Tuple, Union
|
|
4
|
+
from typing import TYPE_CHECKING, Any, Callable, List, Optional, Sequence, Tuple, Union
|
|
5
5
|
|
|
6
6
|
import numpy as np
|
|
7
7
|
import pandas as pd
|
|
@@ -170,6 +170,10 @@ def _min_max_norm(vec: Union[spmatrix, NDArrayA]) -> NDArrayA:
|
|
|
170
170
|
)
|
|
171
171
|
|
|
172
172
|
|
|
173
|
+
def _swap_coordinates(data: List[Any]) -> List[Any]:
|
|
174
|
+
return [[(y, x) for x, y in sublist] for sublist in data]
|
|
175
|
+
|
|
176
|
+
|
|
173
177
|
def _get_transform(element: SpatialElement, coordinate_system_name: Optional[str] = None) -> NDArrayA:
|
|
174
178
|
affine: NDArrayA
|
|
175
179
|
transformations = get_transformation(element, get_all=True)
|
{napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata.egg-info/SOURCES.txt
RENAMED
|
@@ -31,6 +31,7 @@ docs/notebooks/spatialdata.ipynb
|
|
|
31
31
|
examples/README.md
|
|
32
32
|
examples/spatialdata_mibitof.py
|
|
33
33
|
examples/spatialdata_nanostring.py
|
|
34
|
+
examples/spatialdata_visium.py
|
|
34
35
|
src/napari_spatialdata/__init__.py
|
|
35
36
|
src/napari_spatialdata/_categoricals_utils.py
|
|
36
37
|
src/napari_spatialdata/_interactive.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/docs/notebooks/nanostring_analysis.ipynb
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata/_categoricals_utils.py
RENAMED
|
File without changes
|
{napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata/_constants/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata/_constants/_utils.py
RENAMED
|
File without changes
|
|
File without changes
|
{napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata/_scatterwidgets.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata.egg-info/requires.txt
RENAMED
|
File without changes
|
{napari-spatialdata-0.2.2 → napari-spatialdata-0.2.3}/src/napari_spatialdata.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|