From 140c54b7132ff8f6de7392b63d45d42062c57e9c Mon Sep 17 00:00:00 2001 From: Isaac Virshup Date: Thu, 28 Mar 2024 19:12:39 +0000 Subject: [PATCH] scanpy<1.10 compat --- muon/_core/preproc.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/muon/_core/preproc.py b/muon/_core/preproc.py index 2e39562..695c3aa 100644 --- a/muon/_core/preproc.py +++ b/muon/_core/preproc.py @@ -18,6 +18,7 @@ from sklearn.utils import check_random_state from anndata import AnnData +import scanpy from scanpy import logging from scanpy.tools._utils import _choose_representation from scanpy.neighbors._connectivity import umap @@ -26,6 +27,13 @@ from umap.umap_ import nearest_neighbors from numba import njit, prange +from packaging.version import Version + +if Version(scanpy.__version__) < Version("1.10"): + from scanpy.neighbors import _compute_connectivities_umap +else: + from scanpy.neighbors._connectivity import umap as _compute_connectivities_umap + from mudata import MuData # Computational methods for preprocessing @@ -585,7 +593,7 @@ def neighdist(cell, nz): neighbordistances = _sparse_csr_fast_knn(neighbordistances, n_neighbors + 1) logging.info("Calculating connectivities...") - connectivities = umap( + connectivities = _compute_connectivities_umap( knn_indices=neighbordistances.indices.reshape( (neighbordistances.shape[0], n_neighbors + 1) ),