cellestial 0.47.0__tar.gz → 0.48.0__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.47.0 → cellestial-0.48.0}/PKG-INFO +2 -2
- {cellestial-0.47.0 → cellestial-0.48.0}/README.md +1 -1
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/__init__.py +3 -3
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/datasets/datasets.py +10 -26
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/layers/_deferred.py +1 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/layers/arrow.py +1 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/layers/bracket.py +1 -4
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/layers/outline.py +1 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/layers/stream.py +1 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/layers/utilities.py +2 -1
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/basic/__init__.py +1 -1
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/basic/scatter.py +2 -2
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/common/xyplots.py +9 -9
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/core/distribution.py +3 -1
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/core/distributions.py +18 -18
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/differential/markers.py +17 -14
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/differential/volcano.py +4 -3
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/heatmap/_key_groups.py +6 -20
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/heatmap/_rank_genes_groups.py +2 -2
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/heatmap/dotplot.py +2 -8
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/heatmap/heatmap.py +3 -4
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/heatmap/stacked_violin.py +1 -4
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/quick/ridge.py +11 -9
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/spatial/_components.py +10 -30
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/spatial/spatial.py +2 -2
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/spatial/spatials.py +2 -2
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/themes/_scatters.py +20 -26
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/util/__init__.py +4 -3
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/util/colors.py +0 -1
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/util/operations.py +74 -31
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/util/utilities.py +5 -13
- {cellestial-0.47.0 → cellestial-0.48.0}/pyproject.toml +3 -3
- {cellestial-0.47.0 → cellestial-0.48.0}/LICENSE +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/_version.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/datasets/__init__.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/frames/__init__.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/frames/build.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/frames/operations.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/layers/__init__.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/layers/ondata_legend.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/__init__.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/base/__init__.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/base/base.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/basic/bar.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/common/__init__.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/common/xyplot.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/core/__init__.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/core/dimensional.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/core/subdimensional.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/core/subdimensionals.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/differential/__init__.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/heatmap/__init__.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/quick/__init__.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/quick/elbow.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/single/quick/highest.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/spatial/__init__.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/themes/__init__.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/themes/_distributions.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/themes/_heatmaps.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/util/dendrogram.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/util/errors.py +0 -0
- {cellestial-0.47.0 → cellestial-0.48.0}/cellestial/util/save.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cellestial
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.48.0
|
|
4
4
|
Summary:
|
|
5
5
|
License-Expression: Apache-2.0
|
|
6
6
|
License-File: LICENSE
|
|
@@ -29,6 +29,7 @@ Description-Content-Type: text/markdown
|
|
|
29
29
|
|
|
30
30
|
[](https://github.com/DataVil/Cellestial)
|
|
31
31
|
[](https://pypi.org/project/cellestial/)
|
|
32
|
+
[](https://codecov.io/gh/datavil/cellestial)
|
|
32
33
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
33
34
|
[](https://www.pola.rs/)
|
|
34
35
|
[](https://lets-plot.org/)
|
|
@@ -262,4 +263,3 @@ See the [migration guide](sphinx/migrating_from_scanpy.rst) for a side-by-side m
|
|
|
262
263
|
|
|
263
264
|
Apache 2.0. See [LICENSE](LICENSE).
|
|
264
265
|
|
|
265
|
-
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://github.com/DataVil/Cellestial)
|
|
4
4
|
[](https://pypi.org/project/cellestial/)
|
|
5
|
+
[](https://codecov.io/gh/datavil/cellestial)
|
|
5
6
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
6
7
|
[](https://www.pola.rs/)
|
|
7
8
|
[](https://lets-plot.org/)
|
|
@@ -234,4 +235,3 @@ See the [migration guide](sphinx/migrating_from_scanpy.rst) for a side-by-side m
|
|
|
234
235
|
## License
|
|
235
236
|
|
|
236
237
|
Apache 2.0. See [LICENSE](LICENSE).
|
|
237
|
-
|
|
@@ -37,8 +37,7 @@ from cellestial.single import (
|
|
|
37
37
|
xyplots,
|
|
38
38
|
)
|
|
39
39
|
from cellestial.spatial import spatial, spatials
|
|
40
|
-
from cellestial.util import get_mapping, retrieve, save
|
|
41
|
-
from cellestial.util import get_slice as slice
|
|
40
|
+
from cellestial.util import get_figure, get_figures, get_mapping, retrieve, save
|
|
42
41
|
from cellestial.util.colors import (
|
|
43
42
|
BLUE,
|
|
44
43
|
CHERRY,
|
|
@@ -80,6 +79,8 @@ __all__ = [
|
|
|
80
79
|
"elbow",
|
|
81
80
|
"expression",
|
|
82
81
|
"expressions",
|
|
82
|
+
"get_figure",
|
|
83
|
+
"get_figures",
|
|
83
84
|
"get_mapping",
|
|
84
85
|
"heatmap",
|
|
85
86
|
"highest_expressed_genes",
|
|
@@ -96,7 +97,6 @@ __all__ = [
|
|
|
96
97
|
"scatter",
|
|
97
98
|
"setup_html",
|
|
98
99
|
"show_colors",
|
|
99
|
-
"slice",
|
|
100
100
|
"spatial",
|
|
101
101
|
"spatials",
|
|
102
102
|
"stacked_violin",
|
|
@@ -21,7 +21,7 @@ def _require_extras(function_name: str, *modules: str) -> None:
|
|
|
21
21
|
missing = [m for m in modules if importlib.util.find_spec(m) is None]
|
|
22
22
|
if missing:
|
|
23
23
|
message = (
|
|
24
|
-
f"{function_name} requires optional dependencies: {', '.join(missing)}. "
|
|
24
|
+
f"datasets.{function_name} requires optional dependencies: {', '.join(missing)}. "
|
|
25
25
|
"Install them with: pip install 'cellestial[extras]'"
|
|
26
26
|
)
|
|
27
27
|
raise ImportError(message)
|
|
@@ -50,12 +50,7 @@ def _resolve_cache_file(
|
|
|
50
50
|
|
|
51
51
|
cache_file = cache_directory / filename
|
|
52
52
|
|
|
53
|
-
if (
|
|
54
|
-
use_cache
|
|
55
|
-
and bring
|
|
56
|
-
and cache_directory != _GLOBAL_CACHE
|
|
57
|
-
and not cache_file.exists()
|
|
58
|
-
):
|
|
53
|
+
if use_cache and bring and cache_directory != _GLOBAL_CACHE and not cache_file.exists():
|
|
59
54
|
global_cache_file = _GLOBAL_CACHE / filename
|
|
60
55
|
if global_cache_file.exists():
|
|
61
56
|
print(f"Bringing cached file from {global_cache_file} to {cache_file}")
|
|
@@ -102,10 +97,7 @@ def _run_steps(
|
|
|
102
97
|
# The static prefix is baked into bar_format (escaping any literal braces)
|
|
103
98
|
# so that {desc} is free to carry the per-step info after the bar.
|
|
104
99
|
prefix = desc.replace("{", "{{").replace("}", "}}")
|
|
105
|
-
bar_format =
|
|
106
|
-
f"{prefix} | "
|
|
107
|
-
"{percentage:3.0f}%|{bar}| {n_fmt}/{total_fmt} {desc}"
|
|
108
|
-
)
|
|
100
|
+
bar_format = f"{prefix} | {{percentage:3.0f}}%|{{bar}}| {{n_fmt}}/{{total_fmt}} {{desc}}"
|
|
109
101
|
|
|
110
102
|
# Keep a handle on the real stdout/stderr from before the redirects so our
|
|
111
103
|
# own bar can stay visible. Route the bar to *stdout* (same stream as the
|
|
@@ -131,6 +123,7 @@ def _run_steps(
|
|
|
131
123
|
def silence_nested_tqdm():
|
|
132
124
|
originals = [(cls, cls.__init__) for cls in tqdm_classes]
|
|
133
125
|
for cls, original in originals:
|
|
126
|
+
|
|
134
127
|
def patched(self, *args, _original=original, **kwargs): # type: ignore[no-untyped-def]
|
|
135
128
|
kwargs["disable"] = True
|
|
136
129
|
_original(self, *args, **kwargs)
|
|
@@ -302,9 +295,7 @@ def pbmc3k(
|
|
|
302
295
|
(
|
|
303
296
|
"highly variable genes",
|
|
304
297
|
"sc.pp.highly_variable_genes(adata, n_top_genes=2000, batch_key='sample')",
|
|
305
|
-
lambda: sc.pp.highly_variable_genes(
|
|
306
|
-
adata, n_top_genes=2000, batch_key="sample"
|
|
307
|
-
),
|
|
298
|
+
lambda: sc.pp.highly_variable_genes(adata, n_top_genes=2000, batch_key="sample"),
|
|
308
299
|
),
|
|
309
300
|
("PCA", "sc.tl.pca(adata)", lambda: sc.tl.pca(adata)),
|
|
310
301
|
("neighbors graph", "sc.pp.neighbors(adata)", lambda: sc.pp.neighbors(adata)),
|
|
@@ -479,15 +470,10 @@ def from_url(
|
|
|
479
470
|
else:
|
|
480
471
|
filename = Path(urlparse(url).path).name
|
|
481
472
|
if not filename:
|
|
482
|
-
message =
|
|
483
|
-
"Could not derive a filename from the URL; "
|
|
484
|
-
"pass `name=...` explicitly."
|
|
485
|
-
)
|
|
473
|
+
message = "Could not derive a filename from the URL; pass `name=...` explicitly."
|
|
486
474
|
raise ValueError(message)
|
|
487
475
|
|
|
488
|
-
cache_file = _resolve_cache_file(
|
|
489
|
-
cache_directory, filename, use_cache=use_cache, bring=bring
|
|
490
|
-
)
|
|
476
|
+
cache_file = _resolve_cache_file(cache_directory, filename, use_cache=use_cache, bring=bring)
|
|
491
477
|
|
|
492
478
|
if cache_file.exists():
|
|
493
479
|
return read_h5ad(cache_file)
|
|
@@ -514,10 +500,9 @@ def from_url(
|
|
|
514
500
|
|
|
515
501
|
if total_size != 0 and progress_bar.n != total_size:
|
|
516
502
|
message = (
|
|
517
|
-
f"Download incomplete: expected {total_size} bytes, "
|
|
518
|
-
f"got {progress_bar.n}."
|
|
503
|
+
f"Download incomplete: expected {total_size} bytes, got {progress_bar.n}."
|
|
519
504
|
)
|
|
520
|
-
raise OSError(message)
|
|
505
|
+
raise OSError(message) # noqa: TRY301
|
|
521
506
|
|
|
522
507
|
partial_file.replace(cache_file)
|
|
523
508
|
except BaseException:
|
|
@@ -580,8 +565,7 @@ def from_cellxgene(
|
|
|
580
565
|
match = _UUID_PATTERN.search(source)
|
|
581
566
|
if match is None:
|
|
582
567
|
message = (
|
|
583
|
-
"source must be a CELLxGENE dataset UUID or a URL containing one, "
|
|
584
|
-
f"got {source!r}"
|
|
568
|
+
f"source must be a CELLxGENE dataset UUID or a URL containing one, got {source!r}"
|
|
585
569
|
)
|
|
586
570
|
raise ValueError(message)
|
|
587
571
|
|
|
@@ -79,10 +79,7 @@ def _expand_comparisons(
|
|
|
79
79
|
if group == "*":
|
|
80
80
|
return
|
|
81
81
|
if group not in available_groups:
|
|
82
|
-
msg =
|
|
83
|
-
f"Group {group!r} in `comparisons` was not found. "
|
|
84
|
-
f"Available groups: {groups}"
|
|
85
|
-
)
|
|
82
|
+
msg = f"Group {group!r} in `comparisons` was not found. Available groups: {groups}"
|
|
86
83
|
raise InvalidComparisonError(msg)
|
|
87
84
|
|
|
88
85
|
def _add(group_a: str, group_b: str) -> None:
|
|
@@ -7,6 +7,7 @@ from lets_plot import element_rect, theme
|
|
|
7
7
|
if TYPE_CHECKING:
|
|
8
8
|
from lets_plot.plot.core import FeatureSpec
|
|
9
9
|
|
|
10
|
+
|
|
10
11
|
def borders(
|
|
11
12
|
panel_color="green",
|
|
12
13
|
legend_color="blue",
|
|
@@ -15,7 +16,7 @@ def borders(
|
|
|
15
16
|
panel_size=4,
|
|
16
17
|
legend_size=4,
|
|
17
18
|
plot_size=4,
|
|
18
|
-
)-> FeatureSpec:
|
|
19
|
+
) -> FeatureSpec:
|
|
19
20
|
"""Add colored rectangels around panel, legend, and plot areas."""
|
|
20
21
|
return theme(
|
|
21
22
|
panel_background=element_rect(color=panel_color, size=panel_size),
|
|
@@ -121,9 +121,9 @@ def scatter(
|
|
|
121
121
|
"""
|
|
122
122
|
keys = [v for v in mapping.as_dict().values() if v is not None]
|
|
123
123
|
if variable_keys is None:
|
|
124
|
-
variable_keys = _select_variable_keys(data,keys)
|
|
124
|
+
variable_keys = _select_variable_keys(data, keys)
|
|
125
125
|
else:
|
|
126
|
-
list(variable_keys).extend(_select_variable_keys(data,keys))
|
|
126
|
+
list(variable_keys).extend(_select_variable_keys(data, keys))
|
|
127
127
|
|
|
128
128
|
axis = axis or _determine_axis(data=data, keys=keys)
|
|
129
129
|
# BUILD: the scatter plot
|
|
@@ -210,15 +210,15 @@ def xyplots(
|
|
|
210
210
|
|
|
211
211
|
scttrs = gggrid(
|
|
212
212
|
plots,
|
|
213
|
-
ncol=ncol,
|
|
214
|
-
sharex=sharex,
|
|
215
|
-
sharey=sharey,
|
|
216
|
-
widths=widths,
|
|
217
|
-
heights=heights,
|
|
218
|
-
hspace=hspace,
|
|
219
|
-
vspace=vspace,
|
|
220
|
-
fit=fit,
|
|
221
|
-
align=align,
|
|
213
|
+
ncol=ncol, # ty:ignore[invalid-argument-type]
|
|
214
|
+
sharex=sharex, # ty:ignore[invalid-argument-type]
|
|
215
|
+
sharey=sharey, # ty:ignore[invalid-argument-type]
|
|
216
|
+
widths=widths, # ty:ignore[invalid-argument-type]
|
|
217
|
+
heights=heights, # ty:ignore[invalid-argument-type]
|
|
218
|
+
hspace=hspace, # ty:ignore[invalid-argument-type]
|
|
219
|
+
vspace=vspace, # ty:ignore[invalid-argument-type]
|
|
220
|
+
fit=fit, # ty:ignore[invalid-argument-type]
|
|
221
|
+
align=align, # ty:ignore[invalid-argument-type]
|
|
222
222
|
guides=guides,
|
|
223
223
|
)
|
|
224
224
|
|
|
@@ -99,7 +99,9 @@ def _distribution(
|
|
|
99
99
|
point_kwargs = {} if point_kwargs is None else dict(point_kwargs)
|
|
100
100
|
|
|
101
101
|
# determine index to unpivot
|
|
102
|
-
index = list(
|
|
102
|
+
index = list(
|
|
103
|
+
dict.fromkeys(c for c in (group_by, mapping_fill, mapping_color) if c is not None)
|
|
104
|
+
)
|
|
103
105
|
if add_keys is not None:
|
|
104
106
|
if isinstance(add_keys, str):
|
|
105
107
|
add_keys = [add_keys]
|
|
@@ -254,15 +254,15 @@ def violins(
|
|
|
254
254
|
|
|
255
255
|
dsts = gggrid(
|
|
256
256
|
plots,
|
|
257
|
-
ncol=ncol,
|
|
258
|
-
sharex=sharex,
|
|
259
|
-
sharey=sharey,
|
|
260
|
-
widths=widths,
|
|
261
|
-
heights=heights,
|
|
262
|
-
hspace=hspace,
|
|
263
|
-
vspace=vspace,
|
|
264
|
-
fit=fit,
|
|
265
|
-
align=align,
|
|
257
|
+
ncol=ncol, # ty:ignore[invalid-argument-type]
|
|
258
|
+
sharex=sharex, # ty:ignore[invalid-argument-type]
|
|
259
|
+
sharey=sharey, # ty:ignore[invalid-argument-type]
|
|
260
|
+
widths=widths, # ty:ignore[invalid-argument-type]
|
|
261
|
+
heights=heights, # ty:ignore[invalid-argument-type]
|
|
262
|
+
hspace=hspace, # ty:ignore[invalid-argument-type]
|
|
263
|
+
vspace=vspace, # ty:ignore[invalid-argument-type]
|
|
264
|
+
fit=fit, # ty:ignore[invalid-argument-type]
|
|
265
|
+
align=align, # ty:ignore[invalid-argument-type]
|
|
266
266
|
guides=guides,
|
|
267
267
|
)
|
|
268
268
|
|
|
@@ -509,15 +509,15 @@ def boxplots(
|
|
|
509
509
|
|
|
510
510
|
dsts = gggrid(
|
|
511
511
|
plots,
|
|
512
|
-
ncol=ncol,
|
|
513
|
-
sharex=sharex,
|
|
514
|
-
sharey=sharey,
|
|
515
|
-
widths=widths,
|
|
516
|
-
heights=heights,
|
|
517
|
-
hspace=hspace,
|
|
518
|
-
vspace=vspace,
|
|
519
|
-
fit=fit,
|
|
520
|
-
align=align,
|
|
512
|
+
ncol=ncol, # ty:ignore[invalid-argument-type]
|
|
513
|
+
sharex=sharex, # ty:ignore[invalid-argument-type]
|
|
514
|
+
sharey=sharey, # ty:ignore[invalid-argument-type]
|
|
515
|
+
widths=widths, # ty:ignore[invalid-argument-type]
|
|
516
|
+
heights=heights, # ty:ignore[invalid-argument-type]
|
|
517
|
+
hspace=hspace, # ty:ignore[invalid-argument-type]
|
|
518
|
+
vspace=vspace, # ty:ignore[invalid-argument-type]
|
|
519
|
+
fit=fit, # ty:ignore[invalid-argument-type]
|
|
520
|
+
align=align, # ty:ignore[invalid-argument-type]
|
|
521
521
|
guides=guides,
|
|
522
522
|
)
|
|
523
523
|
|
|
@@ -153,7 +153,7 @@ def _build_markers_frame(
|
|
|
153
153
|
frame = pl.concat(group_frames)
|
|
154
154
|
|
|
155
155
|
params = record["params"]
|
|
156
|
-
stored_group_by = params
|
|
156
|
+
stored_group_by = params.get("groupby")
|
|
157
157
|
if stored_group_by is None:
|
|
158
158
|
msg = (
|
|
159
159
|
f"`adata.uns[{uns_key!r}]['params']` is missing 'groupby'; "
|
|
@@ -426,19 +426,22 @@ def markers(
|
|
|
426
426
|
|
|
427
427
|
plots.append(plot)
|
|
428
428
|
|
|
429
|
-
grid =
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
429
|
+
grid = (
|
|
430
|
+
gggrid(
|
|
431
|
+
plots,
|
|
432
|
+
ncol=ncol, # ty:ignore[invalid-argument-type]
|
|
433
|
+
sharex=sharex, # ty:ignore[invalid-argument-type]
|
|
434
|
+
sharey=sharey, # ty:ignore[invalid-argument-type]
|
|
435
|
+
widths=widths, # ty:ignore[invalid-argument-type]
|
|
436
|
+
heights=heights, # ty:ignore[invalid-argument-type]
|
|
437
|
+
hspace=hspace, # ty:ignore[invalid-argument-type]
|
|
438
|
+
vspace=vspace, # ty:ignore[invalid-argument-type]
|
|
439
|
+
fit=fit, # ty:ignore[invalid-argument-type]
|
|
440
|
+
align=align, # ty:ignore[invalid-argument-type]
|
|
441
|
+
guides=guides,
|
|
442
|
+
)
|
|
443
|
+
+ theme_bw()
|
|
444
|
+
)
|
|
442
445
|
|
|
443
446
|
if interactive:
|
|
444
447
|
grid += ggtb(size_zoomin=-1)
|
|
@@ -181,6 +181,7 @@ def _build_volcano_frame(
|
|
|
181
181
|
|
|
182
182
|
return frame
|
|
183
183
|
|
|
184
|
+
|
|
184
185
|
def volcano(
|
|
185
186
|
data: AnnData,
|
|
186
187
|
group: str,
|
|
@@ -377,9 +378,9 @@ def volcano(
|
|
|
377
378
|
# CAP: rows where -log10(pvalue) underflowed to +inf (pvalue == 0)
|
|
378
379
|
# Dropping them would silently hide the most significant features (and their labels).
|
|
379
380
|
# Push them just above the densest finite cluster instead.
|
|
380
|
-
finite_max = (
|
|
381
|
-
|
|
382
|
-
)
|
|
381
|
+
finite_max = frame.filter(pl.col(neg_log_pvalue_column).is_finite())[
|
|
382
|
+
neg_log_pvalue_column
|
|
383
|
+
].max()
|
|
383
384
|
cap = (finite_max or 0.0) * 1.05 + 1.0
|
|
384
385
|
frame = frame.with_columns(
|
|
385
386
|
pl.when(pl.col(neg_log_pvalue_column).is_finite())
|
|
@@ -41,10 +41,7 @@ def _resolve_key_groups(
|
|
|
41
41
|
groups: dict[str, list[str]] = {}
|
|
42
42
|
for label, values in grouped_keys.items():
|
|
43
43
|
if isinstance(values, str):
|
|
44
|
-
msg =
|
|
45
|
-
f"Keys for group {label!r} must be a sequence of strings, "
|
|
46
|
-
"not a single string."
|
|
47
|
-
)
|
|
44
|
+
msg = f"Keys for group {label!r} must be a sequence of strings, not a single string."
|
|
48
45
|
raise TypeError(msg)
|
|
49
46
|
groups[label] = list(values)
|
|
50
47
|
flat: list[str] = []
|
|
@@ -110,9 +107,7 @@ _Y_CHAR_WIDTH_PER_SIZE = 0.40
|
|
|
110
107
|
_Y_PADDING_SAFETY_FRACTION = 0.030
|
|
111
108
|
|
|
112
109
|
|
|
113
|
-
def _label_size_absolute(
|
|
114
|
-
groups: dict[str, list[str]], *, scale: float = 1.0
|
|
115
|
-
) -> float:
|
|
110
|
+
def _label_size_absolute(groups: dict[str, list[str]], *, scale: float = 1.0) -> float:
|
|
116
111
|
"""Label size in absolute lets-plot text units (used without ``size_unit``)."""
|
|
117
112
|
n_keys = sum(len(values) for values in groups.values())
|
|
118
113
|
max_chars = max((len(label) for label in groups), default=0)
|
|
@@ -129,9 +124,7 @@ def _label_size_absolute(
|
|
|
129
124
|
return max(_ABS_LABEL_TEXT_SIZE_MIN, size * scale)
|
|
130
125
|
|
|
131
126
|
|
|
132
|
-
def _label_size_y_units(
|
|
133
|
-
groups: dict[str, list[str]], *, span: float, scale: float = 1.0
|
|
134
|
-
) -> float:
|
|
127
|
+
def _label_size_y_units(groups: dict[str, list[str]], *, span: float, scale: float = 1.0) -> float:
|
|
135
128
|
"""
|
|
136
129
|
Label size in y-axis units (used with ``geom_text(size_unit='y')``).
|
|
137
130
|
|
|
@@ -142,9 +135,7 @@ def _label_size_y_units(
|
|
|
142
135
|
max_chars = max((len(label) for label in groups), default=0)
|
|
143
136
|
visual_fraction = _Y_LABEL_VISUAL_CAP_FRACTION
|
|
144
137
|
if max_chars > _Y_LABEL_LONG_THRESHOLD:
|
|
145
|
-
visual_fraction *= max(
|
|
146
|
-
_Y_LABEL_LONG_MIN_FRACTION, _Y_LABEL_LONG_THRESHOLD / max_chars
|
|
147
|
-
)
|
|
138
|
+
visual_fraction *= max(_Y_LABEL_LONG_MIN_FRACTION, _Y_LABEL_LONG_THRESHOLD / max_chars)
|
|
148
139
|
return max(_Y_LABEL_SIZE_FLOOR, visual_fraction * span * scale)
|
|
149
140
|
|
|
150
141
|
|
|
@@ -181,10 +172,7 @@ def _resolve_padding(
|
|
|
181
172
|
_BAR_OFFSET_FRACTION
|
|
182
173
|
+ _LABEL_GAP_FRACTION
|
|
183
174
|
+ _ABS_LABEL_PADDING_BASE_FRACTION
|
|
184
|
-
+ _ABS_LABEL_PADDING_PER_CHAR_SIZE_FRACTION
|
|
185
|
-
* max_chars
|
|
186
|
-
* label_size
|
|
187
|
-
* density_scale,
|
|
175
|
+
+ _ABS_LABEL_PADDING_PER_CHAR_SIZE_FRACTION * max_chars * label_size * density_scale,
|
|
188
176
|
_ABS_LABEL_PADDING_MAX_TARGET_FRACTION,
|
|
189
177
|
)
|
|
190
178
|
resolved = target_fraction * data / (1.0 - target_fraction) * scale
|
|
@@ -194,9 +182,7 @@ def _resolve_padding(
|
|
|
194
182
|
|
|
195
183
|
# y-unit mode: padding fits the rotated text extent directly in y units.
|
|
196
184
|
approx_total_span = data * 1.3
|
|
197
|
-
label_size = _label_size_y_units(
|
|
198
|
-
groups, span=approx_total_span, scale=label_size_scale
|
|
199
|
-
)
|
|
185
|
+
label_size = _label_size_y_units(groups, span=approx_total_span, scale=label_size_scale)
|
|
200
186
|
text_extent = max_chars * _Y_CHAR_WIDTH_PER_SIZE * label_size
|
|
201
187
|
bar_offset = _BAR_OFFSET_FRACTION * data
|
|
202
188
|
label_gap = _LABEL_GAP_FRACTION * data
|
|
@@ -14,7 +14,7 @@ if TYPE_CHECKING:
|
|
|
14
14
|
_DEFAULT_RANK_GENES_KEY = "rank_genes_groups"
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
def _resolve_rank_genes_groups_key(rank_genes_groups: bool | str) -> str:
|
|
17
|
+
def _resolve_rank_genes_groups_key(rank_genes_groups: bool | str) -> str: # noqa: FBT001
|
|
18
18
|
"""Translate the user-facing flag into the ``adata.uns`` key to read."""
|
|
19
19
|
if rank_genes_groups is True:
|
|
20
20
|
return _DEFAULT_RANK_GENES_KEY
|
|
@@ -133,7 +133,7 @@ def _extract_rank_genes_groups(
|
|
|
133
133
|
)
|
|
134
134
|
|
|
135
135
|
params = record["params"]
|
|
136
|
-
stored_group_by = params
|
|
136
|
+
stored_group_by = params.get("groupby")
|
|
137
137
|
if stored_group_by is None:
|
|
138
138
|
msg = (
|
|
139
139
|
f"`adata.uns[{uns_key!r}]['params']` is missing 'groupby'; "
|
|
@@ -270,10 +270,7 @@ def dotplot(
|
|
|
270
270
|
group_by=group_by,
|
|
271
271
|
)
|
|
272
272
|
elif keys is None or group_by is None:
|
|
273
|
-
msg = (
|
|
274
|
-
"`keys` and `group_by` are required "
|
|
275
|
-
"(or enable `markers` to derive them)."
|
|
276
|
-
)
|
|
273
|
+
msg = "`keys` and `group_by` are required (or enable `markers` to derive them)."
|
|
277
274
|
raise ValueError(msg)
|
|
278
275
|
|
|
279
276
|
mapping = mapping or aes()
|
|
@@ -323,10 +320,7 @@ def dotplot(
|
|
|
323
320
|
# HANDLE: Sorting pseudo-categorical integer labels numerically when possible.
|
|
324
321
|
numeric_group_by = "__cellestial_group_by_numeric"
|
|
325
322
|
frame = frame.with_columns(
|
|
326
|
-
pl.col(group_by)
|
|
327
|
-
.cast(pl.String)
|
|
328
|
-
.cast(pl.Int64, strict=False)
|
|
329
|
-
.alias(numeric_group_by)
|
|
323
|
+
pl.col(group_by).cast(pl.String).cast(pl.Int64, strict=False).alias(numeric_group_by)
|
|
330
324
|
)
|
|
331
325
|
if frame[numeric_group_by].null_count() == 0:
|
|
332
326
|
frame = (
|
|
@@ -187,6 +187,7 @@ def _get_group_lines_frame(
|
|
|
187
187
|
}
|
|
188
188
|
)
|
|
189
189
|
|
|
190
|
+
|
|
190
191
|
def heatmap(
|
|
191
192
|
data: AnnData,
|
|
192
193
|
keys: Sequence[str] | Mapping[str, Sequence[str]] | None = None,
|
|
@@ -454,10 +455,7 @@ def heatmap(
|
|
|
454
455
|
group_by=group_by,
|
|
455
456
|
)
|
|
456
457
|
elif keys is None or group_by is None:
|
|
457
|
-
msg = (
|
|
458
|
-
"`keys` and `group_by` are required "
|
|
459
|
-
"(or enable `markers` to derive them)."
|
|
460
|
-
)
|
|
458
|
+
msg = "`keys` and `group_by` are required (or enable `markers` to derive them)."
|
|
461
459
|
raise ValueError(msg)
|
|
462
460
|
|
|
463
461
|
mapping = mapping or aes()
|
|
@@ -646,6 +644,7 @@ def heatmap(
|
|
|
646
644
|
|
|
647
645
|
return htmp
|
|
648
646
|
|
|
647
|
+
|
|
649
648
|
def matrixplot(
|
|
650
649
|
data: AnnData,
|
|
651
650
|
keys: Sequence[str] | Mapping[str, Sequence[str]] | None = None,
|
|
@@ -422,10 +422,7 @@ def stacked_violin(
|
|
|
422
422
|
group_by=group_by,
|
|
423
423
|
)
|
|
424
424
|
elif keys is None or group_by is None:
|
|
425
|
-
msg = (
|
|
426
|
-
"`keys` and `group_by` are required "
|
|
427
|
-
"(or enable `markers` to derive them)."
|
|
428
|
-
)
|
|
425
|
+
msg = "`keys` and `group_by` are required (or enable `markers` to derive them)."
|
|
429
426
|
raise ValueError(msg)
|
|
430
427
|
|
|
431
428
|
mapping = mapping or aes()
|
|
@@ -29,6 +29,7 @@ if TYPE_CHECKING:
|
|
|
29
29
|
from lets_plot.plot.core import PlotSpec
|
|
30
30
|
from lets_plot.plot.subplots import SupPlotsSpec
|
|
31
31
|
|
|
32
|
+
|
|
32
33
|
def ridge(
|
|
33
34
|
data: AnnData,
|
|
34
35
|
key: str,
|
|
@@ -199,6 +200,7 @@ def ridge(
|
|
|
199
200
|
|
|
200
201
|
return rdg + scale_fill_hue()
|
|
201
202
|
|
|
203
|
+
|
|
202
204
|
def ridges(
|
|
203
205
|
data: AnnData,
|
|
204
206
|
keys: Sequence[str],
|
|
@@ -363,15 +365,15 @@ def ridges(
|
|
|
363
365
|
|
|
364
366
|
rdgs = gggrid(
|
|
365
367
|
plots,
|
|
366
|
-
ncol=ncol,
|
|
367
|
-
sharex=sharex,
|
|
368
|
-
sharey=sharey,
|
|
369
|
-
widths=widths,
|
|
370
|
-
heights=heights,
|
|
371
|
-
hspace=hspace,
|
|
372
|
-
vspace=vspace,
|
|
373
|
-
fit=fit,
|
|
374
|
-
align=align,
|
|
368
|
+
ncol=ncol, # ty:ignore[invalid-argument-type]
|
|
369
|
+
sharex=sharex, # ty:ignore[invalid-argument-type]
|
|
370
|
+
sharey=sharey, # ty:ignore[invalid-argument-type]
|
|
371
|
+
widths=widths, # ty:ignore[invalid-argument-type]
|
|
372
|
+
heights=heights, # ty:ignore[invalid-argument-type]
|
|
373
|
+
hspace=hspace, # ty:ignore[invalid-argument-type]
|
|
374
|
+
vspace=vspace, # ty:ignore[invalid-argument-type]
|
|
375
|
+
fit=fit, # ty:ignore[invalid-argument-type]
|
|
376
|
+
align=align, # ty:ignore[invalid-argument-type]
|
|
375
377
|
guides=guides,
|
|
376
378
|
)
|
|
377
379
|
|
|
@@ -46,9 +46,7 @@ def _element_in_coordinate_system(elem, coordinate_system: str) -> bool:
|
|
|
46
46
|
return coordinate_system in get_transformation(elem, get_all=True)
|
|
47
47
|
|
|
48
48
|
|
|
49
|
-
def _resolve_shapes_name(
|
|
50
|
-
data: SpatialData, shapes_name: str | None, table: AnnData
|
|
51
|
-
) -> str:
|
|
49
|
+
def _resolve_shapes_name(data: SpatialData, shapes_name: str | None, table: AnnData) -> str:
|
|
52
50
|
"""Pick a shapes element, falling back to the table's annotated region."""
|
|
53
51
|
if shapes_name is not None:
|
|
54
52
|
if shapes_name not in data.shapes:
|
|
@@ -78,10 +76,7 @@ def _resolve_coordinate_system(
|
|
|
78
76
|
|
|
79
77
|
if coordinate_system is not None:
|
|
80
78
|
if coordinate_system not in systems:
|
|
81
|
-
msg =
|
|
82
|
-
f"coordinate_system `{coordinate_system}` not found. "
|
|
83
|
-
f"Available: {systems}"
|
|
84
|
-
)
|
|
79
|
+
msg = f"coordinate_system `{coordinate_system}` not found. Available: {systems}"
|
|
85
80
|
raise KeyError(msg)
|
|
86
81
|
return coordinate_system
|
|
87
82
|
|
|
@@ -97,14 +92,10 @@ def _resolve_coordinate_system(
|
|
|
97
92
|
return True
|
|
98
93
|
if image_name is not None:
|
|
99
94
|
return _element_in_coordinate_system(data.images[image_name], cs)
|
|
100
|
-
return any(
|
|
101
|
-
_element_in_coordinate_system(img, cs) for img in data.images.values()
|
|
102
|
-
)
|
|
95
|
+
return any(_element_in_coordinate_system(img, cs) for img in data.images.values())
|
|
103
96
|
|
|
104
97
|
candidates = [
|
|
105
|
-
cs
|
|
106
|
-
for cs in systems
|
|
107
|
-
if _element_in_coordinate_system(shapes_elem, cs) and _has_image(cs)
|
|
98
|
+
cs for cs in systems if _element_in_coordinate_system(shapes_elem, cs) and _has_image(cs)
|
|
108
99
|
]
|
|
109
100
|
if len(candidates) == 1:
|
|
110
101
|
return candidates[0]
|
|
@@ -117,9 +108,7 @@ def _resolve_coordinate_system(
|
|
|
117
108
|
cs
|
|
118
109
|
for cs in candidates
|
|
119
110
|
if [
|
|
120
|
-
name
|
|
121
|
-
for name, img in data.images.items()
|
|
122
|
-
if _element_in_coordinate_system(img, cs)
|
|
111
|
+
name for name, img in data.images.items() if _element_in_coordinate_system(img, cs)
|
|
123
112
|
]
|
|
124
113
|
== [image_name]
|
|
125
114
|
]
|
|
@@ -127,8 +116,7 @@ def _resolve_coordinate_system(
|
|
|
127
116
|
return specialised[0]
|
|
128
117
|
|
|
129
118
|
msg = (
|
|
130
|
-
f"Multiple coordinate systems present: {systems}. "
|
|
131
|
-
"Pass `coordinate_system=` to select one."
|
|
119
|
+
f"Multiple coordinate systems present: {systems}. Pass `coordinate_system=` to select one."
|
|
132
120
|
)
|
|
133
121
|
raise ValueError(msg)
|
|
134
122
|
|
|
@@ -262,9 +250,7 @@ def spatialdata_components(
|
|
|
262
250
|
want_image=image,
|
|
263
251
|
)
|
|
264
252
|
chosen_image_name = (
|
|
265
|
-
_resolve_image_name(data, image_name, coordinate_system=target_cs)
|
|
266
|
-
if image
|
|
267
|
-
else None
|
|
253
|
+
_resolve_image_name(data, image_name, coordinate_system=target_cs) if image else None
|
|
268
254
|
)
|
|
269
255
|
|
|
270
256
|
# spatialdata's transform mutates the underlying GeoDataFrame via chained
|
|
@@ -276,9 +262,7 @@ def spatialdata_components(
|
|
|
276
262
|
category=FutureWarning,
|
|
277
263
|
module=r"geopandas\..*",
|
|
278
264
|
)
|
|
279
|
-
shapes_geo = data.transform_element_to_coordinate_system(
|
|
280
|
-
chosen_shapes_name, target_cs
|
|
281
|
-
)
|
|
265
|
+
shapes_geo = data.transform_element_to_coordinate_system(chosen_shapes_name, target_cs)
|
|
282
266
|
|
|
283
267
|
geom_types = set(shapes_geo.geometry.geom_type.unique())
|
|
284
268
|
spot_coordinates: NDArray | None = None
|
|
@@ -292,9 +276,7 @@ def spatialdata_components(
|
|
|
292
276
|
polygon_frame = _polygon_vertex_frame(shapes_geo)
|
|
293
277
|
else:
|
|
294
278
|
centroids = shapes_geo.geometry.centroid
|
|
295
|
-
spot_coordinates = np.column_stack(
|
|
296
|
-
[centroids.x.to_numpy(), centroids.y.to_numpy()]
|
|
297
|
-
)
|
|
279
|
+
spot_coordinates = np.column_stack([centroids.x.to_numpy(), centroids.y.to_numpy()])
|
|
298
280
|
else:
|
|
299
281
|
msg = (
|
|
300
282
|
f"Shapes element `{chosen_shapes_name}` contains "
|
|
@@ -304,9 +286,7 @@ def spatialdata_components(
|
|
|
304
286
|
|
|
305
287
|
image_array = None
|
|
306
288
|
if image and chosen_image_name is not None:
|
|
307
|
-
image_elem = data.transform_element_to_coordinate_system(
|
|
308
|
-
chosen_image_name, target_cs
|
|
309
|
-
)
|
|
289
|
+
image_elem = data.transform_element_to_coordinate_system(chosen_image_name, target_cs)
|
|
310
290
|
image_array = _image_to_yxc(image_elem)
|
|
311
291
|
|
|
312
292
|
return image_array, spot_coordinates, polygon_frame, table
|
|
@@ -126,7 +126,7 @@ def spatial(
|
|
|
126
126
|
*,
|
|
127
127
|
library_id: str | None = None,
|
|
128
128
|
image: bool = True,
|
|
129
|
-
image_key: Literal["hires", "lowres"] | str = "
|
|
129
|
+
image_key: Literal["hires", "lowres"] | str = "lowres",
|
|
130
130
|
greyscale: bool = False,
|
|
131
131
|
image_alpha: float | None = None,
|
|
132
132
|
cmap: str | list | None = None,
|
|
@@ -174,7 +174,7 @@ def spatial(
|
|
|
174
174
|
Ignored for SpatialData inputs.
|
|
175
175
|
image : bool, default=True
|
|
176
176
|
Whether to render the tissue image as a background layer.
|
|
177
|
-
image_key : str, default='
|
|
177
|
+
image_key : str, default='lowres'
|
|
178
178
|
Which image variant to render. Visium ships with 'hires' and 'lowres'.
|
|
179
179
|
Ignored for SpatialData inputs.
|
|
180
180
|
greyscale : bool, default=False
|
|
@@ -21,7 +21,7 @@ def spatials(
|
|
|
21
21
|
*,
|
|
22
22
|
library_id: str | None = None,
|
|
23
23
|
image: bool = True,
|
|
24
|
-
image_key: Literal["hires", "lowres"] | str = "
|
|
24
|
+
image_key: Literal["hires", "lowres"] | str = "lowres",
|
|
25
25
|
greyscale: bool = False,
|
|
26
26
|
image_alpha: float | None = None,
|
|
27
27
|
cmap: str | list | None = None,
|
|
@@ -83,7 +83,7 @@ def spatials(
|
|
|
83
83
|
Ignored for SpatialData inputs.
|
|
84
84
|
image : bool, default=True
|
|
85
85
|
Whether to render the tissue image as a background layer.
|
|
86
|
-
image_key : str, default='
|
|
86
|
+
image_key : str, default='lowres'
|
|
87
87
|
Which image variant to render. Visium ships with 'hires' and 'lowres'.
|
|
88
88
|
Ignored for SpatialData inputs.
|
|
89
89
|
greyscale : bool, default=False
|
|
@@ -7,32 +7,26 @@ from lets_plot import (
|
|
|
7
7
|
theme_classic,
|
|
8
8
|
)
|
|
9
9
|
|
|
10
|
-
_THEME_DIMENSION = (
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
legend_text=element_text(color="#1f1f1f", size=11, face="plain"),
|
|
21
|
-
# customize legend columns
|
|
22
|
-
)
|
|
10
|
+
_THEME_DIMENSION = theme_classic() + theme(
|
|
11
|
+
# customize all text
|
|
12
|
+
text=element_text(color="#1f1f1f", family="Arial"),
|
|
13
|
+
# customize all titles (includes legend)
|
|
14
|
+
title=element_text(color="#1f1f1f", family="Arial"),
|
|
15
|
+
# customize axis titles (labels)
|
|
16
|
+
axis_title=element_text(color="#3f3f3f", family="Arial"),
|
|
17
|
+
# customize legend text
|
|
18
|
+
legend_text=element_text(color="#1f1f1f", size=11, face="plain"),
|
|
19
|
+
# customize legend columns
|
|
23
20
|
)
|
|
24
21
|
|
|
25
|
-
_THEME_SPATIAL = (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
axis_line=element_blank(),
|
|
34
|
-
legend_text=element_text(color="#1f1f1f", size=11, face="plain"),
|
|
35
|
-
)
|
|
22
|
+
_THEME_SPATIAL = theme_classic() + theme(
|
|
23
|
+
text=element_text(color="#1f1f1f", family="Arial"),
|
|
24
|
+
title=element_text(color="#1f1f1f", family="Arial"),
|
|
25
|
+
axis_title=element_blank(),
|
|
26
|
+
axis_text=element_blank(),
|
|
27
|
+
axis_ticks=element_blank(),
|
|
28
|
+
axis_line=element_blank(),
|
|
29
|
+
legend_text=element_text(color="#1f1f1f", size=11, face="plain"),
|
|
36
30
|
)
|
|
37
31
|
|
|
38
32
|
_THEME_SCATTER = theme(
|
|
@@ -72,7 +66,7 @@ _THEME_DOTPLOT = (
|
|
|
72
66
|
legend_box_spacing=0,
|
|
73
67
|
legend_key_spacing_y=0,
|
|
74
68
|
)
|
|
75
|
-
|
|
76
|
-
|
|
69
|
+
# + scale_y_discrete(expand=[0.05, 0.05]) # offsets for points from the frame
|
|
70
|
+
# + scale_x_discrete(expand=[0.025, 0.025])
|
|
77
71
|
+ scale_size(trans="sqrt", breaks=[25, 50, 75, 100]) # to be replaced by scale_size_area
|
|
78
72
|
)
|
|
@@ -2,7 +2,7 @@ from cellestial.util.dendrogram import (
|
|
|
2
2
|
_get_dendrogram,
|
|
3
3
|
_get_dendrogram_path_frame,
|
|
4
4
|
)
|
|
5
|
-
from cellestial.util.operations import
|
|
5
|
+
from cellestial.util.operations import get_figure, get_figures, get_mapping, retrieve
|
|
6
6
|
from cellestial.util.save import save
|
|
7
7
|
from cellestial.util.utilities import (
|
|
8
8
|
_color_gradient,
|
|
@@ -38,8 +38,9 @@ __all__ = [
|
|
|
38
38
|
"_tooltip_fields",
|
|
39
39
|
"_validate_tooltips",
|
|
40
40
|
"_warn",
|
|
41
|
+
"get_figure",
|
|
42
|
+
"get_figures",
|
|
41
43
|
"get_mapping",
|
|
42
|
-
"get_slice",
|
|
43
44
|
"retrieve",
|
|
44
|
-
"save"
|
|
45
|
+
"save",
|
|
45
46
|
]
|
|
@@ -11,32 +11,35 @@ if TYPE_CHECKING:
|
|
|
11
11
|
from polars import DataFrame
|
|
12
12
|
|
|
13
13
|
|
|
14
|
-
def
|
|
15
|
-
|
|
16
|
-
)
|
|
14
|
+
def _grid_figures(grid: SupPlotsSpec) -> list[PlotSpec]:
|
|
15
|
+
# Lets-Plot does not expose the underlying PlotSpec list on SupPlotsSpec;
|
|
16
|
+
# `.as_dict()["figures"]` returns serialized dicts that `gggrid` cannot consume.
|
|
17
|
+
# Name-mangled access is the only path to the live PlotSpec objects.
|
|
18
|
+
return vars(grid)["_SupPlotsSpec__figures"]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def get_figure(grid: SupPlotsSpec, index: int) -> PlotSpec:
|
|
17
22
|
"""
|
|
18
|
-
|
|
23
|
+
Get a single figure from a grid (SupPlotsSpec) by index.
|
|
19
24
|
|
|
20
25
|
Parameters
|
|
21
26
|
----------
|
|
22
27
|
grid : SupPlotsSpec
|
|
23
|
-
The grid to
|
|
24
|
-
index : int
|
|
25
|
-
The index
|
|
26
|
-
**kwargs : dict[str, Any]
|
|
27
|
-
Additional arguments for the `gggrid` function.
|
|
28
|
-
see: https://lets-plot.org/python/pages/api/lets_plot.gggrid.html
|
|
28
|
+
The grid to pull a figure from.
|
|
29
|
+
index : int
|
|
30
|
+
The index of the figure to return. Negative indices are supported.
|
|
29
31
|
|
|
30
32
|
Returns
|
|
31
33
|
-------
|
|
32
|
-
PlotSpec
|
|
33
|
-
The
|
|
34
|
+
PlotSpec
|
|
35
|
+
The selected figure.
|
|
34
36
|
|
|
35
37
|
Raises
|
|
36
38
|
------
|
|
37
39
|
TypeError
|
|
38
|
-
If
|
|
39
|
-
|
|
40
|
+
If `grid` is not a SupPlotsSpec or `index` is not an int.
|
|
41
|
+
IndexError
|
|
42
|
+
If `index` is out of range for the grid.
|
|
40
43
|
|
|
41
44
|
Examples
|
|
42
45
|
--------
|
|
@@ -59,9 +62,52 @@ def get_slice(
|
|
|
59
62
|
ncol=2,
|
|
60
63
|
)
|
|
61
64
|
|
|
62
|
-
cl.
|
|
65
|
+
cl.get_figure(grid, index=3)
|
|
66
|
+
|
|
67
|
+
"""
|
|
68
|
+
if not isinstance(grid, SupPlotsSpec):
|
|
69
|
+
msg = f"Expected `SupPlotsSpec`, but received {type(grid)}"
|
|
70
|
+
raise TypeError(msg)
|
|
71
|
+
if not isinstance(index, int) or isinstance(index, bool):
|
|
72
|
+
msg = f"Expected int for index, but received {type(index)}"
|
|
73
|
+
raise TypeError(msg)
|
|
74
|
+
|
|
75
|
+
figures = _grid_figures(grid)
|
|
76
|
+
if not -len(figures) <= index < len(figures):
|
|
77
|
+
msg = f"index {index} is out of range for a grid with {len(figures)} figures."
|
|
78
|
+
raise IndexError(msg)
|
|
79
|
+
return figures[index]
|
|
63
80
|
|
|
64
|
-
|
|
81
|
+
|
|
82
|
+
def get_figures(grid: SupPlotsSpec, indices: Sequence[int], **kwargs) -> SupPlotsSpec:
|
|
83
|
+
"""
|
|
84
|
+
Get multiple figures from a grid (SupPlotsSpec) as a new grid.
|
|
85
|
+
|
|
86
|
+
Parameters
|
|
87
|
+
----------
|
|
88
|
+
grid : SupPlotsSpec
|
|
89
|
+
The grid to pull figures from.
|
|
90
|
+
indices : Sequence[int]
|
|
91
|
+
The indices of the figures to include. Negative indices are supported.
|
|
92
|
+
**kwargs : dict[str, Any]
|
|
93
|
+
Additional arguments forwarded to `gggrid`.
|
|
94
|
+
see: https://lets-plot.org/python/pages/api/lets_plot.gggrid.html
|
|
95
|
+
|
|
96
|
+
Returns
|
|
97
|
+
-------
|
|
98
|
+
SupPlotsSpec
|
|
99
|
+
A new grid containing the selected figures.
|
|
100
|
+
|
|
101
|
+
Raises
|
|
102
|
+
------
|
|
103
|
+
TypeError
|
|
104
|
+
If `grid` is not a SupPlotsSpec or `indices` is not a Sequence of ints.
|
|
105
|
+
IndexError
|
|
106
|
+
If any value in `indices` is out of range for the grid.
|
|
107
|
+
|
|
108
|
+
Examples
|
|
109
|
+
--------
|
|
110
|
+
Get multiple plots from a grid.
|
|
65
111
|
|
|
66
112
|
.. jupyter-execute ::
|
|
67
113
|
|
|
@@ -80,25 +126,22 @@ def get_slice(
|
|
|
80
126
|
ncol=2,
|
|
81
127
|
)
|
|
82
128
|
|
|
83
|
-
cl.
|
|
129
|
+
cl.get_figures(grid, indices=[1, 3])
|
|
84
130
|
|
|
85
131
|
"""
|
|
86
|
-
if isinstance(grid, SupPlotsSpec):
|
|
87
|
-
figures = vars(grid).get("_SupPlotsSpec__figures")
|
|
88
|
-
|
|
89
|
-
if figures is not None:
|
|
90
|
-
if isinstance(index, int):
|
|
91
|
-
plot = figures[index]
|
|
92
|
-
return plot
|
|
93
|
-
elif isinstance(index, Sequence):
|
|
94
|
-
list_plots = [figures[i] for i in index]
|
|
95
|
-
return gggrid(list_plots, **kwargs)
|
|
96
|
-
else:
|
|
97
|
-
msg = f"Expected int or Sequence for index, but received {type(index)}"
|
|
98
|
-
raise TypeError(msg)
|
|
99
|
-
else:
|
|
132
|
+
if not isinstance(grid, SupPlotsSpec):
|
|
100
133
|
msg = f"Expected `SupPlotsSpec`, but received {type(grid)}"
|
|
101
134
|
raise TypeError(msg)
|
|
135
|
+
if not isinstance(indices, Sequence) or isinstance(indices, str):
|
|
136
|
+
msg = f"Expected Sequence[int] for indices, but received {type(indices)}"
|
|
137
|
+
raise TypeError(msg)
|
|
138
|
+
|
|
139
|
+
figures = _grid_figures(grid)
|
|
140
|
+
out_of_range = [i for i in indices if not -len(figures) <= i < len(figures)]
|
|
141
|
+
if out_of_range:
|
|
142
|
+
msg = f"indices {out_of_range} are out of range for a grid with {len(figures)} figures"
|
|
143
|
+
raise IndexError(msg)
|
|
144
|
+
return gggrid([figures[i] for i in indices], **kwargs)
|
|
102
145
|
|
|
103
146
|
|
|
104
147
|
def get_mapping(plot: PlotSpec, *, index: int = 0) -> dict:
|
|
@@ -29,9 +29,7 @@ from cellestial.util.errors import CellestialWarning
|
|
|
29
29
|
_PACKAGE_ROOT = str(Path(__file__).parents[1])
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
def _format_warning(
|
|
33
|
-
message: Warning | str, category: type[Warning], *_args: object
|
|
34
|
-
) -> str:
|
|
32
|
+
def _format_warning(message: Warning | str, category: type[Warning], *_args: object) -> str:
|
|
35
33
|
"""Render a cellestial warning as one line, dropping the source location."""
|
|
36
34
|
return f"{category.__name__}: {message}\n"
|
|
37
35
|
|
|
@@ -234,6 +232,7 @@ def _color_gradient(
|
|
|
234
232
|
midpoint=mid_value,
|
|
235
233
|
)
|
|
236
234
|
|
|
235
|
+
|
|
237
236
|
def _fill_gradient(
|
|
238
237
|
series,
|
|
239
238
|
color_low=None,
|
|
@@ -286,7 +285,6 @@ def _fill_gradient(
|
|
|
286
285
|
)
|
|
287
286
|
|
|
288
287
|
|
|
289
|
-
|
|
290
288
|
def _share_labels(plot, i: int, keys: Sequence[str], ncol: int | None) -> SupPlotsSpec:
|
|
291
289
|
if ncol is None:
|
|
292
290
|
ncol = len(keys)
|
|
@@ -298,9 +296,7 @@ def _share_labels(plot, i: int, keys: Sequence[str], ncol: int | None) -> SupPlo
|
|
|
298
296
|
# the bottom-most plot lives in the penultimate row.
|
|
299
297
|
last_row_count = total - ncol * (nrow - 1)
|
|
300
298
|
if nrow >= 2 and last_row_count < ncol:
|
|
301
|
-
bottom_places.extend(
|
|
302
|
-
ncol * (nrow - 2) + col for col in range(last_row_count, ncol)
|
|
303
|
-
)
|
|
299
|
+
bottom_places.extend(ncol * (nrow - 2) + col for col in range(last_row_count, ncol))
|
|
304
300
|
if i not in bottom_places: # remove x axis title except for bottom row
|
|
305
301
|
plot = plot + theme(axis_title_x=element_blank())
|
|
306
302
|
if i not in left_places: # remove y axis title except for left column
|
|
@@ -322,9 +318,7 @@ def _share_axis(
|
|
|
322
318
|
# the bottom-most plot lives in the penultimate row.
|
|
323
319
|
last_row_count = total - ncol * (nrow - 1)
|
|
324
320
|
if nrow >= 2 and last_row_count < ncol:
|
|
325
|
-
bottom_places.extend(
|
|
326
|
-
ncol * (nrow - 2) + col for col in range(last_row_count, ncol)
|
|
327
|
-
)
|
|
321
|
+
bottom_places.extend(ncol * (nrow - 2) + col for col in range(last_row_count, ncol))
|
|
328
322
|
|
|
329
323
|
if axis_type == "axis":
|
|
330
324
|
if i not in bottom_places: # remove x axis title except for bottom row
|
|
@@ -361,9 +355,7 @@ def _share_ticks(plot, i: int, keys: Sequence[str], ncol: int | None) -> SupPlot
|
|
|
361
355
|
# the bottom-most plot lives in the penultimate row.
|
|
362
356
|
last_row_count = total - ncol * (nrow - 1)
|
|
363
357
|
if nrow >= 2 and last_row_count < ncol:
|
|
364
|
-
bottom_places.extend(
|
|
365
|
-
ncol * (nrow - 2) + col for col in range(last_row_count, ncol)
|
|
366
|
-
)
|
|
358
|
+
bottom_places.extend(ncol * (nrow - 2) + col for col in range(last_row_count, ncol))
|
|
367
359
|
if i not in bottom_places: # remove x axis title except for bottom row
|
|
368
360
|
plot = plot + theme(axis_text_x=element_blank())
|
|
369
361
|
if i not in left_places: # remove y axis title except for left column
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "cellestial"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.48.0"
|
|
4
4
|
description = ""
|
|
5
5
|
authors = [
|
|
6
6
|
{ name = "Zaf4", email = "zafermolbio@gmail.com" },
|
|
@@ -37,7 +37,7 @@ pycairo = "^1.27.0"
|
|
|
37
37
|
cairosvg = "^2.7.1"
|
|
38
38
|
scvelo = "^0.3.3"
|
|
39
39
|
ty = "^0.0.34"
|
|
40
|
-
pandas = "2.2.
|
|
40
|
+
pandas = ">=2.2.3,<3" # >=2.2.3 for cp313 wheels; <3 to avoid 3.0
|
|
41
41
|
tqdm = "^4.67.3"
|
|
42
42
|
pytest = "^9.0.3"
|
|
43
43
|
pytest-cov = "^7.1.0"
|
|
@@ -55,7 +55,7 @@ squidpy = "^1.8.1"
|
|
|
55
55
|
|
|
56
56
|
[tool.pytest.ini_options]
|
|
57
57
|
testpaths = ["tests"]
|
|
58
|
-
addopts = "--cov=cellestial --cov-report=term-missing"
|
|
58
|
+
addopts = "--cov=cellestial --cov-report=xml:tests/coverage.xml --cov-report=term-missing"
|
|
59
59
|
|
|
60
60
|
[tool.coverage.run]
|
|
61
61
|
data_file = "tests/.coverage"
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|