Skip to content

Commit

Permalink
Merge pull request #585 from Sichao25/vel
Browse files Browse the repository at this point in the history
Debug the cell_velocities
  • Loading branch information
Xiaojieqiu authored Oct 6, 2023
2 parents dcfa5e0 + 152a3dd commit 8817a2c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 7 additions & 4 deletions dynamo/tools/Markov.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from sklearn.neighbors import NearestNeighbors
from tqdm import tqdm

from ..dynamo_logger import LoggerManager
from ..dynamo_logger import LoggerManager, main_warning
from ..simulation.utils import directMethod
from .utils import append_iterative_neighbor_indices, flatten

Expand Down Expand Up @@ -555,9 +555,12 @@ def is_normalized(self, P=None, tol=1e-3, sumto=1, axis=0, ignore_nan=True):
0 - check if the matrix is column normalized;
1 - check if the matrix is row normalized.
"""
P = self.P if P is None else P
sumfunc = np.sum if not ignore_nan else np.nansum
return np.all(np.abs(sumfunc(P, axis=axis) - sumto) < tol)
if not P:
main_warning("No transition matrix input. Normalization check is skipped.")
return True
else:
sumfunc = np.sum if not ignore_nan else np.nansum
return np.all(np.abs(sumfunc(P, axis=axis) - sumto) < tol)

def __reset__(self):
self.D = None
Expand Down
5 changes: 3 additions & 2 deletions dynamo/tools/cell_velocities.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ def cell_velocities(
if method == "kmc" and n_pca_components is None:
n_pca_components = 30
if n_pca_components is not None:
X = log1p_(adata, X)
X_plus_V = log1p_(adata, X + V)
X = log1p_(adata, X)
if "velocity_pca_fit" not in adata.uns_keys() or type(adata.uns["velocity_pca_fit"]) == str:
pca_monocle = PCA(
n_components=min(n_pca_components, X.shape[1] - 1),
Expand Down Expand Up @@ -562,7 +562,8 @@ def cell_velocities(
else:
transition_key = add_transition_key

adata.obsp[transition_key] = T
if method != "transform":
adata.obsp[transition_key] = T
if add_velocity_key is None:
velocity_key, grid_velocity_key = "velocity_" + basis, "grid_velocity_" + basis
else:
Expand Down

0 comments on commit 8817a2c

Please sign in to comment.