Trajectory inference

spaTrack.set_start_cells(adata: AnnData, select_way: Literal['coordinates', 'cell_type'], cell_type: Union[None, str] = None, start_point: Optional[Tuple[int, int]] = None, basis: str = 'spatial', split: bool = False, n_clusters: int = 2, n_neigh: int = 5) list[source]

Use coordinates or cell type to manually select starting cells.

Parameters:
  • adata – An AnnData object.

  • select_way

    Ways to select starting cells.

    1. 'cell_type': select by cell type.

    2. 'coordinates': select by coordinates.

  • cell_type – Restrict the cell type of starting cells. (Deafult: None)

  • start_point – The coordinates of the start point in ‘coordinates’ mode.

  • basis – The basis in adata.obsm to store position information.

  • split – Whether to split the specific type of cells into several small clusters according to cell density.

  • n_clsuters – The number of cluster centers after splitting.

  • n_neigh – The number of neighbors next to the start point/cluster center selected as the starting cell.

Returns:

The index number of selected starting cells.

Return type:

list

spaTrack.get_ot_matrix(adata: AnnData, data_type: str, alpha1: int = 0.5, alpha2: int = 0.5, random_state: Union[None, int, RandomState] = 0, pattern: Literal['run', 'test', 'test2'] = 'run', n_pcs: int = 50) ndarray[source]

Calculate transfer probabilities between cells.

Using optimal transport theory based on gene expression and/or spatial location information.

Parameters:
  • adata – An AnnData object.

  • data_type

    The type of sequencing data.

    • 'spatial': for the spatial transcriptome data.

    • 'single-cell': for the single-cell sequencing data.

  • alpha1 – The proportion of gene expression information. (Default: 0.5)

  • alpha2 – The proportion of spatial location information. (Default: 0.5)

  • random_state – Different initial states for the pca. (Default: 0)

  • n_pcs – The number of used pcs. (Default: 50)

Returns:

Cell transition probability matrix.

Return type:

ndarray

spaTrack.get_ptime(adata: AnnData, start_cells: list)[source]

Get the cell pseudotime based on transition probabilities from initial cells.

Parameters:
  • adata – An AnnData object.

  • start_cells – List of index numbers of starting cells.

Returns:

Ptime correspongding to cells.

Return type:

ndarray

spaTrack.get_velocity(adata: AnnData, basis: str, n_neigh_pos: int = 10, n_neigh_gene: int = 0, grid_num=50, smooth=0.5, density=1.0) tuple[source]

Get the velocity of each cell.

The speed can be determined in terms of the cell location and/or gene expression.

Parameters:
  • adata – An AnnData object.

  • basis – The label of cell coordinates, for example, umap or spatial.

  • n_neigh_pos – Number of neighbors based on cell positions such as spatial or umap coordinates. (Default: 10)

  • n_neigh_gene – Number of neighbors based on gene expression. (Default: 0)

Returns:

The grid coordinates and cell velocities on each grid to draw the streamplot figure.

Return type:

tuple

class spaTrack.Lasso(adata)[source]

Lasso an region of interest (ROI) based on spatial cluster.

Parameters:

adata – An AnnData object.

vi_plot(basis: str = 'spatial', cell_type: Union[None, str] = None)[source]

Plot figures.

Parameters:
  • basis – The basis in adata.obsm to store position information. (Deafult: ‘spatial’)

  • cell_type – Restrict the cell type of starting cells. (Deafult: None)

Return type:

The container of cell scatter plot and table.