Skip to content

Commit

Permalink
fix #132 for minimalistic xenium datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaMarconato committed Mar 30, 2024
1 parent 27c3b2f commit 070c716
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ and this project adheres to [Semantic Versioning][].
[keep a changelog]: https://keepachangelog.com/en/1.0.0/
[semantic versioning]: https://semver.org/spec/v2.0.0.html

## [0.1.2] - xxxx-xx-xx
## [0.1.2] - 2024-03-30

### Added

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

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

## [0.1.1] - 2024-03-24

Expand Down
36 changes: 20 additions & 16 deletions src/spatialdata_io/readers/xenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def xenium(
transcripts: bool = True,
morphology_mip: bool = True,
morphology_focus: bool = True,
aligned_images: bool = True,
imread_kwargs: Mapping[str, Any] = MappingProxyType({}),
image_models_kwargs: Mapping[str, Any] = MappingProxyType({}),
labels_models_kwargs: Mapping[str, Any] = MappingProxyType({}),
Expand Down Expand Up @@ -107,9 +108,11 @@ def xenium(
transcripts
Whether to read transcripts.
morphology_mip
Whether to read morphology mip.
Whether to read the morphology mip image (available in versions < 2.0.0).
morphology_focus
Whether to read morphology focus.
Whether to read the morphology focus image.
aligned_images
Whether to also parse, when available, additional H&E or IF aligned images.
imread_kwargs
Keyword arguments to pass to the image reader.
image_models_kwargs
Expand Down Expand Up @@ -190,17 +193,17 @@ def xenium(
labels_name="cell_labels",
labels_models_kwargs=labels_models_kwargs,
)
if cell_labels_indices_mapping is not None:
if not pd.DataFrame.equals(cell_labels_indices_mapping["cell_id"], table.obs[str(XeniumKeys.CELL_ID)]):
warnings.warn(
"The cell_id column in the cell_labels_table does not match the cell_id column derived from the cell "
"labels data. This could be due to trying to read a new version that is not supported yet. Please "
"report this issue.",
UserWarning,
stacklevel=2,
)
else:
table.obs["cell_labels"] = cell_labels_indices_mapping["label_index"]
if cell_labels_indices_mapping is not None:
if not pd.DataFrame.equals(cell_labels_indices_mapping["cell_id"], table.obs[str(XeniumKeys.CELL_ID)]):
warnings.warn(
"The cell_id column in the cell_labels_table does not match the cell_id column derived from the cell "
"labels data. This could be due to trying to read a new version that is not supported yet. Please "
"report this issue.",
UserWarning,
stacklevel=2,
)
else:
table.obs["cell_labels"] = cell_labels_indices_mapping["label_index"]

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

# find and add additional aligned images
aligned_images = _add_aligned_images(path, imread_kwargs, image_models_kwargs)
for key, value in aligned_images.items():
sdata.images[key] = value
if aligned_images:
extra_images = _add_aligned_images(path, imread_kwargs, image_models_kwargs)
for key, value in extra_images.items():
sdata.images[key] = value

return sdata

Expand Down

0 comments on commit 070c716

Please sign in to comment.