Skip to content

Commit abdd72f

Browse files
add run_name argument for the xenium explorer (#139)
1 parent ea94902 commit abdd72f

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
### Changed
1818
- The `sopa.io.uniform` dataset is now deprecated (use `sopa.io.toy_dataset` instead)
1919

20+
### New contributors
21+
- TODO
22+
2023
## [1.1.5] - 2024-09-17
2124

2225
### Fix

sopa/io/explorer/converter.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def write(
6060
ram_threshold_gb: int | None = 4,
6161
mode: str = None,
6262
save_h5ad: bool = False,
63+
run_name: str | None = None,
6364
) -> None:
6465
"""
6566
Transform a SpatialData object into inputs for the Xenium Explorer.
@@ -99,6 +100,7 @@ def write(
99100
ram_threshold_gb: Threshold (in gygabytes) from which image can be loaded in memory. If `None`, the image is never loaded in memory.
100101
mode: 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.
101102
save_h5ad: 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)
103+
run_name: Name of the run displayed in the Xenium Explorer. If `None`, uses the `image_key`.
102104
"""
103105
path: Path = Path(path)
104106
_check_explorer_directory(path)
@@ -158,7 +160,7 @@ def write(
158160

159161
### Saving experiment.xenium file
160162
if _should_save(mode, "m"):
161-
write_metadata(path, image_key, shapes_key, _get_n_obs(sdata, geo_df), pixel_size)
163+
write_metadata(path, run_name or image_key, shapes_key, _get_n_obs(sdata, geo_df), pixel_size)
162164

163165
if save_h5ad and SopaKeys.TABLE in sdata.tables:
164166
sdata.tables[SopaKeys.TABLE].write_h5ad(path / FileNames.H5AD)
@@ -175,7 +177,7 @@ def _get_n_obs(sdata: SpatialData, geo_df: gpd.GeoDataFrame) -> int:
175177

176178
def write_metadata(
177179
path: str,
178-
image_key: str = "NA",
180+
run_name: str = "NA",
179181
shapes_key: str = "NA",
180182
n_obs: int = 0,
181183
is_dir: bool = True,
@@ -188,7 +190,7 @@ def write_metadata(
188190
189191
Args:
190192
path: Path to the Xenium Explorer directory where the metadata file will be written
191-
image_key: Key of `SpatialData` object containing the primary image used on the explorer.
193+
run_name: Key of `SpatialData` object containing the primary image used on the explorer.
192194
shapes_key: Key of `SpatialData` object containing the boundaries shown on the explorer.
193195
n_obs: Number of cells
194196
is_dir: If `False`, then `path` is a path to a single file, not to the Xenium Explorer directory.
@@ -197,5 +199,5 @@ def write_metadata(
197199
path = explorer_file_path(path, FileNames.METADATA, is_dir)
198200

199201
with open(path, "w") as f:
200-
metadata = experiment_dict(image_key, shapes_key, n_obs, pixel_size)
202+
metadata = experiment_dict(run_name, shapes_key, n_obs, pixel_size)
201203
json.dump(metadata, f, indent=4)

0 commit comments

Comments
 (0)