From de6351efb407ae3fbc3b339888a8225124fdb6f6 Mon Sep 17 00:00:00 2001 From: Laurens Lehner Date: Mon, 24 Apr 2023 16:14:51 +0200 Subject: [PATCH 01/12] Update reqs and tests --- requirements.txt | 4 ++-- squidpy/pl/_ligrec.py | 9 +++++++++ tests/graph/test_ligrec.py | 4 +++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 90f71664..eac87e09 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ aiohttp>=3.8.1 -anndata>=0.8 +anndata>=0.9 cycler>=0.11.0 dask-image>=0.5.0 dask[array]>=2021.02.0 @@ -14,7 +14,7 @@ numpy>=1.23.0 omnipath>=1.0.5 pandas>=1.5.0 Pillow>=8.0.0 -scanpy>=1.9.2 +scanpy>=1.9.3 scikit-image>=0.19 scikit-learn>=0.24.0 statsmodels>=0.12.0 diff --git a/squidpy/pl/_ligrec.py b/squidpy/pl/_ligrec.py index d4ad817d..dd86e974 100644 --- a/squidpy/pl/_ligrec.py +++ b/squidpy/pl/_ligrec.py @@ -267,6 +267,15 @@ def get_dendrogram(adata: AnnData, linkage: str = "complete") -> Mapping[str, An target_groups = adata["pvalues"].columns.get_level_values(1) if isinstance(target_groups, str): target_groups = (target_groups,) + + if not isinstance(adata, AnnData): + for s in source_groups: + if s not in adata["means"].columns.get_level_values(0): + raise ValueError(f"Invalid cluster in source group: {s}.") + for t in target_groups: + if t not in adata["means"].columns.get_level_values(1): + raise ValueError(f"Invalid cluster in target group: {t}.") + if title is None: title = "Receptor-ligand test" diff --git a/tests/graph/test_ligrec.py b/tests/graph/test_ligrec.py index ab407c1a..01943a56 100644 --- a/tests/graph/test_ligrec.py +++ b/tests/graph/test_ligrec.py @@ -33,7 +33,9 @@ def test_adata_no_raw(self, adata: AnnData): def test_raw_has_different_n_obs(self, adata: AnnData): adata.raw = blobs(n_observations=adata.n_obs + 1) - with pytest.raises(ValueError, match=rf"Expected `{adata.n_obs}` cells in `.raw`"): + # raise below happend with anndata < 0.9 + # with pytest.raises(ValueError, match=rf"Expected `{adata.n_obs}` cells in `.raw`"): + with pytest.raises(ValueError, match=rf"Index length mismatch: {adata.n_obs} vs. {adata.n_obs + 1}"): ligrec(adata, _CK) def test_invalid_cluster_key(self, adata: AnnData, interactions: Interactions_t): From 1e2d2f5619edbe542636d45a976100d70feeef1c Mon Sep 17 00:00:00 2001 From: Laurens Lehner Date: Mon, 24 Apr 2023 16:30:21 +0200 Subject: [PATCH 02/12] Fix --- .github/workflows/test.yml | 2 +- .pre-commit-config.yaml | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b0756461..ee860f0e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -58,7 +58,7 @@ jobs: - name: Install pip dependencies run: | python -m pip install --upgrade pip - pip install tox tox-gh-actions codecov + pip install tox tox-gh-actions - name: Restore data cache id: data-cache diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index dc09a69c..d9320ae5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -69,7 +69,3 @@ repos: - id: rst-backticks - id: rst-directive-colons - id: rst-inline-touching-normal - - repo: https://github.com/PyCQA/doc8 - rev: v1.1.1 - hooks: - - id: doc8 From 6960f2d5063013910e4607febf9fd35221c33a6c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 24 Apr 2023 14:30:47 +0000 Subject: [PATCH 03/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ee860f0e..c38654a1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -58,7 +58,7 @@ jobs: - name: Install pip dependencies run: | python -m pip install --upgrade pip - pip install tox tox-gh-actions + pip install tox tox-gh-actions - name: Restore data cache id: data-cache From b7187eddc4bfae1d4ce7b5e82bc624f749915497 Mon Sep 17 00:00:00 2001 From: Laurens Lehner Date: Mon, 24 Apr 2023 17:56:21 +0200 Subject: [PATCH 04/12] Fix test --- tests/plotting/test_graph.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/plotting/test_graph.py b/tests/plotting/test_graph.py index 0fbfc136..7c4b47cc 100644 --- a/tests/plotting/test_graph.py +++ b/tests/plotting/test_graph.py @@ -143,8 +143,10 @@ def test_invalid_means_range_size(self, ligrec_result: Mapping[str, pd.DataFrame pl.ligrec(ligrec_result, means_range=[0, 1, 2]) def test_invalid_clusters(self, ligrec_result: Mapping[str, pd.DataFrame]): - with pytest.raises(ValueError, match=r"No valid clusters have been selected."): - pl.ligrec(ligrec_result, source_groups="foo", target_groups="bar") + source_groups = "foo" + target_groups = "bar" + with pytest.raises(ValueError, match=r"Invalid cluster in .*"): + pl.ligrec(ligrec_result, source_groups=source_groups, target_groups=target_groups) def test_all_interactions_empty(self, ligrec_result: Mapping[str, pd.DataFrame]): empty = pd.DataFrame(np.nan, index=ligrec_result["pvalues"].index, columns=ligrec_result["pvalues"].columns) From 00a5ab8789d32eff4db575f6cda652190a9e3e05 Mon Sep 17 00:00:00 2001 From: Giovanni Palla <25887487+giovp@users.noreply.github.com> Date: Tue, 2 May 2023 14:05:55 +0200 Subject: [PATCH 05/12] Update requirements.txt --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index eac87e09..a4f241cb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,7 +11,7 @@ matplotlib-scalebar>=0.8.0 networkx>=2.6.0 numba>=0.56.4 numpy>=1.23.0 -omnipath>=1.0.5 +omnipath @ git+https://github.com/saezlab/omnipath@master pandas>=1.5.0 Pillow>=8.0.0 scanpy>=1.9.3 From d9bf7fae09068ce47b8ac6d77dfcdc5386ad266b Mon Sep 17 00:00:00 2001 From: LLehner Date: Mon, 8 May 2023 22:30:48 +0200 Subject: [PATCH 06/12] Fix tutorial paths --- docs/source/tutorials.rst | 40 +++++++++++++++++++-------------------- docs/source/utils.py | 2 +- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/docs/source/tutorials.rst b/docs/source/tutorials.rst index 05b1f408..79d4c124 100644 --- a/docs/source/tutorials.rst +++ b/docs/source/tutorials.rst @@ -9,17 +9,17 @@ to a diverse set of different spatial datasets. .. nbgallery:: - auto_tutorials/tutorial_imc - auto_tutorials/tutorial_seqfish - auto_tutorials/tutorial_slideseqv2 - auto_tutorials/tutorial_visium_fluo - auto_tutorials/tutorial_visium_hne - auto_tutorials/tutorial_mibitof - auto_tutorials/tutorial_fouri - external_tutorials/tutorial_nanostring - external_tutorials/tutorial_vizgen - external_tutorials/tutorial_vizgen_mouse_liver - external_tutorials/tutorial_xenium + tutorials/tutorial_imc + tutorials/tutorial_seqfish + tutorials/tutorial_slideseqv2 + tutorials/tutorial_visium_fluo + tutorials/tutorial_visium_hne + tutorials/tutorial_mibitof + tutorials/tutorial_fouri + tutorials/tutorial_nanostring + tutorials/tutorial_vizgen + tutorials/tutorial_vizgen_mouse_liver + tutorials/tutorial_xenium Advanced Tutorials ------------------ @@ -31,10 +31,10 @@ This section contains tutorials showcasing advanced :mod:`squidpy` functionaliti .. nbgallery:: - auto_tutorials/tutorial_read_spatial - auto_tutorials/tutorial_image_container - external_tutorials/tutorial_napari - auto_tutorials/tutorial_image_container_zstacks + tutorials/tutorial_read_spatial + tutorials/tutorial_image_container + tutorials/tutorial_napari + tutorials/tutorial_image_container_zstacks External tutorials ------------------ @@ -42,8 +42,8 @@ This section contains tutorials showcasing how :mod:`squidpy` can interface with .. nbgallery:: - external_tutorials/tutorial_tf - external_tutorials/tutorial_tangram - external_tutorials/tutorial_cellpose_segmentation - external_tutorials/tutorial_stardist - external_tutorials/tutorial_cellprofiler + tutorials/tutorial_tf + tutorials/tutorial_tangram + tutorials/tutorial_cellpose_segmentation + tutorials/tutorial_stardist + tutorials/tutorial_cellprofiler diff --git a/docs/source/utils.py b/docs/source/utils.py index 444f2e15..51728233 100644 --- a/docs/source/utils.py +++ b/docs/source/utils.py @@ -17,7 +17,7 @@ def _fetch_notebooks(repo_url: str) -> None: def copy_files(repo_path: Union[str, Path]) -> None: repo_path = Path(repo_path) - for dirname in ["external_tutorials", "auto_examples", "auto_tutorials", "gen_modules"]: + for dirname in ["tutorials", "auto_examples", "gen_modules"]: rmtree(dirname, ignore_errors=True) # locally re-cloning copytree(repo_path / "docs" / "source" / dirname, dirname) From f3a858d2062c2c554f5f125960fee891205477bf Mon Sep 17 00:00:00 2001 From: LLehner Date: Mon, 8 May 2023 22:41:55 +0200 Subject: [PATCH 07/12] Fix test --- tests/image/test_container.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/image/test_container.py b/tests/image/test_container.py index b53a5739..774361c1 100644 --- a/tests/image/test_container.py +++ b/tests/image/test_container.py @@ -156,7 +156,7 @@ def test_load_ext(self, shape: Tuple[int, ...], ext: str, tmpdir): fname = tmpdir / f"tmp.{ext}" imageio.imsave(str(fname), img_orig) - gt = imageio.imread(str(fname)) # because of compression, we load again + gt = imageio.v2.imread(str(fname)) # because of compression, we load again cont = ImageContainer(str(fname)) np.testing.assert_array_equal(cont["image"].values.squeeze(), gt.squeeze()) From 1b40d116cb894c764fe8f26bfe06baa7c308a2ee Mon Sep 17 00:00:00 2001 From: LLehner Date: Mon, 8 May 2023 22:57:52 +0200 Subject: [PATCH 08/12] Fix test --- tests/image/test_container.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/image/test_container.py b/tests/image/test_container.py index 774361c1..de5424e7 100644 --- a/tests/image/test_container.py +++ b/tests/image/test_container.py @@ -154,9 +154,9 @@ def test_add_img_invalid_zdim(self, cont: ImageContainer): def test_load_ext(self, shape: Tuple[int, ...], ext: str, tmpdir): img_orig = np.random.randint(low=0, high=255, size=shape, dtype=np.uint8) fname = tmpdir / f"tmp.{ext}" - imageio.imsave(str(fname), img_orig) + imageio.v3.imwrite(str(fname), img_orig) - gt = imageio.v2.imread(str(fname)) # because of compression, we load again + gt = imageio.v3.imread(str(fname)) # because of compression, we load again cont = ImageContainer(str(fname)) np.testing.assert_array_equal(cont["image"].values.squeeze(), gt.squeeze()) From 5606161efc99476bc69e2197f9313dacb99f24f9 Mon Sep 17 00:00:00 2001 From: LLehner Date: Mon, 8 May 2023 23:14:39 +0200 Subject: [PATCH 09/12] Fix test --- tests/image/test_container.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/image/test_container.py b/tests/image/test_container.py index de5424e7..ec6526e4 100644 --- a/tests/image/test_container.py +++ b/tests/image/test_container.py @@ -7,7 +7,7 @@ import anndata as ad import dask.array as da -import imageio +import imageio.v3 as iio import numpy as np import pytest import tifffile @@ -154,9 +154,9 @@ def test_add_img_invalid_zdim(self, cont: ImageContainer): def test_load_ext(self, shape: Tuple[int, ...], ext: str, tmpdir): img_orig = np.random.randint(low=0, high=255, size=shape, dtype=np.uint8) fname = tmpdir / f"tmp.{ext}" - imageio.v3.imwrite(str(fname), img_orig) + iio.imwrite(str(fname), img_orig) - gt = imageio.v3.imread(str(fname)) # because of compression, we load again + gt = iio.imread(str(fname)) # because of compression, we load again cont = ImageContainer(str(fname)) np.testing.assert_array_equal(cont["image"].values.squeeze(), gt.squeeze()) From 442acbf4d89cb43c5027c8acc7dc5a912d7a3cf9 Mon Sep 17 00:00:00 2001 From: LLehner Date: Tue, 9 May 2023 00:36:09 +0200 Subject: [PATCH 10/12] Fix test --- tests/image/test_container.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/image/test_container.py b/tests/image/test_container.py index ec6526e4..cc7222d7 100644 --- a/tests/image/test_container.py +++ b/tests/image/test_container.py @@ -152,7 +152,10 @@ def test_add_img_invalid_zdim(self, cont: ImageContainer): @pytest.mark.parametrize("ext", ["jpg", "png"]) @pytest.mark.parametrize("shape", [(100, 200, 3), (100, 200, 1)]) def test_load_ext(self, shape: Tuple[int, ...], ext: str, tmpdir): - img_orig = np.random.randint(low=0, high=255, size=shape, dtype=np.uint8) + if shape == (100, 200, 1): + img_orig = np.random.randint(256, size=(100, 200), dtype=np.uint8) + else: + img_orig = np.random.randint(low=0, high=255, size=shape, dtype=np.uint8) fname = tmpdir / f"tmp.{ext}" iio.imwrite(str(fname), img_orig) From e0e4230fbba442121a5973ed707b30b411abae11 Mon Sep 17 00:00:00 2001 From: LLehner Date: Tue, 9 May 2023 00:44:39 +0200 Subject: [PATCH 11/12] Fix test --- tests/image/test_container.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/image/test_container.py b/tests/image/test_container.py index cc7222d7..2b7ab735 100644 --- a/tests/image/test_container.py +++ b/tests/image/test_container.py @@ -8,6 +8,7 @@ import anndata as ad import dask.array as da import imageio.v3 as iio +from PIL import Image import numpy as np import pytest import tifffile @@ -152,11 +153,13 @@ def test_add_img_invalid_zdim(self, cont: ImageContainer): @pytest.mark.parametrize("ext", ["jpg", "png"]) @pytest.mark.parametrize("shape", [(100, 200, 3), (100, 200, 1)]) def test_load_ext(self, shape: Tuple[int, ...], ext: str, tmpdir): + fname = tmpdir / f"tmp.{ext}" + if shape == (100, 200, 1): - img_orig = np.random.randint(256, size=(100, 200), dtype=np.uint8) + img = np.random.randint(256, size=(100, 200), dtype=np.uint8) + img_orig = Image.fromarray(img) else: img_orig = np.random.randint(low=0, high=255, size=shape, dtype=np.uint8) - fname = tmpdir / f"tmp.{ext}" iio.imwrite(str(fname), img_orig) gt = iio.imread(str(fname)) # because of compression, we load again From d332c89efd3e6f6def3332783f861d100a144490 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 8 May 2023 22:45:00 +0000 Subject: [PATCH 12/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/image/test_container.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/image/test_container.py b/tests/image/test_container.py index 2b7ab735..d1071a75 100644 --- a/tests/image/test_container.py +++ b/tests/image/test_container.py @@ -8,12 +8,12 @@ import anndata as ad import dask.array as da import imageio.v3 as iio -from PIL import Image import numpy as np import pytest import tifffile import xarray as xr from anndata import AnnData +from PIL import Image from pytest_mock import MockerFixture import squidpy as sq