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 function is partly based on Monocle R package (https://github.com/cole-trapnell-lab/monocle3). |
|
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
|
Function to search nearest neighbors of the adata object. |
|
Function to calculate mutual nearest neighbor graph across specific data layers. |
|
Calculate kNN based first and second moments (including uncentered covariance) for |
Kinetic parameters and RNA/protein velocity
|
Inclusive model of expression dynamics considers splicing, metabolic labeling and protein translation. |
Dimension reduction
|
Compute a low dimension reduction projection of an annodata object first with PCA, followed by non-linear dimension reduction methods |
|
This function is a pure Python implementation of the DDRTree algorithm. |
|
This function is a pure Python implementation of the PSL algorithm. |
Clustering
|
Apply hdbscan to cluster cells in the space defined by basis. |
|
Cluster cells based on vector field features. |
Velocity projection
|
Project high dimensional velocity vectors onto given low dimensional embeddings, and/or compute cell transition probabilities. |
|
Confidently compute transition probability and project high dimension velocity vector to existing low dimension embeddings using progeintors and mature cell groups priors. |
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 values 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. |
Converter
|
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 |
Vector field (vf)¶
Vector field reconstruction
Note
Vector field class is internally to vf.VectorField. See our vector field classes here: vector field
|
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. |
|
Learn a function of high dimensional vector field from sparse single cell samples in the entire space robustly. |
Vector field topology
|
Map the topography of the single cell vector field in (first) two dimensions. |
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 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. |
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 gene’s absolute, positive, negative speed by different cell groups. |
|
Rank gene’s absolute, positive, negative divergence by different cell groups. |
|
Rank gene’s absolute, positive, negative acceleration by different cell groups. |
|
Rank gene’s absolute, positive, negative curvature by different cell groups. |
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 intial 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. |
|
Stochastic processes
|
“Calculate the diffusion matrix from the estimated velocity vector and the reconstructed vector field. |
Vector field graph
|
A class for manipulating the graph creating from the transition matrix, built from the (reconstructed) vector field. |
Prediction (pd)¶
|
Predict the historical and future cell transcriptomic states over arbitrary time scales. |
|
Calculate the lineage (fate) bias of states whose trajectory are predicted. |
|
Estimate the transition probability between cell types using method of vector field integrations. |
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. |
|
Plot the accumulative variance explained by the principal components. |
|
Plot the (labeled) expression values of genes across different groups (time points). |
Cell cycle staging
|
Plot a heatmap of cells ordered by cell cycle position |
Scatter base
|
Plot an embedding as points. |
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 gene expression 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. |
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 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 grid from the associated data. |
|
Plot the energy and energy change rate over each optimization iteration. |
Vector field topology
|
Plots the flow field with line thickness proportional to speed. |
|
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. |
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 curl (and other information if provided). |
|
Scatter plot with cells colored by the estimated curvature (and other information if provided). |
|
Scatter plot with pca basis. |
|
Plot the Jacobian matrix for each cell as a heatmap. |
Potential landscape
|
Plot the quasi-potential landscape. |
Cell fate
|
Plot the lineage (fate) bias of cells states whose vector field trajectories are predicted. |
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
|
The ODE model for the famous Pu.1-Gata.1 like network motif with self-activation and mutual inhibition. |
|
The ODE model for the neurogenesis system that used in benchmarking Monocle 2, Scribe and dynamo (here), original from Xiaojie Qiu, et. |
|
Right hand side (rhs) for toggle ODEs. |
|
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. |
|
Apply Scribe to calculate causal network from spliced/unspliced, metabolic labeling based and other “real” time series datasets. |
|
Calculate mutual information (as well as pearson correlation) of genes between two different layers. |
|
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 |