API reference
The package is imported as import kdomainbench as kdb. Its functions form four groups
(methods, run, scores, figures) plus setup. Each name links to its reference entry,
with the parameters and examples.
1. Methods
import kdomainbench as kdb
kdb.list_methods(gpu_only=True) # ['CellCharter', 'DeepST', 'SpatialDE2']
kdb.get_method("DR.SC").uses_kmax # True
2. Run
| call |
returns |
kdb.run(method, h5ad, kmax=, device=, out_root=, gpu_id=) |
The domain of each spot. The run folder keeps the log and run_info.json. |
kdb.run_all(h5ad, kmax=, device=, methods=, out_root=, gpu_id=) |
Method name → domains, for every method that succeeded. |
kdb.MethodFailed |
Raised by run when a method stops with an error or writes no labels. |
h5ad = "data/D3_151509_5k.h5ad"
clusters = kdb.run("SpaGCN", h5ad, kmax=30, device="cpu")
results = kdb.run_all(h5ad, kmax=30, device="gpu", gpu_id=0, out_root="kdb_results_gpu")
3. Scores
| call |
returns |
kdb.read_clusters(path) |
The domains of one run folder. |
kdb.reference_annotation(h5ad, reference_key=) |
The annotated domain of each spot. |
kdb.evaluate(clusters, reference, reference_key=) |
k_estimated, k_reference, k_error, ARI, NMI, n_spots_scored. |
kdb.metrics(run, h5ad=, recompute=) |
The twelve metrics of the paper for one run, saved as metric.csv. |
kdb.MetricsFailed |
Raised by metrics when the metric code stops. |
kdb.load_results(root, reference_key=, score=, h5ad=) |
One row per run under root, scored. |
kdb.k_accuracy(summary) |
One row per method: mean |k error|, exact-k rate, mean ARI. |
kdb.evaluate("kdb_results/SpaGCN/D3_151509_5k_cpu", h5ad)
summary = kdb.load_results("kdb_results")
kdb.k_accuracy(summary)
kdb.pl.plot_k_estimates(summary).figure.savefig("k.png", dpi=150, bbox_inches="tight")
kdb.pl.plot_spatial_grid(results, h5ad, ncols=5).savefig("domains.png")
Setup
| call |
does |
kdb.set_env(key, interpreter=, r_lib=) |
Points an environment at an interpreter for this session. |
kdb.example_data(folder=) |
Downloads the example file of the tutorials to data/. |
kdomainbench command |
methods, install, check, run, metrics and summarize from the shell. |
| Environment variables |
KDB_PY_PYTHON, KDB_SPATIALDE_PYTHON, KDB_RSCRIPT, KDB_R_LIB, … |