Skip to content

Commit

Permalink
added test cases for paste2 projection
Browse files Browse the repository at this point in the history
  • Loading branch information
anushka255 committed Aug 20, 2024
1 parent 0b53544 commit eeb1586
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions tests/test_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
stack_slices_center,
generalized_procrustes_analysis,
)
from paste2.projection import partial_stack_slices_pairwise, partial_procrustes_analysis
from pandas.testing import assert_frame_equal

test_dir = Path(__file__).parent
Expand Down Expand Up @@ -112,11 +113,11 @@ def test_generalized_procrustes_analysis(slices):
)

assert_frame_equal(
pd.DataFrame(aligned_center, columns=['0', '1']),
pd.DataFrame(aligned_center, columns=["0", "1"]),
pd.read_csv(output_dir / "aligned_center.csv"),
)
assert_frame_equal(
pd.DataFrame(aligned_slice, columns=['0', '1']),
pd.DataFrame(aligned_slice, columns=["0", "1"]),
pd.read_csv(output_dir / "aligned_slice.csv"),
)
expected_theta = 0.0
Expand Down Expand Up @@ -144,3 +145,43 @@ def test_generalized_procrustes_analysis(slices):
equal_nan=True,
)
)


def test_partial_stack_slices_pairwise(slices):
n_slices = len(slices)

pairwise_info = [
np.genfromtxt(input_dir / f"slices_{i}_{i + 1}_pairwise.csv", delimiter=",")
for i in range(1, n_slices)
]

new_slices = partial_stack_slices_pairwise(slices, pairwise_info)

for i, slice in enumerate(new_slices, start=1):
assert_frame_equal(
pd.DataFrame(slice.obsm["spatial"], columns=["0", "1"]),
pd.read_csv(output_dir / f"aligned_spatial_{i}_{i + 1}.csv"),
)


def test_partial_procrustes_analysis(slices):
center_slice = sc.read_h5ad(input_dir / "center_slice.h5ad")

pairwise_info = np.genfromtxt(
input_dir / "center_slice1_pairwise.csv", delimiter=","
)

aligned_center, aligned_slice = partial_procrustes_analysis(
center_slice.obsm["spatial"],
slices[0].obsm["spatial"],
pairwise_info,
)

assert_frame_equal(
pd.DataFrame(aligned_center, columns=["0", "1"]),
pd.read_csv(output_dir / "aligned_center.csv"),
)
assert_frame_equal(
pd.DataFrame(aligned_slice, columns=["0", "1"]),
pd.read_csv(output_dir / "aligned_slice.csv"),
)

0 comments on commit eeb1586

Please # to comment.