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

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.3.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.3-cp313-cp313-win_amd64.whl (1.0 MB view details)

Uploaded CPython 3.13Windows x86-64

rsfgseapy-0.3.3-cp313-cp313-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

rsfgseapy-0.3.3-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.3.tar.gz.

File metadata

  • Download URL: rsfgseapy-0.3.3.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.3.tar.gz
Algorithm Hash digest
SHA256 9dc16134ed3dfcc232a27c7edca212fbf31bb0d03fe7382907358a0659590974
MD5 818f089186f296698c88101b9412609a
BLAKE2b-256 a83f3e8907ff855fa7ed174b2020b11fbd4a88ff59c9ca42c463bdfea90132c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsfgseapy-0.3.3.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.3-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: rsfgseapy-0.3.3-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.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 cf20730ce30714529ed3572dd930c51c99c4defc67935267c5780b0aaafd3b3a
MD5 ba32f94770a95fa942ae37843bb3d5d0
BLAKE2b-256 bc0ac7e5c43bce0ef93245caa1222634b50ba5f7c4af4d0a933e6b425030139b

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsfgseapy-0.3.3-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.3-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for rsfgseapy-0.3.3-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8dd8c9ce48bce8ee02e6a6a964cd734b53079c6c6c464648cb5a3f51c19be01b
MD5 80b1380bd98973bd4465d010f006e3f5
BLAKE2b-256 4ea78305bc3d7a763290b028c6c1c12c656e04f0307a7553b6322b87961fac8a

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsfgseapy-0.3.3-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.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for rsfgseapy-0.3.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 972be8158c44083475979e03562c695a39304639e1b7d3919b613443d49d7dc1
MD5 7595472a9b0b89d3836a165a6ce350e8
BLAKE2b-256 a8b803861f3ad2a7daad064cd2e58c8d10b041e4c3b8c415cf83d7a5a9fc8f6b

See more details on using hashes here.

Provenance

The following attestation bundles were made for rsfgseapy-0.3.3-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