Skip to content

Commit

Permalink
Parameterize standardization
Browse files Browse the repository at this point in the history
  • Loading branch information
asistradition committed Dec 10, 2023
1 parent 491fce0 commit db96ad0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
6 changes: 5 additions & 1 deletion inferelator_velocity/program_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
def global_graph(
data,
layer="X",
standardize_layer_data=True,
neighbors=None,
npcs=None,
use_sparse=True,
Expand All @@ -31,6 +32,8 @@ def global_graph(
:type data: ad.AnnData
:param layer: Layer to use for kNN, defaults to "X"
:type layer: str, optional
:param standardize_layer_data: Depth-normalize and log1p data
:type standardize_layer_data: bool, optional
:param neighbors: Search space for k neighbors,
defaults to 15 - 105 by 10
:type neighbors: np.ndarray, optional
Expand Down Expand Up @@ -63,7 +66,8 @@ def global_graph(
npcs=npcs,
verbose=verbose,
use_sparse=use_sparse,
connectivity=connectivity
connectivity=connectivity,
standardize_count_data=standardize_layer_data
)

vprint(
Expand Down
9 changes: 6 additions & 3 deletions inferelator_velocity/utils/noise2self.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ def knn_noise2self(
metric='euclidean',
return_errors=False,
use_sparse=True,
connectivity=False
connectivity=False,
standardize_count_data=True
):
"""
Select an optimal set of graph parameters based on noise2self
Expand Down Expand Up @@ -100,8 +101,10 @@ def knn_noise2self(

data_obj = ad.AnnData(count_data.astype(np.float32))

sc.pp.normalize_per_cell(data_obj)
sc.pp.log1p(data_obj)
if standardize_count_data:
sc.pp.normalize_per_cell(data_obj)
sc.pp.log1p(data_obj)

sc.pp.pca(data_obj, n_comps=np.max(npcs), zero_center=True)

mses = np.zeros((len(npcs), len(neighbors)))
Expand Down
14 changes: 7 additions & 7 deletions inferelator_velocity/velocity.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def calc_velocity(
(n_idx == i).nonzero()[0][0],
wrap_time=wrap_time
)
for i, n_idx in _find_local(expr, neighbor_graph)
for i, n_idx in _find_local(neighbor_graph)
]
)

Expand Down Expand Up @@ -93,18 +93,18 @@ def _calc_local_velocity(
return _np.dot(x_for_hat, y_diff)


def _find_local(expr, neighbor_graph):
def _find_local(neighbor_graph):
"""
Find a return an expression matrix for a locally connected graph
Find a return indices from a locally connected graph
:param expr: Samples x Genes numpy or scipy with expression data
:type expr: np.ndarray, sp.sparse.csr_matrix
:param neighbor_graph: Samples x Samples connectivity matrix,
where any non-zero value is connected.
:return:
:type neighbor_graph: np.ndarray, sp.sparse.spmatrix
:yield: Center index, connected indices
:rtype: int, np.ndarray
"""

n, m = expr.shape
n, _ = neighbor_graph.shape
neighbor_sparse = _is_sparse(neighbor_graph)

for i in trange(n):
Expand Down

0 comments on commit db96ad0

Please sign in to comment.