-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4d8cba9
commit 4937188
Showing
4 changed files
with
49 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,25 @@ | ||
from scvelo.tools.utils import prod_sum_obs, prod_sum_var, norm | ||
import numpy as np | ||
import scvelo as scv | ||
import scanpy.api as sc | ||
from scvelo.tools.utils import * | ||
from scipy import sparse, stats | ||
|
||
|
||
def test_data(n_obs=1000, n_vars=100): | ||
adata = sc.AnnData(sparse.random(n_obs, n_vars, data_rvs=stats.poisson(1).rvs, density=.6, format='csr')) | ||
adata.layers['spliced'] = adata.X | ||
adata.layers['unspliced'] = \ | ||
.5 * adata.X + .3 * sparse.random(n_obs, n_vars, density=.6, data_rvs=stats.poisson(1).rvs, format='csr') | ||
|
||
sc.pp.filter_genes(adata, min_counts=10) | ||
sc.pp.filter_genes_dispersion(adata) | ||
sc.pp.normalize_per_cell(adata, layers='all') | ||
sc.pp.pca(adata, n_comps=10) | ||
sc.pp.neighbors(adata, use_rep='X_pca') | ||
scv.pp.moments(adata) | ||
return adata | ||
|
||
|
||
def test_einsum(): | ||
adata = test_data() | ||
adata = scv.datasets.toy_data(n_obs=100, n_vars=100) | ||
adata = scv.pp.recipe_velocity(adata) | ||
Ms, Mu = adata.layers['Ms'], adata.layers['Mu'] | ||
assert np.allclose(prod_sum_obs(Ms, Mu), np.sum(Ms * Mu, 0)) | ||
assert np.allclose(prod_sum_var(Ms, Mu), np.sum(Ms * Mu, 1)) | ||
assert np.allclose(norm(Ms), np.linalg.norm(Ms, axis=1)) | ||
|
||
|
||
# def test_velocity_graph(): | ||
# adata = test_data() | ||
# scv.tl.velocity_graph(adata) | ||
# | ||
# graph1 = adata.uns['velocity_graph'].copy() | ||
# | ||
# scv.tl.velocity_graph(adata, n_jobs=2) | ||
# graph2 = adata.uns['velocity_graph'].copy() | ||
# | ||
# assert np.allclose((scv.tl.transition_matrix(adata) > 0).toarray(), (graph1 > 0).toarray()) | ||
# assert np.allclose(graph1.toarray(), graph2.toarray()) | ||
def test_velocity_graph(): | ||
adata = scv.datasets.toy_data(n_obs=1000, n_vars=100) | ||
scv.tl.velocity_graph(adata) | ||
|
||
graph1 = adata.uns['velocity_graph'].copy() | ||
|
||
scv.tl.velocity_graph(adata, n_jobs=2) | ||
graph2 = adata.uns['velocity_graph'].copy() | ||
|
||
assert np.allclose((scv.tl.transition_matrix(adata) > 0).toarray(), (graph1 > 0).toarray()) | ||
assert np.allclose(graph1.toarray(), graph2.toarray()) |