Skip to content

Commit

Permalink
Fix plotting tests for networkx >= 2.6.2 (scverse#1960)
Browse files Browse the repository at this point in the history
* Update PAGA plots
* Update umap edges plot
  • Loading branch information
ivirshup authored Jul 27, 2021
1 parent ecd2845 commit d7dc745
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 73 deletions.
Binary file modified scanpy/tests/_images/master_paga.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_paga_continuous.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_paga_continuous_multiple.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_paga_continuous_obs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_paga_pie.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scanpy/tests/_images/master_umap_with_edges.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions scanpy/tests/test_paga.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
from functools import partial
from pathlib import Path

from matplotlib import cm

import scanpy as sc

import pytest

HERE: Path = Path(__file__).parent
ROOT = HERE / '_images'
FIGS = HERE / 'figures'


@pytest.fixture(scope="module")
def pbmc():
pbmc = sc.datasets.pbmc68k_reduced()
sc.tl.paga(pbmc, groups='bulk_labels')
pbmc.obs['cool_feature'] = pbmc[:, 'CST3'].X.squeeze()
return pbmc


@pytest.mark.parametrize(
"test_id,func",
[
("master_paga", sc.pl.paga),
("master_paga_continuous", partial(sc.pl.paga, color="CST3")),
("master_paga_continuous_obs", partial(sc.pl.paga, color="cool_feature")),
(
"master_paga_continuous_multiple",
partial(sc.pl.paga, color=['CST3', 'GATA2']),
),
("master_paga_compare", partial(sc.pl.paga_compare, legend_fontoutline=2)),
(
"master_paga_compare_continuous",
partial(sc.pl.paga_compare, color='CST3', legend_fontsize=5),
),
(
"master_paga_compare_pca",
partial(sc.pl.paga_compare, basis='X_pca', legend_fontweight='normal'),
),
],
)
def test_paga_plots(image_comparer, pbmc, test_id, func):
save_and_compare_images = image_comparer(ROOT, FIGS, tol=30)
common = dict(threshold=0.5, max_edge_width=1.0, random_state=0, show=False)

func(pbmc, **common)
save_and_compare_images(test_id)


def test_paga_pie(image_comparer, pbmc):
save_and_compare_images = image_comparer(ROOT, FIGS, tol=30)

colors = {
c: {cm.Set1(_): 0.33 for _ in range(3)}
for c in pbmc.obs["bulk_labels"].cat.categories
}
colors["Dendritic"] = {cm.Set2(_): 0.25 for _ in range(4)}

sc.pl.paga(pbmc, color=colors, colorbar=False)
save_and_compare_images('master_paga_pie')


def test_paga_path(image_comparer, pbmc):
save_and_compare_images = image_comparer(ROOT, FIGS, tol=15)

pbmc.uns['iroot'] = 0
sc.tl.dpt(pbmc)
sc.pl.paga_path(
pbmc,
nodes=['Dendritic'],
keys=['HES4', 'SRM', 'CSTB'],
show=False,
)
save_and_compare_images('master_paga_path')


def test_paga_compare(image_comparer):
# Tests that https://github.com/theislab/scanpy/issues/1887 is fixed
save_and_compare_images = image_comparer(ROOT, FIGS, tol=15)

pbmc = sc.datasets.pbmc3k_processed()
sc.tl.paga(pbmc, groups="louvain")

sc.pl.paga_compare(pbmc, basis="umap", show=False)

save_and_compare_images('master_paga_compare_pbmc3k')
73 changes: 0 additions & 73 deletions scanpy/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1284,79 +1284,6 @@ def test_scatter_rep(tmpdir):
assert "Error" in comp, f"{s1.outpth}, {s2.outpth} aren't supposed to match"


def test_paga(image_comparer):
# Sometimes things shift a pixel or so, resulting in diffs up to ~27
# The 1px-edges aren’t that good actually as they’re ignored at this tol …
save_and_compare_images = image_comparer(ROOT, FIGS, tol=30)

pbmc = sc.datasets.pbmc68k_reduced()
sc.tl.paga(pbmc, groups='bulk_labels')

common = dict(threshold=0.5, max_edge_width=1.0, random_state=0, show=False)

# delete bulk_labels_colors to test the creation of color list by paga
del pbmc.uns['bulk_labels_colors']
sc.pl.paga(pbmc, **common)
save_and_compare_images('master_paga')

sc.pl.paga(pbmc, color='CST3', **common)
save_and_compare_images('master_paga_continuous')

pbmc.obs['cool_feature'] = pbmc[:, 'CST3'].X.squeeze()
sc.pl.paga(pbmc, color='cool_feature', **common)
save_and_compare_images('master_paga_continuous_obs')

sc.pl.paga(pbmc, color=['CST3', 'GATA2'], **common)
save_and_compare_images('master_paga_continuous_multiple')

sc.pl.paga_compare(pbmc, legend_fontoutline=2, **common)
save_and_compare_images('master_paga_compare')

sc.pl.paga_compare(pbmc, color='CST3', legend_fontsize=5, **common)
save_and_compare_images('master_paga_compare_continuous')

sc.pl.paga_compare(pbmc, basis='X_pca', legend_fontweight='normal', **common)
save_and_compare_images('master_paga_compare_pca')

colors = {
c: {cm.Set1(_): 0.33 for _ in range(3)}
for c in pbmc.obs["bulk_labels"].cat.categories
}
colors["Dendritic"] = {cm.Set2(_): 0.25 for _ in range(4)}

sc.pl.paga(pbmc, color=colors, colorbar=False)
save_and_compare_images('master_paga_pie')


def test_paga_path(image_comparer):
save_and_compare_images = image_comparer(ROOT, FIGS, tol=15)

pbmc = sc.datasets.pbmc68k_reduced()
sc.tl.paga(pbmc, groups='bulk_labels')

pbmc.uns['iroot'] = 0
sc.tl.dpt(pbmc)
sc.pl.paga_path(
pbmc,
nodes=['Dendritic'],
keys=['HES4', 'SRM', 'CSTB'],
show=False,
)
save_and_compare_images('master_paga_path')


def test_paga_compare(image_comparer):
# Tests that https://github.com/theislab/scanpy/issues/1887 is fixed
save_and_compare_images = image_comparer(ROOT, FIGS, tol=15)

pbmc = sc.datasets.pbmc3k_processed()
sc.tl.paga(pbmc, groups="louvain")

sc.pl.paga_compare(pbmc, basis="umap", show=False)

save_and_compare_images('master_paga_compare_pbmc3k')


def test_no_copy():
# https://github.com/theislab/scanpy/issues/1000
# Tests that plotting functions don't make a copy from a view unless they
Expand Down

0 comments on commit d7dc745

Please sign in to comment.