# dynamo.mv.StreamFuncAnim¶

class dynamo.mv.StreamFuncAnim(adata, basis='umap', dims=None, n_steps=100, cell_states=None, color='ntr', ax=None, ln=None, logspace=False)[source]

Animating cell fate commitment prediction via reconstructed vector field function.

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)

• ax (matplotlib.Axis (optional, default None)) – The matplotlib axes object that will be used as background plot of the vector field animation.

• ln (tuple or None (default: None)) – An iterable of artists (for example, matplotlib.lines.Line2D) used to draw a clear frame.

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

Returns

• A class that contains .fig attribute and .update, .init_background that can be used to produce an animation

• of the prediction of cell fate commitment.

>>> from matplotlib import animation
>>> fate_progenitor = progenitor
>>> dyn.pd.fate(adata, basis='umap', init_cells=fate_progenitor, interpolation_num=100,  direction='forward',
...    inverse_transform=False, average=False, arclen_sampling=True)
>>> anim = animation.FuncAnimation(instance.fig, instance.update, init_func=instance.init_background,
...                                frames=np.arange(100), interval=100, blit=True)
>>> from IPython.core.display import display, HTML
>>> HTML(anim.to_jshtml()) # embedding to jupyter notebook.
>>> anim.save('fate_ani.gif',writer="imagemagick") # save as gif file.

>>> from matplotlib import animation
>>> fate_progenitor = progenitor
>>> dyn.pd.fate(adata, basis='umap', init_cells=fate_progenitor, interpolation_num=100,  direction='forward',
...    inverse_transform=False, average=False, arclen_sampling=True)
>>> fig, ax = plt.subplots()
>>> ln, = ax.plot([], [], 'ro')
>>> ax.set_xlim(xlim)
>>> ax.set_ylim(ylim)
>>> anim = animation.FuncAnimation(fig, instance.update, init_func=instance.init_background,
...                                frames=np.arange(100), interval=100, blit=True)
>>> from IPython.core.display import display, HTML
>>> HTML(anim.to_jshtml()) # embedding to jupyter notebook.
>>> anim.save('fate_ani.gif',writer="imagemagick") # save as gif file.

>>> from matplotlib import animation
>>> fate_progenitor = progenitor
>>> dyn.pd.fate(adata, basis='umap', init_cells=fate_progenitor, interpolation_num=100,  direction='forward',
...    inverse_transform=False, average=False, arclen_sampling=True)

__init__(adata, basis='umap', dims=None, n_steps=100, cell_states=None, color='ntr', ax=None, ln=None, logspace=False)[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)

• ax (matplotlib.Axis (optional, default None)) – The matplotlib axes object that will be used as background plot of the vector field animation.

• ln (tuple or None (default: None)) – An iterable of artists (for example, matplotlib.lines.Line2D) used to draw a clear frame.

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

Returns

• A class that contains .fig attribute and .update, .init_background that can be used to produce an animation

• of the prediction of cell fate commitment.

>>> from matplotlib import animation
>>> fate_progenitor = progenitor
>>> dyn.pd.fate(adata, basis='umap', init_cells=fate_progenitor, interpolation_num=100,  direction='forward',
...    inverse_transform=False, average=False, arclen_sampling=True)
>>> anim = animation.FuncAnimation(instance.fig, instance.update, init_func=instance.init_background,
...                                frames=np.arange(100), interval=100, blit=True)
>>> from IPython.core.display import display, HTML
>>> HTML(anim.to_jshtml()) # embedding to jupyter notebook.
>>> anim.save('fate_ani.gif',writer="imagemagick") # save as gif file.

>>> from matplotlib import animation
>>> fate_progenitor = progenitor
>>> dyn.pd.fate(adata, basis='umap', init_cells=fate_progenitor, interpolation_num=100,  direction='forward',
...    inverse_transform=False, average=False, arclen_sampling=True)
>>> fig, ax = plt.subplots()
>>> ln, = ax.plot([], [], 'ro')
>>> ax.set_xlim(xlim)
>>> ax.set_ylim(ylim)
>>> anim = animation.FuncAnimation(fig, instance.update, init_func=instance.init_background,
...                                frames=np.arange(100), interval=100, blit=True)
>>> from IPython.core.display import display, HTML
>>> HTML(anim.to_jshtml()) # embedding to jupyter notebook.
>>> anim.save('fate_ani.gif',writer="imagemagick") # save as gif file.

>>> from matplotlib import animation

 __init__(adata[, basis, dims, n_steps, …]) Animating cell fate commitment prediction via reconstructed vector field function. init_background() update(frame) Update locations of “particles” in flow on each frame frame.