Skip to main content

PyPI Docs CI

edge-rs

edgeR's quasi-likelihood pipeline, limma-voom and NEBULA for Python, with the numerics in the edge-rs Rust crate. No R, no rpy2, and every function named after the R function it reproduces.

Two ways in, each speaking the dialect of its crowd:

  • Bulk and pseudobulk: NumPy counts in, polars frames out.
  • Single cell: an AnnData in, a pandas frame out. NEBULA runs straight on the counts layer, optionally on the GPU.

Docs, API reference and vignettes: https://gregorlueg.github.io/edge-rs/

Install

uv pip install edge-rs              # bulk: NumPy, polars and beartype
uv pip install 'edge-rs[anndata]'   # plus NEBULA on AnnData

The GPU path is compiled into every wheel. It goes through wgpu (Metal, Vulkan or DX12), so there is no CUDA toolkit to install; edge_rs.gpu_available() says whether this machine has a usable adapter.

Bulk and pseudobulk

import edge_rs

# counts: (n_genes, n_samples), as in edgeR
res = edge_rs.run_edger_ql(counts, design, feature_ids=genes, coef="treated")
res = edge_rs.run_limma_voom(counts, design, feature_ids=genes, coef="treated")

Or step by step, as in edgeR and limma:

keep = edge_rs.filter_by_expr(counts, design=design)
lib_size = counts.sum(axis=0)
nf = edge_rs.calc_norm_factors(counts[keep], lib_size=lib_size)

fit = edge_rs.glm_ql_fit(counts[keep], design, lib_size=lib_size, norm_factors=nf)
edge_rs.top_tags(edge_rs.glm_ql_ftest(fit, coef="treated"))

vfit = edge_rs.voom_lm_fit(counts[keep], design, lib_size=lib_size, norm_factors=nf)
edge_rs.top_table(edge_rs.ebayes(vfit), coef="treated")

Would rather not carry lib_size around? make_dgelist bundles counts, library sizes, normalisation factors and annotation. Subsetting it keeps the library sizes of the full matrix, as edgeR's keep.lib.sizes = TRUE does, and every function above takes it in place of the counts:

dge = edge_rs.make_dgelist(counts, genes=pl.DataFrame({"gene_id": genes}))
dge = edge_rs.calc_norm_factors(dge[edge_rs.filter_by_expr(dge, design=design)])
fit = edge_rs.glm_ql_fit(dge, design)
edge_rs.top_tags(
    edge_rs.glm_ql_ftest(fit, coef="treated"), feature_ids=dge.genes["gene_id"]
)

Counts are genes x samples. Pseudobulk from bixverse is the other way round, so it goes in as pb.counts.T. A design is a NumPy matrix or a polars frame; with a frame, the column names become coefficient names and coef="treated" works. Everything is 0-based. Results are polars frames with snake_case columns (log_fc, p_value, fdr, adj_p_value).

Single cell: NEBULA on AnnData

Donors in a single cell experiment are the replicates, not the cells. NEBULA models that with a subject-level random effect, and edge_rs.nebula runs it straight on an AnnData:

fit = edge_rs.nebula(adata, "donor", "~ condition + age", genes=hvgs)
fit.test(coef="condition[T.treated]").sort_values("p_value").head()

Cells x genes, as scanpy keeps them. Counts come from layers["counts"] by default (layer=None for X, "raw" for adata.raw.X) and have to be raw integers. Cells need not be sorted by donor. Offsets default to the library sizes. Only want the B cells? mask_obs=adata.obs["cell_type"] == "B" fits those without subsetting the AnnData.

The design is a Formulaic formula over obs, so interactions, transforms and other contrast codings all work. Formulaic names the columns its own way: condition[T.treated], not R's conditiontreated. Already have a design matrix? Pass a DataFrame indexed by obs_names, or an array in obs order.

nebula() returns a NebulaFit: the coefficients, their covariance per gene and the overdispersions. The fit doesn't care what you test, so test as many coefficients or contrasts as you like off one fit:

fit.test(coef="age")
fit.test(contrast="condition[T.drug_b] - condition[T.drug_a]")

Yes, test() returns pandas, indexed by gene: it's what the scverse crowd expects. Columns are log_fc (natural log, as NEBULA reports it), se, z, p_value, fdr, both overdispersions and the convergence flags.

The layer's CSR is read in place and transposed one block of genes at a time, so memory on top of the counts stays at one block. A fit is milliseconds to seconds per gene, so pass the HVGs or a candidate set rather than all 30k genes. Need data larger than memory? bixverse runs the same Rust out of core.

On the GPU

if edge_rs.gpu_available():
    fit = edge_rs.nebula(adata, "donor", "~ condition", genes=hvgs, device="gpu")

device="gpu" moves NEBULA's stage two, the penalised fits behind the variance components, onto the device. wgpu has no float64, so those fits run in float32 and the results land close to the CPU's, not on them. Designs up to eight columns. A design of categoricals only, "~ condition" say, runs on the CPU regardless: cells share design rows within each donor, the zero counts sum from tables, and that beats the device. Under the default NEBULA-LN most genes never reach stage two either, so method="hl" with a continuous covariate is where the device has work to do. Measure on your data before you switch.

What's in it

Python R
make_dgelist, DgeList edgeR::DGEList
filter_by_expr edgeR::filterByExpr
calc_norm_factors edgeR::calcNormFactors
cpm, ave_log_cpm edgeR::cpm, edgeR::aveLogCPM
remove_batch_effect limma::removeBatchEffect
glm_ql_fit, glm_ql_ftest, top_tags edgeR::glmQLFit, edgeR::glmQLFTest, edgeR::topTags
voom, voom_lm_fit, lm_fit limma::voom, edgeR::voomLmFit, limma::lmFit
make_contrasts, contrasts_fit limma::makeContrasts, limma::contrasts.fit
ebayes, top_table limma::eBayes, limma::topTable
run_edger_ql, run_limma_voom the above, chained
nebula (on AnnData) nebula::nebula

Not exposed yet: the exact test, glmFit/glmLRT/glmTreat and diffSpliceDGE. The crate has all of them.

How close to R?

The crate is gated against edgeR 4.10.7, limma 3.68.5 and nebula 1.5.9 on committed fixtures, and the Python tests run the same fixtures through the bindings. The bulk vignette reruns the edgeR QL F1000 workflow on GSE60450 and matches R on every number it shows. The GPU path is checked against the CPU path on the same fixture.

Vignettes

Three notebooks: bulk DGE on GSE60450, pseudobulk DGE on the Kang PBMCs with bixverse, and NEBULA on the same PBMCs as an AnnData. Each is a jupytext .py in docs/vignettes/ with its executed .ipynb next to it, and the data download on first use.

uv sync --group dev --group vignettes
uv run maturin develop --release
uv run python dev/vignettes.py execute             # all of them
uv run python dev/vignettes.py execute pseudobulk  # or by name

Development

uv sync --group dev
uv run maturin develop --release
uv run pytest tests -q

The wheel builds against the crate in the parent directory, so it always tracks this checkout. maturin develop --no-default-features builds without the GPU path.

Metadata

Release files for edge-rs 0.2.0

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

Built distributions (wheels)

Table of built distributions (wheels) for edge-rs 0.2.0
File Actions
edge_rs-0.2.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.11 abi3 Linux glibc 2.17+ x86-64 Details for edge_rs-0.2.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
edge_rs-0.2.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.11 abi3 Linux glibc 2.17+ ARM64 Details for edge_rs-0.2.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
edge_rs-0.2.0-cp311-abi3-macosx_11_0_arm64.whl CPython 3.11 abi3 macOS 11.0+ ARM64 Details for edge_rs-0.2.0-cp311-abi3-macosx_11_0_arm64.whl
edge_rs-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl CPython 3.11 abi3 macOS 10.12+ x86-64 Details for edge_rs-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl

Total release size: 54.3 MB

Release files / edge_rs-0.2.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL edge_rs-0.2.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 14.5 MB
Tags CPython 3.11 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
57f1c493a4a0cd42d8f15cf2e162e828e91258a7e07815d8ed9900a8247878cc
BLAKE2b-256 checksum
How to use checksums
2fa06ef4f2b8e778f2d7c5a71abd75c254f22edc3ac2f7604f8b96a805348fa7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / edge_rs-0.2.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL edge_rs-0.2.0-cp311-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 13.5 MB
Tags CPython 3.11 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
d6e87e4a0d8d2421c583f3f1c85a21f91ec7e394c151e03bb10e048174f4ef64
BLAKE2b-256 checksum
How to use checksums
8eba9d4f26dde8bb8a10670fe30a8c3a2e7a9a7a2b5944221b0ddc84818fdb9b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / edge_rs-0.2.0-cp311-abi3-macosx_11_0_arm64.whl

Download URL edge_rs-0.2.0-cp311-abi3-macosx_11_0_arm64.whl
Size 12.7 MB
Tags CPython 3.11 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
6f9447288596fc4b1b70a46b7e0997a0a5add50b36ecba27ae9e2b0cee8f2eff
BLAKE2b-256 checksum
How to use checksums
539e270a02d00720cd2aa8b776e36bfd2c68dcbe67f859239a70ecdd3968ca2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Release files / edge_rs-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl

Download URL edge_rs-0.2.0-cp311-abi3-macosx_10_12_x86_64.whl
Size 13.6 MB
Tags CPython 3.11 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
bc8b6392e940bfcad17f219721ab1b4f8a0b4ca1bbc62cede3c31e4a21cb7c72
BLAKE2b-256 checksum
How to use checksums
6f5ce559063e2b0a08c49ad323be94fc47bad671f995250383e9dac8a25f6a2c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

Security for edge-rs 0.2.0

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.

Full provenance

All 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for edge_rs-0.2.0-cp311-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 30, 2026.

Transparency log

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.0 This release

4 release files Full 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