Skip to main content

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, pca_key="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

  1. Grassmann subspaces — For each cell, a local PCA neighborhood defines a point on the Grassmann manifold (dimension p).
  2. Optimal transport — Sinkhorn OT computes a soft coupling gamma (n_ref × n_query) and hard anchors between reference and query cells.
  3. Mapping — Anchors (+ gamma-sampled soft pairs) supervise a neural network that projects query cells into reference PCA space.
  4. 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.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gotmap 0.1.0
File Size Uploaded Provenance Actions
gotmap-0.1.0.tar.gz 17.0 kB Without provenance Details for gotmap-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gotmap 0.1.0
File Interpreter ABI Platform Actions
gotmap-0.1.0-py3-none-any.whl Python 3 none any Details for gotmap-0.1.0-py3-none-any.whl

Total release size: 35.9 kB

Release files / gotmap-0.1.0.tar.gz

Download URL gotmap-0.1.0.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
9d50426d2c625c5020b9cb3299c76c703a1004bcc7ed612723ca10941504a4b1
BLAKE2b-256 checksum
How to use checksums
4d77aed51c972a3a6736b557fe9b998b6141f3675a6d5adeffd598bf5110602a
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.1.0-py3-none-any.whl

Download URL gotmap-0.1.0-py3-none-any.whl
Size 18.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b40df0face5d9dc878c512cef708f360ba0ae303d7a08fd86bf41f60847023ac
BLAKE2b-256 checksum
How to use checksums
0fc7d67a3508cc2f85d8c15b4d16c120d7ed486a7e5ac69c771bbd40d04e1998
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.1.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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page