Skip to content

Commit

Permalink
Wrap scanpy.pp.log1p
Browse files Browse the repository at this point in the history
  • Loading branch information
michalk8 committed May 23, 2023
1 parent 11d8f44 commit 2d22a2f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
14 changes: 4 additions & 10 deletions scvelo/preprocessing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from scipy.sparse import issparse
from sklearn.utils import sparsefuncs

from anndata import AnnData

from scvelo import logging as logg
from scvelo.core import get_initial_size, get_size, multiply, set_initial_size, sum

Expand Down Expand Up @@ -587,14 +585,10 @@ def log1p(data, copy=False):
-------
Returns or updates `adata` depending on `copy`.
"""
adata = data.copy() if copy else data
X = (
(adata.X.data if issparse(adata.X) else adata.X)
if isinstance(adata, AnnData)
else adata
)
np.log1p(X, out=X)
return adata if copy else None
from scanpy.pp import log1p as _log1p

res = _log1p(data, copy=copy)
return res if copy else None


def filter_and_normalize(
Expand Down
4 changes: 3 additions & 1 deletion tests/preprocessing/test_moments.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,11 @@ def test_analytic_example(self, sparse: bool):
)

second_order_moment_centered = get_moments(adata=adata, second_order=True)
np.testing.assert_almost_equal(
np.testing.assert_allclose(
second_order_moment_centered,
second_order_moment_uncentered - first_order_moment_ground_truth**2,
rtol=1e-6,
atol=1e-6,
)


Expand Down
4 changes: 2 additions & 2 deletions tests/preprocessing/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2321,7 +2321,7 @@ def test_pancreas50obs(self, capfd, pancreas_50obs):
)
)
assert pancreas_50obs.var.columns.equals(pd.Index(["gene_count_corr"]))
assert [*pancreas_50obs.uns] == ["pca", "neighbors"]
assert [*pancreas_50obs.uns] == ["log1p", "pca", "neighbors"]
assert [*pancreas_50obs.obsm] == ["X_pca"]
assert [*pancreas_50obs.varm] == ["PCs"]
assert [*pancreas_50obs.layers] == ["spliced", "unspliced", "Ms", "Mu"]
Expand Down Expand Up @@ -2373,7 +2373,7 @@ def test_dentategyrus50obs(self, capfd, dentategyrus_50obs):
)
)
assert dentategyrus_50obs.var.columns.equals(pd.Index([]))
assert [*dentategyrus_50obs.uns] == ["pca", "neighbors"]
assert [*dentategyrus_50obs.uns] == ["log1p", "pca", "neighbors"]
assert [*dentategyrus_50obs.obsm] == ["X_pca"]
assert [*dentategyrus_50obs.varm] == ["PCs"]
assert [*dentategyrus_50obs.layers] == [
Expand Down

0 comments on commit 2d22a2f

Please sign in to comment.