Metadata-Version: 2.4
Name: GOTClust
Version: 0.1.0
Summary: Grassmann-Optimal-Transport Clustering for Single-Cell Data
Home-page: https://github.com/gotclust/gotclust
Author: GOTClust Developers
License: MIT
Project-URL: Homepage, https://github.com/ZengFLab/gotclust
Project-URL: Documentation, https://github.com/ZengFLab/gotclust#readme
Project-URL: Repository, https://github.com/ZengFLab/gotclust
Project-URL: Issues, https://github.com/ZengFLab/gotclust/issues
Keywords: single-cell,clustering,grassmann-manifold,optimal-transport,single-cell-rna-seq,computational-biology
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Operating System :: OS Independent
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.20
Requires-Dist: scipy>=1.6
Requires-Dist: scikit-learn>=0.24
Requires-Dist: grassmann-ot>=0.3.0
Provides-Extra: gpu
Requires-Dist: torch>=1.9; extra == "gpu"
Provides-Extra: faiss
Requires-Dist: faiss-cpu>=1.7; extra == "faiss"
Provides-Extra: dev
Requires-Dist: pytest>=7.0; extra == "dev"
Requires-Dist: matplotlib>=3.3; extra == "dev"
Requires-Dist: seaborn>=0.11; extra == "dev"
Requires-Dist: scanpy>=1.8; extra == "dev"
Dynamic: license-file

# GOTClust

**Grassmann-Optimal-Transport Clustering for Single-Cell Data**

A subspace-aware clustering framework that represents each cell by a local
principal subspace (capturing local transcriptional regulatory structure),
then clusters these subspaces on the Grassmann manifold.

---

## Why GOTClust?

| Aspect | Vector-space methods (Leiden, KMeans) | GOTClust |
|---|---|---|
| Object being clustered | Cell vector (expression values) | Local **subspace** (covariance structure) |
| Distance | Euclidean / cosine | **Grassmann projection distance** |
| Rotations | Sensitive | **Invariant** |
| Batch robustness | Low | **High** (rotation-invariant) |
| Biological interpretation | "Cells look similar" | **"Regulatory programs look similar"** |

GOTClust provides two algorithms:

- **GSC** — Grassmann Spectral Clustering
- **GWC** — Grassmann Wasserstein Clustering (Frechet-mean barycenters)

---

## Installation

```bash
pip install GOTClust
```

With GPU acceleration (via the underlying `grassmann-ot` backends):

```bash
pip install GOTClust[gpu]
```

---

## Quick start

```python
import numpy as np
from gotclust import grassmann_sc

# H: expression / composition matrix, shape (n_genes, n_cells)
H = np.random.randn(50, 300)

# ---- Grassmann Spectral Clustering (recommended) ----
labels, info = grassmann_sc(
    H, n_clusters=4, method="spectral",
    k=30, p=3, backend="pca", affinity="local", random_state=42,
)

# ---- Grassmann Wasserstein Clustering ----
labels, info = grassmann_sc(
    H, n_clusters=4, method="wasserstein",
    k=30, p=3, backend="pca", n_iter=50, init="kmeans++", random_state=42,
)
```

### Returned `info`

| Key | Shape | Description |
|---|---|---|
| `U_list` | `list[(r,p)]` | Per-cell Grassmann points |
| `C` | `(n,n)` | Pairwise Grassmann cost matrix |
| `affinity` | `(n,n)` | Affinity matrix (GSC only) |
| `centroids` | `list[(r,p)]` | Cluster barycenters (GWC only) |
| `inertia` | `list[float]` | Inertia history (GWC only) |

---

## Algorithm reference

### `grassmann_sc(H, n_clusters, method, **kwargs)`

Unified entry point.

- `method="spectral"` → forwards to `grassmann_spectral_clustering`
- `method="wasserstein"` → forwards to `grassmann_wasserstein_clustering`

### `grassmann_spectral_clustering(...)`

Pipeline:
1. `cells_to_grassmann` → local subspaces `U_i`
2. `grassmann_cost_matrix` → cost matrix `C`
3. `grassmann_affinity` → affinity matrix `A` (Zelnik-Perona local scaling)
4. `sklearn.SpectralClustering(affinity="precomputed")`

### `grassmann_wasserstein_clustering(...)`

Lloyd-style alternating optimization:
- **E-step** — assign each cell to the nearest cluster center
  (Grassmann projection distance)
- **M-step** — update each center to the Frechet mean of its members

### `grassmann_frechet_mean(V_list, weights, p)`

Closed-form Grassmann barycenter: eigen-decomposition of
`Σ w_j V_j V_j^T`, take top-`p` eigenvectors.

### `grassmann_affinity(C, method, sigma)`

Build an affinity matrix from a Grassmann cost matrix.
`method` ∈ `{"local", "global", "knn"}`.

---

## Parameters

| Parameter | Default | Meaning |
|---|---|---|
| `k` | 30 | Neighborhood size for local subspace construction |
| `p` | 3 | Subspace dimension |
| `backend` | `"pca"` | Subspace construction backend (`loop`/`pca`/`batched`/`faiss`/`subsampling`) |
| `affinity` | `"local"` | Affinity construction (`local`/`global`/`knn`) |
| `n_iter` | 50 | Lloyd iterations (GWC) |
| `init` | `"kmeans++"` | Centroid initialization (GWC) |

---

## Citation

*Coming soon.*

---

## License

MIT
