spateo.tdr.models.models_backbone.backbone#

Module Contents#

Functions#

construct_backbone(→ Tuple[pyvista.PolyData, float, ...)

Organ's backbone construction based on 3D point cloud model.

update_backbone(→ Union[pyvista.PolyData, ...)

Update the bakcbone through interaction or input of selected nodes.

backbone_scc(→ Optional[anndata.AnnData])

Spatially constrained clustering (scc) along the backbone.

spateo.tdr.models.models_backbone.backbone.construct_backbone(model: pyvista.PolyData | pyvista.UnstructuredGrid, spatial_key: str | None = None, nodes_key: str = 'nodes', rd_method: Literal[ElPiGraph, SimplePPT, PrinCurve] = 'ElPiGraph', num_nodes: int = 50, color: str = 'gainsboro', **kwargs) Tuple[pyvista.PolyData, float, str | None][source]#

Organ’s backbone construction based on 3D point cloud model.

Parameters:
model

A point cloud model.

spatial_key

If spatial_key is None, the spatial coordinates are in model.points, otherwise in model[spatial_key].

nodes_key

The key that corresponds to the coordinates of the nodes in the backbone.

rd_method

The method of constructing a backbone model. Available rd_method are:

  • 'ElPiGraph': Generate a principal elastic tree.

  • 'SimplePPT': Generate a simple principal tree.

  • 'PrinCurve': This is the global module that contains principal curve and nonlinear principal

    component analysis algorithms that work to optimize a line over an entire dataset.

num_nodes

Number of nodes for the backbone model.

color

Color to use for plotting backbone model.

**kwargs

Additional parameters that will be passed to ElPiGraph_method, SimplePPT_method or PrinCurve_method function.

Returns:

A three-dims backbone model. backbone_length: The length of the backbone model. plot_cmap: Recommended colormap parameter values for plotting.

Return type:

backbone_model

spateo.tdr.models.models_backbone.backbone.update_backbone(backbone: pyvista.PolyData, nodes_key: str = 'nodes', key_added: str = 'updated_nodes', select_nodes: list | numpy.ndarray | None = None, interactive: bool | None = True, model_size: float | list = 8.0, colormap: str = 'Spectral') pyvista.PolyData | pyvista.UnstructuredGrid[source]#

Update the bakcbone through interaction or input of selected nodes.

Parameters:
backbone

The backbone model.

nodes_key

The key that corresponds to the coordinates of the nodes in the backbone.

key_added

The key under which to add the labels of new nodes.

select_nodes

Nodes that need to be retained.

interactive

Whether to delete useless nodes interactively. When interactive is True, select_nodes is invalid.

model_size

Thickness of backbone. When interactive is False, model_size is invalid.

colormap

Colormap of backbone. When interactive is False, colormap is invalid.

Returns:

The updated backbone model.

Return type:

updated_backbone

spateo.tdr.models.models_backbone.backbone.backbone_scc(adata: anndata.AnnData, backbone: pyvista.PolyData, genes: list | None = None, adata_nodes_key: str = 'backbone_nodes', backbone_nodes_key: str = 'updated_nodes', key_added: str | None = 'backbone_scc', layer: str | None = None, e_neigh: int = 10, s_neigh: int = 6, cluster_method: Literal[leiden, louvain] = 'leiden', resolution: float | None = None, inplace: bool = True) anndata.AnnData | None[source]#

Spatially constrained clustering (scc) along the backbone.

Parameters:
adata

The anndata object.

backbone

The backbone model.

genes

The list of genes that will be used to subset the data for clustering. If genes = None, all genes will be used.

adata_nodes_key

The key that corresponds to the nodes in the adata.

backbone_nodes_key

The key that corresponds to the nodes in the backbone.

key_added

adata.obs key under which to add the cluster labels.

layer

The layer that will be used to retrieve data for dimension reduction and clustering. If layer = None, .X is used.

e_neigh

the number of nearest neighbor in gene expression space.

s_neigh

the number of nearest neighbor in physical space.

cluster_method

the method that will be used to cluster the cells.

resolution

the resolution parameter of the louvain clustering algorithm.

inplace

Whether to copy adata or modify it inplace.

Returns:

An AnnData object is updated/copied with the key_added in the .obs attribute, storing the clustering results.