Skip to content

Commit 070c716

Browse files
committed
fix #132 for minimalistic xenium datasets
1 parent 27c3b2f commit 070c716

2 files changed

Lines changed: 22 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning][].
88
[keep a changelog]: https://keepachangelog.com/en/1.0.0/
99
[semantic versioning]: https://semver.org/spec/v2.0.0.html
1010

11-
## [0.1.2] - xxxx-xx-xx
11+
## [0.1.2] - 2024-03-30
1212

1313
### Added
1414

@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning][].
1717
### Fixed
1818

1919
- (Xenium) reader for 1.0.1 (paper data) and unknown versions
20+
- (Xenium) fix in reading "minimalistic" Xenium datasets #132
2021

2122
## [0.1.1] - 2024-03-24
2223

src/spatialdata_io/readers/xenium.py

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def xenium(
6161
transcripts: bool = True,
6262
morphology_mip: bool = True,
6363
morphology_focus: bool = True,
64+
aligned_images: bool = True,
6465
imread_kwargs: Mapping[str, Any] = MappingProxyType({}),
6566
image_models_kwargs: Mapping[str, Any] = MappingProxyType({}),
6667
labels_models_kwargs: Mapping[str, Any] = MappingProxyType({}),
@@ -107,9 +108,11 @@ def xenium(
107108
transcripts
108109
Whether to read transcripts.
109110
morphology_mip
110-
Whether to read morphology mip.
111+
Whether to read the morphology mip image (available in versions < 2.0.0).
111112
morphology_focus
112-
Whether to read morphology focus.
113+
Whether to read the morphology focus image.
114+
aligned_images
115+
Whether to also parse, when available, additional H&E or IF aligned images.
113116
imread_kwargs
114117
Keyword arguments to pass to the image reader.
115118
image_models_kwargs
@@ -190,17 +193,17 @@ def xenium(
190193
labels_name="cell_labels",
191194
labels_models_kwargs=labels_models_kwargs,
192195
)
193-
if cell_labels_indices_mapping is not None:
194-
if not pd.DataFrame.equals(cell_labels_indices_mapping["cell_id"], table.obs[str(XeniumKeys.CELL_ID)]):
195-
warnings.warn(
196-
"The cell_id column in the cell_labels_table does not match the cell_id column derived from the cell "
197-
"labels data. This could be due to trying to read a new version that is not supported yet. Please "
198-
"report this issue.",
199-
UserWarning,
200-
stacklevel=2,
201-
)
202-
else:
203-
table.obs["cell_labels"] = cell_labels_indices_mapping["label_index"]
196+
if cell_labels_indices_mapping is not None:
197+
if not pd.DataFrame.equals(cell_labels_indices_mapping["cell_id"], table.obs[str(XeniumKeys.CELL_ID)]):
198+
warnings.warn(
199+
"The cell_id column in the cell_labels_table does not match the cell_id column derived from the cell "
200+
"labels data. This could be due to trying to read a new version that is not supported yet. Please "
201+
"report this issue.",
202+
UserWarning,
203+
stacklevel=2,
204+
)
205+
else:
206+
table.obs["cell_labels"] = cell_labels_indices_mapping["label_index"]
204207

205208
if nucleus_boundaries:
206209
polygons["nucleus_boundaries"] = _get_polygons(
@@ -302,9 +305,10 @@ def filter(self, record: logging.LogRecord) -> bool:
302305
sdata = SpatialData(**elements_dict)
303306

304307
# find and add additional aligned images
305-
aligned_images = _add_aligned_images(path, imread_kwargs, image_models_kwargs)
306-
for key, value in aligned_images.items():
307-
sdata.images[key] = value
308+
if aligned_images:
309+
extra_images = _add_aligned_images(path, imread_kwargs, image_models_kwargs)
310+
for key, value in extra_images.items():
311+
sdata.images[key] = value
308312

309313
return sdata
310314

0 commit comments

Comments
 (0)