|
a |
|
b/tests/plotting/test_utils.py |
|
|
1 |
from typing import List, Optional |
|
|
2 |
|
|
|
3 |
import pytest |
|
|
4 |
|
|
|
5 |
import numpy as np |
|
|
6 |
|
|
|
7 |
import matplotlib as mpl |
|
|
8 |
|
|
|
9 |
from anndata import AnnData |
|
|
10 |
|
|
|
11 |
import moscot as msc |
|
|
12 |
from moscot.plotting._utils import _input_to_adatas |
|
|
13 |
from tests._utils import Problem |
|
|
14 |
|
|
|
15 |
|
|
|
16 |
class TestMoscotPl: |
|
|
17 |
def test_input_to_adatas_problem(self, adata_time: AnnData): |
|
|
18 |
p = Problem(adata_time) |
|
|
19 |
adata1, adata2 = _input_to_adatas(p) |
|
|
20 |
assert isinstance(adata1, AnnData) |
|
|
21 |
assert isinstance(adata2, AnnData) |
|
|
22 |
np.testing.assert_array_equal(adata1.X.toarray(), adata_time.X.toarray()) |
|
|
23 |
np.testing.assert_array_equal(adata2.X.toarray(), adata_time.X.toarray()) |
|
|
24 |
|
|
|
25 |
def test_input_to_adatas_adata(self, adata_time: AnnData): |
|
|
26 |
adata1, adata2 = _input_to_adatas(adata_time) |
|
|
27 |
assert isinstance(adata1, AnnData) |
|
|
28 |
assert isinstance(adata2, AnnData) |
|
|
29 |
np.testing.assert_array_equal(adata1.X.toarray(), adata_time.X.toarray()) |
|
|
30 |
np.testing.assert_array_equal(adata2.X.toarray(), adata_time.X.toarray()) |
|
|
31 |
|
|
|
32 |
@pytest.mark.parametrize("return_fig", [True, False]) |
|
|
33 |
def test_cell_transition(self, adata_pl_cell_transition: AnnData, return_fig: bool): |
|
|
34 |
fig = msc.plotting.cell_transition(adata_pl_cell_transition, return_fig=return_fig) |
|
|
35 |
if return_fig: |
|
|
36 |
assert fig is not None |
|
|
37 |
assert isinstance(fig, mpl.figure.Figure) |
|
|
38 |
else: |
|
|
39 |
assert fig is None |
|
|
40 |
|
|
|
41 |
@pytest.mark.parametrize("time_points", [None, [0]]) |
|
|
42 |
@pytest.mark.parametrize("return_fig", [True, False]) |
|
|
43 |
def test_push(self, adata_pl_push: AnnData, time_points: Optional[List[int]], return_fig: bool): |
|
|
44 |
fig = msc.plotting.push(adata_pl_push, time_points=time_points, return_fig=return_fig) |
|
|
45 |
|
|
|
46 |
if return_fig: |
|
|
47 |
assert fig is not None |
|
|
48 |
assert isinstance(fig, mpl.figure.Figure) |
|
|
49 |
else: |
|
|
50 |
assert fig is None |
|
|
51 |
|
|
|
52 |
@pytest.mark.parametrize("time_points", [None, [0]]) |
|
|
53 |
@pytest.mark.parametrize("return_fig", [True, False]) |
|
|
54 |
def test_pull( |
|
|
55 |
self, |
|
|
56 |
adata_pl_pull: AnnData, |
|
|
57 |
time_points: Optional[List[int]], |
|
|
58 |
return_fig: bool, |
|
|
59 |
): |
|
|
60 |
fig = msc.plotting.pull(adata_pl_pull, time_points=time_points, return_fig=return_fig) |
|
|
61 |
if return_fig: |
|
|
62 |
assert fig is not None |
|
|
63 |
assert isinstance(fig, mpl.figure.Figure) |
|
|
64 |
else: |
|
|
65 |
assert fig is None |
|
|
66 |
|
|
|
67 |
@pytest.mark.parametrize("return_fig", [True, False]) |
|
|
68 |
@pytest.mark.parametrize("interpolate_color", [True, False]) |
|
|
69 |
def test_sankey(self, adata_pl_sankey: AnnData, return_fig: bool, interpolate_color: bool): |
|
|
70 |
fig = msc.plotting.sankey( |
|
|
71 |
adata_pl_sankey, |
|
|
72 |
return_fig=return_fig, |
|
|
73 |
interpolate_color=interpolate_color, |
|
|
74 |
) |
|
|
75 |
if return_fig: |
|
|
76 |
assert fig is not None |
|
|
77 |
assert isinstance(fig, mpl.figure.Figure) |
|
|
78 |
else: |
|
|
79 |
assert fig is None |