goatpy.graphpca_mod
===================

.. py:module:: goatpy.graphpca_mod

.. autoapi-nested-parse::

   gpca_mod_spatial.py

   GraphPCA replacement with spatial smoothing using cKDTree.



Functions
---------

.. autoapisummary::

   goatpy.graphpca_mod.kneighbors_graph_spatial
   goatpy.graphpca_mod.graphpca_spatialdata
   goatpy.graphpca_mod.get_kmean_clusters


Module Contents
---------------

.. py:function:: kneighbors_graph_spatial(coords: numpy.ndarray, n_neighbors: int = 10, include_self: bool = False, mode: str = 'connectivity') -> scipy.sparse.csr_matrix

   Build a KNN graph (sparse adjacency) using spatial coordinates.


.. py:function:: graphpca_spatialdata(sd, tables: str = 'maldi_adata', library_id: Optional[str] = 'spatial', n_components: int = 50, n_neighbors: int = 10, alpha: float = 0.0, center: bool = True, kneighbors_mode: str = 'connectivity') -> Tuple[numpy.ndarray, Optional[numpy.ndarray], Optional[scipy.sparse.csr_matrix]]

   PCA with optional spatial smoothing.

   :param sd:
   :type sd: spatialdata object containing glycomics data
   :param tables:
   :type tables: str, table name in sd.tables
   :param library_id:
   :type library_id: str, key in adata.obsm for spatial coordinates
   :param n_components:
   :type n_components: int
   :param n_neighbors:
   :type n_neighbors: int for spatial KNN
   :param alpha:
   :type alpha: float, smoothing strength
   :param center:
   :type center: bool
   :param return_scores:
   :type return_scores: bool
   :param return_adjacency:
   :type return_adjacency: bool

   :returns: * **components** (*(n_components, n_features)*)
             * **scores** (*(n_samples, n_components)*)
             * **adjacency** (*CSR adjacency used for smoothing*)


.. py:function:: get_kmean_clusters(sd, tables: str = 'maldi_adata', n_clusters=8, cluster_key: str = 'GPCA_clusters')

   Perform KMeans clustering on GraphPCA scores stored in adata.obsm.

   :param sd:
   :type sd: SpatialData object with GraphPCA scores in sd.tables[tables].obsm["GraphPCA"]
   :param tables:
   :type tables: str, table name in sd.tables (default "maldi_adata")
   :param n_clusters:
   :type n_clusters: int, number of clusters for KMeans (default 8)
   :param cluster_key:
   :type cluster_key: str, key for storing cluster labels in adata.obs (default "GPCA_clusters")

   :rtype: adata with cluster labels in adata.obs["GPCA_pred"]


