|
11 | 11 | from typing import TYPE_CHECKING, Any |
12 | 12 |
|
13 | 13 | import dask.array as da |
| 14 | +import h5py |
14 | 15 | import numpy as np |
15 | 16 | import packaging.version |
16 | 17 | import pandas as pd |
17 | 18 | import pyarrow.compute as pc |
18 | 19 | import pyarrow.parquet as pq |
| 20 | +import scanpy as sc |
19 | 21 | import tifffile |
20 | 22 | import zarr |
21 | 23 | from dask.dataframe import read_parquet |
|
35 | 37 |
|
36 | 38 | from spatialdata_io._constants._constants import XeniumKeys |
37 | 39 | from spatialdata_io._docs import inject_docs |
38 | | -from spatialdata_io._utils import deprecation_alias, zarr_open |
39 | | -from spatialdata_io.readers._utils._read_10x_h5 import _read_10x_h5 |
| 40 | +from spatialdata_io._utils import deprecation_alias |
40 | 41 | from spatialdata_io.readers._utils._utils import _initialize_raster_models_kwargs, _set_reader_metadata |
41 | 42 |
|
42 | 43 | if TYPE_CHECKING: |
@@ -676,7 +677,13 @@ def _get_tables_and_circles( |
676 | 677 | gex_only: bool, |
677 | 678 | cells_zarr_ctx: _XeniumCells, |
678 | 679 | ) -> tuple[AnnData, GeoDataFrame]: |
679 | | - adata = _read_10x_h5(path / XeniumKeys.CELL_FEATURE_MATRIX_FILE, gex_only=gex_only) |
| 680 | + adata = sc.read_10x_h5(path / XeniumKeys.CELL_FEATURE_MATRIX_FILE, gex_only=gex_only) |
| 681 | + # Undo fixed-point scaling factor applied to Xenium Protein data stored in HDF5. |
| 682 | + with h5py.File(path / XeniumKeys.CELL_FEATURE_MATRIX_FILE, "r") as f: |
| 683 | + if "protein_scaling_factor" in f.attrs: |
| 684 | + protein_feats = np.flatnonzero(adata.var["feature_types"] == "Protein Expression") |
| 685 | + if len(protein_feats) > 0: |
| 686 | + adata.X[:, protein_feats] /= f.attrs["protein_scaling_factor"] |
680 | 687 | # get_cell_metadata decodes cell_id and cross-checks it against cells.zarr.zip |
681 | 688 | metadata = cells_zarr_ctx.get_cell_metadata(path) |
682 | 689 | _assert_arrays_equal_sampled(metadata[XeniumKeys.CELL_ID].astype(str).values, adata.obs_names.values) |
|
0 commit comments