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, 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.

  • adata – annData object that already went through the fate prediction.

  • basis – 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 – the dimensions of low embedding space where cells will be drawn, and it should correspond to the space fate prediction take place.

  • n_steps – the number of times steps (frames) fate prediction will take.

  • cell_states – 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)

  • color – the key of the data that will be used to color the embedding.

  • fig – the figure that will contain both the background and animated components.

  • ax – 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.

  • logspacewhether 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.

  • max_time – the maximum time that will be used to scale the time vector.

  • interval – delay between frames in milliseconds.

  • blit – 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 – whether to save, show or return the figure. By default, a gif will be used.

  • save_kwargs – a dictionary that will be 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.


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

Examples 1

>>> 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()