cellrank.tl.transition_matrix
- cellrank.tl.transition_matrix(adata, backward=False, vkey='velocity', xkey='Ms', conn_key='connectivities', gene_subset=None, model=VelocityModel.DETERMINISTIC, backward_mode=BackwardMode.TRANSPOSE, similarity=Similarity.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 andcellrank.tl.kernels.ConnectivityKernel
for the similarity-based transition matrix.- Parameters
adata (
anndata.AnnData
) – Annotated data object.backward (
bool
) – Direction of the process.vkey (
str
) – Key fromadata.layers
to access the velocities.xkey (
str
) – Key inadata.layers
where expected gene expression counts are stored.conn_key (
str
) – Key inanndata.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 fromadata.var['velocity_genes']
are used.mode –
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.
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 –
Similarity measure between cells as described in [Li et al., 2021]. Can be one of the following:
’correlation’ -
cellrank.tl.kernels.utils.Correlation
.’cosine’ -
cellrank.tl.kernels.utils.Cosine
.’dot_product’ -
cellrank.tl.kernels.utils.DotProduct
.
Alternatively, any function can be passed as long as it follows the signature of
cellrank.tl.kernels.utils.SimilarityABC.__call__()
.softmax_scale (
Optional
[float
]) – Scaling parameter for the softmax. If None, it will be estimated using1 / 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 toadata
. If None, the key will be determined automatically.kwargs – Keyword arguments for
cellrank.tl.kernels.VelocityKernel.compute_transition_matrix()
.
- Return type
KernelExpression
- Returns
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 the calculation.