goatpy.graphpca_mod

gpca_mod_spatial.py

GraphPCA replacement with spatial smoothing using cKDTree.

Functions

kneighbors_graph_spatial(→ scipy.sparse.csr_matrix)

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

graphpca_spatialdata(→ Tuple[numpy.ndarray, ...)

PCA with optional spatial smoothing.

get_kmean_clusters(sd[, tables, n_clusters, cluster_key])

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

Module Contents

goatpy.graphpca_mod.kneighbors_graph_spatial(coords: numpy.ndarray, n_neighbors: int = 10, include_self: bool = False, mode: str = 'connectivity') scipy.sparse.csr_matrix[source]

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

goatpy.graphpca_mod.graphpca_spatialdata(sd, tables: str = 'maldi_adata', library_id: str | None = 'spatial', n_components: int = 50, n_neighbors: int = 10, alpha: float = 0.0, center: bool = True, kneighbors_mode: str = 'connectivity') Tuple[numpy.ndarray, numpy.ndarray | None, scipy.sparse.csr_matrix | None][source]

PCA with optional spatial smoothing.

Parameters:
  • sd (spatialdata object containing glycomics data)

  • tables (str, table name in sd.tables)

  • library_id (str, key in adata.obsm for spatial coordinates)

  • n_components (int)

  • n_neighbors (int for spatial KNN)

  • alpha (float, smoothing strength)

  • center (bool)

  • return_scores (bool)

  • return_adjacency (bool)

Returns:

  • components ((n_components, n_features))

  • scores ((n_samples, n_components))

  • adjacency (CSR adjacency used for smoothing)

goatpy.graphpca_mod.get_kmean_clusters(sd, tables: str = 'maldi_adata', n_clusters=8, cluster_key: str = 'GPCA_clusters')[source]

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

Parameters:
  • sd (SpatialData object with GraphPCA scores in sd.tables[tables].obsm["GraphPCA"])

  • tables (str, table name in sd.tables (default "maldi_adata"))

  • n_clusters (int, number of clusters for KMeans (default 8))

  • cluster_key (str, key for storing cluster labels in adata.obs (default "GPCA_clusters"))

Return type:

adata with cluster labels in adata.obs[“GPCA_pred”]