Skip to content

Commit 2e32cd8

Browse files
committed
Merge branch 'main' into fix/macsima_pad_images_of_differing_dimensions
2 parents b309f29 + 3101b5b commit 2e32cd8

10 files changed

Lines changed: 554 additions & 477 deletions

File tree

.gitignore

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ __pycache__/
3535
_version.py
3636
node_modules/
3737
.code-workspace
38+
.asv/
39+
uv.lock
3840

3941
# memray report
4042
*.bin
@@ -43,11 +45,7 @@ node_modules/
4345
profile.speedscope.json
4446

4547
# test datasets (e.g. Xenium ones)
46-
# symlinks
47-
data
4848
# data folder
4949
data/
5050
tests/data
51-
uv.lock
52-
.asv/
53-
.venv/
51+
.venv

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ default_stages:
77
minimum_pre_commit_version: 2.16.0
88
repos:
99
- repo: https://github.com/rbubley/mirrors-prettier
10-
rev: v3.8.1
10+
rev: v3.8.3
1111
hooks:
1212
- id: prettier
1313
- repo: https://github.com/astral-sh/ruff-pre-commit
14-
rev: v0.15.2
14+
rev: v0.15.12
1515
hooks:
1616
- id: ruff
1717
args: [--fix, --exit-non-zero-on-fix, --unsafe-fixes]
1818
- id: ruff-format
1919
- repo: https://github.com/pre-commit/mirrors-mypy
20-
rev: v1.19.1
20+
rev: v1.20.2
2121
hooks:
2222
- id: mypy
2323
additional_dependencies: [numpy, types-PyYAML]

src/spatialdata_io/readers/_utils/_read_10x_h5.py

Lines changed: 0 additions & 144 deletions
This file was deleted.

src/spatialdata_io/readers/_utils/_utils.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@
22

33
import os
44
from pathlib import Path
5-
from typing import TYPE_CHECKING, Any, Union
5+
from typing import TYPE_CHECKING, Any
66

7-
from anndata import AnnData
7+
import scanpy as sc
88
from anndata.io import read_text
99
from h5py import File
1010
from spatialdata._logging import logger
1111

12-
from spatialdata_io.readers._utils._read_10x_h5 import _read_10x_h5
13-
1412
if TYPE_CHECKING:
1513
from collections.abc import Mapping
1614

@@ -29,7 +27,7 @@ def _read_counts(
2927
) -> tuple[AnnData, str]:
3028
path = Path(path)
3129
if counts_file.endswith(".h5"):
32-
adata: AnnData = _read_10x_h5(path / counts_file, **kwargs)
30+
adata: AnnData = sc.read_10x_h5(path / counts_file, **kwargs)
3331
with File(path / counts_file, mode="r") as f:
3432
attrs = dict(f.attrs)
3533
if library_id is None:

src/spatialdata_io/readers/cosmx.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ def cosmx(
105105
if not labels_dir.exists():
106106
raise FileNotFoundError(f"Labels directory not found: {labels_dir}.")
107107

108-
counts = pd.read_csv(path / counts_file, header=0, index_col=CosmxKeys.INSTANCE_KEY)
108+
counts = pd.read_csv(counts_file, header=0, index_col=CosmxKeys.INSTANCE_KEY)
109109
counts.index = counts.index.astype(str).str.cat(counts.pop(CosmxKeys.FOV).astype(str).values, sep="_")
110110

111-
obs = pd.read_csv(path / meta_file, header=0, index_col=CosmxKeys.INSTANCE_KEY)
111+
obs = pd.read_csv(meta_file, header=0, index_col=CosmxKeys.INSTANCE_KEY)
112112
obs[CosmxKeys.FOV] = pd.Categorical(obs[CosmxKeys.FOV].astype(str))
113113
obs[CosmxKeys.REGION_KEY] = pd.Categorical(obs[CosmxKeys.FOV].astype(str).apply(lambda s: s + "_labels"))
114114
obs[CosmxKeys.INSTANCE_KEY] = obs.index.astype(np.int64)
@@ -254,9 +254,9 @@ def cosmx(
254254
import pyarrow.parquet as pq
255255

256256
with tempfile.TemporaryDirectory() as tmpdir:
257-
print("converting .csv to .parquet to improve the speed of the slicing operations... ", end="")
257+
print("converting .csv to .parquet to improve the speed of the slicing operations... ", end="", flush=True)
258258
assert transcripts_file is not None
259-
transcripts_data = pd.read_csv(path / transcripts_file, header=0)
259+
transcripts_data = pd.read_csv(transcripts_file, header=0)
260260
transcripts_data.to_parquet(Path(tmpdir) / "transcripts.parquet")
261261
print("done")
262262

src/spatialdata_io/readers/macsima.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"B": "bleach", # v1
3939
"AntigenCycle": "stain", # v0
4040
"S": "stain", # v1
41-
"AF": "autofluorescence",
41+
"AF": "autofluorescence", # v1
4242
}
4343

4444

@@ -552,7 +552,7 @@ def _parse_v0_ome_metadata(ome: OME) -> dict[str, Any]:
552552

553553
# Harmonize imagetype across versions
554554
if metadata["imagetype"]:
555-
metadata["imagetype"] = IMAGETYPE_DICT[metadata["imagetype"]]
555+
metadata["imagetype"] = IMAGETYPE_DICT.get(metadata["imagetype"], metadata["imagetype"])
556556

557557
return metadata
558558

@@ -632,7 +632,7 @@ def _parse_v1_ome_metadata(ome: OME) -> dict[str, Any]:
632632

633633
# Harmonize imagetype across versions
634634
if metadata["imagetype"]:
635-
metadata["imagetype"] = IMAGETYPE_DICT[metadata["imagetype"]]
635+
metadata["imagetype"] = IMAGETYPE_DICT.get(metadata["imagetype"], metadata["imagetype"])
636636

637637
return metadata
638638

src/spatialdata_io/readers/steinbock.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,29 @@ def steinbock(
5050
Returns
5151
-------
5252
:class:`spatialdata.SpatialData`
53+
54+
Notes
55+
-----
56+
Mandatory outputs of the Steinbock pipeline required by this reader:
57+
58+
- ``cells.h5ad``: the AnnData object in the main working directory
59+
- ``ome/``: directory containing the steinbock OME-TIFF images (``*.ome.tiff``)
60+
- ``masks_deepcell/`` or ``masks_ilastik/``: the masks directory, selected via the
61+
``labels_kind`` parameter (only one is used at a time)
62+
63+
When exporting to AnnData with ``steinbock export anndata``, the ``--info`` option
64+
(default: ``images.csv``) controls whether image metadata is embedded. When present,
65+
steinbock copies the ``image`` column from ``images.csv`` into ``adata.obs.image`` for
66+
every cell; this reader requires that column to map cells to their source image. Without
67+
it, ``adata.obs.image`` will not exist and the reader will fail. ``images.csv`` is
68+
generated automatically by ``steinbock preprocess imc images`` when starting from
69+
``.mcd`` files. Users who start from TIFF images must hand-craft ``images.csv`` with at
70+
least the columns ``image``, ``width_px``, ``height_px``, and ``num_channels`` as
71+
described in the
72+
`Steinbock file types documentation <https://bodenmillergroup.github.io/steinbock/latest/file-types/>`_.
73+
74+
All AnnData tables, masks, and OME-TIFFs must follow the steinbock naming conventions so
75+
that the reader can correctly match all instances.
5376
"""
5477
path = Path(path)
5578

0 commit comments

Comments
 (0)