Skip to main content

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-boundary theta = Inf
  • Cross-gene overdispersion_shrinkage (R glm_gp default)
  • 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| ~2.5×10⁻⁹
Genes with |Δ Intercept| < 0.01 100%
Inf theta match 463/463
Speed vs R (8 threads) ~6.4× (7.1 s vs 46.5 s)

Latest release: v0.2.1 — 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).

Metadata

Release files for pyglmGamPoi 0.2.1

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

Source distribution (sdist)

Source distribution for pyglmGamPoi 0.2.1
File Size Uploaded Provenance
pyglmgampoi-0.2.1.tar.gz 348.4 kB Without provenance Details

Release files / pyglmgampoi-0.2.1.tar.gz

Download URL pyglmgampoi-0.2.1.tar.gz
Size 348.4 kB
Tags Source
SHA-256 checksum
How to use checksums
af9afd5344eb0302e080a1cad8ece70e3d42a7f4dddcfdcbc2e738780fb462e3
BLAKE2b-256 checksum
How to use checksums
dd708f96a2c9d42e3f0f2f9ff2cba1b8e032afe27304ece853c16526304bafac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Security for pyglmGamPoi 0.2.1

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.

Release history Release notifications | RSS feed

This release

0.2.1 This release

1 release file No provenance

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