Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

import squidpy as sq
from squidpy._constants._pkg_constants import Key
from squidpy.gr import spatial_neighbors
from squidpy.gr import spatial_neighbors_grid
from squidpy.im._container import ImageContainer

HERE: Path = Path(__file__).parent
Expand Down Expand Up @@ -59,7 +59,7 @@ def adata_hne() -> AnnData:
@pytest.fixture(scope="session")
def adata_hne_concat() -> AnnData:
adata1 = sq.datasets.visium_hne_adata_crop()
spatial_neighbors(adata1)
spatial_neighbors_grid(adata1)
adata2 = adata1[:100, :].copy()
adata2.uns["spatial"] = {}
adata2.uns["spatial"]["V2_Adult_Mouse_Brain"] = adata1.uns["spatial"]["V1_Adult_Mouse_Brain"]
Expand Down Expand Up @@ -101,7 +101,7 @@ def nhood_data(adata: AnnData) -> AnnData:
sc.pp.pca(adata)
sc.pp.neighbors(adata)
sc.tl.leiden(adata, key_added="leiden")
sq.gr.spatial_neighbors(adata)
sq.gr.spatial_neighbors_grid(adata)

return adata

Expand All @@ -112,7 +112,7 @@ def dummy_adata() -> AnnData:
adata = AnnData(r.rand(200, 100), obs={"cluster": r.randint(0, 3, 200)})

adata.obsm[Key.obsm.spatial] = np.stack([r.randint(0, 500, 200), r.randint(0, 500, 200)], axis=1)
sq.gr.spatial_neighbors(adata, spatial_key=Key.obsm.spatial, n_rings=2)
sq.gr.spatial_neighbors_knn(adata, spatial_key=Key.obsm.spatial)

return adata

Expand Down
8 changes: 4 additions & 4 deletions tests/graph/test_nhood.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
centrality_scores,
interaction_matrix,
nhood_enrichment,
spatial_neighbors,
spatial_neighbors_grid,
)

_CK = "leiden"
Expand All @@ -25,22 +25,22 @@ def _assert_common(self, adata: AnnData):
assert adata.uns[key]["count"].shape[0] == adata.obs.leiden.cat.categories.shape[0]

def test_nhood_enrichment(self, adata: AnnData):
spatial_neighbors(adata)
spatial_neighbors_grid(adata)
nhood_enrichment(adata, cluster_key=_CK)

self._assert_common(adata)

@pytest.mark.parametrize("backend", ["threading", "multiprocessing", "loky"])
def test_parallel_works(self, adata: AnnData, backend: str):
spatial_neighbors(adata)
spatial_neighbors_grid(adata)

nhood_enrichment(adata, cluster_key=_CK, n_jobs=2, n_perms=20, backend=backend)

self._assert_common(adata)

@pytest.mark.parametrize("n_jobs", [1, 2])
def test_reproducibility(self, adata: AnnData, n_jobs: int):
spatial_neighbors(adata)
spatial_neighbors_grid(adata)

res1 = nhood_enrichment(adata, cluster_key=_CK, seed=42, n_jobs=n_jobs, n_perms=20, copy=True)
res2 = nhood_enrichment(adata, cluster_key=_CK, seed=42, n_jobs=n_jobs, n_perms=20, copy=True)
Expand Down
8 changes: 4 additions & 4 deletions tests/graph/test_niche.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pandas.testing import assert_frame_equal
from scipy.sparse import issparse

from squidpy.gr import calculate_niche, spatial_neighbors
from squidpy.gr import calculate_niche, spatial_neighbors_knn
from squidpy.gr._niche import _calculate_neighborhood_profile, _utag

SPATIAL_CONNECTIVITIES_KEY = "spatial_connectivities"
Expand All @@ -14,7 +14,7 @@

def test_niche_calc_nhood(adata_seqfish: AnnData):
"""Check whether niche calculation using neighborhood profile approach works as intended."""
spatial_neighbors(adata_seqfish, coord_type="generic", delaunay=False, n_neighs=N_NEIGHBORS)
spatial_neighbors_knn(adata_seqfish, n_neighs=N_NEIGHBORS)
calculate_niche(
adata_seqfish,
groups=GROUPS,
Expand Down Expand Up @@ -53,7 +53,7 @@ def test_niche_calc_nhood(adata_seqfish: AnnData):

def test_niche_calc_utag(adata_seqfish: AnnData):
"""Check whether niche calculation using UTAG approach works as intended."""
spatial_neighbors(adata_seqfish, coord_type="generic", delaunay=False, n_neighs=N_NEIGHBORS)
spatial_neighbors_knn(adata_seqfish, n_neighs=N_NEIGHBORS)
calculate_niche(adata_seqfish, flavor="utag", n_neighbors=N_NEIGHBORS, resolutions=[0.1, 1.0])

niches = adata_seqfish.obs["utag_niche_res=1.0"]
Expand All @@ -71,7 +71,7 @@ def test_niche_calc_utag(adata_seqfish: AnnData):
assert new_feature_matrix.shape == adata_seqfish.X.shape
assert issparse(new_feature_matrix)

spatial_neighbors(adata_seqfish, coord_type="generic", delaunay=False, n_neighs=40)
spatial_neighbors_knn(adata_seqfish, n_neighs=40)
new_feature_matrix_more_neighs = _utag(
adata_seqfish,
normalize_adj=True,
Expand Down
8 changes: 4 additions & 4 deletions tests/graph/test_sepal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from anndata import AnnData
from pandas.testing import assert_frame_equal

from squidpy.gr import sepal, spatial_neighbors
from squidpy.gr import sepal, spatial_neighbors_grid, spatial_neighbors_radius

UNS_KEY = "sepal_score"


def test_sepal_seq_par(adata: AnnData):
"""Check whether sepal results are the same for seq. and parallel computation."""
spatial_neighbors(adata, coord_type="grid")
spatial_neighbors_grid(adata)
rng = np.random.default_rng(42)
adata.var["highly_variable"] = rng.choice([True, False], size=adata.var_names.shape, p=[0.005, 0.995])

Expand All @@ -37,7 +37,7 @@ def test_sepal_seq_par(adata: AnnData):
def test_sepal_square_seq_par(adata_squaregrid: AnnData):
"""Test sepal for square grid."""
adata = adata_squaregrid
spatial_neighbors(adata, radius=1.0)
spatial_neighbors_radius(adata, radius=1.0)
rng = np.random.default_rng(42)
adata.var["highly_variable"] = rng.choice([True, False], size=adata.var_names.shape)

Expand All @@ -60,7 +60,7 @@ def test_sepal_square_seq_par(adata_squaregrid: AnnData):

def test_sepal_dense(adata: AnnData):
"""Check whether sepal results are identical for sparse and dense data."""
spatial_neighbors(adata, coord_type="grid")
spatial_neighbors_grid(adata)
rng = np.random.default_rng(42)
adata.var["highly_variable"] = rng.choice([True, False], size=adata.var_names.shape, p=[0.05, 0.95])

Expand Down
18 changes: 9 additions & 9 deletions tests/plotting/test_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,45 @@

class TestGraph(PlotTester, metaclass=PlotTesterMeta):
def test_plot_interaction(self, adata: AnnData):
gr.spatial_neighbors(adata)
gr.spatial_neighbors_grid(adata)
gr.interaction_matrix(adata, cluster_key=C_KEY)

pl.interaction_matrix(adata, cluster_key=C_KEY)

def test_plot_interaction_dendro(self, adata: AnnData):
gr.spatial_neighbors(adata)
gr.spatial_neighbors_grid(adata)
gr.interaction_matrix(adata, cluster_key=C_KEY)

pl.interaction_matrix(adata, cluster_key=C_KEY, method="single")

def test_plot_centrality_scores(self, adata: AnnData):
gr.spatial_neighbors(adata)
gr.spatial_neighbors_grid(adata)
gr.centrality_scores(adata, cluster_key=C_KEY)

pl.centrality_scores(adata, cluster_key=C_KEY)

def test_plot_centrality_scores_single(self, adata: AnnData):
selected_score = "degree_centrality"
gr.spatial_neighbors(adata)
gr.spatial_neighbors_grid(adata)
gr.centrality_scores(adata, cluster_key=C_KEY)

pl.centrality_scores(adata, cluster_key=C_KEY, score=selected_score, dpi=DPI)

def test_plot_nhood_enrichment(self, adata: AnnData):
gr.spatial_neighbors(adata)
gr.spatial_neighbors_grid(adata)
gr.nhood_enrichment(adata, cluster_key=C_KEY)

pl.nhood_enrichment(adata, cluster_key=C_KEY)

def test_plot_nhood_enrichment_ax(self, adata: AnnData):
gr.spatial_neighbors(adata)
gr.spatial_neighbors_grid(adata)
gr.nhood_enrichment(adata, cluster_key=C_KEY)

fig, ax = plt.subplots(figsize=(2, 2), constrained_layout=True)
pl.nhood_enrichment(adata, cluster_key=C_KEY, ax=ax)

def test_plot_nhood_enrichment_dendro(self, adata: AnnData):
gr.spatial_neighbors(adata)
gr.spatial_neighbors_grid(adata)
gr.nhood_enrichment(adata, cluster_key=C_KEY)

# use count to avoid nan for scipy.cluster.hierarchy
Expand Down Expand Up @@ -110,13 +110,13 @@ def test_tol_plot_co_occurrence_palette(self, adata_palette: AnnData):

class TestHeatmap(PlotTester, metaclass=PlotTesterMeta):
def test_plot_cbar_vmin_vmax(self, adata: AnnData):
gr.spatial_neighbors(adata)
gr.spatial_neighbors_grid(adata)
gr.nhood_enrichment(adata, cluster_key=C_KEY)

pl.nhood_enrichment(adata, cluster_key=C_KEY, vmin=10, vmax=20)

def test_plot_cbar_kwargs(self, adata: AnnData):
gr.spatial_neighbors(adata)
gr.spatial_neighbors_grid(adata)
gr.nhood_enrichment(adata, cluster_key=C_KEY)

pl.nhood_enrichment(adata, cluster_key=C_KEY, cbar_kwargs={"label": "FOOBARBAZQUUX"})
Expand Down
8 changes: 4 additions & 4 deletions tests/plotting/test_spatial_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from squidpy import pl
from squidpy._constants._pkg_constants import Key
from squidpy.gr import spatial_neighbors
from squidpy.gr import spatial_neighbors_grid, spatial_neighbors_radius
from squidpy.pl._spatial_utils import _get_library_id
from tests.conftest import PlotTester, PlotTesterMeta

Expand Down Expand Up @@ -80,7 +80,7 @@ def test_plot_spatial_scatter_crop_noorigin(self, adata_hne_concat: AnnData):
)

def test_plot_spatial_scatter_group_multi(self, adata_hne: AnnData):
spatial_neighbors(adata_hne)
spatial_neighbors_grid(adata_hne)
pl.spatial_scatter(
adata_hne,
shape="circle",
Expand Down Expand Up @@ -109,7 +109,7 @@ def test_plot_spatial_scatter_group(self, adata_hne_concat: AnnData):

def test_plot_spatial_scatter_nospatial(self, adata_hne_concat: AnnData):
adata = adata_hne_concat.copy()
spatial_neighbors(adata)
spatial_neighbors_grid(adata)
adata.uns.pop("spatial")
pl.spatial_scatter(
adata_hne_concat,
Expand All @@ -134,7 +134,7 @@ def test_plot_spatial_scatter_axfig(self, adata_hne: AnnData):

@pytest.mark.skipif(platform.system() == "Darwin", reason="Fails on macOS 3.8 CI")
def test_plot_spatial_scatter_novisium(self, adata_mibitof: AnnData):
spatial_neighbors(adata_mibitof, coord_type="generic", radius=50)
spatial_neighbors_radius(adata_mibitof, radius=50)
pl.spatial_scatter(
adata_mibitof,
library_key="library_id",
Expand Down
Loading