From 353f75526bb2c0a5f21ffc450325ea0d06bcb7fa Mon Sep 17 00:00:00 2001 From: Blampey Quentin Date: Tue, 24 Sep 2024 16:03:57 +0200 Subject: [PATCH 01/22] MERSCOPE: adding feature_key attribute for points --- CHANGELOG.md | 2 +- src/spatialdata_io/_constants/_constants.py | 1 + src/spatialdata_io/readers/merscope.py | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76f559a6..55094b6b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,7 +13,7 @@ and this project adheres to [Semantic Versioning][]. ### Added - (Xenium) added `dims` parameter for more control in `xenium_aligned_image()` - +- (MERSCOPE) added `feature_key` attribute for points (i.e., the `'gene'` column) ### Fixed - Passing `rgb=None` to image model parser for both visium and visiumhd, leading to 3-4 channel images being diff --git a/src/spatialdata_io/_constants/_constants.py b/src/spatialdata_io/_constants/_constants.py index 9ec43fa9..34848137 100644 --- a/src/spatialdata_io/_constants/_constants.py +++ b/src/spatialdata_io/_constants/_constants.py @@ -322,6 +322,7 @@ class MerscopeKeys(ModeEnum): GLOBAL_Z = "global_z" Z_INDEX = "ZIndex" REGION_KEY = "cells_region" + GENE_KEY = "gene" @unique diff --git a/src/spatialdata_io/readers/merscope.py b/src/spatialdata_io/readers/merscope.py index c5c5cf03..2d916ea7 100644 --- a/src/spatialdata_io/readers/merscope.py +++ b/src/spatialdata_io/readers/merscope.py @@ -303,6 +303,7 @@ def _get_points(transcript_path: Path, transformations: dict[str, BaseTransforma transcript_df, coordinates={"x": MerscopeKeys.GLOBAL_X, "y": MerscopeKeys.GLOBAL_Y}, transformations=transformations, + feature_key=MerscopeKeys.GENE_KEY, ) transcripts["gene"] = transcripts["gene"].astype("category") return transcripts From dd6d762d25abfdfa55b91812542bcb45997b245f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:05:25 +0000 Subject: [PATCH 02/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 55094b6b..a38420e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning][]. - (Xenium) added `dims` parameter for more control in `xenium_aligned_image()` - (MERSCOPE) added `feature_key` attribute for points (i.e., the `'gene'` column) + ### Fixed - Passing `rgb=None` to image model parser for both visium and visiumhd, leading to 3-4 channel images being From 0b7b0d220904c1491ffd1e6deb03f4a4573b8c88 Mon Sep 17 00:00:00 2001 From: LucaMarconato <2664412+LucaMarconato@users.noreply.github.com> Date: Wed, 25 Sep 2024 10:57:55 +0200 Subject: [PATCH 03/22] Update CHANGELOG.md --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 76f559a6..06df562b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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.4] - xxxx-xx-xx +## [0.1.5] - 2024-09-25 ### Added @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning][]. - Passing `rgb=None` to image model parser for both visium and visiumhd, leading to 3-4 channel images being interpreted as RGB(A) +- Fix header bug Visium data #200 +- (Visium HD) Fix path parsing when images are missing #204 #206 ## [0.1.4] - 2024-08-07 From 4671acbf0a8b9f892e1c99e0bda954b77c9e5ff1 Mon Sep 17 00:00:00 2001 From: Luca Marconato Date: Wed, 25 Sep 2024 10:59:02 +0200 Subject: [PATCH 04/22] fix path bug visium hd --- src/spatialdata_io/readers/visium_hd.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/spatialdata_io/readers/visium_hd.py b/src/spatialdata_io/readers/visium_hd.py index efec22ef..a19262e9 100644 --- a/src/spatialdata_io/readers/visium_hd.py +++ b/src/spatialdata_io/readers/visium_hd.py @@ -272,6 +272,8 @@ def _get_bins(path: Path) -> list[str]: fullres_image_paths = [path_fullres / image_filename for image_filename in fullres_image_filenames] elif list((path_fullres := (path / f"{filename_prefix}tissue_image")).parent.glob(f"{path_fullres.name}.*")): fullres_image_paths = list(path_fullres.parent.glob(f"{path_fullres.name}.*")) + else: + fullres_image_paths = [] if len(fullres_image_paths) > 1: warnings.warn( f"Multiple files found in {path_fullres}, using the first one: {fullres_image_paths[0].stem}. Please" From 03e6878fcaa56320ae728527fb621b18df8b0b7e Mon Sep 17 00:00:00 2001 From: LucaMarconato <2664412+LucaMarconato@users.noreply.github.com> Date: Thu, 26 Sep 2024 18:28:59 +0200 Subject: [PATCH 05/22] fixed changelog --- CHANGELOG.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a38420e6..89af6cb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,12 +8,14 @@ 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.4] - xxxx-xx-xx +## [0.1.6] - xxxx-xx-xx +- (MERSCOPE) added `feature_key` attribute for points (i.e., the `'gene'` column) #210 + +## [0.1.5] - 2024-09-25 ### Added - (Xenium) added `dims` parameter for more control in `xenium_aligned_image()` -- (MERSCOPE) added `feature_key` attribute for points (i.e., the `'gene'` column) ### Fixed From cff48962861e833f324f0828154d05afa8b82c92 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 26 Sep 2024 16:30:23 +0000 Subject: [PATCH 06/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa2914cc..6483c889 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning][]. [semantic versioning]: https://semver.org/spec/v2.0.0.html ## [0.1.6] - xxxx-xx-xx + - (MERSCOPE) added `feature_key` attribute for points (i.e., the `'gene'` column) #210 ## [0.1.5] - 2024-09-25 From 17119c05aefa1722e728c86f0bbb8e1d8062ff8e Mon Sep 17 00:00:00 2001 From: LucaMarconato <2664412+LucaMarconato@users.noreply.github.com> Date: Wed, 2 Oct 2024 18:43:49 +0200 Subject: [PATCH 07/22] fix visium hd: get transformation matrices only if images are parsed --- src/spatialdata_io/readers/visium_hd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spatialdata_io/readers/visium_hd.py b/src/spatialdata_io/readers/visium_hd.py index a19262e9..aa443a37 100644 --- a/src/spatialdata_io/readers/visium_hd.py +++ b/src/spatialdata_io/readers/visium_hd.py @@ -107,7 +107,6 @@ def load_image(path: Path, suffix: str, scale_factors: list[int] | None = None) ) metadata, hd_layout = _parse_metadata(path, filename_prefix) - transform_matrices = _get_transform_matrices(metadata, hd_layout) file_format = hd_layout[VisiumHDKeys.FILE_FORMAT] if file_format != "1.0": warnings.warn( @@ -347,6 +346,7 @@ def _get_bins(path: Path) -> list[str]: suffix="_cytassist_image", ) image = images[dataset_id + "_cytassist_image"] + transform_matrices = _get_transform_matrices(metadata, hd_layout) affine0 = transform_matrices["cytassist_colrow_to_spot_colrow"] affine1 = transform_matrices["spot_colrow_to_microscope_colrow"] set_transformation(image, Sequence([affine0, affine1]), "global") From 6d20d76233cdc4d439dee7ec759f6420109de68f Mon Sep 17 00:00:00 2001 From: LucaMarconato <2664412+LucaMarconato@users.noreply.github.com> Date: Thu, 3 Oct 2024 17:48:29 +0200 Subject: [PATCH 08/22] Requiring spatialdata>=0.2.3 in pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 199868c4..6b12efe6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ dependencies = [ "anndata", "numpy", "scanpy", - "spatialdata>=0.2.2", + "spatialdata>=0.2.3", "scikit-image", "h5py", "joblib", From 3c6be23040b6ab596f05a6f24c86a3903dfae3d8 Mon Sep 17 00:00:00 2001 From: Luca Marconato Date: Thu, 31 Oct 2024 01:41:06 +0900 Subject: [PATCH 09/22] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6483c889..47d8d607 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning][]. ## [0.1.6] - xxxx-xx-xx - (MERSCOPE) added `feature_key` attribute for points (i.e., the `'gene'` column) #210 +- (Visium HD) get transformation matrices even when only images are parsed #215 ## [0.1.5] - 2024-09-25 From 54c634d4fb642d82b28a2379b09bdb7ff24c18eb Mon Sep 17 00:00:00 2001 From: Wouter-Michiel Vierdag Date: Tue, 5 Nov 2024 11:18:32 +0100 Subject: [PATCH 10/22] update datatree from xarray --- src/spatialdata_io/readers/xenium.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/spatialdata_io/readers/xenium.py b/src/spatialdata_io/readers/xenium.py index 74034f37..b273d3a1 100644 --- a/src/spatialdata_io/readers/xenium.py +++ b/src/spatialdata_io/readers/xenium.py @@ -22,7 +22,6 @@ from anndata import AnnData from dask.dataframe import read_parquet from dask_image.imread import imread -from datatree.datatree import DataTree from geopandas import GeoDataFrame from joblib import Parallel, delayed from pyarrow import Table @@ -38,7 +37,7 @@ TableModel, ) from spatialdata.transformations.transformations import Affine, Identity, Scale -from xarray import DataArray +from xarray import DataArray, DataTree from spatialdata_io._constants._constants import XeniumKeys from spatialdata_io._docs import inject_docs From 6cc60b8377fccc35b7ab0cf7da017789a4707344 Mon Sep 17 00:00:00 2001 From: Wouter-Michiel Vierdag Date: Tue, 12 Nov 2024 01:20:46 +0100 Subject: [PATCH 11/22] update python version --- .mypy.ini | 2 +- pyproject.toml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.mypy.ini b/.mypy.ini index 4da7a91d..f658d6f6 100644 --- a/.mypy.ini +++ b/.mypy.ini @@ -1,5 +1,5 @@ [mypy] -python_version = 3.9 +python_version = 3.10 plugins = numpy.typing.mypy_plugin ignore_errors = False diff --git a/pyproject.toml b/pyproject.toml index 6b12efe6..c323cd19 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ dynamic= [ ] description = "SpatialData IO for common techs" readme = "README.md" -requires-python = ">=3.9" +requires-python = ">=3.10" license = {file = "LICENSE"} authors = [ {name = "scverse"}, @@ -83,7 +83,7 @@ skip_glob = ["docs/*"] [tool.black] line-length = 120 -target-version = ['py39'] +target-version = ['py310'] include = '\.pyi?$' exclude = ''' ( From a7cde002bbfaca060ddbc9bf4dad8fddc6c18046 Mon Sep 17 00:00:00 2001 From: Wouter-Michiel Vierdag Date: Tue, 12 Nov 2024 01:21:36 +0100 Subject: [PATCH 12/22] update pre-commit config --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 84472fb3..c5dc660c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,8 +2,8 @@ fail_fast: false default_language_version: python: python3 default_stages: - - commit - - push + - pre-commit + - pre-push minimum_pre_commit_version: 2.16.0 repos: - repo: https://github.com/psf/black From 124c10aa9e077f3f4708177cf694b5fc5e04a170 Mon Sep 17 00:00:00 2001 From: LucaMarconato <2664412+LucaMarconato@users.noreply.github.com> Date: Tue, 26 Nov 2024 15:23:41 +0100 Subject: [PATCH 13/22] python >= 3.10 in tests --- .github/workflows/test.yaml | 2 +- .pre-commit-config.yaml | 2 +- .readthedocs.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 1335bdaa..d721928e 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -18,7 +18,7 @@ jobs: strategy: fail-fast: false matrix: - python: ["3.9", "3.10"] + python: ["3.10", "3.12"] os: [ubuntu-latest] env: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c5dc660c..396d67df 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -73,7 +73,7 @@ repos: rev: v3.17.0 hooks: - id: pyupgrade - args: [--py3-plus, --py39-plus, --keep-runtime-typing] + args: [--py3-plus, --py310-plus, --keep-runtime-typing] - repo: local hooks: - id: forbid-to-commit diff --git a/.readthedocs.yaml b/.readthedocs.yaml index ec4886d3..f3a78576 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -3,7 +3,7 @@ version: 2 build: os: ubuntu-20.04 tools: - python: "3.9" + python: "3.10" sphinx: configuration: docs/conf.py fail_on_warning: true From 2e832e5bbdc99346265b1e3c32b407063e5237dd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 26 Nov 2024 14:24:52 +0000 Subject: [PATCH 14/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/spatialdata_io/_constants/_enum.py | 3 ++- src/spatialdata_io/_docs.py | 3 ++- src/spatialdata_io/_utils.py | 3 ++- src/spatialdata_io/readers/_utils/_read_10x_h5.py | 6 +++--- src/spatialdata_io/readers/_utils/_utils.py | 2 +- src/spatialdata_io/readers/cosmx.py | 2 +- src/spatialdata_io/readers/dbit.py | 14 +++++++------- src/spatialdata_io/readers/merscope.py | 3 ++- src/spatialdata_io/readers/steinbock.py | 4 ++-- src/spatialdata_io/readers/stereoseq.py | 2 +- src/spatialdata_io/readers/xenium.py | 2 +- 11 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/spatialdata_io/_constants/_enum.py b/src/spatialdata_io/_constants/_enum.py index 63ba74fb..8d06485d 100644 --- a/src/spatialdata_io/_constants/_enum.py +++ b/src/spatialdata_io/_constants/_enum.py @@ -1,7 +1,8 @@ from abc import ABC, ABCMeta from enum import Enum, EnumMeta from functools import wraps -from typing import Any, Callable +from typing import Any +from collections.abc import Callable class PrettyEnum(Enum): diff --git a/src/spatialdata_io/_docs.py b/src/spatialdata_io/_docs.py index becd920d..c03c1362 100644 --- a/src/spatialdata_io/_docs.py +++ b/src/spatialdata_io/_docs.py @@ -1,7 +1,8 @@ from __future__ import annotations from textwrap import dedent -from typing import Any, Callable +from typing import Any +from collections.abc import Callable def inject_docs(**kwargs: Any) -> Callable[..., Any]: # noqa: D103 diff --git a/src/spatialdata_io/_utils.py b/src/spatialdata_io/_utils.py index 65e5e930..bdb9b227 100644 --- a/src/spatialdata_io/_utils.py +++ b/src/spatialdata_io/_utils.py @@ -2,7 +2,8 @@ import functools import warnings -from typing import Any, Callable, TypeVar +from typing import Any, TypeVar +from collections.abc import Callable RT = TypeVar("RT") diff --git a/src/spatialdata_io/readers/_utils/_read_10x_h5.py b/src/spatialdata_io/readers/_utils/_read_10x_h5.py index 55aa344b..11ee6331 100644 --- a/src/spatialdata_io/readers/_utils/_read_10x_h5.py +++ b/src/spatialdata_io/readers/_utils/_read_10x_h5.py @@ -40,8 +40,8 @@ def _read_10x_h5( - filename: Union[str, Path], - genome: Optional[str] = None, + filename: str | Path, + genome: str | None = None, gex_only: bool = True, ) -> AnnData: """ @@ -96,7 +96,7 @@ def _read_10x_h5( return adata -def _read_v3_10x_h5(filename: Union[str, Path], *, start: Optional[Any] = None) -> AnnData: +def _read_v3_10x_h5(filename: str | Path, *, start: Any | None = None) -> AnnData: """Read hdf5 file from Cell Ranger v3 or later versions.""" with h5py.File(str(filename), "r") as f: try: diff --git a/src/spatialdata_io/readers/_utils/_utils.py b/src/spatialdata_io/readers/_utils/_utils.py index 4623fced..d4dd38f8 100644 --- a/src/spatialdata_io/readers/_utils/_utils.py +++ b/src/spatialdata_io/readers/_utils/_utils.py @@ -25,7 +25,7 @@ def _read_counts( path: str | Path, counts_file: str, - library_id: Optional[str] = None, + library_id: str | None = None, **kwargs: Any, ) -> tuple[AnnData, str]: path = Path(path) diff --git a/src/spatialdata_io/readers/cosmx.py b/src/spatialdata_io/readers/cosmx.py index 9b8df25b..3cd9deb6 100644 --- a/src/spatialdata_io/readers/cosmx.py +++ b/src/spatialdata_io/readers/cosmx.py @@ -38,7 +38,7 @@ @inject_docs(cx=CosmxKeys) def cosmx( path: str | Path, - dataset_id: Optional[str] = None, + dataset_id: str | None = None, transcripts: bool = True, imread_kwargs: Mapping[str, Any] = MappingProxyType({}), image_models_kwargs: Mapping[str, Any] = MappingProxyType({}), diff --git a/src/spatialdata_io/readers/dbit.py b/src/spatialdata_io/readers/dbit.py index 26d3790d..12880eba 100644 --- a/src/spatialdata_io/readers/dbit.py +++ b/src/spatialdata_io/readers/dbit.py @@ -27,9 +27,9 @@ def _check_path( path: Path, pattern: Pattern[str], key: DbitKeys, - path_specific: Optional[str | Path] = None, + path_specific: str | Path | None = None, optional_arg: bool = False, -) -> tuple[Union[Path, None], bool]: +) -> tuple[Path | None, bool]: """ Check that the path is valid and match a regex pattern. @@ -218,11 +218,11 @@ def _xy2edges(xy: list[int], scale: float = 1.0, border: bool = True, border_sca @inject_docs(vx=DbitKeys) def dbit( - path: Optional[str | Path] = None, - anndata_path: Optional[str] = None, - barcode_position: Optional[str] = None, - image_path: Optional[str] = None, - dataset_id: Optional[str] = None, + path: str | Path | None = None, + anndata_path: str | None = None, + barcode_position: str | None = None, + image_path: str | None = None, + dataset_id: str | None = None, border: bool = True, border_scale: float = 1, ) -> SpatialData: diff --git a/src/spatialdata_io/readers/merscope.py b/src/spatialdata_io/readers/merscope.py index 2d916ea7..5e706993 100644 --- a/src/spatialdata_io/readers/merscope.py +++ b/src/spatialdata_io/readers/merscope.py @@ -5,7 +5,8 @@ from collections.abc import Mapping from pathlib import Path from types import MappingProxyType -from typing import Any, Callable, Literal +from typing import Any, Literal +from collections.abc import Callable import anndata import dask.dataframe as dd diff --git a/src/spatialdata_io/readers/steinbock.py b/src/spatialdata_io/readers/steinbock.py index 2f0283a5..f80ce58f 100644 --- a/src/spatialdata_io/readers/steinbock.py +++ b/src/spatialdata_io/readers/steinbock.py @@ -95,7 +95,7 @@ def _get_images( sample: str, imread_kwargs: Mapping[str, Any] = MappingProxyType({}), image_models_kwargs: Mapping[str, Any] = MappingProxyType({}), -) -> Union[SpatialImage, MultiscaleSpatialImage]: +) -> SpatialImage | MultiscaleSpatialImage: image = imread(path / SteinbockKeys.IMAGES_DIR / f"{sample}{SteinbockKeys.IMAGE_SUFFIX}", **imread_kwargs) return Image2DModel.parse(data=image, transformations={sample: Identity()}, rgb=None, **image_models_kwargs) @@ -106,6 +106,6 @@ def _get_labels( labels_kind: str, imread_kwargs: Mapping[str, Any] = MappingProxyType({}), image_models_kwargs: Mapping[str, Any] = MappingProxyType({}), -) -> Union[SpatialImage, MultiscaleSpatialImage]: +) -> SpatialImage | MultiscaleSpatialImage: image = imread(path / labels_kind / f"{sample}{SteinbockKeys.LABEL_SUFFIX}", **imread_kwargs).squeeze() return Labels2DModel.parse(data=image, transformations={sample: Identity()}, **image_models_kwargs) diff --git a/src/spatialdata_io/readers/stereoseq.py b/src/spatialdata_io/readers/stereoseq.py index 0405192b..17af17a5 100644 --- a/src/spatialdata_io/readers/stereoseq.py +++ b/src/spatialdata_io/readers/stereoseq.py @@ -29,7 +29,7 @@ @inject_docs(xx=SK) def stereoseq( path: str | Path, - dataset_id: Union[str, None] = None, + dataset_id: str | None = None, read_square_bin: bool = True, optional_tif: bool = False, imread_kwargs: Mapping[str, Any] = MappingProxyType({}), diff --git a/src/spatialdata_io/readers/xenium.py b/src/spatialdata_io/readers/xenium.py index b273d3a1..c5fa9f58 100644 --- a/src/spatialdata_io/readers/xenium.py +++ b/src/spatialdata_io/readers/xenium.py @@ -363,7 +363,7 @@ def _decode_cell_id_column(cell_id_column: pd.Series) -> pd.Series: def _get_polygons( - path: Path, file: str, specs: dict[str, Any], n_jobs: int, idx: Optional[ArrayLike] = None + path: Path, file: str, specs: dict[str, Any], n_jobs: int, idx: ArrayLike | None = None ) -> GeoDataFrame: def _poly(arr: ArrayLike) -> Polygon: return Polygon(arr[:-1]) From db35663c3c2425fb9813e1c2a3dd7bd9a3068b77 Mon Sep 17 00:00:00 2001 From: Wouter-Michiel Vierdag Date: Tue, 26 Nov 2024 15:41:29 +0100 Subject: [PATCH 15/22] remove unused types --- src/spatialdata_io/readers/_utils/_utils.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/spatialdata_io/readers/_utils/_utils.py b/src/spatialdata_io/readers/_utils/_utils.py index 4623fced..bbd435bf 100644 --- a/src/spatialdata_io/readers/_utils/_utils.py +++ b/src/spatialdata_io/readers/_utils/_utils.py @@ -5,7 +5,6 @@ from pathlib import Path from typing import Any, Optional, Union -import numpy as np from anndata import AnnData, read_text from h5py import File @@ -13,14 +12,6 @@ PathLike = Union[os.PathLike, str] # type:ignore[type-arg] -try: - from numpy.typing import NDArray - - NDArrayA = NDArray[Any] -except (ImportError, TypeError): - NDArray = np.ndarray - NDArrayA = np.ndarray - def _read_counts( path: str | Path, From f80bc3cfbc930c7e5dee6231cd32cfeebb9aa80e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 26 Nov 2024 14:42:06 +0000 Subject: [PATCH 16/22] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/spatialdata_io/_constants/_enum.py | 2 +- src/spatialdata_io/_docs.py | 2 +- src/spatialdata_io/_utils.py | 2 +- src/spatialdata_io/readers/_utils/_read_10x_h5.py | 2 +- src/spatialdata_io/readers/_utils/_utils.py | 2 +- src/spatialdata_io/readers/cosmx.py | 2 +- src/spatialdata_io/readers/dbit.py | 1 - src/spatialdata_io/readers/merscope.py | 3 +-- src/spatialdata_io/readers/steinbock.py | 2 +- src/spatialdata_io/readers/stereoseq.py | 2 +- src/spatialdata_io/readers/xenium.py | 2 +- 11 files changed, 10 insertions(+), 12 deletions(-) diff --git a/src/spatialdata_io/_constants/_enum.py b/src/spatialdata_io/_constants/_enum.py index 8d06485d..55decf37 100644 --- a/src/spatialdata_io/_constants/_enum.py +++ b/src/spatialdata_io/_constants/_enum.py @@ -1,8 +1,8 @@ from abc import ABC, ABCMeta +from collections.abc import Callable from enum import Enum, EnumMeta from functools import wraps from typing import Any -from collections.abc import Callable class PrettyEnum(Enum): diff --git a/src/spatialdata_io/_docs.py b/src/spatialdata_io/_docs.py index c03c1362..34efbd5e 100644 --- a/src/spatialdata_io/_docs.py +++ b/src/spatialdata_io/_docs.py @@ -1,8 +1,8 @@ from __future__ import annotations +from collections.abc import Callable from textwrap import dedent from typing import Any -from collections.abc import Callable def inject_docs(**kwargs: Any) -> Callable[..., Any]: # noqa: D103 diff --git a/src/spatialdata_io/_utils.py b/src/spatialdata_io/_utils.py index bdb9b227..90dee2ac 100644 --- a/src/spatialdata_io/_utils.py +++ b/src/spatialdata_io/_utils.py @@ -2,8 +2,8 @@ import functools import warnings -from typing import Any, TypeVar from collections.abc import Callable +from typing import Any, TypeVar RT = TypeVar("RT") diff --git a/src/spatialdata_io/readers/_utils/_read_10x_h5.py b/src/spatialdata_io/readers/_utils/_read_10x_h5.py index 11ee6331..4c5b33cc 100644 --- a/src/spatialdata_io/readers/_utils/_read_10x_h5.py +++ b/src/spatialdata_io/readers/_utils/_read_10x_h5.py @@ -31,7 +31,7 @@ # code below taken from https://github.com/scverse/scanpy/blob/master/scanpy/readwrite.py from pathlib import Path -from typing import Any, Optional, Union +from typing import Any import h5py import numpy as np diff --git a/src/spatialdata_io/readers/_utils/_utils.py b/src/spatialdata_io/readers/_utils/_utils.py index 0f84f9fb..da0ac9e3 100644 --- a/src/spatialdata_io/readers/_utils/_utils.py +++ b/src/spatialdata_io/readers/_utils/_utils.py @@ -3,7 +3,7 @@ import os from collections.abc import Mapping from pathlib import Path -from typing import Any, Optional, Union +from typing import Any, Union from anndata import AnnData, read_text from h5py import File diff --git a/src/spatialdata_io/readers/cosmx.py b/src/spatialdata_io/readers/cosmx.py index 3cd9deb6..8f4ec38f 100644 --- a/src/spatialdata_io/readers/cosmx.py +++ b/src/spatialdata_io/readers/cosmx.py @@ -5,7 +5,7 @@ from collections.abc import Mapping from pathlib import Path from types import MappingProxyType -from typing import Any, Optional +from typing import Any import dask.array as da import numpy as np diff --git a/src/spatialdata_io/readers/dbit.py b/src/spatialdata_io/readers/dbit.py index 12880eba..4fc1afdb 100644 --- a/src/spatialdata_io/readers/dbit.py +++ b/src/spatialdata_io/readers/dbit.py @@ -4,7 +4,6 @@ import re from pathlib import Path from re import Pattern -from typing import Optional, Union import anndata as ad import numpy as np diff --git a/src/spatialdata_io/readers/merscope.py b/src/spatialdata_io/readers/merscope.py index 5e706993..af258857 100644 --- a/src/spatialdata_io/readers/merscope.py +++ b/src/spatialdata_io/readers/merscope.py @@ -2,11 +2,10 @@ import re import warnings -from collections.abc import Mapping +from collections.abc import Callable, Mapping from pathlib import Path from types import MappingProxyType from typing import Any, Literal -from collections.abc import Callable import anndata import dask.dataframe as dd diff --git a/src/spatialdata_io/readers/steinbock.py b/src/spatialdata_io/readers/steinbock.py index f80ce58f..763311a9 100644 --- a/src/spatialdata_io/readers/steinbock.py +++ b/src/spatialdata_io/readers/steinbock.py @@ -4,7 +4,7 @@ from collections.abc import Mapping from pathlib import Path from types import MappingProxyType -from typing import Any, Literal, Union +from typing import Any, Literal import anndata as ad from dask_image.imread import imread diff --git a/src/spatialdata_io/readers/stereoseq.py b/src/spatialdata_io/readers/stereoseq.py index 17af17a5..c2af7951 100644 --- a/src/spatialdata_io/readers/stereoseq.py +++ b/src/spatialdata_io/readers/stereoseq.py @@ -5,7 +5,7 @@ from collections.abc import Mapping from pathlib import Path from types import MappingProxyType -from typing import Any, Union +from typing import Any import anndata as ad import h5py diff --git a/src/spatialdata_io/readers/xenium.py b/src/spatialdata_io/readers/xenium.py index c5fa9f58..54f911d2 100644 --- a/src/spatialdata_io/readers/xenium.py +++ b/src/spatialdata_io/readers/xenium.py @@ -10,7 +10,7 @@ from collections.abc import Mapping from pathlib import Path from types import MappingProxyType -from typing import Any, Optional +from typing import Any import dask.array as da import numpy as np From 512e299db2d2b2eb1eef38d4cec3c6a99ab00ce0 Mon Sep 17 00:00:00 2001 From: Wouter-Michiel Vierdag Date: Tue, 26 Nov 2024 15:46:17 +0100 Subject: [PATCH 17/22] remove unused imports --- src/spatialdata_io/readers/_utils/_read_10x_h5.py | 2 +- src/spatialdata_io/readers/_utils/_utils.py | 2 +- src/spatialdata_io/readers/cosmx.py | 2 +- src/spatialdata_io/readers/dbit.py | 1 - src/spatialdata_io/readers/steinbock.py | 2 +- src/spatialdata_io/readers/stereoseq.py | 2 +- src/spatialdata_io/readers/xenium.py | 2 +- 7 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/spatialdata_io/readers/_utils/_read_10x_h5.py b/src/spatialdata_io/readers/_utils/_read_10x_h5.py index 11ee6331..4c5b33cc 100644 --- a/src/spatialdata_io/readers/_utils/_read_10x_h5.py +++ b/src/spatialdata_io/readers/_utils/_read_10x_h5.py @@ -31,7 +31,7 @@ # code below taken from https://github.com/scverse/scanpy/blob/master/scanpy/readwrite.py from pathlib import Path -from typing import Any, Optional, Union +from typing import Any import h5py import numpy as np diff --git a/src/spatialdata_io/readers/_utils/_utils.py b/src/spatialdata_io/readers/_utils/_utils.py index 0f84f9fb..da0ac9e3 100644 --- a/src/spatialdata_io/readers/_utils/_utils.py +++ b/src/spatialdata_io/readers/_utils/_utils.py @@ -3,7 +3,7 @@ import os from collections.abc import Mapping from pathlib import Path -from typing import Any, Optional, Union +from typing import Any, Union from anndata import AnnData, read_text from h5py import File diff --git a/src/spatialdata_io/readers/cosmx.py b/src/spatialdata_io/readers/cosmx.py index 3cd9deb6..8f4ec38f 100644 --- a/src/spatialdata_io/readers/cosmx.py +++ b/src/spatialdata_io/readers/cosmx.py @@ -5,7 +5,7 @@ from collections.abc import Mapping from pathlib import Path from types import MappingProxyType -from typing import Any, Optional +from typing import Any import dask.array as da import numpy as np diff --git a/src/spatialdata_io/readers/dbit.py b/src/spatialdata_io/readers/dbit.py index 12880eba..4fc1afdb 100644 --- a/src/spatialdata_io/readers/dbit.py +++ b/src/spatialdata_io/readers/dbit.py @@ -4,7 +4,6 @@ import re from pathlib import Path from re import Pattern -from typing import Optional, Union import anndata as ad import numpy as np diff --git a/src/spatialdata_io/readers/steinbock.py b/src/spatialdata_io/readers/steinbock.py index f80ce58f..763311a9 100644 --- a/src/spatialdata_io/readers/steinbock.py +++ b/src/spatialdata_io/readers/steinbock.py @@ -4,7 +4,7 @@ from collections.abc import Mapping from pathlib import Path from types import MappingProxyType -from typing import Any, Literal, Union +from typing import Any, Literal import anndata as ad from dask_image.imread import imread diff --git a/src/spatialdata_io/readers/stereoseq.py b/src/spatialdata_io/readers/stereoseq.py index 17af17a5..c2af7951 100644 --- a/src/spatialdata_io/readers/stereoseq.py +++ b/src/spatialdata_io/readers/stereoseq.py @@ -5,7 +5,7 @@ from collections.abc import Mapping from pathlib import Path from types import MappingProxyType -from typing import Any, Union +from typing import Any import anndata as ad import h5py diff --git a/src/spatialdata_io/readers/xenium.py b/src/spatialdata_io/readers/xenium.py index c5fa9f58..54f911d2 100644 --- a/src/spatialdata_io/readers/xenium.py +++ b/src/spatialdata_io/readers/xenium.py @@ -10,7 +10,7 @@ from collections.abc import Mapping from pathlib import Path from types import MappingProxyType -from typing import Any, Optional +from typing import Any import dask.array as da import numpy as np From 52d388eaf6fc0b1126db69206bfc61c42e181c6b Mon Sep 17 00:00:00 2001 From: Wouter-Michiel Vierdag Date: Tue, 26 Nov 2024 16:06:35 +0100 Subject: [PATCH 18/22] ignore flake8 --- .flake8 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.flake8 b/.flake8 index a30ef821..43ded24c 100644 --- a/.flake8 +++ b/.flake8 @@ -38,6 +38,8 @@ ignore = D400 # First line should be in imperative mood; try rephrasing D401 + # Abstract base class without abstractmethod. + B024 exclude = .git,__pycache__,build,docs/_build,dist per-file-ignores = tests/*: D From 3d74434f302791a60816ddbfa1dd23d94132b4b3 Mon Sep 17 00:00:00 2001 From: Luca Marconato Date: Tue, 26 Nov 2024 16:19:31 +0100 Subject: [PATCH 19/22] fix docs --- src/spatialdata_io/readers/visium_hd.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spatialdata_io/readers/visium_hd.py b/src/spatialdata_io/readers/visium_hd.py index aa443a37..121ca5ae 100644 --- a/src/spatialdata_io/readers/visium_hd.py +++ b/src/spatialdata_io/readers/visium_hd.py @@ -79,7 +79,7 @@ def visium_hd( image_models_kwargs Keyword arguments for :class:`spatialdata.models.Image2DModel`. anndata_kwargs - Keyword arguments for :func:`anndata.read_h5ad`. + Keyword arguments for :func:`anndata.io.read_h5ad`. Returns ------- From a571681ebfffd0dd7a7b99c31c191584f815d1a9 Mon Sep 17 00:00:00 2001 From: Luca Marconato Date: Tue, 26 Nov 2024 16:24:13 +0100 Subject: [PATCH 20/22] fix docs; attempt 2 --- docs/conf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/conf.py b/docs/conf.py index e32e9f58..15bf1458 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -90,6 +90,7 @@ } intersphinx_mapping = { + "python": ("https://docs.python.org/3", None), "anndata": ("https://anndata.readthedocs.io/en/stable/", None), "spatialdata": ("https://scverse-spatialdata.readthedocs.io/en/latest/", None), "numpy": ("https://numpy.org/doc/stable/", None), From ed60d9fbf4e28ee03e5a72f86c216e7cd3474bf6 Mon Sep 17 00:00:00 2001 From: Luca Marconato Date: Tue, 26 Nov 2024 16:29:59 +0100 Subject: [PATCH 21/22] fix test xenium --- .github/workflows/test.yaml | 4 ++-- tests/test_xenium.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index d721928e..8546b3d7 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -52,7 +52,7 @@ jobs: pip install --pre -e ".[dev,test]" - name: Download artifact of test data - if: matrix.python == '3.10' + if: matrix.python == '3.12' uses: dawidd6/action-download-artifact@v2 with: workflow: prepare_test_data.yaml @@ -60,7 +60,7 @@ jobs: path: ./data - name: List the data directory - if: matrix.python == '3.10' + if: matrix.python == '3.12' run: | ls -l ./data pwd diff --git a/tests/test_xenium.py b/tests/test_xenium.py index f5127a85..1c64a912 100644 --- a/tests/test_xenium.py +++ b/tests/test_xenium.py @@ -46,7 +46,7 @@ def test_roundtrip_with_data_limits() -> None: # pointing to "data". # The GitHub workflow "prepare_test_data.yaml" takes care of downloading the datasets and uploading an artifact for the # tests to use -@pytest.mark.skipif(sys.version_info < (3, 10), reason="Test requires Python 3.10 or higher") +@pytest.mark.skipif(sys.version_info < (3, 12), reason="Test requires Python 3.10 or higher") @pytest.mark.parametrize( "dataset,expected", [ From ea6797d1c94fec59ab358a42c157b766c5eda9bf Mon Sep 17 00:00:00 2001 From: Luca Marconato Date: Tue, 26 Nov 2024 19:17:31 +0100 Subject: [PATCH 22/22] changelog and min spatialdata dep --- CHANGELOG.md | 3 ++- pyproject.toml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47d8d607..47f2900a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,11 @@ 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.6] - xxxx-xx-xx +## [0.1.6] - 2024-11-26 - (MERSCOPE) added `feature_key` attribute for points (i.e., the `'gene'` column) #210 - (Visium HD) get transformation matrices even when only images are parsed #215 +- Support for `xarray.DataTree` (which was moved from `datatree.DataTree`) #232 ## [0.1.5] - 2024-09-25 diff --git a/pyproject.toml b/pyproject.toml index c323cd19..2bdebfe0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ dependencies = [ "anndata", "numpy", "scanpy", - "spatialdata>=0.2.3", + "spatialdata>=0.2.6", "scikit-image", "h5py", "joblib",