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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.13macOS 11.0+ ARM64

rsfgseapy-0.3.2-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.2.tar.gz.

File metadata

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

File hashes

Hashes for rsfgseapy-0.3.2.tar.gz
Algorithm Hash digest
SHA256 c05f0cdc92d99365b1e5aa3ce6a17c576890351889db3c1824fb2304dc5d66c9
MD5 cf9431eea323ad170e7b99f50120895c
BLAKE2b-256 c2f2a3931f4021c7a14b1be1ed911be890d885f23404e6b45f3558bdd904a432

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: rsfgseapy-0.3.2-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.7

File hashes

Hashes for rsfgseapy-0.3.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 eae3d50f5aaecc76b1fac093f7830950868862ea9d0b146435f5b8147a30fa04
MD5 cdad28f4c20ba4f41aa9d8449b554649
BLAKE2b-256 d8c5d7014a42c6db49f302370d5cdd170da58b3465aa0d9b0f48800bbc35e2ac

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rsfgseapy-0.3.2-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1139aaf3c675db2c524b66ff9cb24af5e57bca9a9ab1ff808c103cdfe50a253e
MD5 f9da62d2a4d07cb4c0e6a8696f2e781f
BLAKE2b-256 7ac779b8041f814f3af5785c3633b624c1909212e94c4c27dbe348e0adae7347

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for rsfgseapy-0.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d3cf4fd4cdc87c357892be8f3da68b33d6d00d99f008c27c1ab20b9ad25cab66
MD5 266d5e42cea55a3aceeb76b26c34aaa4
BLAKE2b-256 caddda5581ca2be2333cdce3a7d08d3f88240827185e94f83e5583353fb9a798

See more details on using hashes here.

Provenance

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