Skip to main content

BayesPrism (Python)

A pure functional Python and PyTorch implementation of BayesPrism for Bayesian cell type and gene expression deconvolution using single-cell RNA-seq references.

License: MIT Python 3.10+


Overview

BayesPrism infers the cellular composition and cell-type-specific gene expression profiles of heterogeneous bulk RNA-seq data by leveraging single-cell transcriptomics as a prior.

This package is a high-performance Python port built upon:

  • PyTorch for accelerated matrix computations and GPU tensor operations.
  • Polars for fast, declarative data processing.
  • Pure Functional Design ensuring immutable state transitions, railway-oriented error handling via returns, and strict type safety.

Installation

pip install bayesprism

Or install directly from GitHub:

pip install git+https://github.com/LuJoHae/bayesprism-python.git

Quick Start

import numpy as np
from bayesprism import new_prism, run_prism, get_fraction, get_exp

# 1. Prepare raw count matrices (samples x genes, cell_types x genes)
# Bulk mixture: X (samples x genes)
# scRNA-seq reference: phi_ref (cell_types x genes)
gene_names = ("CD3D", "CD8A", "CD4", "MS4A1", "CD68", ...)

# 2. Initialize the Prism model container
prism_result = new_prism(
    X_bulk=X_bulk_counts,
    phi_ref=phi_sc_reference,
    gene_names=gene_names,
)

# Unwrap monadic Result safely
prism = prism_result.unwrap()

# 3. Run Bayesian MCMC deconvolution
fitted_prism = run_prism(prism)

# 4. Extract inferred cell type fractions (theta)
fractions = get_fraction(fitted_prism)

# 5. Extract cell-type-specific expression profiles (Z)
expression_profiles = get_exp(fitted_prism)

Key Features

  • Bayesian Joint Estimation: Jointly infers cell-type proportions ($\theta$) and cell-type-specific gene expression ($Z$).
  • Linear Count Space: Operates directly on unnormalized raw sequencing counts to preserve count distributions without log-transformation artifacts.
  • Batched GPU Acceleration: PyTorch tensors enable fast vectorized updates across large patient cohorts.
  • Modular Pipeline: Full functional pipeline with separate Gibbs sampling, Nelder-Mead reference updating, and NMF embedding learning.

Citation & Acknowledgments

If you use BayesPrism in your research, please cite the original BayesPrism methodology:

Chu, T., Wang, Z., Pe'er, D., & Danko, C. G. (2022). Cell type and gene expression deconvolution with BayesPrism. Nature Cancer, 3(4), 505-517. doi:10.1038/s43018-022-00356-3


License

This project is licensed under the MIT License.

Metadata

Release files for bayesprism 0.1.0

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

Source distribution (sdist)

Source distribution for bayesprism 0.1.0
File Size Uploaded Provenance
bayesprism-0.1.0.tar.gz 18.7 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for bayesprism 0.1.0
File Interpreter ABI Platform
bayesprism-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 37.0 kB

Release files / bayesprism-0.1.0.tar.gz

Download URL bayesprism-0.1.0.tar.gz
Size 18.7 kB
Tags Source
SHA-256 checksum
How to use checksums
89ab73fae462484d0c3751d48c5d1f0a915b4b01c0628e534654700f7c3e476a
BLAKE2b-256 checksum
How to use checksums
b3e1ed70dc7f5ddbfdd087c17e3995769534a0d5b8e4ba56658d340ce186658c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 16, 2026.

Transparency log

Release files / bayesprism-0.1.0-py3-none-any.whl

Download URL bayesprism-0.1.0-py3-none-any.whl
Size 18.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0d7e9a4f13ed7467bcce86b3891caa266b1b863783b74e69bbc13b4f82a0ada9
BLAKE2b-256 checksum
How to use checksums
0430df5cf5c8d8b31af858d8a483b1d90e9b99e479149addf888041be4327689
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 16, 2026.

Transparency log

Security for bayesprism 0.1.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 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bayesprism-0.1.0.tar.gz

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 Sep 16, 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 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