cellestial 0.48.4__tar.gz → 0.49.1__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.
- {cellestial-0.48.4 → cellestial-0.49.1}/PKG-INFO +1 -1
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/datasets/datasets.py +1 -1
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/frames/build.py +23 -14
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/frames/operations.py +29 -14
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/layers/arrow.py +125 -75
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/layers/bracket.py +5 -6
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/layers/outline.py +1 -1
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/core/dimensional.py +2 -2
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/core/distribution.py +3 -209
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/core/subdimensional.py +8 -8
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/core/subdimensionals.py +10 -10
- cellestial-0.49.1/cellestial/single/core/utilities.py +221 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/differential/markers.py +2 -145
- cellestial-0.49.1/cellestial/single/differential/utilities.py +309 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/differential/volcano.py +1 -152
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/heatmap/dotplot.py +2 -2
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/heatmap/heatmap.py +25 -148
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/heatmap/stacked_violin.py +10 -134
- cellestial-0.49.1/cellestial/single/heatmap/utilities.py +872 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/spatial/spatial.py +1 -90
- cellestial-0.48.4/cellestial/spatial/_components.py → cellestial-0.49.1/cellestial/spatial/utilities.py +95 -10
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/util/dendrogram.py +1 -4
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/util/utilities.py +15 -29
- {cellestial-0.48.4 → cellestial-0.49.1}/pyproject.toml +1 -1
- cellestial-0.48.4/cellestial/single/heatmap/_key_groups.py +0 -317
- cellestial-0.48.4/cellestial/single/heatmap/_rank_genes_groups.py +0 -187
- {cellestial-0.48.4 → cellestial-0.49.1}/LICENSE +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/README.md +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/__init__.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/_version.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/datasets/__init__.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/frames/__init__.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/layers/__init__.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/layers/_deferred.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/layers/ondata_legend.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/layers/stream.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/layers/utilities.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/__init__.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/base/__init__.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/base/base.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/basic/__init__.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/basic/bar.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/basic/scatter.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/common/__init__.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/common/xyplot.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/common/xyplots.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/core/__init__.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/core/distributions.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/differential/__init__.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/heatmap/__init__.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/quick/__init__.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/quick/elbow.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/quick/highest.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/single/quick/ridge.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/spatial/__init__.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/spatial/spatials.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/themes/__init__.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/themes/_distributions.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/themes/_heatmaps.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/themes/_scatters.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/util/__init__.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/util/colors.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/util/errors.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/util/operations.py +0 -0
- {cellestial-0.48.4 → cellestial-0.49.1}/cellestial/util/save.py +0 -0
|
@@ -487,7 +487,7 @@ def from_url(
|
|
|
487
487
|
print(f"No cache at {cache_file} !")
|
|
488
488
|
print(f"Downloading from {url} ...")
|
|
489
489
|
|
|
490
|
-
block_size = 1024
|
|
490
|
+
block_size = 1024 * 1024
|
|
491
491
|
# Stream to a .part file and atomically rename on success, so an interrupted
|
|
492
492
|
# download cannot poison the cache.
|
|
493
493
|
partial_file = cache_file.with_name(cache_file.name + ".part")
|
|
@@ -2,9 +2,11 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from typing import TYPE_CHECKING, Literal
|
|
4
4
|
|
|
5
|
+
import numpy as np
|
|
5
6
|
import pandas as pd
|
|
6
7
|
import polars as pl
|
|
7
8
|
from anndata import AnnData
|
|
9
|
+
from scipy.sparse import issparse
|
|
8
10
|
from spatialdata import SpatialData
|
|
9
11
|
|
|
10
12
|
from cellestial.util.errors import UnsupportedDataTypeError, VariableNotFoundError
|
|
@@ -29,17 +31,23 @@ def anndata_variable_columns(
|
|
|
29
31
|
columns = []
|
|
30
32
|
if isinstance(keys, str):
|
|
31
33
|
keys = [keys]
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
34
|
+
# remove keys that are already in column_names to avoid repeats
|
|
35
|
+
keys = [key for key in keys if key not in column_names]
|
|
36
|
+
# check that all keys are in data.var_names
|
|
37
|
+
available_names = set(data.var_names)
|
|
38
|
+
missing = [key for key in keys if key not in available_names]
|
|
39
|
+
if missing:
|
|
40
|
+
msg = f"Keys not found in data.var_names: {missing}"
|
|
41
|
+
raise VariableNotFoundError(msg)
|
|
42
|
+
|
|
43
|
+
# subset X
|
|
44
|
+
X = data[:, keys].X
|
|
45
|
+
|
|
46
|
+
if issparse(X):
|
|
47
|
+
X = X.toarray() # ty:ignore[unresolved-attribute]
|
|
48
|
+
else:
|
|
49
|
+
X = np.asarray(X)
|
|
50
|
+
columns = [pl.Series(key, X[:, i]) for i, key in enumerate(keys)]
|
|
43
51
|
|
|
44
52
|
return columns
|
|
45
53
|
|
|
@@ -210,7 +218,7 @@ def anndata_variables_frame(
|
|
|
210
218
|
|
|
211
219
|
|
|
212
220
|
def build_frame(
|
|
213
|
-
data: AnnData,
|
|
221
|
+
data: AnnData | SpatialData,
|
|
214
222
|
*,
|
|
215
223
|
variable_keys: str | Sequence[str] | None = None,
|
|
216
224
|
axis: Literal[0, 1] | None = None,
|
|
@@ -223,8 +231,8 @@ def build_frame(
|
|
|
223
231
|
|
|
224
232
|
Parameters
|
|
225
233
|
----------
|
|
226
|
-
data : AnnData
|
|
227
|
-
The AnnData object containing the variables.
|
|
234
|
+
data : AnnData | SpatialData
|
|
235
|
+
The AnnData or SpatialData object containing the variables.
|
|
228
236
|
variable_keys : str | Sequence[str] | None
|
|
229
237
|
Variable keys to add to the DataFrame. If None, no additional keys are added.
|
|
230
238
|
axis : {0,1} | None
|
|
@@ -282,6 +290,7 @@ def build_frame(
|
|
|
282
290
|
if isinstance(data, SpatialData):
|
|
283
291
|
tables = list(data.tables.keys())
|
|
284
292
|
if len(tables) == 1:
|
|
293
|
+
# retrieve an anndata
|
|
285
294
|
data = data.tables[tables[0]]
|
|
286
295
|
elif len(tables) == 0:
|
|
287
296
|
msg = "No annotation tables found in the SpatialData object."
|
|
@@ -6,7 +6,6 @@ from anndata import AnnData
|
|
|
6
6
|
from polars import DataFrame
|
|
7
7
|
from scipy.sparse import issparse
|
|
8
8
|
|
|
9
|
-
from cellestial.frames.build import anndata_variable_columns
|
|
10
9
|
from cellestial.util.errors import UnsupportedDataTypeError
|
|
11
10
|
|
|
12
11
|
|
|
@@ -16,28 +15,44 @@ def _highest_expressed_genes_frame(
|
|
|
16
15
|
) -> DataFrame:
|
|
17
16
|
"""Get the top n highest expressed genes by mean percentage across all cells."""
|
|
18
17
|
if isinstance(data, AnnData):
|
|
18
|
+
# VALIDATE: inputs
|
|
19
19
|
if n > data.n_vars:
|
|
20
20
|
msg = f"Requested n={n} genes, but only {data.n_vars} genes available in data."
|
|
21
21
|
raise ValueError(msg)
|
|
22
22
|
X = data.X
|
|
23
|
-
#
|
|
23
|
+
# matmul and fancy indexing below require an in-memory ndarray/sparse;
|
|
24
|
+
# fail fast on backed/dask/zappy rather than crashing deep in the math.
|
|
25
|
+
if not (isinstance(X, np.ndarray) or issparse(X)):
|
|
26
|
+
msg = (
|
|
27
|
+
f"Unsupported `X` type for this operation: {type(X).__name__}. "
|
|
28
|
+
"Load AnnData in non-backed mode or materialize `X` manually."
|
|
29
|
+
)
|
|
30
|
+
raise UnsupportedDataTypeError(msg)
|
|
31
|
+
|
|
32
|
+
# BUILD: per-cell normalizer so each cell's expression sums to 100
|
|
24
33
|
if issparse(X):
|
|
25
|
-
row_sums = np.
|
|
26
|
-
row_sums[row_sums == 0] = 1
|
|
27
|
-
X_normalized = X.multiply(100 / row_sums[:, np.newaxis])
|
|
28
|
-
mean_percent = np.array(X_normalized.mean(axis=0)).ravel()
|
|
34
|
+
row_sums = np.asarray(X.sum(axis=1)).ravel()
|
|
29
35
|
else:
|
|
30
|
-
row_sums = X.sum(axis=1
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
mean_percent = X_normalized.mean(axis=0)
|
|
36
|
+
row_sums = X.sum(axis=1)
|
|
37
|
+
row_sums[row_sums == 0] = 1 # guard cells with zero total to avoid div-by-zero
|
|
38
|
+
inv_rows = 100.0 / row_sums
|
|
34
39
|
|
|
40
|
+
# RANK: gene means via a single matvec instead of materializing the
|
|
41
|
+
# full normalized matrix. Identity: mean(X / row_sums * 100, axis=0)
|
|
42
|
+
# equals (inv_rows @ X) / n_cells, but uses O(n_vars) memory instead of O(n_obs * n_vars).
|
|
43
|
+
mean_percent = np.asarray(inv_rows @ X).ravel() / X.shape[0]
|
|
35
44
|
top_idx = np.argsort(mean_percent)[::-1][:n]
|
|
36
45
|
genes = data.var_names[top_idx].tolist()
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
|
|
47
|
+
# EXTRACT: normalize only the top n columns (small n_obs * n slice),
|
|
48
|
+
# skipping the full n_obs * n_vars materialization the naive path would do.
|
|
49
|
+
X_top = X[:, top_idx]
|
|
50
|
+
if issparse(X_top):
|
|
51
|
+
X_top = X_top.toarray()
|
|
52
|
+
X_top_normalized = X_top * inv_rows[:, np.newaxis]
|
|
53
|
+
|
|
54
|
+
# BUILD: polars frame keyed by gene name
|
|
55
|
+
frame = pl.DataFrame({gene: X_top_normalized[:, i] for i, gene in enumerate(genes)})
|
|
41
56
|
else:
|
|
42
57
|
msg = f"Unsupported data type: `{type(data)}`"
|
|
43
58
|
raise UnsupportedDataTypeError(msg)
|
|
@@ -2,11 +2,14 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
from typing import TYPE_CHECKING, Literal
|
|
4
4
|
|
|
5
|
+
import polars as pl
|
|
5
6
|
from lets_plot import (
|
|
7
|
+
aes,
|
|
6
8
|
arrow,
|
|
7
9
|
element_blank,
|
|
8
10
|
element_text,
|
|
9
11
|
geom_blank,
|
|
12
|
+
geom_path,
|
|
10
13
|
geom_segment,
|
|
11
14
|
theme,
|
|
12
15
|
)
|
|
@@ -19,6 +22,111 @@ if TYPE_CHECKING:
|
|
|
19
22
|
from lets_plot.plot.core import FeatureSpecArray, PlotSpec
|
|
20
23
|
from polars import DataFrame
|
|
21
24
|
|
|
25
|
+
# fraction of each axis arm drawn as the arrowhead-bearing tip segment;
|
|
26
|
+
# lets_plot caps the arrowhead to ~half the segment length, so the tip must be
|
|
27
|
+
# long enough to render a full-size head
|
|
28
|
+
_TIP_FRACTION = 0.3
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _axis_arrow_layers(
|
|
32
|
+
frame: DataFrame,
|
|
33
|
+
*,
|
|
34
|
+
x: str,
|
|
35
|
+
y: str,
|
|
36
|
+
length: float,
|
|
37
|
+
size: float,
|
|
38
|
+
color: str,
|
|
39
|
+
angle: float,
|
|
40
|
+
arrow_kwargs: dict | None = None,
|
|
41
|
+
) -> FeatureSpecArray:
|
|
42
|
+
"""
|
|
43
|
+
Build the arrow-axis as an L-shaped path plus two arrowhead tip segments.
|
|
44
|
+
|
|
45
|
+
The semi-square L is one continuous `geom_path` that stops short of each
|
|
46
|
+
open end so the corner joins cleanly with no overlap. Each tip is completed
|
|
47
|
+
by a `geom_segment` carrying the arrowhead, meeting the path end-to-end.
|
|
48
|
+
|
|
49
|
+
Parameters
|
|
50
|
+
----------
|
|
51
|
+
frame : `polars.DataFrame`
|
|
52
|
+
DataFrame holding the `x` and `y` columns.
|
|
53
|
+
x : str
|
|
54
|
+
Name of the x axis column.
|
|
55
|
+
y : str
|
|
56
|
+
Name of the y axis column.
|
|
57
|
+
length : float
|
|
58
|
+
Length of each axis arm as a fraction of its data range.
|
|
59
|
+
size : float
|
|
60
|
+
Line width of the path and tip segments.
|
|
61
|
+
color : str
|
|
62
|
+
Color of the path and tip segments.
|
|
63
|
+
angle : float
|
|
64
|
+
Angle of the arrowhead in degrees.
|
|
65
|
+
arrow_kwargs : dict | None
|
|
66
|
+
Additional parameters for the `arrow` layer.
|
|
67
|
+
|
|
68
|
+
Returns
|
|
69
|
+
-------
|
|
70
|
+
`FeatureSpecArray`
|
|
71
|
+
The path and tip-segment layers.
|
|
72
|
+
"""
|
|
73
|
+
arrow_kwargs = arrow_kwargs or {}
|
|
74
|
+
|
|
75
|
+
x_min = frame[x].min()
|
|
76
|
+
x_max = frame[x].max()
|
|
77
|
+
y_min = frame[y].min()
|
|
78
|
+
y_max = frame[y].max()
|
|
79
|
+
|
|
80
|
+
# find total difference between the max and min for both axis
|
|
81
|
+
x_diff = x_max - x_min
|
|
82
|
+
y_diff = y_max - y_min
|
|
83
|
+
|
|
84
|
+
# find the ends of the arrows
|
|
85
|
+
xend = x_min + length * x_diff
|
|
86
|
+
yend = y_min + length * y_diff
|
|
87
|
+
|
|
88
|
+
# adjust bottom ends of arrows
|
|
89
|
+
adjust_rate = 0.025
|
|
90
|
+
x0 = x_min - x_diff * adjust_rate
|
|
91
|
+
y0 = y_min - y_diff * adjust_rate
|
|
92
|
+
|
|
93
|
+
# tip segments carry the arrowheads; the path stops short of each tip
|
|
94
|
+
tip_x = (xend - x0) * _TIP_FRACTION
|
|
95
|
+
tip_y = (yend - y0) * _TIP_FRACTION
|
|
96
|
+
|
|
97
|
+
# semi-square L (stopping short of both tips), drawn as one connected path
|
|
98
|
+
path_frame = pl.DataFrame(
|
|
99
|
+
{"x": [xend - tip_x, x0, x0], "y": [y0, y0, yend - tip_y]}
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
layers = geom_path(
|
|
103
|
+
data=path_frame,
|
|
104
|
+
mapping=aes(x="x", y="y"),
|
|
105
|
+
color=color,
|
|
106
|
+
size=size,
|
|
107
|
+
)
|
|
108
|
+
# X axis tip
|
|
109
|
+
layers += geom_segment(
|
|
110
|
+
x=xend - tip_x,
|
|
111
|
+
y=y0,
|
|
112
|
+
xend=xend,
|
|
113
|
+
yend=y0,
|
|
114
|
+
color=color,
|
|
115
|
+
size=size,
|
|
116
|
+
arrow=arrow(angle, **arrow_kwargs),
|
|
117
|
+
)
|
|
118
|
+
# Y axis tip
|
|
119
|
+
layers += geom_segment(
|
|
120
|
+
x=x0,
|
|
121
|
+
y=yend - tip_y,
|
|
122
|
+
xend=x0,
|
|
123
|
+
yend=yend,
|
|
124
|
+
color=color,
|
|
125
|
+
size=size,
|
|
126
|
+
arrow=arrow(angle, **arrow_kwargs),
|
|
127
|
+
)
|
|
128
|
+
return layers
|
|
129
|
+
|
|
22
130
|
|
|
23
131
|
def _modify_axis(
|
|
24
132
|
frame: DataFrame,
|
|
@@ -45,13 +153,13 @@ def _modify_axis(
|
|
|
45
153
|
axis_type : {'axis', 'arrow'} | None
|
|
46
154
|
Whether to use regular axis or arrows as the axis.
|
|
47
155
|
arrow_size : float
|
|
48
|
-
|
|
156
|
+
Width of the axis lines.
|
|
49
157
|
arrow_color : str
|
|
50
158
|
Color of the arrow.
|
|
51
159
|
arrow_angle : float
|
|
52
160
|
Angle of the arrow head in degrees.
|
|
53
161
|
arrow_length : float
|
|
54
|
-
|
|
162
|
+
Span of each axis line as a fraction of its data range (0.25 covers 25%).
|
|
55
163
|
|
|
56
164
|
Returns
|
|
57
165
|
-------
|
|
@@ -86,44 +194,14 @@ def _modify_axis(
|
|
|
86
194
|
axis_title_x=element_text(hjust=arrow_length / 2.5), # better than 2
|
|
87
195
|
axis_title_y=element_text(hjust=arrow_length / 2.5),
|
|
88
196
|
)
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
# find total difference between the max and min for both axis
|
|
95
|
-
x_diff = x_max - x_min # ty:ignore[unsupported-operator]
|
|
96
|
-
y_diff = y_max - y_min # ty:ignore[unsupported-operator]
|
|
97
|
-
|
|
98
|
-
# find the ends of the arrows
|
|
99
|
-
# ensure the arrow length is the same for both axis
|
|
100
|
-
xend = x_min + arrow_length * x_diff
|
|
101
|
-
yend = y_min + arrow_length * y_diff
|
|
102
|
-
|
|
103
|
-
# adjust bottom ends of arrows
|
|
104
|
-
adjust_rate = 0.025
|
|
105
|
-
x0 = x_min - x_diff * adjust_rate
|
|
106
|
-
y0 = y_min - y_diff * adjust_rate
|
|
107
|
-
|
|
108
|
-
# X axis
|
|
109
|
-
new_layer += geom_segment(
|
|
110
|
-
x=x0,
|
|
111
|
-
y=y0,
|
|
112
|
-
xend=xend,
|
|
113
|
-
yend=y0,
|
|
114
|
-
color=arrow_color,
|
|
197
|
+
new_layer += _axis_arrow_layers(
|
|
198
|
+
frame,
|
|
199
|
+
x=x,
|
|
200
|
+
y=y,
|
|
201
|
+
length=arrow_length,
|
|
115
202
|
size=arrow_size,
|
|
116
|
-
arrow=arrow(arrow_angle),
|
|
117
|
-
)
|
|
118
|
-
# Y axis
|
|
119
|
-
new_layer += geom_segment(
|
|
120
|
-
x=x0,
|
|
121
|
-
y=y0,
|
|
122
|
-
xend=x0,
|
|
123
|
-
yend=yend,
|
|
124
203
|
color=arrow_color,
|
|
125
|
-
|
|
126
|
-
arrow=arrow(arrow_angle),
|
|
204
|
+
angle=arrow_angle,
|
|
127
205
|
)
|
|
128
206
|
else:
|
|
129
207
|
msg = f"expected 'axis' or 'arrow' for 'axis_type' argument, but received {axis_type}"
|
|
@@ -151,13 +229,13 @@ def arrow_axis(
|
|
|
151
229
|
regardless of which plot the resulting layer is added to. When `None`,
|
|
152
230
|
the layer is deferred and introspects the plot it is added to via `+`.
|
|
153
231
|
size : float
|
|
154
|
-
|
|
232
|
+
Width of the axis lines.
|
|
155
233
|
color : str
|
|
156
234
|
Color of the arrow.
|
|
157
235
|
angle : float
|
|
158
236
|
Angle of the arrow head in degrees.
|
|
159
237
|
length : float
|
|
160
|
-
|
|
238
|
+
Span of each axis line as a fraction of its data range (0.25 covers 25%).
|
|
161
239
|
**arrow_kwargs
|
|
162
240
|
Additional parameters for the `arrow` layer.
|
|
163
241
|
For more information on arrow parameters, see:
|
|
@@ -242,43 +320,15 @@ def arrow_axis(
|
|
|
242
320
|
axis_title_x=element_text(hjust=length / 2.5), # better than 2
|
|
243
321
|
axis_title_y=element_text(hjust=length / 2.5),
|
|
244
322
|
)
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
# find total difference between the max and min for both axis
|
|
251
|
-
x_diff = x_max - x_min
|
|
252
|
-
y_diff = y_max - y_min
|
|
253
|
-
|
|
254
|
-
# find the ends of the arrows
|
|
255
|
-
xend = x_min + length * x_diff
|
|
256
|
-
yend = y_min + length * y_diff
|
|
257
|
-
|
|
258
|
-
# adjust bottom ends of arrows
|
|
259
|
-
adjust_rate = 0.025
|
|
260
|
-
x0 = x_min - x_diff * adjust_rate
|
|
261
|
-
y0 = y_min - y_diff * adjust_rate
|
|
262
|
-
|
|
263
|
-
# X axis
|
|
264
|
-
new_layer += geom_segment(
|
|
265
|
-
x=x0,
|
|
266
|
-
y=y0,
|
|
267
|
-
xend=xend,
|
|
268
|
-
yend=y0,
|
|
269
|
-
color=color,
|
|
323
|
+
new_layer += _axis_arrow_layers(
|
|
324
|
+
frame,
|
|
325
|
+
x=x,
|
|
326
|
+
y=y,
|
|
327
|
+
length=length,
|
|
270
328
|
size=size,
|
|
271
|
-
arrow=arrow(angle, **arrow_kwargs),
|
|
272
|
-
)
|
|
273
|
-
# Y axis
|
|
274
|
-
new_layer += geom_segment(
|
|
275
|
-
x=x0,
|
|
276
|
-
y=y0,
|
|
277
|
-
xend=x0,
|
|
278
|
-
yend=yend,
|
|
279
329
|
color=color,
|
|
280
|
-
|
|
281
|
-
|
|
330
|
+
angle=angle,
|
|
331
|
+
arrow_kwargs=arrow_kwargs,
|
|
282
332
|
)
|
|
283
333
|
return new_layer
|
|
284
334
|
|
|
@@ -6,6 +6,7 @@ from typing import TYPE_CHECKING, Literal
|
|
|
6
6
|
import numpy as np
|
|
7
7
|
import polars as pl
|
|
8
8
|
from lets_plot import aes, geom_bracket
|
|
9
|
+
from scipy.stats import mannwhitneyu, ttest_ind
|
|
9
10
|
|
|
10
11
|
from cellestial.layers._deferred import DeferredLayer
|
|
11
12
|
from cellestial.util import get_mapping, retrieve
|
|
@@ -134,8 +135,6 @@ def _compute_bracket_frame(
|
|
|
134
135
|
y_padding: float,
|
|
135
136
|
) -> DataFrame:
|
|
136
137
|
"""Build a `geom_bracket` DataFrame from pairwise significance tests."""
|
|
137
|
-
from scipy.stats import mannwhitneyu, ttest_ind
|
|
138
|
-
|
|
139
138
|
# determine which pairs to compare
|
|
140
139
|
groups = frame[x].drop_nulls().unique(maintain_order=True).to_list()
|
|
141
140
|
if comparisons is None:
|
|
@@ -238,10 +237,10 @@ def _compute_bracket_frame(
|
|
|
238
237
|
brackets = brackets.with_columns(label=pl.Series(labels))
|
|
239
238
|
|
|
240
239
|
# compute y positions so brackets stack above the data without overlapping
|
|
241
|
-
|
|
242
|
-
data_min =
|
|
243
|
-
data_max =
|
|
244
|
-
data_range = data_max - data_min
|
|
240
|
+
|
|
241
|
+
data_min = frame[y].min()
|
|
242
|
+
data_max = frame[y].max()
|
|
243
|
+
data_range = data_max - data_min # ty:ignore[unsupported-operator]
|
|
245
244
|
_y_position = data_max + data_range * y_padding if y_position is None else y_position
|
|
246
245
|
_y_step = data_range * y_padding if y_step is None else y_step
|
|
247
246
|
positions = [_y_position + _y_step * index for index in range(len(brackets))]
|
|
@@ -5,6 +5,7 @@ from typing import TYPE_CHECKING, Literal
|
|
|
5
5
|
import numpy as np
|
|
6
6
|
import polars as pl
|
|
7
7
|
from lets_plot import aes, geom_path
|
|
8
|
+
from scipy.stats import gaussian_kde
|
|
8
9
|
|
|
9
10
|
from cellestial.layers._deferred import DeferredLayer
|
|
10
11
|
from cellestial.util import get_mapping
|
|
@@ -28,7 +29,6 @@ def _get_density_boundaries(
|
|
|
28
29
|
grid_size: int = 200,
|
|
29
30
|
) -> DataFrame:
|
|
30
31
|
"""Creates and Returns a DataFrame to encircle the cluster via `geom_path`."""
|
|
31
|
-
from scipy.stats import gaussian_kde
|
|
32
32
|
from skimage import measure
|
|
33
33
|
|
|
34
34
|
# 1. Normalize input to a Sequence of Sequences: List[List[str]]
|
|
@@ -116,9 +116,9 @@ def dimensional(
|
|
|
116
116
|
axis_type : {'axis', 'arrow'} | None
|
|
117
117
|
Whether to use regular axis or arrows as the axis.
|
|
118
118
|
arrow_length : float, default=0.25
|
|
119
|
-
|
|
119
|
+
Span of each axis line as a fraction of its data range (0.25 covers 25%).
|
|
120
120
|
arrow_size : float, default=1
|
|
121
|
-
|
|
121
|
+
Width of the axis lines.
|
|
122
122
|
arrow_color : str, default='#3f3f3f'
|
|
123
123
|
Color of the arrows.
|
|
124
124
|
arrow_angle : float, default=10
|