Plotting
Methods to compute and visualize velocity graphs and trajectories
- Cell2fate_DynamicalModel.compute_velocity_graph_Bergen2020(adata, n_neighbours=None, full_posterior=True, spliced_key='Ms', velocity_key='velocity')[source]
Computes a “velocity graph” similar to the method in: “Bergen et al. (2020), Generalizing RNA velocity to transient cell states through dynamical modeling”
- Parameters:
adata – AnnData object with velocity information in
adata.layers['velocity'](expectation value) oradata.uns['velocity_posterior'](full posterior). Also normalized spliced counts inadata.layers['spliced_nor']n_neighbours – How many nearest neighbours to consider (all non nearest neighbours have edge weights set to 0). If not specified, 10% of the total number of cells is used.
full_posterior – Whether to use full posterior to compute velocity graph (otherwise expectation value is used).
velocity_key – Key to access velocity information in adata.
spliced_key – Key to access normalized spliced counts in adata.
- Returns:
Velocity graph
- Return type:
Numpy.ndarray
- Cell2fate_DynamicalModel.compute_and_plot_module_velocity(adata, delete=True, plot=True, save=None, plotting_kwargs={'color': 'clusters', 'legend_fontsize': 10, 'legend_loc': 'right_margin', 'min_mass': 4})[source]
Computes the RNA velocity produced by each module, as well as associated “velocity graph” and then plots results on a UMAP based on the method in: “Bergen et al. (2020), Generalizing RNA velocity to transient cell states through dynamical modeling”
- Parameters:
adata – AnnData object with spliced and unspliced count data.
delete – Whether to delete computed layers after processing.
plot – Whether to plot the results.
save – Filepath to save the plot.
plotting_kwargs – Keyword arguments for plotting.
- Cell2fate_DynamicalModel.compute_and_plot_total_velocity(adata, delete=True, plot=True, save=None, plotting_kwargs={'color': 'clusters', 'legend_fontsize': 10, 'legend_loc': 'right_margin'}, return_adata=False)[source]
Computes total RNA velocity, as well as associated “velocity graph” and then plots results on a UMAP based on the method in: “Bergen et al. (2020), Generalizing RNA velocity to transient cell states through dynamical modeling”
- Parameters:
adata – AnnData object with spliced and unspliced count data.
delete – Whether to delete computed layers after processing.
plot – Whether to plot the results.
save – Filepath to save the plot.
plotting_kwargs – Keyword arguments for plotting.
- Cell2fate_DynamicalModel.visualize_module_trajectories(adata, chosen_module, delete=True, plot=True, save=None, smooth=None, min_mass=None, n_neighbors=None, cutoff_perc=None, plotting_kwargs={'cmap': 'Greys', 'color': 'clusters', 'dpi': 300, 'legend_fontsize': 10, 'legend_loc': 'on data'})[source]
Visualize relative module activation trajectories using velocity-based embedding.
- Parameters:
adata – AnnData object containing cell information and embeddings.
chosen_module – The number / name of the chosen module.
delete – Delete temporary data structures after use, by default True.
plot – Whether to generate the plot, by default True.
save – File path to save the generated plot, by default None.
smooth – Smoothing parameter for grid-based velocity calculations, by default None.
min_mass – Minimum cell mass for grid-based velocity calculations, by default None.
n_neighbors – Number of neighbors for grid-based velocity calculations, by default None.
cutoff_perc – Cutoff percentile for adjusting grid-based velocity calculations, by default None.
plotting_kwargs – Additional keyword arguments for customizing the plot appearance, by default
{"color": 'clusters', 'legend_fontsize': 10, 'legend_loc': 'on data', 'dpi': 300, 'cmap': 'inferno'}.
- Cell2fate_DynamicalModel.compute_and_plot_total_velocity_scvelo(adata, delete=True, plot=True, save=None, plotting_kwargs={'color': 'clusters', 'legend_fontsize': 10, 'legend_loc': 'right_margin'})[source]
Computes total RNA velocity, as well as associated “velocity graph” and then plots results on a UMAP based on the method in: “Bergen et al. (2020), Generalizing RNA velocity to transient cell states through dynamical modeling”
- Parameters:
adata – AnnData object with spliced and unspliced count data.
delete – Whether to delete computed layers after processing.
plot – Whether to plot the results.
save – Filepath to save the plot.
plotting_kwargs – Keyword arguments for plotting.
- utils.compute_velocity_graph_Bergen2020(n_neighbours=None, full_posterior=True, spliced_key='Ms')
Computes a “velocity graph” similar to the method in: “Bergen et al. (2020), Generalizing RNA velocity to transient cell states through dynamical modeling”
- Parameters:
adata – anndata object with velocity information in
adata.layers['velocity'](expectation value) oradata.uns['velocity_posterior'](full posterior). Also normalized spliced counts in adata.layers[‘spliced_norm’].n_neighbours – how many nearest neighbours to consider (all non nearest neighbours have edge weights set to 0) if not specified, 10% of the total number of cells is used.
full_posterior – whether to use full posterior to compute velocity graph (otherwise expectation value is used)
- Returns:
Velocity graph
- Return type:
Array
- utils.plot_velocity_umap_Bergen2020(use_full_posterior=True, n_neighbours=None, plotting_kwargs=None, save=False, spliced_key='Ms')
Visualizes RNAvelocity with arrows on a UMAP, using the method introduced in “Bergen et al. (2020), Generalizing RNA velocity to transient cell states through dynamical modeling” The method computes a “velocity graph” before plotting (see the referenced paper for details), unless such a graph is already available. The graph is based on the full velocity posterior distribution if available, otherwise it is based on the velocity expectation values. Velocity is expected in
adata.layers['velocity']oradata.uns['velocity_posterior'](for the full posterior) and the graph is saved/expected inadata.layers['velocity_graph'].- Parameters:
adata – AnnData object with velocity information
use_full_posterior – Use full posterior to compute velocity graph (if available)
plotting_kwargs
Methods to plot module summary statistics and activations
- Cell2fate_DynamicalModel.compare_module_activation(adata, chosen_modules, time_max=None, time_min=0, save=None, ncol=1)[source]
Compares the activation of chosen modules across time.
- Parameters:
adata – AnnData object.
chosen_modules – List of module indices to compare.
time_max – Maximum time point for comparison.
time_min – Minimum time point for comparison.
save – Filepath to save the plot.
ncol – Number of columns in the legend.
- Cell2fate_DynamicalModel.plot_module_summary_statistics(adata, save=None)[source]
Plots weight, activation, velocity, switch ON/OFF time histograms for each module.
- Parameters:
adata – AnnData object containing single-cell RNA sequencing data.
save – File path to save the plot. If not provided, the plot will not be saved.
Other methods to plot top features, genes, and technical variables
- Cell2fate_DynamicalModel.plot_top_features(adata, tab, chosen_modules, mode='all genes', n_top_features=3, save=False, process=True)[source]
Plot top features for chosen modules.
- Parameters:
adata – AnnData object.
tab – Table containing feature rankings.
chosen_modules – List of module indices to plot.
mode – Mode for selecting features.
n_top_features – Number of top features to plot.
save – Whether to save the plot.
process – Whether to preprocess the data.
- Cell2fate_DynamicalModel.plot_genes(adata, chosen_clusters, marker_genes, cluster_key='clusters', save=None)[source]
Plot expression of marker genes across chosen clusters.
- Parameters:
adata – AnnData object.
chosen_clusters – List of cluster names to include.
marker_genes – List of marker genes to plot.
cluster_key – Key in adata.obs storing cluster information.
save – Filepath to save the plot.