API

Tools

preprocess(adata: AnnData, min_cells: int = 10, target_sum: float = 10000.0, n_top_genes: int = 2000, n_neighbors: int = 30, n_pcs: int = 30, svd_solver: str = 'arpack', copy: bool = True) AnnData

Standard preprocessing steps for single-cell RNA-seq data.

Parameters:
  • adata (AnnData) – Input single-cell data.

  • min_cells (int, optional) – Minimum cells required to keep a gene. Default is 10.

  • target_sum (float, optional) – Normalization target per cell. Default is 10000.

  • n_top_genes (int, optional) – Number of highly variable genes to select. Default is 2000.

  • n_neighbors (int, optional) – Number of neighbors for graph construction. Default is 30.

  • n_pcs (int, optional) – Number of principal components. Default is 30.

  • svd_solver (str, optional) – SVD solver for PCA. Default is ‘arpack’.

  • copy (bool, optional) – Whether to return a copy of the data. Default is True.

Returns:

Preprocessed AnnData object.

Return type:

AnnData

recover_dyc(adata: AnnData, time_key: str = 'time_point', time_weight: float = 0.1, model_path: str | None = None, save_path: str | None = None, n_epochs=None) AnnData

Predicts transcriptomic velocities and gene-embedded time using a semi-supervised model.

Parameters:
  • adata (AnnData) – Input single-cell data with temporal labels.

  • time_key (str, optional) – Key in adata.obs containing temporal labels. Default is ‘time_point’.

  • time_weight (float, optional) – Control the relative weighting of the two loss components in the dual-loss training architecture. Default is 0.1.

  • model_path (str, optional) – Path to a pre-trained model file. If None, train a new model. Default is None.

  • save_path (str, optional) – Path to save the trained model. If None, model is not saved. Default is None.

  • n_epochs (int, optional) – Number of training epochs. If None, the model automatically determines the iteration count.

Returns:

Modified AnnData object with the following additions: - adata.obs[‘getime’]: Predicted gene-embedded time - adata.layers[‘velocity’]: Predicted velocities matrix

Return type:

AnnData

Plotting

plot_velocity_projection(adata: AnnData, velocity_key: str = 'velocity', basis: str = 'umap', xkey: str | None = None, color: str | None = None, legend_loc: str = 'on data', title: str = '', show: bool = True, figsize: Tuple[int, int] = (8, 6), size: int | None = None, cmap: str | None = None, alpha: float = 0.3, colorbar: bool = True, palette: str | None = None, n_jobs: int = 10, graph_T: bool = False) None

Computes a velocity graph from the calculated velocity vectors and projects it as a stream plot on the embedding.

Parameters:
  • adata (AnnData) – Input AnnData object with velocities data and embedding coordinates.

  • velocity_key (str, optional) – Layer containing velocities data. Default is ‘velocity’.

  • basis (str, optional) – Embedding basis to use (e.g., ‘umap’, ‘tsne’). Default is ‘umap’.

  • xkey (str, optional) – Layer to use as expression data. If None, uses adata.X converted to dense array. Default is None.

  • color (str, optional) – Column name in obs for coloring points. If None, no coloring is applied. Default is None.

  • legend_loc (str, optional) – Location of legend. Default is ‘on data’.

  • title (str, optional) – Plot title. Default is empty string.

  • show (bool, optional) – Whether to display the plot. Default is True.

  • figsize (tuple of int, optional) – Figure size (width, height) in inches. Default is (8, 6).

  • size (int, optional) – Size of points in scatter plot. If None, uses default. Default is None.

  • cmap (str, optional) – Colormap for coloring. If None, uses default. Default is None.

  • alpha (float, optional) – Transparency of points. Default is 0.3.

  • colorbar (bool, optional) – Whether to show colorbar. Default is True.

  • palette (str, optional) – Color palette for categorical coloring. If None, uses default. Default is None.

  • n_jobs (int, optional) – Number of jobs for parallel computation. Default is 10.

  • graph_T (bool, optional) – If True, transpose the adjacency matrix. Default is False.

Returns:

Shows the velocity projection plot.

Return type:

None

Raises:

ValueError – If required layers or embeddings are not found.

getime_violin(adata: AnnData, key_cont: str, key_cat: str, rotation: float = 45, palette: str | None = 'tab10', stripplot: bool = False, xlabel: str = 'Time point', ylabel: str | None = None, fontsize: int = 12, remove_ticks: bool = True, figsize: Tuple[int, int] = (3, 3), ax: Axes | None = None, show: bool = True, arrow_size: float = 15, arrow_style: str = '->', **kwargs) Axes

Creates violin plots for a variable across different categories.

Parameters:
  • adata (AnnData) – Input AnnData object.

  • key_cont (str) – Variable column name in adata.obs for y-axis values.

  • key_cat (str) – Categorical column name in adata.obs for grouping.

  • rotation (float, optional) – Rotation angle for x-axis labels. Default is 45.

  • palette (str, optional) – Color palette for violin plots. Default is tab10.

  • stripplot (bool, optional) – Whether to overlay strip plot on violins. Default is False.

  • xlabel (str, optional) – Label for x-axis. Default is ‘Time point’.

  • ylabel (str, optional) – Label for y-axis. If None, uses default labels based on key_cont. Default is None.

  • fontsize (int, optional) – Font size for label in the plot.

  • remove_ticks (bool, optional) – Whether to remove axis ticks. Default is True.

  • figsize (tuple of int, optional) – Figure size (width, height) in inches. Default is (3, 3).

  • ax (matplotlib.axes.Axes, optional) – Axes object to plot on. If None, creates new figure and axes.

  • show (bool, optional) – Whether to display the plot. Default is True.

  • arrow_size (float, optional) – Size of the arrow heads in points. Default is 15.

  • arrow_style (str, optional) – Style of the arrow heads. Default is ‘->’.

  • **kwargs (dict) – Additional arguments for sc.pl.violin.

Returns:

Returns the axes object by default.

Return type:

matplotlib.axes.Axes

Raises:

ValueError – If required columns are not found in adata.obs.

velocity_hot(adata: AnnData, gene: str, layer: str = 'velocity', basis: str = 'umap', cmap: str = 'RdBu_r', figsize: Tuple[int, int] = (6, 6), fontsize: int = 10, show: bool = True, dpi: int = 300, save_format: str = 'png', save_path: str | None = None, **kwargs) Tuple[Figure, Axes]

Plot the velocity of a single gene on the embedding space.

Parameters:
  • adata (AnnData) – AnnData object with embedding coordinates and gene velocity data.

  • gene (str) – Gene name to plot.

  • layer (str, optional) – Layer containing gene velocity data. Default is “velocity”.

  • basis (str, optional) – Embedding basis to use (e.g., ‘umap’, ‘tsne’). Default is ‘umap’.

  • cmap (str, optional) – Colormap for gene expression values. Default is ‘RdBu_r’.

  • figsize (tuple of int, optional) – Figure size (width, height) in inches. Default is (6, 6).

  • fontsize (int, optional) – Font size for title in the plot.

  • show (bool, optional) – Whether to display the figure. Default is True.

  • dpi (int, optional) – Resolution for saved figure. Default is 300.

  • save_format (str, optional) – File format for saving figure. Default is ‘png’.

  • save_path (str, optional) – Path to save the figure. If None, figure is not saved. Default is None.

  • **kwargs (dict) – Additional arguments for sc.pl.embedding.

Returns:

Figure and axes objects of the embedding plot.

Return type:

tuple

Raises:

ValueError – If gene is not found in adata.var_names. If embedding coordinates are not found in adata.obsm. If specified layer is not found.