Skip to content
This repository was archived by the owner on Aug 27, 2025. It is now read-only.

Commit 423fb73

Browse files
fix when table but no shapes_key provided
1 parent 2ddefd1 commit 423fb73

3 files changed

Lines changed: 26 additions & 14 deletions

File tree

spatialdata_xenium_explorer/cli/app.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,24 @@ def write(
1212
None,
1313
help="Path to a directory where Xenium Explorer's outputs will be saved. By default, writes to the same path as `sdata_path` but with the `.explorer` suffix",
1414
),
15+
image_key: str = typer.Option(
16+
None,
17+
help="Name of the image of interest (key of `sdata.images`). This argument doesn't need to be provided if there is only one image.",
18+
),
19+
shapes_key: str = typer.Option(
20+
None,
21+
help="Name of the cell shapes (key of `sdata.shapes`). This argument doesn't need to be provided if there is only one shapes key or a table with only one region.",
22+
),
23+
points_key: str = typer.Option(
24+
None,
25+
help="Name of the transcripts (key of `sdata.points`). This argument doesn't need to be provided if there is only one points key.",
26+
),
1527
gene_column: str = typer.Option(
1628
None, help="Column name of the points dataframe containing the gene names"
1729
),
18-
shapes_key: str = typer.Option(
30+
layer: str = typer.Option(
1931
None,
20-
help="Key for the boundaries. By default, uses the baysor boundaires, else the cellpose boundaries",
32+
help="Layer of `sdata.table` where the gene counts are saved. If `None`, uses `sdata.table.X`.",
2133
),
2234
lazy: bool = typer.Option(
2335
True,
@@ -31,10 +43,6 @@ def write(
3143
None,
3244
help="string that indicated which files should be created. `'-ib'` means everything except images and boundaries, while `'+tocm'` means only transcripts/observations/counts/metadata (each letter corresponds to one explorer file). By default, keeps everything",
3345
),
34-
save_h5ad: bool = typer.Option(
35-
True,
36-
help="Whether to save the adata as h5ad in the explorer directory (for convenience only, since h5ad is faster to open than the original .zarr table)",
37-
),
3846
):
3947
"""Convert a spatialdata object to Xenium Explorer's inputs"""
4048
from pathlib import Path
@@ -51,12 +59,14 @@ def write(
5159
write(
5260
output_path,
5361
sdata,
62+
image_key=image_key,
5463
shapes_key=shapes_key,
64+
points_key=points_key,
5565
gene_column=gene_column,
66+
layer=layer,
5667
lazy=lazy,
5768
ram_threshold_gb=ram_threshold_gb,
5869
mode=mode,
59-
save_h5ad=save_h5ad,
6070
)
6171

6272

spatialdata_xenium_explorer/converter.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ def write(
7474
image_key, image = get_spatial_image(sdata, image_key, return_key=True)
7575

7676
### Saving cell categories and gene counts
77-
if sdata.table is not None and shapes_key is not None:
77+
if sdata.table is not None:
7878
adata = sdata.table
7979

8080
region = adata.uns["spatialdata_attrs"]["region"]
81-
region = region if isinstance(region, list) else region
81+
region = region if isinstance(region, list) else [region]
8282

8383
if len(region) == 1:
8484
assert (

spatialdata_xenium_explorer/utils.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import logging
34
from pathlib import Path
45

56
import dask.array as da
@@ -12,6 +13,8 @@
1213
from spatialdata.models import SpatialElement
1314
from spatialdata.transformations import Identity, get_transformation, set_transformation
1415

16+
log = logging.getLogger(__name__)
17+
1518

1619
def explorer_file_path(path: str, filename: str, is_dir: bool):
1720
path: Path = Path(path)
@@ -94,13 +97,12 @@ def get_key(sdata: SpatialData, attr: str, key: str | None = None):
9497

9598
elements = getattr(sdata, attr)
9699

97-
if not len(elements):
100+
if len(elements) != 1:
101+
log.warn(
102+
f"Trying to get an element key of `sdata.{attr}`, but it contains multiple values and no key was provided. It will not be saved to the xenium explorer."
103+
)
98104
return None
99105

100-
assert (
101-
len(elements) == 1
102-
), f"Trying to get an element key of `sdata.{attr}`, but it contains multiple values and no dict key was provided"
103-
104106
return next(iter(elements.keys()))
105107

106108

0 commit comments

Comments
 (0)