cellrank.tl.transition_matrix¶
-
cellrank.tl.
transition_matrix
(adata, backward=False, vkey='velocity', xkey='Ms', conn_key='connectivities', gene_subset=None, mode='deterministic', backward_mode='transpose', 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 andcellrank.tl.kernels.ConnectivityKernel
for the similarity-based transition matrix.- Parameters
adata¶ (
anndata.AnnData
) – Annotated data object.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. Only used whenweight_connectivities > 0
.gene_subset¶ (
Optional
[Iterable
]) – List of genes to be used to compute transition probabilities. By default, genes fromadata.var['velocity_genes']
are used.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.
How to compute the backward transitions. Valid options are:
’transpose’ - compute transitions from neighboring cells j to cell i.
’negate’ - negate the velocity vector.
Similarity scheme between cells as described in [Li2020]. Can be one of the following:
’dot_product’ -
cellrank.tl.kernels.DotProductScheme
.’cosine’ -
cellrank.tl.kernels.CosineScheme
.’correlation’ -
cellrank.tl.kernels.CorrelationScheme
.
Alternatively, any function can be passed as long as it follows the call signature of
cellrank.tl.kernels.SimilaritySchemeABC
.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 counteract everything tending to orthogonality in high dimensions.weight_connectivities¶ (
Optional
[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 [Haghverdi16].key¶ (
Optional
[str
]) – Key used when writing transition matrix toadata
. If None, thekey
is set to ‘T_bwd’ ifbackward
is True, else ‘T_fwd’.kwargs¶ – Keyword arguments for
cellrank.tl.kernels.VelocityKernel.compute_transition_matrix()
.
- 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 calculation.
- Return type
cellrank.tl.KernelExpression