CoSpar - dynamic inference by integrating transcriptome and lineage information


Import CoSpar as:

import cospar as cs

CoSpar is built around the AnnData object (usually called adata). For each cell, we store its RNA count matrix at adata.X, the gene names at adata.var_names,time information at adata.obs['time_info'], state annotation at adata.obs['state_info'], clonal information at adata.obsm['X_clone'], and 2-d embedding at adata.obsm['X_emb'].

Once the AnnData object is initialized via cs.pp.initialize_adata_object(), the typical flow of analysis is to 1) perform preprocessing and dimension reduction (cs.pp.*); 2) visualize and analyze clonal data alone (*); 3) infer transition map (cs.tmap.*); and 4) analyze inferred map (*) and then visualize the results with the plotting functions (*). Typically, each* function has a corresponding* function. We also provide several built-in datasets (cs.datasets.*) and miscellaneous functions to assist with the analysis (cs.hf.*). See tutorial for details.


pp.initialize_adata_object([adata, X_state, …])

Initialized the AnnData object.

pp.get_highly_variable_genes(adata[, …])

Get highly variable genes.


Remove cell-cycle correlated genes.

pp.get_X_pca(adata[, n_pca_comp])

Get X_pca.

pp.get_X_emb(adata[, n_neighbors, umap_min_dist])

Get X_emb using

pp.get_X_clone(adata, clone_data_cell_id, …)

Build the X_clone matrix from data.

pp.get_state_info(adata[, n_neighbors, …])

Update state_info using

pp.refine_state_info_by_marker_genes(adata, …)

Refine state info according to marker gene expression.


Refine state info by clustering states at given time points.

Transition map inference


Infer transition map for clonal data with multiple time points.


Infer transition map from clones with a single time point


Infer transition map from state information alone.


Compute transition map using only the lineage information.


tl.clonal_fate_bias(adata[, selected_fate, …])

Compute clonal fate bias towards a cluster.

tl.fate_biased_clones(adata, selected_fate)

Find clones that significantly biased towards a given fate

tl.fate_coupling(adata[, selected_fates, …])

Compute fate coupling determined by the transition map.

tl.fate_hierarchy(adata[, selected_fates, …])

Build fate hierarchy or lineage trees

tl.fate_map(adata[, selected_fates, source, …])

Compute transition probability to given fate/ancestor clusters.

tl.fate_potency(adata[, selected_fates, …])

Quantify how multi-potent a cell state is.

tl.fate_bias(adata[, selected_fates, …])

Compute fate bias to given two fate clusters (A, B).

tl.progenitor(adata[, selected_fates, …])

Identify trajectories towards/from two given clusters.

tl.iterative_differentiation(adata[, …])

Infer trajectory towards/from a cluster

tl.differential_genes(adata[, cell_group_A, …])

Perform differential gene expression analysis and plot top DGE genes.


Clone analysis (clone visualization, clustering etc.)

pl.clones_on_manifold(adata[, …])

Plot clones on top of state embedding.

pl.barcode_heatmap(adata[, selected_times, …])

Plot barcode heatmap among different fate clusters.

pl.clonal_fate_bias(adata[, show_histogram, FDR])

Plot clonal fate bias towards a cluster.

pl.fate_coupling(adata[, source, color_bar, …])

Plot fate coupling determined by the transition map.

pl.fate_hierarchy(adata[, source, …])

Plot fate hierarchy determined by the transition map.

pl.clonal_fates_across_time(adata, …)

Scatter plot for clonal fate number across time point

pl.clonal_reports(adata[, selected_times])

Report the statistics of the clonal data.

pl.visualize_tree(input_tree[, …])

Visualize a tree structured in ete3 style.

Transition map analysis (fate bias etc.)

pl.single_cell_transition(adata, …[, …])

Plot transition probability from given initial cell states.

pl.fate_map(adata[, selected_fates, source, …])

Plot transition probability to given fate/ancestor clusters.

pl.fate_potency(adata[, source, …])

Plot fate potency.

pl.fate_bias(adata[, selected_fates, …])

Plot fate bias.

pl.progenitor(adata[, selected_fates, …])

Plot the progenitors of given fate clusters.

pl.iterative_differentiation(adata[, …])

Plot the progenitors of given fates across time points

pl.gene_expression_dynamics(adata, …[, …])

Plot gene trend along the inferred dynamic trajectory.

pl.fate_coupling(adata[, source, color_bar, …])

Plot fate coupling determined by the transition map.

pl.fate_hierarchy(adata[, source, …])

Plot fate hierarchy determined by the transition map.


pl.embedding(adata[, basis, color, cmap])

Scatter plot for user-specified embedding basis.

pl.embedding_genes(adata[, basis, color, …])

A test embedding method for plotting genes

pl.gene_expression_on_manifold(adata, …[, …])

Plot gene expression on the state manifold.

pl.gene_expression_heatmap(adata[, …])

Plot heatmap of gene expression within given clusters.

settings.set_figure_params([style, dpi, …])

Set resolution/size, styling and format of figures.



The hematopoiesis data set from


The hematopoiesis data set from


Top 15% most heterogeneous clones of the hematopoiesis data set from


All of the hematopoiesis data set from


The direct lung differentiation dataset from


The reprogramming dataset from


The reprogramming dataset from


Synthetic clonal dataset with static barcoding.

Help functions[, backed, sheet, ext, …])

Read file and return AnnData object.


Save the adata and print the filename prefix.

hf.save_preprocessed_adata(adata[, data_des])

Save preprocessed adata.


Check whether the adata has the right structure.


Check available parameter choices.

hf.update_time_ordering(adata[, …])

Update the ordering of time points at adata.uns[‘time_ordering’]

hf.update_data_description(adata[, …])

Update data_des, a string to distinguish different datasets

tl.get_normalized_covariance(data[, method])

Compute the normalized correlation of the data matrix.


Build the X_clone matrix from data.


simulate.linear_differentiation_model([Nt1, …])

Simulate linear differentiation corrupted with barcode collision (See Fig.

simulate.bifurcation_model([progeny_N, t1, …])

Simulate bifurcation corrupted with clonal dispersion (See Fig.


Quantify the correlation of an inferred fate bias with the actual one, using a map from the Bifurcation Model.


Quantify the True positive rate of a transition map for linear differentiation model.