gotmap-benchmark 0.2.0__tar.gz → 0.2.3__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.
- {gotmap_benchmark-0.2.0 → gotmap_benchmark-0.2.3}/PKG-INFO +13 -2
- {gotmap_benchmark-0.2.0 → gotmap_benchmark-0.2.3}/README.md +12 -1
- {gotmap_benchmark-0.2.0 → gotmap_benchmark-0.2.3}/gotmap_benchmark/__init__.py +1 -1
- {gotmap_benchmark-0.2.0 → gotmap_benchmark-0.2.3}/gotmap_benchmark/methods.py +4 -0
- {gotmap_benchmark-0.2.0 → gotmap_benchmark-0.2.3}/gotmap_benchmark/metrics.py +27 -6
- {gotmap_benchmark-0.2.0 → gotmap_benchmark-0.2.3}/gotmap_benchmark/pipeline.py +10 -0
- {gotmap_benchmark-0.2.0 → gotmap_benchmark-0.2.3}/gotmap_benchmark.egg-info/PKG-INFO +13 -2
- {gotmap_benchmark-0.2.0 → gotmap_benchmark-0.2.3}/pyproject.toml +1 -1
- {gotmap_benchmark-0.2.0 → gotmap_benchmark-0.2.3}/gotmap_benchmark/cli.py +0 -0
- {gotmap_benchmark-0.2.0 → gotmap_benchmark-0.2.3}/gotmap_benchmark/datasets.py +0 -0
- {gotmap_benchmark-0.2.0 → gotmap_benchmark-0.2.3}/gotmap_benchmark.egg-info/SOURCES.txt +0 -0
- {gotmap_benchmark-0.2.0 → gotmap_benchmark-0.2.3}/gotmap_benchmark.egg-info/dependency_links.txt +0 -0
- {gotmap_benchmark-0.2.0 → gotmap_benchmark-0.2.3}/gotmap_benchmark.egg-info/entry_points.txt +0 -0
- {gotmap_benchmark-0.2.0 → gotmap_benchmark-0.2.3}/gotmap_benchmark.egg-info/requires.txt +0 -0
- {gotmap_benchmark-0.2.0 → gotmap_benchmark-0.2.3}/gotmap_benchmark.egg-info/top_level.txt +0 -0
- {gotmap_benchmark-0.2.0 → gotmap_benchmark-0.2.3}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gotmap-benchmark
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: Benchmark pipeline for gotmap (query-to-reference atlas mapping) vs baselines.
|
|
5
5
|
Author: gotmap developers
|
|
6
6
|
License: MIT
|
|
@@ -57,7 +57,18 @@ label_key = "bulk_labels" if "bulk_labels" in adata.obs.columns else "louvain"
|
|
|
57
57
|
if label_key not in adata.obs.columns:
|
|
58
58
|
sc.tl.louvain(adata, resolution=0.8, key_added="louvain"); label_key = "louvain"
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
import numpy as np
|
|
61
|
+
from sklearn.model_selection import train_test_split
|
|
62
|
+
|
|
63
|
+
idx = np.arange(adata.n_obs)
|
|
64
|
+
strat = adata.obs[label_key].values if label_key in adata.obs.columns else None
|
|
65
|
+
train_idx, test_idx = train_test_split(
|
|
66
|
+
idx, test_size=0.3, shuffle=True, random_state=42, stratify=strat
|
|
67
|
+
)
|
|
68
|
+
ref, query = adata[train_idx].copy(), adata[test_idx].copy()
|
|
69
|
+
|
|
70
|
+
# --- alternative: split by batch (preferred for atlas mapping) ---
|
|
71
|
+
# ref, query = sc.pp.train_test_split(adata, test_size=0.3, random_state=42,
|
|
61
72
|
stratify=label_key)
|
|
62
73
|
|
|
63
74
|
bench = BenchmarkPipeline(ref, query, label_key=label_key, use_rep="X_pca",
|
|
@@ -33,7 +33,18 @@ label_key = "bulk_labels" if "bulk_labels" in adata.obs.columns else "louvain"
|
|
|
33
33
|
if label_key not in adata.obs.columns:
|
|
34
34
|
sc.tl.louvain(adata, resolution=0.8, key_added="louvain"); label_key = "louvain"
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
import numpy as np
|
|
37
|
+
from sklearn.model_selection import train_test_split
|
|
38
|
+
|
|
39
|
+
idx = np.arange(adata.n_obs)
|
|
40
|
+
strat = adata.obs[label_key].values if label_key in adata.obs.columns else None
|
|
41
|
+
train_idx, test_idx = train_test_split(
|
|
42
|
+
idx, test_size=0.3, shuffle=True, random_state=42, stratify=strat
|
|
43
|
+
)
|
|
44
|
+
ref, query = adata[train_idx].copy(), adata[test_idx].copy()
|
|
45
|
+
|
|
46
|
+
# --- alternative: split by batch (preferred for atlas mapping) ---
|
|
47
|
+
# ref, query = sc.pp.train_test_split(adata, test_size=0.3, random_state=42,
|
|
37
48
|
stratify=label_key)
|
|
38
49
|
|
|
39
50
|
bench = BenchmarkPipeline(ref, query, label_key=label_key, use_rep="X_pca",
|
|
@@ -123,6 +123,10 @@ def run_gotmap_nn(ref, query, use_rep="X_pca", label_key=None,
|
|
|
123
123
|
mapper.fit(query)
|
|
124
124
|
|
|
125
125
|
projected = mapper.transform(query, method="nn", hidden_dim=hidden_dim, epochs=epochs)
|
|
126
|
+
# ensure the canonical key 'X_mapped' exists (gotmap writes X_gotmap / X_mapped)
|
|
127
|
+
if "X_mapped" not in projected.obsm:
|
|
128
|
+
projected.obsm["X_mapped"] = projected.obsm.get(
|
|
129
|
+
"X_gotmap", projected.X if projected.X is not None else projected.obsm["X_pca"])
|
|
126
130
|
out = {
|
|
127
131
|
"query_mapped": projected,
|
|
128
132
|
"method": "gotmap_nn",
|
|
@@ -61,15 +61,29 @@ def evaluate_mapping(ref, query, result, use_rep="X_pca", label_key=None,
|
|
|
61
61
|
mapped = result["query_mapped"]
|
|
62
62
|
mapped_coords = mapped.obsm["X_mapped"]
|
|
63
63
|
ref_coords = ref.obsm[use_rep]
|
|
64
|
-
|
|
64
|
+
n_query = query.n_obs
|
|
65
|
+
|
|
66
|
+
# robust alignment: if mapped.obs_names is a permutation of query.obs_names,
|
|
67
|
+
# use it to index; otherwise fall back to positional alignment (assumes the
|
|
68
|
+
# method preserved the original cell order, which gotmap and most wrappers do).
|
|
69
|
+
mapped_names = list(mapped.obs_names)
|
|
70
|
+
query_names = list(query.obs_names)
|
|
71
|
+
aligned_by_name = (
|
|
72
|
+
len(mapped_names) == n_query
|
|
73
|
+
and set(mapped_names) == set(query_names)
|
|
74
|
+
)
|
|
65
75
|
|
|
66
76
|
metrics = {}
|
|
67
77
|
|
|
68
78
|
# 1. Label transfer
|
|
69
79
|
if label_key and label_key in ref.obs.columns and "predicted_labels" in result:
|
|
70
|
-
y_true = query.obs[label_key].reindex(mapped.obs_names).to_numpy(str)
|
|
71
80
|
y_pred = np.asarray(result["predicted_labels"]).astype(str)
|
|
72
|
-
if
|
|
81
|
+
if aligned_by_name:
|
|
82
|
+
y_true = query.obs[label_key].reindex(mapped_names).to_numpy(str)
|
|
83
|
+
else:
|
|
84
|
+
# positional: mapped coords are already 1:1 with query cells
|
|
85
|
+
y_true = query.obs[label_key].to_numpy(str)[:len(y_pred)]
|
|
86
|
+
if len(y_true) == len(y_pred) and len(y_true) > 0:
|
|
73
87
|
metrics["label_transfer_accuracy"] = float(accuracy_score(y_true, y_pred))
|
|
74
88
|
metrics["weighted_f1"] = float(f1_score(y_true, y_pred,
|
|
75
89
|
average="weighted", zero_division=0))
|
|
@@ -80,10 +94,14 @@ def evaluate_mapping(ref, query, result, use_rep="X_pca", label_key=None,
|
|
|
80
94
|
metrics["label_transfer_accuracy"] = np.nan
|
|
81
95
|
metrics["weighted_f1"] = np.nan
|
|
82
96
|
|
|
83
|
-
# 2. kNN preservation
|
|
97
|
+
# 2. kNN preservation: needs original query coords aligned to mapped coords
|
|
84
98
|
try:
|
|
99
|
+
if aligned_by_name:
|
|
100
|
+
orig_query = query.obsm[use_rep][query.obs_names.get_indexer(mapped_names)]
|
|
101
|
+
else:
|
|
102
|
+
orig_query = query.obsm[use_rep][:len(mapped_coords)]
|
|
85
103
|
metrics["knn_preservation"] = compute_knn_preservation(
|
|
86
|
-
|
|
104
|
+
orig_query, mapped_coords, ref_coords, k=k)
|
|
87
105
|
except Exception as e:
|
|
88
106
|
if verbose:
|
|
89
107
|
print(f" kNN preservation failed: {e}")
|
|
@@ -91,7 +109,10 @@ def evaluate_mapping(ref, query, result, use_rep="X_pca", label_key=None,
|
|
|
91
109
|
|
|
92
110
|
# 3. Cell-type silhouette in mapped space
|
|
93
111
|
if label_key and label_key in query.obs.columns:
|
|
94
|
-
|
|
112
|
+
if aligned_by_name:
|
|
113
|
+
labs = query.obs[label_key].reindex(mapped_names).to_numpy(str)
|
|
114
|
+
else:
|
|
115
|
+
labs = query.obs[label_key].to_numpy(str)[:len(mapped_coords)]
|
|
95
116
|
if len(np.unique(labs)) > 1 and len(labs) <= 20000:
|
|
96
117
|
sample = min(2000, len(labs))
|
|
97
118
|
idx = np.random.RandomState(42).choice(len(labs), sample, replace=False)
|
|
@@ -65,6 +65,7 @@ class BenchmarkPipeline:
|
|
|
65
65
|
print(f"\n{'='*60}\n[benchmark] running: {method}\n{'='*60}")
|
|
66
66
|
|
|
67
67
|
t0 = time.time()
|
|
68
|
+
result = None
|
|
68
69
|
try:
|
|
69
70
|
result = METHODS[method](
|
|
70
71
|
self.ref_adata, self.query_adata,
|
|
@@ -78,6 +79,15 @@ class BenchmarkPipeline:
|
|
|
78
79
|
traceback.print_exc()
|
|
79
80
|
continue
|
|
80
81
|
|
|
82
|
+
# canonicalize: downstream metrics expect obsm['X_mapped']
|
|
83
|
+
_mapped = result.get("query_mapped")
|
|
84
|
+
if _mapped is not None and "X_mapped" not in _mapped.obsm:
|
|
85
|
+
_mapped.obsm["X_mapped"] = _mapped.obsm.get(
|
|
86
|
+
"X_gotmap",
|
|
87
|
+
_mapped.X if _mapped.X is not None else None)
|
|
88
|
+
if _mapped is None:
|
|
89
|
+
continue
|
|
90
|
+
|
|
81
91
|
elapsed = time.time() - t0
|
|
82
92
|
metrics = evaluate_mapping(
|
|
83
93
|
self.ref_adata, self.query_adata, result,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: gotmap-benchmark
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: Benchmark pipeline for gotmap (query-to-reference atlas mapping) vs baselines.
|
|
5
5
|
Author: gotmap developers
|
|
6
6
|
License: MIT
|
|
@@ -57,7 +57,18 @@ label_key = "bulk_labels" if "bulk_labels" in adata.obs.columns else "louvain"
|
|
|
57
57
|
if label_key not in adata.obs.columns:
|
|
58
58
|
sc.tl.louvain(adata, resolution=0.8, key_added="louvain"); label_key = "louvain"
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
import numpy as np
|
|
61
|
+
from sklearn.model_selection import train_test_split
|
|
62
|
+
|
|
63
|
+
idx = np.arange(adata.n_obs)
|
|
64
|
+
strat = adata.obs[label_key].values if label_key in adata.obs.columns else None
|
|
65
|
+
train_idx, test_idx = train_test_split(
|
|
66
|
+
idx, test_size=0.3, shuffle=True, random_state=42, stratify=strat
|
|
67
|
+
)
|
|
68
|
+
ref, query = adata[train_idx].copy(), adata[test_idx].copy()
|
|
69
|
+
|
|
70
|
+
# --- alternative: split by batch (preferred for atlas mapping) ---
|
|
71
|
+
# ref, query = sc.pp.train_test_split(adata, test_size=0.3, random_state=42,
|
|
61
72
|
stratify=label_key)
|
|
62
73
|
|
|
63
74
|
bench = BenchmarkPipeline(ref, query, label_key=label_key, use_rep="X_pca",
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "gotmap-benchmark"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.3"
|
|
8
8
|
description = "Benchmark pipeline for gotmap (query-to-reference atlas mapping) vs baselines."
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.9"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{gotmap_benchmark-0.2.0 → gotmap_benchmark-0.2.3}/gotmap_benchmark.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{gotmap_benchmark-0.2.0 → gotmap_benchmark-0.2.3}/gotmap_benchmark.egg-info/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|