spateo.tdr.models.models_backbone ================================= .. py:module:: spateo.tdr.models.models_backbone Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/spateo/tdr/models/models_backbone/backbone/index /autoapi/spateo/tdr/models/models_backbone/backbone_methods/index /autoapi/spateo/tdr/models/models_backbone/backbone_utils/index Functions --------- .. autoapisummary:: spateo.tdr.models.models_backbone.backbone_scc spateo.tdr.models.models_backbone.construct_backbone spateo.tdr.models.models_backbone.update_backbone spateo.tdr.models.models_backbone.ElPiGraph_method spateo.tdr.models.models_backbone.PrinCurve_method spateo.tdr.models.models_backbone.SimplePPT_method spateo.tdr.models.models_backbone.map_gene_to_backbone spateo.tdr.models.models_backbone.map_points_to_backbone Package Contents ---------------- .. py:function:: backbone_scc(adata: anndata.AnnData, backbone: pyvista.PolyData, genes: Optional[list] = None, adata_nodes_key: str = 'backbone_nodes', backbone_nodes_key: str = 'updated_nodes', key_added: Optional[str] = 'backbone_scc', layer: Optional[str] = None, e_neigh: int = 10, s_neigh: int = 6, cluster_method: Literal['leiden', 'louvain'] = 'leiden', resolution: Optional[float] = None, inplace: bool = True) -> Optional[anndata.AnnData] Spatially constrained clustering (scc) along the backbone. :param adata: The anndata object. :param backbone: The backbone model. :param genes: The list of genes that will be used to subset the data for clustering. If ``genes = None``, all genes will be used. :param adata_nodes_key: The key that corresponds to the nodes in the adata. :param backbone_nodes_key: The key that corresponds to the nodes in the backbone. :param key_added: adata.obs key under which to add the cluster labels. :param layer: The layer that will be used to retrieve data for dimension reduction and clustering. If ``layer = None``, ``.X`` is used. :param e_neigh: the number of nearest neighbor in gene expression space. :param s_neigh: the number of nearest neighbor in physical space. :param cluster_method: the method that will be used to cluster the cells. :param resolution: the resolution parameter of the louvain clustering algorithm. :param 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. .. py:function:: construct_backbone(model: Union[pyvista.PolyData, pyvista.UnstructuredGrid], spatial_key: Optional[str] = None, nodes_key: str = 'nodes', rd_method: Literal['ElPiGraph', 'SimplePPT', 'PrinCurve'] = 'ElPiGraph', num_nodes: int = 50, color: str = 'gainsboro', **kwargs) -> Tuple[pyvista.PolyData, float, Optional[str]] Organ's backbone construction based on 3D point cloud model. :param model: A point cloud model. :param spatial_key: If spatial_key is None, the spatial coordinates are in model.points, otherwise in model[spatial_key]. :param nodes_key: The key that corresponds to the coordinates of the nodes in the backbone. :param 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. :param num_nodes: Number of nodes for the backbone model. :param color: Color to use for plotting backbone model. :param \*\*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. :rtype: backbone_model .. py:function:: update_backbone(backbone: pyvista.PolyData, nodes_key: str = 'nodes', key_added: str = 'updated_nodes', select_nodes: Optional[Union[list, numpy.ndarray]] = None, interactive: Optional[bool] = True, model_size: Union[float, list] = 8.0, colormap: str = 'Spectral') -> Union[pyvista.PolyData, pyvista.UnstructuredGrid] Update the bakcbone through interaction or input of selected nodes. :param backbone: The backbone model. :param nodes_key: The key that corresponds to the coordinates of the nodes in the backbone. :param key_added: The key under which to add the labels of new nodes. :param select_nodes: Nodes that need to be retained. :param interactive: Whether to delete useless nodes interactively. When ``interactive`` is True, ``select_nodes`` is invalid. :param model_size: Thickness of backbone. When ``interactive`` is False, ``model_size`` is invalid. :param colormap: Colormap of backbone. When ``interactive`` is False, ``colormap`` is invalid. :returns: The updated backbone model. :rtype: updated_backbone .. py:function:: ElPiGraph_method(X: numpy.ndarray, NumNodes: int = 50, topology: Literal['tree', 'circle', 'curve'] = 'curve', Lambda: float = 0.01, Mu: float = 0.1, alpha: float = 0.0, FinalEnergy: Literal['Base', 'Penalized'] = 'Penalized', **kwargs) -> Tuple[numpy.ndarray, numpy.ndarray] Generate a principal elastic tree. Reference: Albergante et al. (2020), Robust and Scalable Learning of Complex Intrinsic Dataset Geometry via ElPiGraph. :param X: DxN, data matrix list. :param NumNodes: The number of nodes of the principal graph. Use a range of 10 to 100 for ElPiGraph approach. :param topology: The appropriate topology used to fit a principal graph for each dataset. :param Lambda: The attractive strength of edges between nodes (constrains edge lengths) :param Mu: The repulsive strength of a node’s neighboring nodes (constrains angles to be close to harmonic) :param alpha: Branching penalty (penalizes number of branches for the principal tree) :param FinalEnergy: Indicating the final elastic emergy associated with the configuration. Currently it can be “Base” or “Penalized” :param \*\*kwargs: Other parameters used in elpigraph.computeElasticPrincipalTree. For details, please see: https://elpigraph-python.readthedocs.io/en/latest/basics.html :returns: The nodes in the principal tree. edges: The edges between nodes in the principal tree. :rtype: nodes .. py:function:: PrinCurve_method(X: numpy.ndarray, NumNodes: int = 50, epochs: int = 500, lr: float = 0.01, scale_factor: Union[int, float] = 1, **kwargs) -> Tuple[numpy.ndarray, numpy.ndarray] 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. Reference: Chen et al. (2016), Constraint local principal curve: Concept, algorithms and applications. :param X: DxN, data matrix list. :param NumNodes: Number of nodes for the construction layers. Defaults to 50. The more complex the curve, the higher this number should be. :param epochs: Number of epochs to train neural network, defaults to 500. :param lr: Learning rate for backprop. Defaults to .01 :param scale_factor: :param \*\*kwargs: Other parameters used in global algorithms. For details, please see: https://github.com/artusoma/prinPy/blob/master/prinpy/glob.py :returns: The nodes in the principal tree. edges: The edges between nodes in the principal tree. :rtype: nodes .. py:function:: SimplePPT_method(X: numpy.ndarray, NumNodes: int = 50, sigma: Optional[Union[float, int]] = 0.1, lam: Optional[Union[float, int]] = 1, metric: str = 'euclidean', nsteps: int = 50, err_cut: float = 0.005, seed: Optional[int] = 1, **kwargs) -> Tuple[numpy.ndarray, numpy.ndarray] Generate a simple principal tree. Reference: Mao et al. (2015), SimplePPT: A simple principal tree algorithm, SIAM International Conference on Data Mining. :param X: DxN, data matrix list. :param NumNodes: The number of nodes of the principal graph. Use a range of 100 to 2000 for PPT approach. :param sigma: Regularization parameter. :param lam: Penalty for the tree length. :param metric: The metric to use to compute distances in high dimensional space. For compatible metrics, check the documentation of sklearn.metrics.pairwise_distances. :param nsteps: Number of steps for the optimisation process. :param err_cut: Stop algorithm if proximity of principal points between iterations less than defined value. :param seed: A numpy random seed. :param \*\*kwargs: Other parameters used in simpleppt.ppt. For details, please see: https://github.com/LouisFaure/simpleppt/blob/main/simpleppt/ppt.py :returns: The nodes in the principal tree. edges: The edges between nodes in the principal tree. :rtype: nodes .. py:function:: map_gene_to_backbone(model: Union[pyvista.PolyData, pyvista.UnstructuredGrid], tree: pyvista.PolyData, key: Union[str, list], nodes_key: Optional[str] = 'nodes', inplace: bool = False) Find the closest principal tree node to any point in the model through KDTree. :param model: A reconstructed model contains the gene expression label. :param tree: A three-dims principal tree model contains the nodes label. :param key: The key that corresponds to the gene expression. :param nodes_key: The key that corresponds to the coordinates of the nodes in the tree. :param inplace: Updates tree model in-place. :returns: `tree.point_data[key]`, the gene expression array. :rtype: A tree, which contains the following properties .. py:function:: map_points_to_backbone(model: Union[pyvista.PolyData, pyvista.UnstructuredGrid], backbone_model: pyvista.PolyData, nodes_key: str = 'nodes', key_added: Optional[str] = 'nodes', inplace: bool = False, **kwargs) Find the closest principal tree node to any point in the model through KDTree. :param model: The reconstructed model. :param backbone_model: The constructed backbone model. :param nodes_key: The key that corresponds to the coordinates of the nodes in the backbone. :param key_added: The key under which to add the nodes labels. :param inplace: Updates model in-place. :param \*\*kwargs: Additional parameters that will be passed to ``scipy.spatial.KDTree.`` function. :returns: `model.point_data[key_added]`, the nodes labels array. :rtype: A model, which contains the following properties