Skip to main content

Fast Gene Set Enrichment Analysis in Rust (Python bindings)

Project description

rsfgseapy

Python bindings for rsfgsea, a Rust implementation of preranked fgsea-compatible gene set enrichment analysis.

What It Exposes

The package currently exposes one public entrypoint:

  • run_gsea_py(...)

The API intentionally keeps fgsea-style parameter names and execution modes:

  • mode="fgsea"
  • mode="simple"
  • mode="multilevel"
  • nPermSimple
  • seed
  • nperm
  • minSize
  • maxSize
  • sampleSize
  • scoreType
  • gseaParam

Installation

From PyPI:

pip install rsfgseapy

From a repository:

git clone https://github.com/deminden/rsfgsea
cd rsfgsea
cd crates/rsfgseapy
maturin develop --release

Input Shape

ranks

  • Python mapping of gene -> score
  • values must be finite numeric scores

gmt_path

  • path to a GMT file

Performance Snapshot

The Python package calls the same Rust backend as the CLI and R wrapper. Current local benchmark snapshots from the main repository, measured on an AMD Ryzen 7950X3D:

  • representative Criterion benchmark, simple: 2.282 s for 10k genes, 1k pathways, 10k permutations
  • representative Criterion benchmark, multilevel: 3.438 s for 10k genes, 1k pathways, nPermSimple=1000
  • file-backed comparison, multilevel large workload, 16 workers: Rust 105 ms vs R 977 ms (9.3x faster)
  • file-backed comparison, simple large workload, 16 workers: Rust 674 ms vs R 798 ms (1.18x faster)
  • real muscle-comparison validation workload: Rust 81 MB peak RSS vs R 329 MB peak RSS (4.1x lower)

Full benchmark setup, thread-scaling tables, and parity notes are in:

Minimal Example

For most users, wrapper mode with defaults is the right starting point.

import rsfgseapy

results = rsfgseapy.run_gsea_py(
    ranks={"GENE_A": 2.0, "GENE_B": 1.0, "GENE_C": -1.0, "GENE_D": -2.0},
    gmt_path="pathways.gmt",
)

for row in results:
    print(row["pathway"], row["pval"])

Full Example

import rsfgseapy

ranks = {
    "GENE_A": 3.2,
    "GENE_B": 1.7,
    "GENE_C": -2.4,
    "GENE_D": -3.1,
}

results = rsfgseapy.run_gsea_py(
    ranks=ranks,
    gmt_path="pathways.gmt",
    mode="fgsea",
    gpu=False,
    nPermSimple=1000,
    seed=None,
    nperm=None,
    minSize=1,
    maxSize=None,
    eps=1e-50,
    sampleSize=101,
    scoreType="std",
    gseaParam=1.0,
    nproc=0,
)

for row in results:
    print(row["pathway"], row["nes"], row["pval"])

Plotting

import rsfgseapy

rsfgseapy.write_enrichment_plot_png_py(
    ranks={"GENE_A": 2.0, "GENE_B": 1.0, "GENE_C": -1.0, "GENE_D": -2.0},
    pathway_genes=["GENE_A", "GENE_B"],
    output_path="enrichment.png",
    pathway_name="PW_A",
    dpi=300,
    title="PW_A",
)

For multi-pathway summaries:

import rsfgseapy

rsfgseapy.write_gsea_table_plot_png_py(
    ranks={"GENE_A": 2.0, "GENE_B": 1.0, "GENE_C": -1.0, "GENE_D": -2.0},
    pathways=[("PW_A", ["GENE_A", "GENE_B"]), ("PW_B", ["GENE_C", "GENE_D"])],
    results=[
        {"pathway": "PW_A", "nes": 1.5, "pval": 0.01, "padj": 0.02},
        {"pathway": "PW_B", "nes": -1.4, "pval": 0.03, "padj": 0.05},
    ],
    output_path="table.png",
    dpi=300,
)

All plotting parameters are available in the Python API; the examples above keep only the most common publication-oriented overrides visible.

For the full cross-interface plotting guide, see:

nPermSimple vs nperm

These two names come from fgsea and they are not interchangeable.

nPermSimple

  • the normal simple-stage permutation count
  • used by default in wrapper mode
  • tune this when you want a different wrapper screening budget

nperm

  • explicit fixed-permutation override
  • in wrapper mode, setting nperm forces simple-mode execution instead of multilevel refinement
  • leave this as None unless you intentionally want simple mode

Practical rule:

  • leave seed=None for a fresh random run, or set seed=<int> for reproducibility
  • light users: keep nperm=None
  • use nPermSimple to tune the default wrapper behavior
  • only set nperm when you deliberately want fixed-permutation simple execution

Returned Results

Each result row is a dictionary with:

  • pathway
  • size
  • es
  • nes
  • pval
  • padj
  • log2err
  • leading_edge

leading_edge is returned as a Python list of genes.

GPU Support

gpu=True enables the hybrid GPU path when the extension is built with the gpu feature.

Current behavior:

  • GPU accelerates simple-stage screening
  • CPU performs parity-focused multilevel refinement

If the extension is built without GPU support, gpu=True raises a runtime error.

Supported Python Versions

The package metadata currently targets Python 3.8 and newer.

Project Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rsfgseapy-0.3.4.tar.gz (2.0 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

rsfgseapy-0.3.4-cp313-cp313-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.13Windows x86-64

rsfgseapy-0.3.4-cp313-cp313-macosx_11_0_arm64.whl (1.2 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

rsfgseapy-0.3.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.8manylinux: glibc 2.17+ x86-64

File details

Details for the file rsfgseapy-0.3.4.tar.gz.

File metadata

  • Download URL: rsfgseapy-0.3.4.tar.gz
  • Upload date:
  • Size: 2.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rsfgseapy-0.3.4.tar.gz
Algorithm Hash digest
SHA256 2025d4bb88afd9556ca8e546b3bb2d4c9de7b5cb8d1cdad79e03ad10bc6220bf
MD5 3502ab04a96f11acb80719809e97decc
BLAKE2b-256 e0922b18835fdb1bf1070a9ad0e94a7a03a82454fb216ad1e3537f19aa3eb98b

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsfgseapy-0.3.4.tar.gz:

Publisher: pypi-publish.yml on deminden/rsfgsea

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rsfgseapy-0.3.4-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: rsfgseapy-0.3.4-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 1.0 MB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for rsfgseapy-0.3.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 a5407393315a2259151bf0abb6ec347cab25da8c07376abf671dd74f14e632bf
MD5 477ff6c40ce6030dba35ff62f8eb9305
BLAKE2b-256 c43754c64816933de499fce4ebcddae6f5b01afa31b7c0620561d22c90c8e96e

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsfgseapy-0.3.4-cp313-cp313-win_amd64.whl:

Publisher: pypi-publish.yml on deminden/rsfgsea

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rsfgseapy-0.3.4-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rsfgseapy-0.3.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 d4361f654ca1c84476f0ce599836cbbc738c45655a40b25e3d7f472dbd089237
MD5 df058ade186f7fb27c25348ca05ead96
BLAKE2b-256 6b92ea90e1d4275fd59e7a1382a6588ba9d62c7e96fda3d206ed7765f0af3eea

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsfgseapy-0.3.4-cp313-cp313-macosx_11_0_arm64.whl:

Publisher: pypi-publish.yml on deminden/rsfgsea

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rsfgseapy-0.3.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rsfgseapy-0.3.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 54713663a336af75a1868b2cde163c74cddc5721dde2393d68bb55b4aa23737b
MD5 36204907836da31d52b9908f2a62657f
BLAKE2b-256 0fff5a93bb27ce9bcd9f8297f1a8d8c9bdde68b4727fcd10e9e713945decd535

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsfgseapy-0.3.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: pypi-publish.yml on deminden/rsfgsea

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page