Mapping Vector Field of Single Cells

# API

Import dynamo as:

import dynamo as dyn


## Data IO

(See more at anndata-docs)

 read(filename[, backed, as_sparse, ...]) Read .h5ad-formatted hdf5 file. read_h5ad(filename[, backed, as_sparse, ...]) Read .h5ad-formatted hdf5 file. read_loom(filename[, sparse, cleanup, ...]) Read .loom-formatted hdf5 file.

## Preprocessing (pp)

 pp.convert2symbol(adata[, scopes, subset]) This helper function converts unofficial gene names to official gene names. pp.filter_cells(adata[, filter_bool, layer, ...]) Select valid cells based on a collection of filters including spliced, unspliced and protein min/max vals. pp.filter_genes(adata[, filter_bool, layer, ...]) Basic filter of genes based a collection of expression filters. pp.filter_genes_by_pattern(adata[, ...]) Utility function to filter mitochondria, ribsome protein and ERCC spike-in genes, etc. pp.normalize_cells(adata[, layers, ...]) Normalize the gene expression value for the AnnData object This function is partly based on Monocle R package (https://github.com/cole-trapnell-lab/monocle3). pp.scale(adata[, layers, scale_to_layer, ...]) scale layers to a particular total expression value, similar to normalize_expr_data function. pp.log1p(adata[, layers, copy]) perform log1p transform on selected adata layers pp.pca_monocle(adata[, X_data, ...]) pp.top_pca_genes(adata[, pc_key, ...]) Define top genes as any gene that is n_top_genes in some principle component. pp.recipe_monocle(adata[, reset_X, tkey, ...]) This function is partly based on Monocle R package (https://github.com/cole-trapnell-lab/monocle3). pp.cell_cycle_scores(adata[, layer, ...]) Call cell cycle positions for cells within the population.

## Estimation (est)

Note

Classes in est are internally to Tools. See our estimation classes here: estimation

## Tools (tl)

kNN and moments of expressions

 tl.neighbors(adata[, X_data, genes, basis, ...]) Function to search nearest neighbors of the adata object. tl.mnn(adata[, n_pca_components, ...]) Function to calculate mutual nearest neighbor graph across specific data layers. tl.moments(adata[, X_data, genes, group, ...]) Calculate kNN based first and second moments (including uncentered covariance) for

Kinetic parameters and RNA/protein velocity

 tl.dynamics(adata[, filter_gene_mode, ...]) Inclusive model of expression dynamics considers splicing, metabolic labeling and protein translation.

Labeling Velocity recipes

 tl.recipe_deg_data(adata[, tkey, reset_X, ...]) An analysis recipe that properly pre-processes different layers for a degradation experiment with both labeling and splicing data or only labeling . tl.recipe_kin_data(adata[, tkey, reset_X, ...]) An analysis recipe that properly pre-processes different layers for an kinetics experiment with both labeling and splicing or only labeling data. tl.recipe_mix_kin_deg_data(adata[, tkey, ...]) An analysis recipe that properly pre-processes different layers for an mixture kinetics and degradation experiment with both labeling and splicing or only labeling data. tl.recipe_one_shot_data(adata[, tkey, ...]) An analysis recipe that properly pre-processes different layers for an one-shot experiment with both labeling and splicing data. tl.velocity_N(adata[, group, ...]) use new RNA based pca, umap, for velocity calculation and projection for kinetics or one-shot experiment.

Dimension reduction

 tl.reduceDimension(adata[, X_data, genes, ...]) Compute a low dimension reduction projection of an annodata object first with PCA, followed by non-linear dimension reduction methods tl.DDRTree(X, maxIter, sigma, gamma[, eps, ...]) This function is a pure Python implementation of the DDRTree algorithm. tl.psl(Y[, sG, dist, K, C, param_gamma, d, ...]) This function is a pure Python implementation of the PSL algorithm.

Clustering

 tl.hdbscan(adata[, X_data, genes, layer, ...]) Apply hdbscan to cluster cells in the space defined by basis. tl.infomap(adata[, use_weight, adj_matrix, ...]) Apply infomap community detection algorithm to cluster adata. tl.leiden(adata[, use_weight, weight, ...]) Apply leiden clustering to adata. tl.louvain(adata[, resolution, use_weight, ...]) Louvain implementation from cdlib. tl.scc(adata[, min_cells, spatial_key, ...]) Spatially constrained clustering (scc) to identify continuous tissue domains.

Velocity projection

 tl.cell_velocities(adata[, ekey, vkey, X, ...]) Project high dimensional velocity vectors onto given low dimensional embeddings, and/or compute cell transition probabilities. tl.confident_cell_velocities(adata, group, ...) Confidently compute transition probability and project high dimension velocity vector to existing low dimension embeddings using progenitors and mature cell groups priors.

Velocity metrics

 tl.cell_wise_confidence(adata[, X_data, ...]) Calculate the cell-wise velocity confidence metric. tl.gene_wise_confidence(adata, group[, ...]) Diagnostic measure to identify genes contributed to "wrong" directionality of the vector flow.

Markov chain

 tl.generalized_diffusion_map(adata, **kwargs) Apply the diffusion map algorithm on the transition matrix build from Itô kernel. tl.stationary_distribution(adata[, method, ...]) Compute stationary distribution of cells using the transition matrix. tl.diffusion(M[, P0, steps, backward]) Find the state distribution of a Markov process. tl.expected_return_time(M[, backward]) Find the expected returning time.

Markers and differential expressions

 tl.moran_i(adata[, X_data, genes, layer, ...]) Identify genes with strong spatial autocorrelation with Moran's I test. tl.find_group_markers(adata, group[, genes, ...]) Find marker genes for each group of cells based on gene expression or velocity values as specified by the layer. tl.two_groups_degs(adata, genes, layer, ...) Find marker genes between two groups of cells based on gene expression or velocity values as specified by the layer. tl.top_n_markers(adata[, with_moran_i, ...]) Filter cluster deg (Moran's I test) results and retrieve top markers for each cluster. tl.glm_degs(adata[, X_data, genes, layer, ...]) Differential genes expression tests using generalized linear regressions.

Cell proliferation and apoptosis

 tl.score_cells(adata[, genes, layer, basis, ...]) Score cells based on a set of genes. tl.cell_growth_rate(adata, group, source, target) Estimate the growth rate via clone information or logistic equation of population dynamics.

*Converter and helper *

 tl.converter(data_in[, from_type, to_type, dir]) convert adata to loom object - we may save_fig to a temp directory automatically - we may write a on-the-fly converter which doesn't involve saving and reading files tl.run_scvelo(adata) set up PCA, UMAP, etc. tl.run_velocyto(adata) convert adata to vlm data tl.vlm_to_adata(vlm[, n_comps, basis, ...]) Conversion function from the velocyto world to the dynamo world.

## Vector field (vf)

Vector field reconstruction

Note

Vector field class is internally to vf.VectorField. See our vector field classes here: vector field

 vf.VectorField(adata[, basis, layer, dims, ...]) Learn a function of high dimensional vector field from sparse single cell samples in the entire space robustly. vf.SparseVFC(X, Y, Grid[, M, a, beta, ecr, ...]) Apply sparseVFC (vector field consensus) algorithm to learn a functional form of the vector field from random samples with outlier on the entire space robustly and efficiently. vf.BaseVectorField([X, V, Grid]) vf.SvcVectorField([X, V, Grid]) Initialize the VectorField class. vf.graphize_vecfld(*args, **kw) vf.vector_field_function(*args, **kw)

Vector field topology

 vf.cluster_field(adata[, basis, features, ...]) Cluster cells based on vector field features. vf.topography(adata[, basis, layer, X, ...]) Map the topography of the single cell vector field in (first) two dimensions. vf.FixedPoints([X, J]) vf.VectorField2D(func[, func_vx, func_vy, ...]) vf.assign_fixedpoints(adata[, basis, cores, ...]) Assign each cell in our data to a fixed point.

Beyond RNA velocity

 vf.velocities(adata, init_cells[, ...]) Calculate the velocities for any cell state with the reconstructed vector field function. vf.speed(adata[, basis, vector_field_class, ...]) Calculate the speed for each cell with the reconstructed vector field function. vf.jacobian(adata[, regulators, effectors, ...]) Calculate Jacobian for each cell with the reconstructed vector field. vf.divergence(adata[, cell_idx, sampling, ...]) Calculate divergence for each cell with the reconstructed vector field function. vf.curl(adata[, basis, vector_field_class, ...]) Calculate Curl for each cell with the reconstructed vector field function. vf.acceleration(adata[, basis, ...]) Calculate acceleration for each cell with the reconstructed vector field function. vf.curvature(adata[, basis, ...]) Calculate curvature for each cell with the reconstructed vector field function. vf.torsion(adata[, basis, vector_field_class]) Calculate torsion for each cell with the reconstructed vector field function. vf.sensitivity(adata[, regulators, ...]) Calculate Sensitivity matrix for each cell with the reconstructed vector field.

Beyond velocity vector field

 vf.cell_accelerations(adata[, vf_basis, ...]) Compute RNA acceleration field via reconstructed vector field and project it to low dimensional embeddings. vf.cell_curvatures(adata[, vf_basis, basis, ...]) Compute RNA curvature field via reconstructed vector field and project it to low dimensional embeddings.

Vector field ranking

 vf.rank_cells(adata, arr_key[, groups, ...]) Rank cell's absolute, positive, negative vector field metrics by different gene groups. vf.rank_genes(adata, arr_key[, groups, ...]) Rank gene's absolute, positive, negative vector field metrics by different cell groups. vf.rank_expression_genes(adata[, ekey, ...]) Rank genes based on their expression values for each cell group. vf.rank_velocity_genes(adata[, vkey, ...]) Rank genes based on their raw and absolute velocities for each cell group. vf.rank_divergence_genes(adata[, jkey, ...]) Rank genes based on their diagonal Jacobian for each cell group. vf.rank_acceleration_genes(adata[, akey, ...]) Rank genes based on their absolute, positive, negative accelerations for each cell group. vf.rank_curvature_genes(adata[, ckey, ...]) Rank gene's absolute, positive, negative curvature by different cell groups. vf.rank_jacobian_genes(adata[, groups, ...]) Rank genes or gene-gene interactions based on their Jacobian elements for each cell group. vf.rank_s_divergence_genes(adata[, skey, ...]) Rank genes based on their diagonal Sensitivity for each cell group. vf.rank_sensitivity_genes(adata[, groups, ...]) Rank genes or gene-gene interactions based on their sensitivity elements for each cell group.

Single cell potential: three approaches

 vf.gen_fixed_points(func, auto_func, ...[, ...]) Calculate the fixed points of (learned) vector field function . vf.gen_gradient(dim, N, Function, ...) Calculate the gradient of the (learned) vector field function for the least action path (LAP) symbolically vf.IntGrad(points, Function, DiffusionMatrix, dt) Calculate the action of the path based on the (reconstructed) vector field function and diffusion matrix (Eq. Diffusion matrix can be variable dependent vf.action(n_points, tmax, point_start, ...) It calculates the minimized action value given an initial path, ODE, and diffusion matrix. vf.Potential(adata[, DiffMat, method]) Function to map out the pseudo-potential landscape. vf.path_integral(VecFnc, x_lim, y_lim, ...) A deterministic map of Waddington’s epigenetic landscape for cell fate specification Sudin Bhattacharya, Qiang Zhang and Melvin E. vf.alignment(numPaths, numTimeSteps, ...[, ...]) Align potential values so all path-potentials end up at same global min and then generate potential surface with interpolation on a grid. vf.Wang_action(X_input, F, D, dim, N[, lamada_]) Calculate action by path integral by Wang's method. vf.Wang_LAP(F, n_points, point_start, point_end) Calculating least action path based methods from Jin Wang and colleagues (http://www.pnas.org/cgi/doi/10.1073/pnas.1017017108) vf.transition_rate(X_input, F[, D, lambda_]) Calculate the rate to convert from one cell state to another cell state by taking the optimal path. vf.MFPT(X_input, F[, D, lambda_]) Calculate the MFPT (mean first passage time) to convert from one cell state to another cell state by taking the optimal path. vf.Ao_pot_map(vecFunc, X[, D]) Mapping potential landscape with the algorithm developed by Ao method. References: Potential in stochastic differential equations: novel construction. Journal of physics A: mathematical and general, Ao Ping, 2004. vf.solveQ(*args, **kw)

Stochastic processes

 vf.diffusionMatrix(adata[, X_data, V_data, ...]) Calculate the diffusion matrix from the estimated velocity vector and the reconstructed vector field.

Vector field clustering and graph

 vf.cluster_field(adata[, basis, features, ...]) Cluster cells based on vector field features. vf.streamline_clusters(adata[, basis, ...]) type adata AnnData vf.vfGraph(*args, **kwds) A class for manipulating the graph creating from the transition matrix, built from the (reconstructed) vector field.

## Prediction (pd)

 pd.andecestor(adata, init_cells[, ...]) Predict the ancestors or descendants of a group of initial cells (states) with the given vector field function. pd.fate(adata, init_cells[, init_states, ...]) Predict the historical and future cell transcriptomic states over arbitrary time scales. pd.fate_bias(adata, group[, basis, inds, ...]) Calculate the lineage (fate) bias of states whose trajectory are predicted. pd.get_init_path(G, start, end, coords[, ...]) pd.least_action(adata, init_cells, target_cells) Calculate the optimal paths between any two cell states. pd.perturbation(adata, genes[, expression, ...]) In silico perturbation of single-cells and prediction of cell fate after perturbation. pd.state_graph(adata, group[, method, ...]) Estimate the transition probability between cell types using method of vector field integrations or Markov chain lumping. pd.KO(adata, KO_genes[, vecfld, vf_key, ...]) In silico knockout genes (and thus the vector field function) and prediction of cell fate after knockout. pd.rank_perturbation_cell_clusters(adata[, ...]) Rank cells based on their raw and absolute perturbation for each cell group. pd.rank_perturbation_cells(adata[, pkey, ...]) Rank cells based on their raw and absolute perturbation for each cell group. pd.rank_perturbation_genes(adata[, pkey, ...]) Rank genes based on their raw and absolute perturbation effects for each cell group. pd.state_graph(adata, group[, method, ...]) Estimate the transition probability between cell types using method of vector field integrations or Markov chain lumping. pd.tree_model(adata, group, progenitor, ...) This function learns a tree model of cell states (types).

## Plotting (pl)

Preprocessing

 pl.basic_stats(adata[, group, figsize, ...]) Plot the basic statics (nGenes, nCounts and pMito) of each category of adata. pl.show_fraction(adata[, genes, group, ...]) Plot the fraction of each category of data used in the velocity estimation. pl.feature_genes(adata[, layer, mode, ...]) Plot selected feature genes on top of the mean vs. pl.biplot(adata[, pca_components, pca_key, ...]) A biplot overlays a score plot and a loadings plot in a single graph. pl.loading(adata[, n_pcs, loading_key, ...]) Plot the top absolute pca loading genes. pl.variance_explained(adata[, threshold, ...]) Plot the accumulative variance explained by the principal components. pl.highest_frac_genes(adata[, n_top, ...]) Plot top genes pl.exp_by_groups(adata, genes[, layer, ...]) Plot the (labeled) expression values of genes across different groups (time points). pl.bubble(adata, genes, group[, gene_order, ...]) Bubble plots generalized to velocity, acceleration, curvature.

Cell cycle staging

 pl.cell_cycle_scores(adata[, cells, ...]) Plot a heatmap of cells ordered by cell cycle position

Scatter base

 pl.scatters(adata[, basis, x, y, z, color, ...]) Plot an embedding as points.

Space plot

 pl.space(adata[, color, genes, gene_cmaps, ...]) Scatter plot for physical coordinates of each cell.

Phase diagram: conventional scRNA-seq

 pl.phase_portraits(adata, genes[, x, y, ...]) Draw the phase portrait, expression values , velocity on the low dimensional embedding.

Kinetic models: labeling based scRNA-seq

 pl.dynamics(adata, genes[, unit, ...]) Plot the data and fitting of different metabolic labeling experiments.

Kinetics

 pl.kinetic_curves(adata, genes[, mode, ...]) Plot the gene expression dynamics over time (pseudotime or inferred real time) as kinetic curves. pl.kinetic_heatmap(adata, genes[, mode, ...]) Plot the gene expression dynamics over time (pseudotime or inferred real time) in a heatmap. pl.jacobian_kinetics(adata[, basis, ...]) Plot the Jacobian dynamics over time (pseudotime or inferred real time) in a heatmap. pl.sensitivity_kinetics(adata[, basis, ...]) Plot the Sensitivity dynamics over time (pseudotime or inferred real time) in a heatmap.

Dimension reduction

 pl.pca(adata, *args, **kwargs) Scatter plot with pca basis. pl.tsne(adata, *args, **kwargs) Scatter plot with tsne basis. pl.umap(adata, *args, **kwargs) Scatter plot with umap basis. pl.trimap(adata, *args, **kwargs) Scatter plot with trimap basis.

Clustering

 pl.leiden(adata[, basis, color]) Scatter plot for leiden community detection in selected basis. pl.louvain(adata[, basis, color, color_key_cmap]) Scatter plot for louvain community detection in selected basis. pl.infomap(adata[, basis, color]) Scatter plot for infomap community detection in selected basis. pl.streamline_clusters(adata[, basis, ...]) Scatter plot for visualizing streamline clusters in selected basis.

Neighbor graph

 pl.nneighbors(adata[, x, y, color, basis, ...]) Plot nearest neighbor graph of cells used to embed data into low dimension space. pl.state_graph(adata[, group, ...]) Plot a summarized cell type (state) transition graph.

Vector field plots: velocities and accelerations

 pl.cell_wise_vectors(adata[, basis, x, y, ...]) Plot the velocity or acceleration vector of each cell. pl.cell_wise_vectors_3d(adata[, basis, x, ...]) Plot the velocity or acceleration vector of each cell. pl.grid_vectors(adata[, basis, x, y, ekey, ...]) Plot the velocity or acceleration vector of each cell on a grid. pl.streamline_plot(adata[, basis, x, y, ...]) Plot the velocity vector of each cell. pl.line_integral_conv(adata[, basis, ...]) Visualize vector field with quiver, streamline and line integral convolution (LIC), using velocity estimates on a pl.plot_energy(adata[, basis, vecfld_dict, ...]) Plot the energy and energy change rate over each optimization iteration. pl.plot_3d_streamtube(adata, color, layer, ...) Plot a interative 3d streamtube plot via plotly.

Vector field topology

 pl.plot_flow_field(vecfld, x_range, y_range) Plots the flow field with line thickness proportional to speed. pl.plot_fixed_points(vecfld[, vecfld_dict, ...]) Plot fixed points stored in the VectorField2D class. pl.plot_fixed_points_2d(vecfld[, marker, ...]) Plot fixed points stored in the VectorField2D class. pl.plot_nullclines(vecfld[, vecfld_dict, ...]) Plot nullclines stored in the VectorField2D class. pl.plot_separatrix(vecfld, x_range, y_range, t) Plot separatrix on phase portrait. pl.plot_traj(f, y0, t[, args, lw, ...]) Plots a trajectory on a phase portrait. pl.topography(adata[, basis, fps_basis, x, ...]) Plot the streamline, fixed points (attractor / saddles), nullcline, separatrices of a recovered dynamic system for single cells. pl.response(adata, pairs_mat[, xkey, ykey, ...]) Plot the lagged DREVI plot pairs of genes across pseudotime.

Beyond RNA velocity

 pl.speed(adata[, basis, color, frontier]) Scatter plot with cells colored by the estimated velocity speed (and other information if provided). pl.divergence(adata[, basis, color, cmap, ...]) Scatter plot with cells colored by the estimated divergence (and other information if provided). pl.acceleration(adata[, basis, color, frontier]) Scatter plot with cells colored by the estimated acceleration (and other information if provided). pl.curl(adata[, basis, color, cmap, ...]) Scatter plot with cells colored by the estimated curl (and other information if provided). pl.curvature(adata[, basis, color, frontier]) Scatter plot with cells colored by the estimated curvature (and other information if provided). pl.jacobian(adata[, regulators, effectors, ...]) Scatter plot of Jacobian values across cells. pl.jacobian_heatmap(adata, cell_idx[, jkey, ...]) Plot the Jacobian matrix for each cell as a heatmap. pl.sensitivity(adata[, regulators, ...]) Scatter plot of Sensitivity value across cells. pl.sensitivity_heatmap(adata, cell_idx[, ...]) Plot the Jacobian matrix for each cell as a heatmap.

Regulatory network

 pl.arcPlot(adata, cluster, cluster_name[, ...]) Arc plot of gene regulatory network for a particular cell cluster. pl.circosPlot(network[, node_label_key, ...]) wrapper for drawing circos plot via nxviz >= 0.7.3 pl.circosPlotDeprecated(adata, cluster, ...) Note: this function is written with nxviz old version (<=0.3.x, or higher) API for the latest nxviz version compatibility, please refer to dyn.pl.circos_plot. pl.hivePlot(adata, edges_list, cluster[, ...]) Hive plot of cell cluster specific gene regulatory networks.

Potential landscape

 pl.show_landscape(adata, Xgrid, Ygrid, Zgrid) Plot the quasi-potential landscape.

Cell fate

 pl.fate(adata[, x, y, basis, color, ax, ...]) Draw the predicted integration paths on the low-dimensional embedding. pl.fate_bias(adata, group[, basis, ...]) Plot the lineage (fate) bias of cells states whose vector field trajectories are predicted.

Heatmaps

 pl.causality(adata, pairs_mat[, xkey, ykey, ...]) Plot the heatmap for the expected value $$y(t)$$ given $$x(t - d)$$ and $$y(t - 1)$$. pl.comb_logic(adata, pairs_mat[, xkey, ...]) Plot the combinatorial influence of two genes $$x$$, $$y$$ to the target $$z$$. pl.plot_hill_function(adata[, pairs_mat, ...]) pl.response(adata, pairs_mat[, xkey, ykey, ...]) Plot the lagged DREVI plot pairs of genes across pseudotime.

Predictions

 pl.lap_min_time(adata[, basis, show_paths, ...])

Save figures

 pl.save_fig([path, prefix, dpi, ext, ...]) Save a figure from pyplot.

## Moive (mv)

Note

animation class is internally to mv.animate_fates. See our animation classes here: animation

 mv.animate_fates(adata[, basis, dims, ...]) Animating cell fate commitment prediction via reconstructed vector field function.

## Simulation (sim)

Simple ODE vector field simulation

 sim.neurogenesis(x[, t, mature_mu, n, k, a, ...]) The ODE model for the neurogenesis system that used in benchmarking Monocle 2, Scribe and dynamo (here), original from Xiaojie Qiu, et. sim.toggle(ab[, t, beta, gamma, n]) Right hand side (rhs) for toggle ODEs. sim.Ying_model(x[, t]) network used in the potential landscape paper from Ying, et.

Gillespie simulation

 sim.Gillespie([a, b, la, aa, ai, si, be, ...]) A simulator of RNA dynamics that includes RNA bursting, transcription, metabolic labeling, splicing, transcription, RNA/protein degradation sim.Simulator([motif, seed_num, clip, cell_num]) Simulate the gene expression dynamics via deterministic ODE model sim.state_space_sampler(ode, dim[, ...]) Sample N points from the dim dimension gene expression space while restricting the values to be between min_val and max_val. sim.evaluate(reference, prediction[, metric]) Function to evaluate the vector field related reference quantities vs.

## External (ext)

 ext.ddhodge(adata[, X_data, layer, basis, ...]) Modeling Latent Flow Structure using Hodge Decomposition based on the creation of sparse diffusion graph from the reconstructed vector field function. ext.enrichr(genes, organism[, background, ...]) Perform gene list enrichment with gseapy. ext.scribe(adata[, genes, TFs, Targets, ...]) Apply Scribe to calculate causal network from spliced/unspliced, metabolic labeling based and other "real" time series datasets. ext.coexp_measure(adata, genes, layer_x, layer_y) Calculate co-expression measures, including mutual information (MI), pearson correlation, etc. ext.scifate_glmnet(adata[, ...]) Reconstruction of regulatory network (Cao, et. al, Nature Biotechnology, 2020) from TFs to other target Gene selection and normalization based on [Lause21]. ext.sctransform(adata[, layers, ...]) a wrapper calls sctransform_core and set dynamo style keys in adata

## Utilities

Package versions

 cleanup(adata[, del_prediction, del_2nd_moments]) clean up adata before saving it to a file
 configuration.set_figure_params([dynamo, ...]) Set resolution/size, styling and format of figures. configuration.set_pub_style([scaler]) formatting helper function that can be used to save publishable figures