Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize code coverage tests #605

Merged
merged 32 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
471fb0b
add sampling tests
Sichao25 Jul 27, 2023
d43915e
create tests for 1nd and 2nd moments
Sichao25 Jul 27, 2023
9292f2e
create tests for markers and growth
Sichao25 Jul 28, 2023
b96f3f1
increase coverage for preprocessor
Sichao25 Aug 1, 2023
a467605
add transform tests
Sichao25 Aug 5, 2023
9d4a8a1
add coverage for dynamics
Sichao25 Aug 5, 2023
30b4ba5
optimize preprocess tests
Sichao25 Nov 1, 2023
58ca01b
merge master
Sichao25 Nov 1, 2023
0bf6de1
remove main function from tests module
Sichao25 Nov 1, 2023
126c8d6
rearrange tool tests
Sichao25 Nov 1, 2023
605bd28
debug and reduce test data size
Sichao25 Nov 2, 2023
b0b49bb
debug cell growth and scores tests
Sichao25 Nov 2, 2023
f6833ba
merge master
Sichao25 Nov 10, 2023
c535d94
merge clustering tests to tools tests
Sichao25 Nov 10, 2023
e412eb9
Merge branch 'aristoteleo:master' into codecov
Sichao25 Nov 20, 2023
9c2bc9d
add more tests for preprocessing
Sichao25 Nov 15, 2023
457fc95
debug umap pytest compatibility issue
Sichao25 Nov 20, 2023
f6b6d10
add tests for pseudotime related funcs and psl
Sichao25 Nov 20, 2023
4249dac
add tests for graph tools
Sichao25 Nov 20, 2023
b3837f3
add more test for tools
Sichao25 Nov 21, 2023
ecf1326
Merge branch 'aristoteleo:master' into codecov
Sichao25 Dec 1, 2023
54de121
create test vector_calculus
Sichao25 Nov 29, 2023
f1128ff
create tests for rank_vf and cell_vectors
Sichao25 Nov 30, 2023
9d34482
create tests for fate perturbation state_graph
Sichao25 Dec 1, 2023
97f32f6
merge master
Sichao25 Dec 14, 2023
80b4c6c
Merge branch 'aristoteleo:master' into codecov
Sichao25 Feb 5, 2024
03ff0eb
add tests for least_graph trajectory_analysis simulate_anndata
Sichao25 Feb 5, 2024
b2c76bb
Merge branch 'aristoteleo:master' into codecov
Sichao25 Feb 29, 2024
0d4a605
increase coverage for plots and debug tl tests
Sichao25 Mar 1, 2024
c7fdf33
increase codecov and add plots test to corresponding steps
Sichao25 Mar 1, 2024
9ea72e5
Merge branch 'aristoteleo:master' into codecov
Sichao25 Mar 26, 2024
e34e003
debug plot tests
Sichao25 Mar 26, 2024
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
1 change: 0 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[pytest]
python_files = *.py
testpaths = tests
xfail_strict = true
13 changes: 11 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,24 @@ def mkdirs_wrapper(path: Union[str, Path], abort=True):

def gen_zebrafish_test_data():
raw_adata = dyn.sample_data.zebrafish()
adata = raw_adata[:, :5000].copy()
adata = raw_adata[:300, :1000].copy()
del raw_adata

preprocessor = dyn.pp.Preprocessor(cell_cycle_score_enable=True)
preprocessor.config_monocle_recipe(adata, n_top_genes=100)
preprocessor.config_monocle_recipe(adata, n_top_genes=40)
preprocessor.filter_genes_by_outliers_kwargs["inplace"] = True
preprocessor.select_genes_kwargs["keep_filtered"] = False
preprocessor.pca_kwargs["n_pca_components"] = 5
preprocessor.preprocess_adata_monocle(adata)

dyn.tl.dynamics(adata, model="stochastic")
dyn.tl.reduceDimension(adata)
dyn.tl.cell_velocities(adata)
dyn.vf.VectorField(adata, basis="umap")

dyn.tl.cell_velocities(adata, basis="pca")
dyn.vf.VectorField(adata, basis="pca")

TestUtils.mkdirs_wrapper(test_data_dir, abort=False)
adata.write_h5ad(test_zebrafish_data_path)

Expand Down
66 changes: 0 additions & 66 deletions tests/test_clustering.py

This file was deleted.

4 changes: 0 additions & 4 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,3 @@ def test_config_change():
import dynamo.configuration as imported_config

assert imported_config.DynamoAdataConfig.data_store_mode == "succinct"


if __name__ == "__main__":
test_config_change()
8 changes: 0 additions & 8 deletions tests/test_data_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,3 @@ def alpha_minus_gamma_s(new, gamma, t, M_s):

dyn.vf.rank_jacobian_genes(adata, groups="leiden")
adata.write_h5ad("debug11.h5ad")


if __name__ == "__main__":
# test_scEU_seq()
# adata = utils.gen_or_read_zebrafish_data()
# test_save_rank_info(adata)
# test_save_adata()
pass
27 changes: 0 additions & 27 deletions tests/test_estimation.py

This file was deleted.

14 changes: 0 additions & 14 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,3 @@ def test_cell_cycle_score_logger_pancreatic_endocrinogenesis():
# genes_to_exclude=["Sbspon", "Adgrb3", "Eif2s3y"],
)
dyn.pp.cell_cycle_scores(adata)


if __name__ == "__main__":
test_tqdm_style_loops()

test_logger_simple_output_1(LoggerManager.get_main_logger())
test_logger_simple_progress_naive(LoggerManager.get_main_logger())
test_logger_simple_progress_logger(LoggerManager.get_main_logger())
test_logger_simple_progress_logger(LoggerManager.get_temp_timer_logger())

test_vectorField_logger()
test_zebrafish_topography_tutorial_logger()
test_cell_cycle_score_logger_pancreatic_endocrinogenesis()
test_sparseVFC_logger()
66 changes: 0 additions & 66 deletions tests/test_neighbors.py

This file was deleted.

102 changes: 96 additions & 6 deletions tests/test_pipeline.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,99 @@
import dynamo as dyn

import pytest

def test_dynamcis(adata):
adata.uns["pp"]["tkey"] = None
dyn.tl.dynamics(adata, model="stochastic")
dyn.tl.reduceDimension(adata)
dyn.tl.cell_velocities(adata)
dyn.vf.VectorField(adata, basis="umap", M=100)
raw_adata = dyn.sample_data.zebrafish()
adata = raw_adata[:300, :1000].copy()
del raw_adata

preprocessor = dyn.pp.Preprocessor(cell_cycle_score_enable=True)
preprocessor.config_monocle_recipe(adata, n_top_genes=100)
preprocessor.filter_genes_by_outliers_kwargs["inplace"] = True
preprocessor.select_genes_kwargs["keep_filtered"] = False
preprocessor.preprocess_adata_monocle(adata)

dyn.tl.dynamics(adata, model="deterministic")


@pytest.mark.skip(reason="extra dependency requests-cache not installed")
def test_run_rpe1_tutorial():
import numpy as np

raw_adata = dyn.sample_data.scEU_seq_rpe1()
rpe1 = raw_adata[5000:, :500].copy()
del raw_adata

# create rpe1 kinectics
rpe1_kinetics = rpe1[rpe1.obs.exp_type == "Pulse", :]
rpe1_kinetics.obs["time"] = rpe1_kinetics.obs["time"].astype(str)
rpe1_kinetics.obs.loc[rpe1_kinetics.obs["time"] == "dmso", "time"] = -1
rpe1_kinetics.obs["time"] = rpe1_kinetics.obs["time"].astype(float)
rpe1_kinetics = rpe1_kinetics[rpe1_kinetics.obs.time != -1, :]

rpe1_kinetics.layers["new"], rpe1_kinetics.layers["total"] = (
rpe1_kinetics.layers["ul"] + rpe1_kinetics.layers["sl"],
rpe1_kinetics.layers["su"]
+ rpe1_kinetics.layers["sl"]
+ rpe1_kinetics.layers["uu"]
+ rpe1_kinetics.layers["ul"],
)

del rpe1_kinetics.layers["uu"], rpe1_kinetics.layers["ul"], rpe1_kinetics.layers["su"], rpe1_kinetics.layers["sl"]
dyn.pl.basic_stats(rpe1_kinetics, save_show_or_return="return")
rpe1_genes = ["UNG", "PCNA", "PLK1", "HPRT1"]

assert np.sum(rpe1_kinetics.var_names.isnull()) == 0

rpe1_kinetics.obs.time = rpe1_kinetics.obs.time.astype("float")
rpe1_kinetics.obs.time = rpe1_kinetics.obs.time / 60
rpe1_kinetics.obs.time.value_counts()
# rpe1_kinetics = dyn.pp.recipe_monocle(rpe1_kinetics, n_top_genes=1000, total_layers=False, copy=True)
dyn.pp.recipe_monocle(rpe1_kinetics, n_top_genes=100, total_layers=False)

dyn.tl.dynamics(rpe1_kinetics, model="deterministic", tkey="time", est_method="twostep", cores=16)
dyn.tl.reduceDimension(rpe1_kinetics, reduction_method="umap")
dyn.tl.cell_velocities(rpe1_kinetics, enforce=True, vkey="velocity_T", ekey="M_t")

rpe1_kinetics.obsm["X_RFP_GFP"] = rpe1_kinetics.obs.loc[
:, ["RFP_log10_corrected", "GFP_log10_corrected"]
].values.astype("float")
rpe1_kinetics.layers["velocity_S"] = rpe1_kinetics.layers["velocity_T"].copy()
dyn.tl.cell_velocities(rpe1_kinetics, enforce=True, vkey="velocity_S", ekey="M_t", basis="RFP_GFP")

rpe1_kinetics.obs.Cell_cycle_relativePos = rpe1_kinetics.obs.Cell_cycle_relativePos.astype(float)
rpe1_kinetics.obs.Cell_cycle_possition = rpe1_kinetics.obs.Cell_cycle_possition.astype(float)

dyn.pl.streamline_plot(
rpe1_kinetics,
color=["Cell_cycle_possition", "Cell_cycle_relativePos"],
basis="RFP_GFP",
save_show_or_return="return",
)
dyn.pl.streamline_plot(rpe1_kinetics, color=["cell_cycle_phase"], basis="RFP_GFP", save_show_or_return="return")
dyn.vf.VectorField(rpe1_kinetics, basis="RFP_GFP")
progenitor = rpe1_kinetics.obs_names[rpe1_kinetics.obs.Cell_cycle_relativePos < 0.1]

np.random.seed(19491001)

from matplotlib import animation

info_genes = rpe1_kinetics.var_names[rpe1_kinetics.var.use_for_transition]
dyn.pd.fate(
rpe1_kinetics,
basis="RFP_GFP",
init_cells=progenitor,
interpolation_num=100,
direction="forward",
inverse_transform=False,
average=False,
)

import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax = dyn.pl.topography(
rpe1_kinetics, basis="RFP_GFP", color="Cell_cycle_relativePos", ax=ax, save_show_or_return="return"
)
ax.set_aspect(0.8)

instance = dyn.mv.StreamFuncAnim(adata=rpe1_kinetics, basis="RFP_GFP", color="Cell_cycle_relativePos", ax=ax)
Loading
Loading