dynamo.mv.animate_fates

dynamo.mv.animate_fates(adata, basis='umap', dims=None, n_steps=100, cell_states=None, color='ntr', fig=None, ax=None, logspace=False, max_time=None, frame_color=None, interval=100, blit=True, save_show_or_return='show', save_kwargs={}, **kwargs)[source]

Animating cell fate commitment prediction via reconstructed vector field function.

This class creates necessary components to produce an animation that describes the exact speed of a set of cells at each time point, its movement in gene expression and the long range trajectory predicted by the reconstructed vector field. Thus it provides intuitive visual understanding of the RNA velocity, speed, acceleration, and cell fate commitment in action.

This function is originally inspired by https://tonysyu.github.io/animating-particles-in-a-flow.html and relies on animation module from matplotlib. Note that you may need to install imagemagick in order to properly show or save the animation. See for example, http://louistiao.me/posts/notebooks/save-matplotlib-animations-as-gifs/ for more details.

Parameters
  • adata (AnnData) – AnnData object that already went through the fate prediction.

  • basis (str or None (default: None)) – The embedding data to use for predicting cell fate. If basis is either umap or pca, the reconstructed trajectory will be projected back to high dimensional space via the inverse_transform function. space.

  • dims (list or None (default: `None’)) – The dimensions of low embedding space where cells will be drawn and it should corresponds to the space fate prediction take place.

  • n_steps (int (default: 100)) – The number of times steps (frames) fate prediction will take.

  • cell_states (int, list or None (default: None)) – The number of cells state that will be randomly selected (if int), the indices of the cells states (if list) or all cell states which fate prediction executed (if None)

  • fig (matplotlib.figure.Figure or None (default: None)) – The figure that will contain both the background and animated components.

  • ax (matplotlib.Axis (optional, default None)) – The matplotlib axes object that will be used as background plot of the vector field animation. If ax is None, topography(adata, basis=basis, color=color, ax=ax, save_show_or_return=’return’) will be used to create an axes.

  • logspace (bool (default: False)) – Whether or to sample time points linearly on log space. If not, the sorted unique set of all time points from all cell states’ fate prediction will be used and then evenly sampled up to n_steps time points.

  • interval (float (default: 200)) – Delay between frames in milliseconds.

  • blit (bool (default: False)) – Whether blitting is used to optimize drawing. Note: when using blitting, any animated artists will be drawn according to their zorder; however, they will be drawn on top of any previous artists, regardless of their zorder.

  • save_show_or_return (str {‘save’, ‘show’, ‘return’} (default: save)) – Whether to save, show or return the figure. By default a gif will be used.

  • save_kwargs (dict (default: {})) – A dictionary that will passed to the anim.save. By default it is an empty dictionary and the save_fig function will use the {“filename”: ‘fate_ani.gif’, “writer”: “imagemagick”} as its parameters. Otherwise you can provide a dictionary that properly modify those keys according to your needs. see https://matplotlib.org/api/_as_gen/matplotlib.animation.Animation.save.html for more details.

  • kwargs – Additional arguments passed to animation.FuncAnimation.

Returns

Return type

Nothing but produce an animation that will be embedded to jupyter notebook or saved to disk.

>>> from matplotlib import animation
>>> progenitor = adata.obs_names[adata.obs.clusters == 'cluster_1']
>>> fate_progenitor = progenitor
>>> info_genes = adata.var_names[adata.var.use_for_transition]
>>> dyn.pd.fate(adata, basis='umap', init_cells=fate_progenitor, interpolation_num=100,  direction='forward',
...    inverse_transform=False, average=False)
>>> dyn.mv.animate_fates(adata)

See also:: StreamFuncAnim()