Mapping Vector Field of Single Cells
API
Import dynamo as:
import dynamo as dyn
Data IO
(See more at anndata-docs)
|
Read .h5ad-formatted hdf5 file. |
|
Read .h5ad-formatted hdf5 file. |
|
Read .loom-formatted hdf5 file. |
Preprocessing (pp)
|
This helper function converts unofficial gene names to official gene names. |
|
Select valid cells based on a collection of filters including spliced, unspliced and protein min/max vals. |
|
Select valid cells based on a collection of filters including spliced, unspliced and protein min/max vals. |
|
Basic filter of genes based a collection of expression filters. |
|
Utility function to filter mitochondria, ribsome protein and ERCC spike-in genes, etc. |
|
Basic filter of genes based a collection of expression filters. |
|
Prepare filtering genes on the basis of cluster-wise expression threshold. |
|
Calculate the size factor of each cell using geometric mean or median of total UMI across cells for a AnnData object. |
|
Normalize the gene expression value for the AnnData object. |
|
Normalize the gene expression value for the AnnData object. |
Normalize the given layers of the AnnData object using Pearson residuals. |
|
|
Calculate the Gini coefficient of a numpy array. |
|
Select genes based on monocle recipe. |
Gene selection and normalization based on [Lause21]. |
|
|
Scale layers to a particular total expression value, similar to normalize_expr_data function. |
|
Perform log1p transform on selected adata layers |
|
Perform PCA reduction for monocle recipe. |
|
Define top genes as any gene that is |
|
A wrapper calls sctransform_core and set dynamo style keys in adata |
|
Preprocessor constructor. |
|
A specialized preprocessor based on cNMF. |
|
Use harmonypy [Korunsky19] to remove batch effects. |
|
Concatenating all anndata objects. |
|
Use lambda (cell-wise detection rate) to estimate the labelled RNA. |
|
Decode an AnnData object. |
|
Estimate cell cycle stage of each cell based on its gene expression pattern. |
Estimation (est)
Note
Classes in est are internally to Tools. See our estimation classes here: estimation
Tools (tl)
kNN and moments of expressions
|
Search nearest neighbors of the adata object. |
|
Calculate mutual nearest neighbor graph across specific data layers. |
|
Calculate kNN based first and second moments (including uncentered covariance) for different layers of data. |
Kinetic parameters and RNA/protein velocity
|
Inclusive model of expression dynamics considers splicing, metabolic labeling and protein translation. |
Labeling Velocity recipes
|
An analysis recipe that properly pre-processes different layers for a degradation experiment with both labeling and splicing data or only labeling. |
|
An analysis recipe that properly pre-processes different layers for an kinetics experiment with both labeling and splicing or only labeling data. |
|
An analysis recipe that properly pre-processes different layers for a mixture kinetics and degradation experiment with both labeling and splicing or only labeling data. |
|
An analysis recipe that properly pre-processes different layers for a one-shot experiment with both labeling and splicing data. |
|
Use new RNA based pca, umap, for velocity calculation and projection for kinetics or one-shot experiment. |
Dimension reduction
|
Compute a low dimension reduction projection of an AnnData object first with PCA, followed by non-linear dimension reduction methods |
|
Provides an implementation of the framework of reversed graph embedding (RGE). |
|
This function is a pure Python implementation of the PSL algorithm. |
Clustering
|
Apply hdbscan to cluster cells in the space defined by basis. |
|
Apply infomap community detection algorithm to cluster adata. |
|
Apply leiden clustering to the input adata. |
|
Apply louvain clustering to adata. |
|
Spatially constrained clustering (scc) to identify continuous tissue domains. |
Velocity projection
|
Project high dimensional velocity vectors onto given low dimensional embeddings, and/or compute cell transition |
|
Compute transition probability and perform velocity projection |
Velocity metrics
|
Calculate the cell-wise velocity confidence metric. |
|
Diagnostic measure to identify genes contributed to "wrong" directionality of the vector flow. |
Markov chain
|
Apply the diffusion map algorithm on the transition matrix build from Itô kernel. |
|
Compute stationary distribution of cells using the transition matrix. |
|
Find the state distribution of a Markov process. |
|
Find the expected returning time. |
Markers and differential expressions
|
Identify genes with strong spatial autocorrelation with Moran's I test. |
|
Find marker genes for each group of cells based on gene expression or velocity values as specified by the layer. |
|
Find marker genes between two groups of cells based on gene expression or velocity as specified by the layer. |
|
Filter cluster deg (Moran's I test) results and retrieve top markers for each cluster. |
|
Differential genes expression tests using generalized linear regressions. |
Cell proliferation and apoptosis
|
Score cells based on a set of genes. |
|
Estimate the growth rate via clone information or logistic equation of population dynamics. |
*Converter and helper *
|
Convert adata to loom object or vice versa. |
|
Run Scvelo over the AnnData. |
|
Run velocyto over the AnnData object. |
|
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
|
Learn a function of high dimensional vector field from sparse single cell samples in the entire space robustly. |
|
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. |
|
The BaseVectorField class is a base class for storing and manipulating vector fields. |
|
Initialize the VectorField class. |
|
|
|
Vector field topology
|
Cluster cells based on vector field features. |
|
Map the topography of the single cell vector field in (first) two dimensions. |
|
The FixedPoints class stores a list of fixed points and their corresponding Jacobian matrices, and provides methods for computing the eigenvalues of the Jacobian matrices, determining the stability of the fixed points, and identifying saddle/stable fixed points. |
|
The VectorField2D class is a class that represents a 2D vector field, which is a type of mathematical object that assigns a 2D vector to each point in a 2D space. |
|
Assign each cell in our data to a fixed point. |
Beyond RNA velocity
|
Calculate the velocities for any cell state with the reconstructed vector field function. |
|
Calculate the speed for each cell with the reconstructed vector field function. |
|
Calculate Jacobian for each cell with the reconstructed vector field. |
|
Calculate divergence for each cell with the reconstructed vector field function. |
|
Calculate Curl for each cell with the reconstructed vector field function. |
|
Calculate acceleration for each cell with the reconstructed vector field function. |
|
Calculate curvature for each cell with the reconstructed vector field function. |
|
Calculate torsion for each cell with the reconstructed vector field function. |
|
Calculate Sensitivity matrix for each cell with the reconstructed vector field. |
Beyond velocity vector field
|
Compute RNA acceleration field via reconstructed vector field and project it to low dimensional embeddings. |
|
Compute RNA curvature field via reconstructed vector field and project it to low dimensional embeddings. |
Vector field ranking
|
Rank cell's absolute, positive, negative vector field metrics by different gene groups. |
|
Rank gene's absolute, positive, negative vector field metrics by different cell groups. |
|
Rank genes based on their expression values for each cell group. |
|
Rank genes based on their raw and absolute velocities for each cell group. |
|
Rank genes based on their diagonal Jacobian for each cell group. |
|
Rank genes based on their absolute, positive, negative accelerations for each cell group. |
|
Rank gene's absolute, positive, negative curvature by different cell groups. |
|
Rank genes or gene-gene interactions based on their Jacobian elements for each cell group. |
|
Rank genes based on their diagonal Sensitivity for each cell group. |
|
Rank genes or gene-gene interactions based on their sensitivity elements for each cell group. |
Single cell potential: three approaches
|
Calculate the fixed points of (learned) vector field function . |
|
Calculate the gradient of the (learned) vector field function for the least action path (LAP) symbolically |
|
Calculate the action of the path based on the (reconstructed) vector field function and diffusion matrix (Eq. |
Diffusion matrix can be variable dependent |
|
|
It calculates the minimized action value given an initial path, ODE, and diffusion matrix. |
|
Function to map out the pseudo-potential landscape. |
|
A deterministic map of Waddington’s epigenetic landscape for cell fate specification Sudin Bhattacharya, Qiang Zhang and Melvin E. |
|
Align potential values so all path-potentials end up at same global min and then generate potential surface with interpolation on a grid. |
|
Calculate action by path integral by Wang's method. |
|
Calculating least action path based methods from Jin Wang and colleagues (http://www.pnas.org/cgi/doi/10.1073/pnas.1017017108) |
|
Calculate the rate to convert from one cell state to another cell state by taking the optimal path. |
|
Calculate the MFPT (mean first passage time) to convert from one cell state to another cell state by taking the optimal path. |
|
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. |
|
Stochastic processes
|
Calculate the diffusion matrix from the estimated velocity vector and the reconstructed vector field. |
Vector field clustering and graph
|
Cluster cells based on vector field features. |
|
Cluster 2D streamlines based on vector field features. |
|
A class for manipulating the graph creating from the transition matrix, built from the (reconstructed) vector field. |
Prediction (pd)
|
Predict the ancestors or descendants of a group of initial cells (states) with the given vector field function. |
|
Predict the historical and future cell transcriptomic states over arbitrary time scales. |
|
Calculate the lineage (fate) bias of states whose trajectory are predicted. |
|
|
|
Calculate the optimal paths between any two cell states. |
|
In silico perturbation of single-cells and prediction of cell fate after perturbation. |
|
Estimate the transition probability between cell types using method of vector field integrations or Markov chain lumping. |
|
In silico knockout genes (and thus the vector field function) and prediction of cell fate after knockout. |
|
Rank cells based on their raw and absolute perturbation for each cell group. |
|
Rank cells based on their raw and absolute perturbation for each cell group. |
|
Rank genes based on their raw and absolute perturbation effects for each cell group. |
|
Estimate the transition probability between cell types using method of vector field integrations or Markov chain lumping. |
|
This function learns a tree model of cell states (types). |
Plotting (pl)
Preprocessing
|
Plot the basic statics (nGenes, nCounts and pMito) of each category of adata. |
|
Plot the fraction of each category of data used in the velocity estimation. |
|
Plot selected feature genes on top of the mean vs. |
|
A biplot overlays a score plot and a loadings plot in a single graph. |
|
Plot the top absolute pca loading genes. |
|
Plot the accumulative variance explained by the principal components. |
|
Plot the top genes. |
|
Plot the (labeled) expression values of genes across different groups (time points). |
|
Bubble plots generalized to velocity, acceleration, curvature. |
Cell cycle staging
|
Plot a heatmap of cells ordered by cell cycle position. |
Scatter base
|
Plot an embedding as points. |
Space plot
|
Scatter plot for physical coordinates of each cell. |
Phase diagram: conventional scRNA-seq
|
Draw the phase portrait, expression values, velocity on the low dimensional embedding. |
Kinetic models: labeling based scRNA-seq
|
Plot the data and fitting of different metabolic labeling experiments. |
Kinetics
|
Plot the gene expression dynamics over time (pseudotime or inferred real time) as kinetic curves. |
|
Plot the gene expression dynamics over time (pseudotime or inferred real time) in a heatmap. |
|
Plot the Jacobian dynamics over time (pseudotime or inferred real time) in a heatmap. |
|
Plot the Sensitivity dynamics over time (pseudotime or inferred real time) in a heatmap. |
Dimension reduction
|
Scatter plot with pca basis. |
|
Scatter plot with tsne basis. |
|
Scatter plot with umap basis. |
|
Scatter plot with trimap basis. |
Clustering
|
Scatter plot for leiden community detection in selected basis. |
|
Scatter plot for louvain community detection in selected basis. |
|
Scatter plot for infomap community detection in selected basis. |
|
Scatter plot for visualizing streamline clusters in selected basis. |
Neighbor graph
|
Plot nearest neighbor graph of cells used to embed data into low dimension space. |
|
Plot a summarized cell type (state) transition graph. |
Vector field plots: velocities and accelerations
|
Plot the velocity or acceleration vector of each cell. |
|
Plot the velocity or acceleration vector of each cell. |
|
Plot the velocity or acceleration vector of each cell on a grid. |
|
Plot the velocity vector of each cell. |
|
Visualize vector field with quiver, streamline and line integral convolution (LIC), using velocity estimates on a |
|
Plot the energy and energy change rate over each optimization iteration. |
|
Plot a interative 3d streamtube plot via plotly. |
Vector field topology
|
Plots the flow field with line thickness proportional to speed. |
|
Plot fixed points stored in the VectorField2D class. |
|
Plot fixed points stored in the VectorField2D class. |
|
Plot nullclines stored in the VectorField2D class. |
|
Plot separatrix on phase portrait. |
|
Plots a trajectory on a phase portrait. |
|
Plot the streamline, fixed points (attractor / saddles), nullcline, separatrices of a recovered dynamic system for single cells. |
|
Plot the lagged DREVI plot pairs of genes across pseudotime. |
Beyond RNA velocity
|
Scatter plot with cells colored by the estimated velocity speed (and other information if provided). |
|
Scatter plot with cells colored by the estimated divergence (and other information if provided). |
|
Scatter plot with cells colored by the estimated acceleration (and other information if provided). |
|
Scatter plot with cells colored by the estimated curl (and other information if provided). |
|
Scatter plot with cells colored by the estimated curvature (and other information if provided). |
|
Scatter plot of Jacobian values across cells. |
|
Plot the Jacobian matrix for each cell or the average Jacobian matrix of the cells from input indices as a heatmap. |
|
Scatter plot of Sensitivity value across cells. |
|
Plot the Jacobian matrix for each cell as a heatmap. |
Regulatory network
|
Arc plot of gene regulatory network for a particular cell cluster. |
|
wrapper for drawing circos plot via nxviz >= 0.7.3 |
|
Deprecated. |
|
Hive plot of cell cluster specific gene regulatory networks. |
Potential landscape
|
Plot the quasi-potential landscape. |
Cell fate
|
Draw the predicted integration paths on the low-dimensional embedding. |
|
Plot the lineage (fate) bias of cells states whose vector field trajectories are predicted. |
Heatmaps
|
Plot the heatmap for the expected value z(t) given x and y data. |
|
Plot the combinatorial influence of two genes x, y to the target z. |
|
Plot the hill function curve generated by dynamo.pl.response. |
|
Plot the lagged DREVI plot pairs of genes across pseudotime. |
Predictions
|
Plot minimum time of the least action paths. |
Save figures
|
Save a figure from pyplot. |
Moive (mv)
Note
animation class is internally to mv.animate_fates. See our animation classes here: animation
|
Animating cell fate commitment prediction via reconstructed vector field function. |
Simulation (sim)
Simple ODE vector field simulation
|
Calculates the right-hand side (RHS) of the differential equations for the toggle switch system. |
|
network used in the potential landscape paper from Ying, et. |
Gillespie simulation
|
A simulator of RNA dynamics that includes RNA bursting, transcription, metabolic labeling, splicing, transcription, RNA/protein degradation |
|
Simulate the gene expression dynamics via deterministic ODE model |
|
Sample N points from the dim dimension gene expression space while restricting the values to be between min_val and max_val. |
|
Function to evaluate the vector field related reference quantities vs. |
External (ext)
|
Modeling Latent Flow Structure using Hodge Decomposition based on the creation of sparse diffusion graph from the reconstructed vector field function. |
|
Perform gene list enrichment with gseapy. |
|
Apply Scribe to calculate causal network from spliced/unspliced, metabolic labeling based and other "real" time series datasets. |
|
Calculate co-expression measures, including mutual information (MI), pearson correlation, etc. |
|
Reconstruction of regulatory network (Cao, et. al, Nature Biotechnology, 2020) from TFs to other target |
Utilities
Package versions
|
Adapted from answer 2 in https://stackoverflow.com/questions/40428931/package-for-listing-version-of-packages-used-in-a-jupyter-notebook |
Clean up adata
|
clean up adata before saving it to a file |
Figures configuration
|
Set resolution/size, styling and format of figures. |
|
formatting helper function that can be used to save publishable figures |