dynamo.pd.tree_model
- dynamo.pd.tree_model(adata, group, progenitor, terminators, basis='umap', n_neighbors=30, neighbor_key=None, graph_mat=None, state_graph_method='vf', prune_graph=True, row_norm=True)[source]
This function learns a tree model of cell states (types).
It is based on the shortest path from the source to target cells of the pruned vector field based cell-type transition graph. The pruning was done by restricting cell state transition that are only between cell states that are nearby in gene expression space (often low gene expression space).
- Parameters
adata (
AnnData
) – AnnData object.group (
str
) – Cell graph that will be used to build transition graph and lineage tree.progenitor (
str
) – The source cell type name of the lineage tree.terminators (
List
[str
]) – The terminal cell type names of the lineage tree.basis (
str
) – The basis that will be used to build the k-nearest neighbor graph when neighbor_key is not set.n_neighbors (
int
) – The number of neighbors that will be used to build the k-nn graph, passed to dyn.tl.neighbors function. Not used when neighbor_key provided.neighbor_key (
Optional
[str
]) – The nearest neighbor graph key in adata.obsp. This nearest neighbor graph will be used to build a gene-expression space based cell-type level connectivity graph.state_graph_method (
str
) – Method that will be used to build the initial state graph.prune_graph (bool (default: True)) – Whether to prune the transition graph based on cell similarities in basis bases first before learning tree model.
row_norm (bool (default: True)) – Whether to normalize each row so that each row sum up to be 1. Note that row, columns in transition matrix correspond to source and targets in dynamo by default.
- Returns
The final tree model of cell groups. See following example on how to visualize the tree via dynamo.
- Return type
res
Examples
>>> import dynamo as dyn >>> adata = dyn.sample_data.pancreatic_endocrinogenesis() >>> dyn.pp.recipe_monocle(adata) >>> dyn.tl.dynamics(adata) >>> dyn.tl.cell_velocities(adata) >>> dyn.vf.VectorField(adata, basis='umap', pot_curl_div=False) >>> dyn.pd.state_graph(adata, group='clusters', basis='umap') >>> res = dyn.pd.tree_model(adata, group='clusters', basis='umap') >>> # in the following we first copy the state_graph result to a new key and then replace the `group_graph` key of >>> # the state_graph result and visualize tree model via dynamo. >>> adata.obs['clusters2'] = adata.obs['clusters'].copy() >>> adata.uns['clusters2_graph'] = adata.uns['clusters_graph'].copy() >>> adata.uns['clusters2_graph']['group_graph'] = res >>> dyn.pl.state_graph(adata, group='clusters2', keep_only_one_direction=False, transition_threshold=None, >>> color='clusters2', basis='umap', show_legend='on data')