GOTMap
Query-to-Reference Atlas Mapping via Grassmann Optimal Transport
GOTMap maps query single-cell data into a fixed reference atlas using grassmann-ot. It is NOT a symmetric batch-integration tool — its purpose is to project new samples into an existing atlas for annotation transfer and quality control.
Why GOTMap?
| Symmetric Integration | GOTMap (Query → Atlas) | |
|---|---|---|
| Goal | Remove batch effects | Map new data into a stable atlas |
| Symmetry | Bidirectional | Unidirectional (reference fixed) |
| Output | Joint embedding | Query coords in reference space |
| Labels | Optional | First-class (transfer + confidence) |
| Use case | Combining batches | Clinical / atlas extension / QC |
Installation
pip install grassmann-ot scanpy torch
pip install gotmap-0.1.0.zip
Quick start
import scanpy as sc
import gotmap
from gotmap.pp import preprocess_reference, preprocess_query
from gotmap.tl import map_query_to_reference, transfer_labels, evaluate_mapping
from gotmap.pl import sanity_check, label_transfer_confidence
# ---- 1. Build & freeze reference atlas ----
ref = sc.read_h5ad("atlas.h5ad")
ref = preprocess_reference(ref, n_comps=50, n_top_genes=2000)
# ---- 2. Preprocess and map query ----
query = sc.read_h5ad("new_sample.h5ad")
query = preprocess_query(query, ref, n_comps=50)
mapped = map_query_to_reference(query, ref, method="nn",
hidden_dim=128, epochs=200)
# ---- 3. Transfer labels ----
labelled = transfer_labels(query, ref, label_key="cell_type")
# ---- 4. Evaluate ----
quality = evaluate_mapping(query, ref)
print(quality) # {'mean_confidence': ..., 'mapping_rate': ..., 'n_anchors': ...}
# ---- 5. Visualize ----
sanity_check(ref, query, mapped_query=mapped, label_key="cell_type")
label_transfer_confidence(labelled, label_key="cell_type")
API
gotmap.pp — Preprocessing
| Function | Purpose |
|---|---|
preprocess_reference(adata, n_comps=50, ...) |
Full pipeline: normalize → HVG → PCA |
preprocess_query(adata, reference, n_comps=50) |
Normalize + project query into reference PCA space |
normalize_and_hvg(adata, ...) |
Normalize and select HVGs |
gotmap.tl — Tools
| Function | Purpose |
|---|---|
map_query_to_reference(query, ref, method="nn", ...) |
Map query → reference space |
transfer_labels(query, ref, label_key, ...) |
Transfer labels + confidence |
evaluate_mapping(query, ref, ...) |
Mapping quality metrics |
gotmap.pl — Plotting
| Function | Purpose |
|---|---|
mapping_scatter(adata, basis="X_gotmap", color=...) |
Scatter of mapped cells |
label_transfer_confidence(adata, label_key) |
Confidence histogram + by-label boxplot |
embedding(adata, basis=..., color=...) |
Generic embedding plot |
sanity_check(ref, query, mapped_query=...) |
Reference / mapped / overlay panels |
gotmap.GOTMap — Low-level class
from gotmap import GOTMap
mapper = GOTMap(ref_adata=ref, use_rep="X_pca", k=30, p=3, reg=0.1)
mapper.fit(query)
# neural-network projection
mapped = mapper.transform(query, method="nn", hidden_dim=128, epochs=200)
# kNN projection
mapped_knn = mapper.transform(query, method="knn")
# transfer labels
labelled = mapper.transfer_labels(query, label_key="cell_type")
# quality
quality = mapper.evaluate_mapping(query)
gotmap.FrozenReference — Lightweight update (scArches-style)
from gotmap import FrozenReference
# freeze
frozen = FrozenReference(ref)
frozen.save("./frozen_atlas")
# load (no recomputation)
frozen = FrozenReference.load("./frozen_atlas")
# project any new query into the SAME space
query_pca = frozen.project_query(new_query)
# extend with new validated cells
report = frozen.extend(new_cells, min_new_cells=500, update_ratio=0.1)
# - lightweight: append only (PCA unchanged)
# - full rebuild triggered when new cells exceed threshold
# full rebuild (call sparingly)
frozen.rebuild_reference(full_atlas)
frozen.save("./frozen_atlas_v2")
How it works
- Grassmann subspaces — For each cell, a local PCA neighborhood
defines a point on the Grassmann manifold (dimension
p). - Optimal transport — Sinkhorn OT computes a soft coupling
gamma(n_ref × n_query) and hard anchors between reference and query cells. - Mapping — Anchors (+ gamma-sampled soft pairs) supervise a neural network that projects query cells into reference PCA space.
- Label transfer — Weighted kNN in reference space assigns cell-type labels; confidence = max class probability.
GOTMap calls grassmann-ot only for coupling (fit, get_hard_anchors).
All mapping logic is implemented independently.
Requirements
- Python ≥ 3.9
- scanpy ≥ 1.9
- grassmann-ot ≥ 0.3.1
- torch ≥ 1.12
- numpy, scipy, scikit-learn
License
MIT
Metadata
Release files for gotmap 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gotmap-0.2.0.tar.gz | 16.9 kB | Without provenance | Details for gotmap-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gotmap-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for gotmap-0.2.0-py3-none-any.whl |
Total release size: 35.8 kB
Release files / gotmap-0.2.0.tar.gz
| Download URL | gotmap-0.2.0.tar.gz |
|---|---|
| Size | 16.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2ccec967bfd6d74fb2c458eb44a884d630414ecb642aed8abeb4ed0acec24bea
|
|
BLAKE2b-256 checksum How to use checksums |
fdae8abd8fe46d3e6b4a145b66742bb76283ba8dee2c88ea9ead8ee442ce1e6d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.18
|
Release files / gotmap-0.2.0-py3-none-any.whl
| Download URL | gotmap-0.2.0-py3-none-any.whl |
|---|---|
| Size | 18.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ae83fe95d9b80638a6cc2b852be3b96b0d717969f28f3ae9debce570f4a58c6b
|
|
BLAKE2b-256 checksum How to use checksums |
aa7cbd78ffa905ce0a99eea732978ebad24d57f5c1efffc2b76db99a75c66ac5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.10.18
|
Security for gotmap 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.