def test_non_unique_names(self, adata: AnnData, path: Path, lin_key: str, _: int): names_key = _lin_names(lin_key) adata.uns[names_key][0] = adata.uns[names_key][1] sc.write(path, adata) with pytest.raises(ValueError): _ = cr.read(path)
def test_no_lineage(self, adata: AnnData, path: Path, lin_key: str, _: int): del adata.obsm[lin_key] sc.write(path, adata) adata_new = cr.read(path) assert adata_new is not adata # sanity check assert lin_key not in adata_new.obsm.keys()
def test_no_colors(self, adata: AnnData, path: Path, lin_key: str, n_lins: int): colors_key = _colors(lin_key) del adata.uns[colors_key] sc.write(path, adata) adata_new = cr.read(path) lins = adata_new.obsm[lin_key] assert isinstance(lins, Lineage) np.testing.assert_array_equal(lins.colors, _create_categorical_colors(n_lins)) np.testing.assert_array_equal(lins.colors, adata_new.uns[colors_key])
def test_no_names(self, adata: AnnData, path: Path, lin_key: str, n_lins: int): names_key = _lin_names(lin_key) del adata.uns[names_key] sc.write(path, adata) adata_new = cr.read(path) lins = adata_new.obsm[lin_key] assert isinstance(lins, Lineage) np.testing.assert_array_equal(lins.names, [f"Lineage {i}" for i in range(n_lins)]) np.testing.assert_array_equal(lins.names, adata_new.uns[names_key])
def test_normal_run(self, adata: AnnData, path: Path, lin_key: str, n_lins: int): colors = _create_categorical_colors(10)[-n_lins:] names = [f"foo {i}" for i in range(n_lins)] adata.uns[_colors(lin_key)] = colors adata.uns[_lin_names(lin_key)] = names sc.write(path, adata) adata_new = cr.read(path) lins_new = adata_new.obsm[lin_key] np.testing.assert_array_equal(lins_new.colors, colors) np.testing.assert_array_equal(lins_new.names, names)
def test_wrong_names_length(self, adata: AnnData, path: Path, lin_key: str, n_lins: int): names_key = _lin_names(lin_key) adata.uns[names_key] = list(adata.uns[names_key]) adata.uns[names_key] += ["foo", "bar", "baz"] sc.write(path, adata) adata_new = cr.read(path) lins = adata_new.obsm[lin_key] assert isinstance(lins, Lineage) np.testing.assert_array_equal(lins.names, [f"Lineage {i}" for i in range(n_lins)]) np.testing.assert_array_equal(lins.names, adata_new.uns[names_key])
n_jobs = 16 n_samples = 50_000 cr.logging.print_versions() scv.settings.set_figure_params("scvelo", dpi_save=400, dpi=80, transparent=True, fontsize=20, color_map="viridis") if os.path.isfile(ROOT / "adata_preprocessed.h5ad") and os.path.isfile( ROOT / "terminal_states.csv"): print(f"Loading data from `{ROOT}`") adata = cr.read(ROOT / "adata_preprocessed.h5ad") terminal_states = pd.read_csv(ROOT / "terminal_states.csv", index_col=0)["0"] terminal_states = terminal_states.astype("category") else: print("Preprocessing") adata = cr.datasets.pancreas(DATA_DIR / "pancreas" / "pancreas.h5ad") scv.pp.filter_and_normalize(adata, min_shared_counts=20, n_top_genes=2000, log=True) sc.tl.pca(adata) sc.pp.neighbors(adata, n_pcs=30, n_neighbors=30) scv.pp.moments(adata, n_pcs=30, n_neighbors=30)