def gen_or_read_zebrafish_data(): # generate data if needed if not os.path.exists(test_zebrafish_data_path): print("generating test data...") gen_zebrafish_test_data() print("reading test data...") # To-do: use a fixture in future adata = dyn.read_h5ad(test_zebrafish_data_path) return adata
def color_set(data, gene): gene_idx = np.where(data.var_names == gene)[0][0] c = np.squeeze(np.asarray(data.X[:, gene_idx].todense())) return c dataset = sys.argv[1] embs = ['X_pca', 'X_umap'] #3 is the stationary distribution, it will used later plots = ['FN1', 'VIM', 3] P = np.loadtxt(dataset + '_P.npy') Idx = np.load(dataset + '_idx.npy', allow_pickle=True) adata = dyn.read_h5ad(dataset + '_processed.h5ad') kmc = dyn.tl.KernelMarkovChain(P=P, Idx=Idx) X = adata.layers['M_s'][:, adata.var['use_for_velocity']] V = adata.layers['velocity_S'][:, adata.var['use_for_velocity']] sd = kmc.compute_stationary_distribution() for plot in plots: for emb in embs: X_emb = adata.obsm[emb] Uc = kmc.compute_density_corrected_drift(X_emb, normalize_vector=True) U_grid, X_grid = dyn.tl.smoothen_drift_on_grid(X_emb[:, :2], Uc[:, :2], 30, k=50,
def read_test_spatial_genomics_data(): return dyn.read_h5ad(test_spatial_genomics_path)
filename = sys.argv[1] dataset_name = filename.split("/")[-1].split(".")[0] #file_extension=filename.split(".")[-1] file_extension = 'h5ad' processed_output_path = dataset_name + '_processed.' + file_extension P_output_path = dataset_name + '_P.' + 'npy' idx_output_path = dataset_name + '_idx.' + 'npy' print() print('Loading Data') print() if filename.endswith('.h5ad'): adata = dyn.read_h5ad(filename) elif filename.endswith('.loom'): adata = dyn.read_loom(filename) else: print('file type not currently supported') print() print('Initial Preprocessing') print() dyn.pp.recipe_monocle(adata, n_top_genes=2000) print() print('Computing Dynamics') print() dyn.tl.dynamics(adata, mode='moment')
def test_space_data(): adata = dyn.read_h5ad("allstage_splice.h5ad")
# dyn.tl.cluster_community(adata, method="infomap") assert np.all(adata.obs["louvain"] != -1) assert np.all(adata.obs["leiden"] != -1) assert np.all(adata.obs["infomap"] != -1) # dyn.pl.louvain(adata, basis="pca") # dyn.pl.leiden(adata, basis="pca") # dyn.pl.infomap(adata, basis="pca") def test_simple_cluster_field(adata): dyn.tl.cluster_field(adata, method="louvain") dyn.tl.cluster_field(adata, method="leiden") if __name__ == "__main__": # generate data if needed if not os.path.exists(test_data_path): print("generating test data...") gen_test_data() print("reading test data...") # To-do: use a fixture in future adata = dyn.read_h5ad(test_data_path) print(adata) # select a subset of adata for testing print("tests begin...") ######### testing begins here ######### test_simple_cluster_community_adata(adata) # test_simple_cluster_field(adata)