gotvis 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
gotvis-0.1.0/LICENSE ADDED
@@ -0,0 +1,15 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 GOTClust developers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
@@ -0,0 +1,4 @@
1
+ include LICENSE README.md
2
+ include gotvis/_version.py
3
+ recursive-include tests *.py
4
+ recursive-include examples *.py
gotvis-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,166 @@
1
+ Metadata-Version: 2.4
2
+ Name: gotvis
3
+ Version: 0.1.0
4
+ Summary: Grassmann / Optimal-Transport embeddings for single-cell data (Sinkhorn-gamma aware)
5
+ Author: GOTVis Developers
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/ZengFLab/gotvis
8
+ Project-URL: Documentation, https://github.com/ZengFLab/gotvis#readme
9
+ Project-URL: Repository, https://github.com/ZengFLab/gotvis
10
+ Project-URL: Issues, https://github.com/ZengFLab/gotvis/issues
11
+ Keywords: single-cell,embedding,visualization,grassmann-manifold,optimal-transport,sinkhorn,single-cell-rna-seq,computational-biology
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: License :: OSI Approved :: MIT License
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.8
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
23
+ Classifier: Topic :: Scientific/Engineering :: Mathematics
24
+ Classifier: Topic :: Scientific/Engineering :: Visualization
25
+ Classifier: Operating System :: OS Independent
26
+ Requires-Python: >=3.8
27
+ Description-Content-Type: text/markdown
28
+ License-File: LICENSE
29
+ Requires-Dist: numpy>=1.20
30
+ Requires-Dist: scipy>=1.6
31
+ Provides-Extra: gotclust
32
+ Requires-Dist: grassmann-ot>=0.3.0; extra == "gotclust"
33
+ Provides-Extra: anndata
34
+ Requires-Dist: anndata>=0.8; extra == "anndata"
35
+ Provides-Extra: plot
36
+ Requires-Dist: matplotlib>=3.3; extra == "plot"
37
+ Requires-Dist: seaborn>=0.11; extra == "plot"
38
+ Provides-Extra: tsne
39
+ Requires-Dist: scikit-learn>=0.24; extra == "tsne"
40
+ Provides-Extra: opentsne
41
+ Requires-Dist: openTSNE>=1.0; extra == "opentsne"
42
+ Provides-Extra: dev
43
+ Requires-Dist: pytest>=7.0; extra == "dev"
44
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
45
+ Requires-Dist: numpy>=1.20; extra == "dev"
46
+ Requires-Dist: scipy>=1.6; extra == "dev"
47
+ Requires-Dist: scikit-learn>=0.24; extra == "dev"
48
+ Requires-Dist: POT>=0.9.0; extra == "dev"
49
+ Provides-Extra: all
50
+ Requires-Dist: anndata>=0.8; extra == "all"
51
+ Requires-Dist: matplotlib>=3.3; extra == "all"
52
+ Requires-Dist: seaborn>=0.11; extra == "all"
53
+ Requires-Dist: scikit-learn>=0.24; extra == "all"
54
+ Requires-Dist: grassmann-ot>=0.3.0; extra == "all"
55
+ Dynamic: license-file
56
+
57
+ # GOTVis
58
+
59
+ **Grassmann / Optimal-Transport embeddings for single-cell data.**
60
+
61
+ GOTVis is the visualisation companion to
62
+ [GOTClust](https://github.com/gotclust/gotclust). It turns the objects
63
+ produced by Grassmann-optimal-transport clustering — above all the
64
+ **Sinkhorn transport plan `gamma`** returned by GSSC — into 2-D / 3-D
65
+ coordinates suitable for plotting, downstream QC and publication figures.
66
+
67
+ ## Why a separate package?
68
+
69
+ GOTClust ships a single functional-proximity embedding
70
+ (`grassmann_functional_embedding`). That embedding is *cell-centric*: it
71
+ preserves Grassmann cost C and says nothing about cluster membership.
72
+ GSSC (Grassmann Sinkhorn Spectral Clustering) introduces a **prototype
73
+ membership matrix `gamma`**, which carries a completely different kind of
74
+ geometry — simplex geometry over prototypes. Rather than overload
75
+ GOTClust's embedding namespace, GOTVis owns that geometry and keeps the
76
+ dependency surface tiny.
77
+
78
+ ## Install
79
+
80
+ ```bash
81
+ pip install gotvis # core: numpy + scipy only
82
+ pip install "gotvis[all]" # + anndata, sklearn, plotting, grassmann-ot
83
+ pip install "gotvis[tsne]" # + scikit-learn TSNE backend
84
+ pip install "gotvis[opentsne]" # + openTSNE backend
85
+ ```
86
+
87
+ ## What's inside
88
+
89
+ | Embedding | Input | Geometry | Cost |
90
+ |---|---|---|---|
91
+ | `sinkhorn_embedding(method="svd")` | gamma | truncated SVD of centred gamma — one axis per membership direction | O(n m²) |
92
+ | `sinkhorn_embedding(method="barycentric")` | gamma | Aitchison ilr / clr on the (m−1)-simplex | O(n m) |
93
+ | `sinkhorn_embedding(method="spectral")` | gamma | Laplacian eigenmaps on ΓΓᵀ / Jensen-Shannon affinity | O(n² m) |
94
+ | `gammagram_embedding()` | gamma | MDS / t-SNE on ‖gᵢ−gⱼ‖ | O(n²) |
95
+ | `functional_embedding()` | H / U_list / C | Laplacian Eigenmaps or classical MDS on Grassmann cost | O(n²) |
96
+ | `mds_embedding()` / `tsne_embedding()` | any distance | generic fallback | O(n³)/O(n²) |
97
+
98
+ ## Quick start
99
+
100
+ ### From a Sinkhorn gamma
101
+
102
+ ```python
103
+ import numpy as np
104
+ import gotvis
105
+
106
+ # gamma: (n_cells, n_prototypes) non-negative soft assignment
107
+ Y = gotvis.sinkhorn_embedding(gamma, method="svd")
108
+ Y = gotvis.sinkhorn_embedding(gamma, method="barycentric", transform="ilr")
109
+ Y, info = gotvis.sinkhorn_embedding(
110
+ gamma, method="spectral", affinity="kl", return_info=True
111
+ )
112
+ ```
113
+
114
+ ### Straight from a GOTClust GSSC run
115
+
116
+ ```python
117
+ from gotclust import grassmann_sinkhorn_clustering
118
+ import gotvis
119
+
120
+ labels, info = grassmann_sinkhorn_clustering(H, n_clusters=5)
121
+
122
+ # info dict is accepted directly — no plumbing
123
+ Y = gotvis.sinkhorn_embedding(info, method="svd")
124
+ Y = gotvis.sinkhorn_embedding(info, method="barycentric")
125
+ ```
126
+
127
+ ### From Grassmann cost (classic functional proximity)
128
+
129
+ ```python
130
+ Y = gotvis.functional_embedding(C=C, method="laplacian", knn=15)
131
+ Y = gotvis.functional_embedding(H=H, p=3, k=30, method="mds",
132
+ landmarks=500)
133
+ ```
134
+
135
+ ### With AnnData
136
+
137
+ ```python
138
+ import gotvis.tools as gt
139
+
140
+ gt.gamma_from_gotclust(info, adata) # adata.uns["gamma"]
141
+ gt.embed(adata, method="svd", key_added="X_gotvis")
142
+ ax = gt.plot_embedding(adata, color="cell_type", basis="X_gotvis")
143
+ ```
144
+
145
+ ## Design notes
146
+
147
+ * **Core is numpy + scipy only.** `anndata`, `matplotlib`, `sklearn`,
148
+ `POT` and `grassmann-ot` are all optional. GOTVis never imports them at
149
+ module scope.
150
+ * **`gamma` is validated everywhere.** Negative, NaN/Inf and degenerate
151
+ shapes raise immediately with an actionable message; all-zero rows are
152
+ tolerated (they embed at the origin).
153
+ * **Sign / rotation ambiguity is handled.** SVD axes are
154
+ sign-stabilised so repeated runs agree.
155
+
156
+ ## Relationship to GOTClust embeddings
157
+
158
+ GOTVis's `functional_embedding` is a **portable re-implementation** of
159
+ `gotclust.grassmann_functional_embedding` — same Laplacian-Eigenmaps /
160
+ MDS semantics, but with no GOTClust import required and an optional
161
+ landmark-MDS fast path. The genuinely new content is the whole
162
+ `gamma`-based family, which GOTClust does not provide.
163
+
164
+ ## License
165
+
166
+ MIT
gotvis-0.1.0/README.md ADDED
@@ -0,0 +1,110 @@
1
+ # GOTVis
2
+
3
+ **Grassmann / Optimal-Transport embeddings for single-cell data.**
4
+
5
+ GOTVis is the visualisation companion to
6
+ [GOTClust](https://github.com/gotclust/gotclust). It turns the objects
7
+ produced by Grassmann-optimal-transport clustering — above all the
8
+ **Sinkhorn transport plan `gamma`** returned by GSSC — into 2-D / 3-D
9
+ coordinates suitable for plotting, downstream QC and publication figures.
10
+
11
+ ## Why a separate package?
12
+
13
+ GOTClust ships a single functional-proximity embedding
14
+ (`grassmann_functional_embedding`). That embedding is *cell-centric*: it
15
+ preserves Grassmann cost C and says nothing about cluster membership.
16
+ GSSC (Grassmann Sinkhorn Spectral Clustering) introduces a **prototype
17
+ membership matrix `gamma`**, which carries a completely different kind of
18
+ geometry — simplex geometry over prototypes. Rather than overload
19
+ GOTClust's embedding namespace, GOTVis owns that geometry and keeps the
20
+ dependency surface tiny.
21
+
22
+ ## Install
23
+
24
+ ```bash
25
+ pip install gotvis # core: numpy + scipy only
26
+ pip install "gotvis[all]" # + anndata, sklearn, plotting, grassmann-ot
27
+ pip install "gotvis[tsne]" # + scikit-learn TSNE backend
28
+ pip install "gotvis[opentsne]" # + openTSNE backend
29
+ ```
30
+
31
+ ## What's inside
32
+
33
+ | Embedding | Input | Geometry | Cost |
34
+ |---|---|---|---|
35
+ | `sinkhorn_embedding(method="svd")` | gamma | truncated SVD of centred gamma — one axis per membership direction | O(n m²) |
36
+ | `sinkhorn_embedding(method="barycentric")` | gamma | Aitchison ilr / clr on the (m−1)-simplex | O(n m) |
37
+ | `sinkhorn_embedding(method="spectral")` | gamma | Laplacian eigenmaps on ΓΓᵀ / Jensen-Shannon affinity | O(n² m) |
38
+ | `gammagram_embedding()` | gamma | MDS / t-SNE on ‖gᵢ−gⱼ‖ | O(n²) |
39
+ | `functional_embedding()` | H / U_list / C | Laplacian Eigenmaps or classical MDS on Grassmann cost | O(n²) |
40
+ | `mds_embedding()` / `tsne_embedding()` | any distance | generic fallback | O(n³)/O(n²) |
41
+
42
+ ## Quick start
43
+
44
+ ### From a Sinkhorn gamma
45
+
46
+ ```python
47
+ import numpy as np
48
+ import gotvis
49
+
50
+ # gamma: (n_cells, n_prototypes) non-negative soft assignment
51
+ Y = gotvis.sinkhorn_embedding(gamma, method="svd")
52
+ Y = gotvis.sinkhorn_embedding(gamma, method="barycentric", transform="ilr")
53
+ Y, info = gotvis.sinkhorn_embedding(
54
+ gamma, method="spectral", affinity="kl", return_info=True
55
+ )
56
+ ```
57
+
58
+ ### Straight from a GOTClust GSSC run
59
+
60
+ ```python
61
+ from gotclust import grassmann_sinkhorn_clustering
62
+ import gotvis
63
+
64
+ labels, info = grassmann_sinkhorn_clustering(H, n_clusters=5)
65
+
66
+ # info dict is accepted directly — no plumbing
67
+ Y = gotvis.sinkhorn_embedding(info, method="svd")
68
+ Y = gotvis.sinkhorn_embedding(info, method="barycentric")
69
+ ```
70
+
71
+ ### From Grassmann cost (classic functional proximity)
72
+
73
+ ```python
74
+ Y = gotvis.functional_embedding(C=C, method="laplacian", knn=15)
75
+ Y = gotvis.functional_embedding(H=H, p=3, k=30, method="mds",
76
+ landmarks=500)
77
+ ```
78
+
79
+ ### With AnnData
80
+
81
+ ```python
82
+ import gotvis.tools as gt
83
+
84
+ gt.gamma_from_gotclust(info, adata) # adata.uns["gamma"]
85
+ gt.embed(adata, method="svd", key_added="X_gotvis")
86
+ ax = gt.plot_embedding(adata, color="cell_type", basis="X_gotvis")
87
+ ```
88
+
89
+ ## Design notes
90
+
91
+ * **Core is numpy + scipy only.** `anndata`, `matplotlib`, `sklearn`,
92
+ `POT` and `grassmann-ot` are all optional. GOTVis never imports them at
93
+ module scope.
94
+ * **`gamma` is validated everywhere.** Negative, NaN/Inf and degenerate
95
+ shapes raise immediately with an actionable message; all-zero rows are
96
+ tolerated (they embed at the origin).
97
+ * **Sign / rotation ambiguity is handled.** SVD axes are
98
+ sign-stabilised so repeated runs agree.
99
+
100
+ ## Relationship to GOTClust embeddings
101
+
102
+ GOTVis's `functional_embedding` is a **portable re-implementation** of
103
+ `gotclust.grassmann_functional_embedding` — same Laplacian-Eigenmaps /
104
+ MDS semantics, but with no GOTClust import required and an optional
105
+ landmark-MDS fast path. The genuinely new content is the whole
106
+ `gamma`-based family, which GOTClust does not provide.
107
+
108
+ ## License
109
+
110
+ MIT
@@ -0,0 +1,19 @@
1
+ """Embed a Sinkhorn gamma matrix from GSSC / GOTClust."""
2
+ import numpy as np
3
+ import gotvis
4
+
5
+ # gamma: (n_cells, n_prototypes) soft assignment from POT Sinkhorn
6
+ gamma = np.random.dirichlet(np.ones(5), size=200)
7
+
8
+ Y_svd = gotvis.sinkhorn_embedding(gamma, method="svd") # (200, 2)
9
+ Y_ilr = gotvis.barycentric_embedding(gamma) # simplex
10
+ Y_clr = gotvis.barycentric_embedding(gamma, transform="clr")
11
+ Y_spec = gotvis.sinkhorn_spectral_embedding(gamma, n_components=2)
12
+ Y_mmds = gotvis.gammagram_embedding(gamma, method="mds") # gamma-gamma^T dist
13
+ Y_info, info = gotvis.sinkhorn_embedding(gamma, method="svd", return_info=True)
14
+ print(Y_svd.shape, Y_ilr.shape, Y_clr.shape, Y_spec.shape, Y_mmds.shape)
15
+ print(sorted(info.keys()))
16
+
17
+ # With GOTClust output:
18
+ # labels, gssc_info = grassmann_sinkhorn_clustering(H, 7, return_info=True) # noqa
19
+ # Y = gotvis.sinkhorn_embedding(gssc_info["gamma"], method="svd")
@@ -0,0 +1,80 @@
1
+ """GOTVis - visualization embeddings for GOTClust (gamma / Grassmann based)."""
2
+ from ._version import __version__
3
+ from ._embeddings import (
4
+ classical_mds_from_dist,
5
+ gamma_affinity,
6
+ laplacian_eigenmaps_from_affinity,
7
+ )
8
+ from . import api as _api
9
+ from ._validate import coerce_gamma, resolve_gamma
10
+
11
+
12
+ def sinkhorn_embedding(gamma, method="svd", n_components=None,
13
+ return_info=False, **kw):
14
+ """Embed a Sinkhorn / soft-assignment matrix gamma.
15
+
16
+ Methods: 'svd', 'barycentric', 'spectral', 'mds', 'tsne'.
17
+ Returns Y, or (Y, info) when return_info=True.
18
+ """
19
+ return _api.sinkhorn_embedding(gamma, method=method,
20
+ n_components=n_components,
21
+ return_info=return_info, **kw)
22
+
23
+
24
+ def sinkhorn_svd_embedding(gamma, n_components=2, return_info=False, **kw):
25
+ return sinkhorn_embedding(gamma, method="svd", n_components=n_components,
26
+ return_info=return_info, **kw)
27
+
28
+
29
+ def barycentric_embedding(gamma, n_components=None, transform="ilr",
30
+ return_info=False, **kw):
31
+ kw.setdefault("transform", transform)
32
+ return sinkhorn_embedding(gamma, method="barycentric",
33
+ n_components=n_components,
34
+ return_info=return_info, **kw)
35
+
36
+
37
+ def sinkhorn_spectral_embedding(gamma, n_components=2, return_info=False,
38
+ **kw):
39
+ return sinkhorn_embedding(gamma, method="spectral",
40
+ n_components=n_components,
41
+ return_info=return_info, **kw)
42
+
43
+
44
+ def gammagram_embedding(gamma, method="mds", n_components=2,
45
+ return_info=False, **kw):
46
+ return sinkhorn_embedding(gamma, method=method, n_components=n_components,
47
+ return_info=return_info, **kw)
48
+
49
+
50
+ def functional_embedding(*a, **kw):
51
+ return _api.functional_embedding(*a, **kw)
52
+
53
+
54
+ def mds_embedding(*a, **kw):
55
+ return _api.mds_embedding(*a, **kw)
56
+
57
+
58
+ def tsne_embedding(*a, **kw):
59
+ return _api.tsne_embedding(*a, **kw)
60
+
61
+
62
+ def gotclust_embed(*a, **kw):
63
+ return _api.gotclust_embed(*a, **kw)
64
+
65
+
66
+ __all__ = [
67
+ "__version__", "sinkhorn_embedding", "sinkhorn_svd_embedding",
68
+ "barycentric_embedding", "sinkhorn_spectral_embedding",
69
+ "gammagram_embedding", "functional_embedding", "mds_embedding",
70
+ "tsne_embedding", "gotclust_embed", "gamma_affinity",
71
+ "classical_mds_from_dist", "laplacian_eigenmaps_from_affinity",
72
+ "coerce_gamma", "resolve_gamma",
73
+ ]
74
+
75
+
76
+ def __getattr__(name):
77
+ if name in ("tools", "plotting"):
78
+ from . import anndata as _m
79
+ return _m
80
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")