cellrank.tl.transition_matrix(adata, backward=False, vkey='velocity', xkey='Ms', conn_key='connectivities', gene_subset=None, mode=VelocityMode.DETERMINISTIC, backward_mode=BackwardMode.TRANSPOSE, scheme=Scheme.CORRELATION, softmax_scale=None, weight_connectivities=0.2, density_normalize=True, key=None, **kwargs)[source]

Compute a transition matrix based on a combination of RNA Velocity and transcriptomic or spatial similarity.

To learn more about the way in which the transition matrices are computed, see cellrank.tl.kernels.VelocityKernel for the velocity-based transition matrix and cellrank.tl.kernels.ConnectivityKernel for the similarity-based transition matrix.

  • adata (anndata.AnnData) – Annotated data object.

  • backward (bool) – Direction of the process.

  • vkey (str) – Key from adata.layers to access the velocities.

  • xkey (str) – Key in adata.layers where expected gene expression counts are stored.

  • conn_key (str) – Key in anndata.AnnData.obsp to obtain the connectivity matrix, describing cell-cell similarity.

  • gene_subset (Optional[Iterable]) – List of genes to be used to compute transition probabilities. By default, genes from adata.var['velocity_genes'] are used.

  • mode (Literal[‘deterministic’, ‘stochastic’, ‘sampling’, ‘monte_carlo’]) –

    How to compute transition probabilities. Valid options are:

    • ’deterministic’ - deterministic computation that doesn’t propagate uncertainty.

    • ’monte_carlo’ - Monte Carlo average of randomly sampled velocity vectors.

    • ’stochastic’ - second order approximation, only available when jax is installed.

    • ’sampling’ - sample 1 transition matrix from the velocity distribution.

  • backward_mode (Literal[‘transpose’, ‘negate’]) –

    How to compute the backward transitions. Valid options are:

    • ’transpose’ - compute transitions from neighboring cells \(j\) to cell \(i\).

    • ’negate’ - negate the velocity vector.

  • scheme (Union[Literal[‘dot_product’, ‘cosine’, ‘correlation’], Callable]) –

    Similarity scheme between cells as described in [Li et al., 2021]. Can be one of the following:

    Alternatively, any function can be passed as long as it follows the signature of cellrank.tl.kernels.SimilaritySchemeABC.__call__().

  • softmax_scale (Optional[float]) – Scaling parameter for the softmax. If None, it will be estimated using 1 / median(correlations). The idea behind this is to scale the softmax to counter everything tending to orthogonality in high dimensions.

  • weight_connectivities (float) – Weight given to similarities as opposed to velocities. Must be in [0, 1].

  • density_normalize (bool) – Whether to use density correction when computing the transition probabilities based on similarities. Density correction is done as by [Haghverdi et al., 2016].

  • key (Optional[str]) – Key used when writing transition matrix to adata. If None, determine the key automatically.

  • kwargs – Keyword arguments for cellrank.tl.kernels.VelocityKernel.compute_transition_matrix().

Return type



A kernel expression object containing the computed transition matrix.

Updates the adata with the following fields:

  • .obsp['{key}'] - the transition matrix.

  • .uns['{key}_params'] - parameters used for calculation.