diff --git a/scprep/run/conversion.py b/scprep/run/conversion.py index 1024df86..fa03bc70 100644 --- a/scprep/run/conversion.py +++ b/scprep/run/conversion.py @@ -3,6 +3,7 @@ from .._lazyload import rpy2 import numpy as np +import scipy.sparse import warnings @@ -46,6 +47,18 @@ def _pysce2rpy(pyobject): return pyobject +def _rpyspmatrix2py(robject): + if utils._try_import("anndata2ri"): + robject = anndata2ri.scipy2ri.rpy2py(robject) + return robject + + +def _pyspmatrix2rpy(pyobject): + if utils._try_import("anndata2ri") and isinstance(pyobject, scipy.sparse.spmatrix): + pyobject = anndata2ri.scipy2ri.py2rpy(pyobject) + return pyobject + + def _is_r_object(obj): return "rpy2.robjects" in str(type(obj)) or "rpy2.rinterface" in str(type(obj)) @@ -76,6 +89,7 @@ def rpy2py(robject): for converter in [ _rpynull2py, _rpysce2py, + _rpyspmatrix2py, rpy2.robjects.pandas2ri.rpy2py, _rpylist2py, rpy2.robjects.numpy2ri.rpy2py, @@ -119,6 +133,7 @@ def py2rpy(pyobject): for converter in [ _pynull2rpy, _pysce2rpy, + _pyspmatrix2rpy, rpy2.robjects.pandas2ri.py2rpy, rpy2.robjects.numpy2ri.py2rpy, rpy2.robjects.conversion.py2rpy, diff --git a/scprep/stats.py b/scprep/stats.py index b79bbaff..f1d922f9 100644 --- a/scprep/stats.py +++ b/scprep/stats.py @@ -11,7 +11,6 @@ import numbers import numpy as np import pandas as pd -import scipy.sparse import warnings plt = matplotlib.pyplot @@ -550,7 +549,7 @@ def differential_expression( X, Y, measure="difference", direction="both", gene_names=None, n_jobs=-2 ): """Calculate the most significant genes between two datasets. - + If using ``measure="emd"``, the test statistic is multiplied by the sign of the mean differencein order to allow for distinguishing between positive and negative shifts. To ignore this, use ``direction="both"`` to sort by the diff --git a/scprep/version.py b/scprep/version.py index c68196d1..a955fdae 100644 --- a/scprep/version.py +++ b/scprep/version.py @@ -1 +1 @@ -__version__ = "1.2.0" +__version__ = "1.2.1" diff --git a/setup.py b/setup.py index f594ac43..1a220d9a 100644 --- a/setup.py +++ b/setup.py @@ -25,7 +25,7 @@ "mock", "h5py", "matplotlib>=3.0", - "rpy2>=3.0", + "rpy2>=3.0,<3.4.3", "black", ] diff --git a/test/test_run.py b/test/test_run.py index aa728b39..e3e20499 100644 --- a/test/test_run.py +++ b/test/test_run.py @@ -596,6 +596,8 @@ def test_conversion_spmatrix(): assert isinstance(x, scipy.sparse.csc_matrix) assert x.shape == (2, 3) assert np.all(x.toarray() == np.array([[1, 3, 5], [2, 4, 6]])) + y = scprep.run.conversion.py2rpy(x) + assert (scprep.run.conversion.rpy2py(y) != x).nnz == 0 def test_conversion_dataframe(): x = scprep.run.conversion.rpy2py( diff --git a/test/test_stats.py b/test/test_stats.py index ae93a952..09598b85 100644 --- a/test/test_stats.py +++ b/test/test_stats.py @@ -7,7 +7,6 @@ import numpy as np import os -import scipy.sparse import scprep import warnings