Skip to content

Commit

Permalink
added test cases for helper functions (#8)
Browse files Browse the repository at this point in the history
* added test cases for helper functions; making copy of lists inside functions likely to have side effects
  • Loading branch information
anushka255 authored Aug 13, 2024
1 parent d55e6f6 commit ce1e72b
Show file tree
Hide file tree
Showing 9 changed files with 7,205 additions and 15 deletions.
12 changes: 8 additions & 4 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
anndata>=0.7.6
scanpy>=1.7.2
POT==0.9.0
numpy
scipy
numpy~=1.24.4
scipy~=1.10.1
scikit-learn>=0.24.0
IPython>=7.18.1
pytest

pytest~=8.3.2
seaborn~=0.13.2
matplotlib~=3.7.5
pandas~=2.0.3
statsmodels~=0.14.1
networkx~=3.1
2 changes: 1 addition & 1 deletion src/paste/PASTE.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from anndata import AnnData
import ot
from sklearn.decomposition import NMF
from .helper import intersect, kl_divergence_backend, to_dense_array, extract_data_matrix
from paste.helper import intersect, kl_divergence_backend, to_dense_array, extract_data_matrix

def pairwise_align(
sliceA: AnnData,
Expand Down
3 changes: 0 additions & 3 deletions src/paste/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from .PASTE import pairwise_align, center_align, center_ot, center_NMF, my_fused_gromov_wasserstein, solve_gromov_linesearch
from .helper import match_spots_using_spatial_heuristic, filter_for_common_genes, apply_trsf, intersect,extract_data_matrix, to_dense_array, kl_divergence_backend
from .visualization import plot_slice, stack_slices_pairwise, stack_slices_center
9 changes: 5 additions & 4 deletions src/paste/paste-cmd-line.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import pandas as pd
import argparse
import os
from src.paste import pairwise_align, center_align, stack_slices_pairwise, stack_slices_center
from paste.PASTE import pairwise_align, center_align
from paste.visualization import stack_slices_pairwise, stack_slices_center

def main(args):
# print(args)
Expand Down Expand Up @@ -56,7 +57,7 @@ def main(args):
pis_init = [pd.read_csv(args.start[i],index_col=0).to_numpy() for i in range(len(args.start))]

# create output folder
output_path = os.path.join(args.direc, "../../paste_output")
output_path = os.path.join(args.direc, "paste_output")
if not os.path.exists(output_path):
os.mkdir(output_path)

Expand All @@ -82,8 +83,8 @@ def main(args):
center_slice, pis = center_align(initial_slice, slices, lmbda, args.alpha, args.n_components, args.threshold, dissimilarity=args.cost, distributions=[slices[i].obsm['weights'] for i in range(n_slices)], pis_init=pis_init)
W = pd.DataFrame(center_slice.uns['paste_W'], index = center_slice.obs.index)
H = pd.DataFrame(center_slice.uns['paste_H'], columns = center_slice.var.index)
W.to_csv(os.path.join(args.direc, "../../paste_output/W_center"))
H.to_csv(os.path.join(args.direc, "../../paste_output/H_center"))
W.to_csv(os.path.join(args.direc, "paste_output/W_center"))
H.to_csv(os.path.join(args.direc, "paste_output/H_center"))
for i in range(len(pis)):
output_filename = "paste_output/slice_center_slice" + str(i+1) + "_pairwise.csv"
pi = pd.DataFrame(pis[i], index = center_slice.obs.index, columns = slices[i].obs.index)
Expand Down
5 changes: 4 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import numpy as np
import scanpy as sc
import pytest
from src.paste import intersect
from paste.helper import intersect

test_dir = Path(__file__).parent
input_dir = test_dir / "data/input"
Expand All @@ -27,6 +27,9 @@ def slices():

@pytest.fixture(scope="session")
def intersecting_slices(slices):
# Make a copy of the list
slices = list(slices)

common_genes = slices[0].var.index
for slice in slices[1:]:
common_genes = intersect(common_genes, slice.var.index)
Expand Down
Loading

0 comments on commit ce1e72b

Please sign in to comment.