cellrank.tl.kernels.CytoTRACEKernel

class cellrank.tl.kernels.CytoTRACEKernel(adata, backward=False, layer='Ms', aggregation=CytoTRACEAggregation.MEAN, use_raw=False, compute_cond_num=False, check_connectivity=False, **kwargs)[source]

Kernel which computes directed transition probabilities based on a KNN graph and the CytoTRACE score [Gulati et al., 2020].

The KNN graph contains information about the (undirected) connectivities among cells, reflecting their similarity. CytoTRACE can be used to estimate cellular plasticity and in turn, a pseudotemporal ordering of cells from more plastic to less plastic states. This kernel internally uses the cellrank.tl.kernels.PseudotimeKernel to direct the KNN graph on the basis of the CytoTRACE-derived pseudotime.

Optionally, we apply a density correction as described in [Coifman et al., 2005], where we use the implementation of [Haghverdi et al., 2016].

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

  • backward (bool) – Direction of the process.

  • layer (str) – Key in anndata.AnnData.layers or ‘X’ for anndata.AnnData.X from where to get the expression.

  • aggregation (Literal[‘mean’, ‘median’, ‘hmean’, ‘gmean’]) –

    How to aggregate expression of the top-correlating genes. Valid options are:

    • ’mean’ - arithmetic mean.

    • ’median’ - median.

    • ’hmean’ - harmonic mean.

    • ’gmean’ - geometric mean.

  • compute_cond_num (bool) – Whether to compute condition number of the transition matrix. Note that this might be costly, since it does not use sparse implementation.

  • check_connectivity (bool) – Check whether the underlying KNN graph is connected.

  • kwargs (Any) – Keyword arguments for cellrank.tl.kernels.PseudotimeKernel.

Example

Workflow:

# import packages and load data
import scvelo as scv
import cellrank as cr
adata = cr.datasets.pancreas()

# standard pre-processing
sc.pp.filter_genes(adata, min_cells=10)
sc.pp.normalize_total(adata)
sc.pp.log1p(adata)
sc.pp.highly_variable_genes(adata)

# CytoTRACE by default uses imputed data - a simple way to compute KNN-imputed data is to use scVelo's moments
# function. However, note that this function expects `spliced` counts because it's designed for RNA velocity,
# so we're using a simple hack here:
if 'spliced' not in adata.layers or 'unspliced' not in adata.layers:
    adata.layers['spliced'] = adata.X
    adata.layers['unspliced'] = adata.X

# compute KNN-imputation using scVelo's moments function
scv.pp.moments(adata)

# import and initialize the CytoTRACE kernel, compute transition matrix - done!
from cellrank.tl.kernels import CytoTRACEKernel
ctk = CytoTRACEKernel(adata).compute_transition_matrix()

Attributes

adata

Annotated data object.

backward

Direction of the process.

condition_number

Condition number of the transition matrix.

kernels

Get the kernels of the kernel expression, except for constants.

params

Parameters which are used to compute the transition matrix.

pseudotime

Pseudotemporal ordering of cells.

shape

(n_cells, n_cells).

transition_matrix

Return row-normalized transition matrix.

Methods

compute_cytotrace([layer, aggregation, use_raw])

Re-implementation of the CytoTRACE algorithm [Gulati et al., 2020] to estimate cellular plasticity.

compute_projection([basis, key_added, copy])

Compute a projection of the transition matrix in the embedding.

compute_transition_matrix([...])

Compute transition matrix based on KNN graph and pseudotemporal ordering.

copy()

Return a copy of self.

plot_random_walks(n_sims[, max_iter, seed, ...])

Plot random walks in an embedding.

plot_single_flow(cluster, cluster_key, time_key)

Visualize outgoing flow from a cluster of cells [Mittnenzweig et al., 2021].

read(fname[, adata, copy])

Deserialize self from a file.

write(fname[, write_adata, ext])

Serialize self to a file.

write_to_adata([key])

Write the transition matrix and parameters used for computation to the underlying adata object.