# Path: scvelo/preprocessing/neighbors.py
# def get_connectivities(
#     adata, mode="connectivities", n_neighbors=None, recurse_neighbors=False
# ):
#     if "neighbors" in adata.uns.keys():
#         C = get_neighs(adata, mode)
#         if n_neighbors is not None and n_neighbors < get_n_neighs(adata):
#             if mode == "connectivities":
#                 C = select_connectivities(C, n_neighbors)
#             else:
#                 C = select_distances(C, n_neighbors)
#         connectivities = C > 0
#         with warnings.catch_warnings():
#             warnings.simplefilter("ignore")
#             connectivities.setdiag(1)
#             if recurse_neighbors:
#                 connectivities += connectivities.dot(connectivities * 0.5)
#                 connectivities.data = np.clip(connectivities.data, 0, 1)
#             connectivities = connectivities.multiply(1.0 / connectivities.sum(1))
#         return connectivities.tocsr().astype(np.float32)
#     else:
#         return None
# 
# def get_neighs(adata, mode="distances"):
#     if hasattr(adata, "obsp") and mode in adata.obsp.keys():
#         return adata.obsp[mode]
#     elif "neighbors" in adata.uns.keys() and mode in adata.uns["neighbors"]:
#         return adata.uns["neighbors"][mode]
#     else:
#         raise ValueError("The selected mode is not valid.")
# 
# Path: scvelo/tools/utils.py
# def normalize(X):
#     with warnings.catch_warnings():
#         warnings.simplefilter("ignore")
#         if issparse(X):
#             return X.multiply(csr_matrix(1.0 / np.abs(X).sum(1)))
#         else:
#             return X / X.sum(1)


import warnings
import numpy as np
import pandas as pd
from scipy.sparse import csr_matrix, SparseEfficiencyWarning
from scipy.spatial.distance import pdist, squareform
from scvelo.preprocessing.neighbors import get_connectivities, get_neighs
from .utils import normalize
        from sklearn.neighbors import NearestNeighbors



warnings.simplefilter("ignore", SparseEfficiencyWarning)


def transition_matrix(
    adata,
    vkey="velocity",
    basis=None,
    backward=False,
    self_transitions=True,

# Path: scvelo/preprocessing/neighbors.py
# def get_connectivities(
#     adata, mode="connectivities", n_neighbors=None, recurse_neighbors=False
# ):
#     if "neighbors" in adata.uns.keys():
#         C = get_neighs(adata, mode)
#         if n_neighbors is not None and n_neighbors < get_n_neighs(adata):
#             if mode == "connectivities":
#                 C = select_connectivities(C, n_neighbors)
#             else:
#                 C = select_distances(C, n_neighbors)
#         connectivities = C > 0
#         with warnings.catch_warnings():
#             warnings.simplefilter("ignore")
#             connectivities.setdiag(1)
#             if recurse_neighbors:
#                 connectivities += connectivities.dot(connectivities * 0.5)
#                 connectivities.data = np.clip(connectivities.data, 0, 1)
#             connectivities = connectivities.multiply(1.0 / connectivities.sum(1))
#         return connectivities.tocsr().astype(np.float32)
#     else:
#         return None
# 
# def get_neighs(adata, mode="distances"):
#     if hasattr(adata, "obsp") and mode in adata.obsp.keys():
#         return adata.obsp[mode]
#     elif "neighbors" in adata.uns.keys() and mode in adata.uns["neighbors"]:
#         return adata.uns["neighbors"][mode]
#     else:
#         raise ValueError("The selected mode is not valid.")
# 
# Path: scvelo/tools/utils.py
# def normalize(X):
#     with warnings.catch_warnings():
#         warnings.simplefilter("ignore")
#         if issparse(X):
#             return X.multiply(csr_matrix(1.0 / np.abs(X).sum(1)))
#         else:
#             return X / X.sum(1)


# Path: scvelo/tools/transition_matrix.py
import warnings
import numpy as np
import pandas as pd
from scipy.sparse import csr_matrix, SparseEfficiencyWarning
from scipy.spatial.distance import pdist, squareform
from scvelo.preprocessing.neighbors import get_connectivities, get_neighs
from .utils import normalize
        from sklearn.neighbors import NearestNeighbors




warnings.simplefilter("ignore", SparseEfficiencyWarning)


def transition_matrix(
    adata,
    vkey="velocity",
    basis=None,
    backward=False,
    self_transitions=True,

    scale=10,