Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update reqs and tests #682

Merged
merged 13 commits into from
May 9, 2023
Merged
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 0 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
40 changes: 20 additions & 20 deletions docs/source/tutorials.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------------
Expand All @@ -31,19 +31,19 @@ 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
------------------
This section contains tutorials showcasing how :mod:`squidpy` can interface with external libraries.

.. 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
2 changes: 1 addition & 1 deletion docs/source/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,10 +11,10 @@ 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.2
scanpy>=1.9.3
scikit-image>=0.19
scikit-learn>=0.24.0
statsmodels>=0.12.0
Expand Down
9 changes: 9 additions & 0 deletions squidpy/pl/_ligrec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 3 additions & 1 deletion tests/graph/test_ligrec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
14 changes: 10 additions & 4 deletions tests/image/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@

import anndata as ad
import dask.array as da
import imageio
import imageio.v3 as iio
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
Expand Down Expand Up @@ -152,11 +153,16 @@ 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)
fname = tmpdir / f"tmp.{ext}"
imageio.imsave(str(fname), img_orig)

gt = imageio.imread(str(fname)) # because of compression, we load again
if shape == (100, 200, 1):
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)
iio.imwrite(str(fname), img_orig)

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())
Expand Down
6 changes: 4 additions & 2 deletions tests/plotting/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down