Pure-Python/C++ glmGamPoi offset fitting for SCTransform v2
Project description
pyglmGamPoi
Pure Python/C++ reimplementation of sctransform::fit_glmGamPoi_offset for
trackcell SCTransform v2, without an R
runtime.
Architecture
pyglmGamPoi/offset.py Python API (AnnData-friendly DataFrame output)
│
pyglmGamPoi/_core.so pybind11 thin binding (numpy ↔ std::vector)
│
src/glm_gp_offset.cpp glm_gp loop per gene (no Rcpp::List)
src/offset_fit.cpp Newton-Raphson + Brent fallback
src/overdispersion.cpp Cox-Reid overdispersion MLE (intercept-only)
The C++ core is rewritten from the algorithms in const-ae/glmGamPoi; R headers and Rtatami are not used.
Install (editable)
git clone https://github.com/seqyuan/pyglmGamPoi.git
cd pyglmGamPoi
pip install -e ".[test]"
Requires a C++17 compiler and CMake.
Usage
import numpy as np
from pyglmGamPoi import fit_glmGamPoi_offset
umi = np.random.poisson(3, size=(100, 50)).astype(float)
log10_umi = np.log10(umi.sum(axis=0) + 1e-9)
model_pars = fit_glmGamPoi_offset(umi, log10_umi)
trackcell integration
Replace trackcell.tl._r_sctransform.fit_glmGamPoi_offset_r with:
from pyglmGamPoi import fit_offset_model
See docs.
Status
- Per-gene offset NB fit (design ~ 1 + offset)
- Overdispersion MLE (Cox-Reid; local search + Newton)
-
allow_inf_theta/ Poisson-boundarytheta = Inf - Cross-gene
overdispersion_shrinkage(Rglm_gpdefault) - R parity on GSE288946 SCT step1 (3 samples, ~2000×2000 each)
| Metric (vs R live, pooled) | Value |
|---|---|
| Samples | GSM8779707–709 |
| Theta med |diff| (finite) | ~2×10⁻⁷ |
| Intercept med |diff| | ~1.6×10⁻⁴ |
| Genes with |Δ Intercept| < 0.01 | 94.6% |
| Inf theta match | 463/463 |
| Speed vs R (8 threads) | ~7× (6.9 s vs 46.3 s) |
Latest release: v0.2.0 — see changelog.
See evaluation docs for full benchmark report.
Docs & benchmark
python scripts/run_all_benchmarks.py # real + synthetic → docs/_generated/
pytest tests/test_theta_od_parity.py -q
License
MIT (this package). Algorithm reference: glmGamPoi (MIT in recent releases).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pyglmgampoi-0.2.0.tar.gz
(346.8 kB
view details)
File details
Details for the file pyglmgampoi-0.2.0.tar.gz.
File metadata
- Download URL: pyglmgampoi-0.2.0.tar.gz
- Upload date:
- Size: 346.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7492779cd71826224b30078288abfbc7521abf10ed6464b3893901950dcb69fe
|
|
| MD5 |
b97bacec37f9f4b2537e33db5bc6e6b2
|
|
| BLAKE2b-256 |
8684199e3359b9b194756e977876f93c7f696ac68d251156872ac4cd01136e67
|