Metadata-Version: 2.4
Name: gotmap-benchmark
Version: 0.2.3
Summary: Benchmark pipeline for gotmap (query-to-reference atlas mapping) vs baselines.
Author: gotmap developers
License: MIT
Project-URL: Homepage, https://github.com/ZengFLab/gotmap-benchmark
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: numpy>=1.21
Requires-Dist: scipy>=1.8
Requires-Dist: pandas>=1.3
Requires-Dist: scikit-learn>=1.0
Requires-Dist: scanpy>=1.9
Requires-Dist: gotmap>=0.2.0
Requires-Dist: grassmann-ot>=0.3.1
Requires-Dist: matplotlib>=3.5
Requires-Dist: seaborn>=0.11
Provides-Extra: all
Requires-Dist: scvi-tools>=0.20; extra == "all"
Requires-Dist: harmonypy>=0.0.6; extra == "all"
Requires-Dist: bbknn>=1.5; extra == "all"
Requires-Dist: rpy2>=3.5; extra == "all"

# gotmap-benchmark

**Benchmark pipeline for gotmap** — compare query-to-reference atlas mapping methods
on real and synthetic single-cell data and get quantitative results + plots out of the box.

> Positioning: this benchmark evaluates **query → reference mapping quality**, not
> symmetric batch mixing. It is designed for the gotmap use case (map a query onto a
> fixed atlas), not to compete with integration-tool comparisons.

---

## Install

```bash
pip install gotmap grassmann-ot scanpy
# optional, for more baselines:
pip install scvi-tools harmonypy bbknn
```

---

## Quick start (Python)

```python
import scanpy as sc
from gotmap_benchmark import BenchmarkPipeline

adata = sc.datasets.pbmc68k_reduced()
if "X_pca" not in adata.obsm:
    sc.pp.normalize_total(adata); sc.pp.log1p(adata); sc.pp.pca(adata, n_comps=30)

label_key = "bulk_labels" if "bulk_labels" in adata.obs.columns else "louvain"
if label_key not in adata.obs.columns:
    sc.tl.louvain(adata, resolution=0.8, key_added="louvain"); label_key = "louvain"

import numpy as np
from sklearn.model_selection import train_test_split

idx = np.arange(adata.n_obs)
strat = adata.obs[label_key].values if label_key in adata.obs.columns else None
train_idx, test_idx = train_test_split(
    idx, test_size=0.3, shuffle=True, random_state=42, stratify=strat
)
ref, query = adata[train_idx].copy(), adata[test_idx].copy()

# --- alternative: split by batch (preferred for atlas mapping) ---
# ref, query = sc.pp.train_test_split(adata, test_size=0.3, random_state=42,
                                    stratify=label_key)

bench = BenchmarkPipeline(ref, query, label_key=label_key, use_rep="X_pca",
                          methods=["gotmap_nn", "gotmap_knn", "direct_knn"])
bench.run()
bench.save_results("benchmark_metrics.csv")
bench.plot(save="benchmark_plot.png")
```

## Quick start (CLI)

```bash
gotmap-benchmark --ref ref.h5ad --query query.h5ad --label cell_type \
    --use-rep X_pca --methods gotmap_nn direct_knn \
    --output ./results
```

---

## Included methods

| Key | Method | Notes |
|-----|--------|-------|
| `gotmap_nn` | gotmap, neural-network mapping | uses anchors + gamma |
| `gotmap_knn` | gotmap, kNN mapping | non-parametric |
| `scArches` | scVI + scArches | needs scvi-tools |
| `harmony_project` | Harmony project | needs R harmony + rpy2 |
| `BBKNN_align` | BBKNN | symmetric, then extracts query |
| `direct_knn` | kNN (no correction) | **baseline** |

---

## Metrics reported

- **Label Transfer Accuracy** / **Weighted F1** — ground-truth label recovery
- **kNN Preservation (kNP)** — overlap of reference-neighbourhoods before/after mapping
- **Cell-type Silhouette** — separation of types in mapped space
- **Mean Confidence** / **Mapping Rate** — placement certainty
- **Runtime (s)**

---

## Output

- `benchmark_metrics.csv` — one row per method
- `benchmark_plot.png` — horizontal bar chart per metric
- `bench.results_` — full per-method outputs (mapped AnnData, labels, confidence)

---

## Project layout

```
gotmap-benchmark/
├── pyproject.toml
├── README.md
├── gotmap_benchmark/
│   ├── __init__.py
│   ├── cli.py            # command-line entry point
│   ├── pipeline.py       # BenchmarkPipeline + plotting
│   ├── methods.py        # method wrappers
│   ├── metrics.py        # evaluation metrics
│   └── datasets.py       # dataset loaders + ref/query splitting
└── examples/
    └── run_pbmc_benchmark.py
```

---

License: MIT
