Skip to main content

A Python port of the MAGICAL hierarchical Bayesian Gibbs sampler for regulatory circuit inference.

Project description

pymagical

pymagical is a high-performance Python port of the MAGICAL (Multiome Accessibility Gene Integration Calling and Looping) algorithm. It provides a method for inferring functional regulatory circuits—triads of Transcription Factors (TFs), cis-regulatory elements (Peaks), and target Genes—from single-cell RNA-seq and ATAC-seq data.

The methodology is based on the framework described in:

Chen et al., "Mapping disease regulatory circuits at cell-type resolution from single-cell multiomics data" Nature Computational Science 2023. (Available here)

Key Features

  • IO Caching: Automatically caches large sparse matrices and genomic metadata into PyArrow-backed Parquet and NumPy formats for near-instant subsequent loads (~15x faster than MATLAB).
  • Numba-Accelerated Sampling: Utilizes JIT-compiled kernels to provide a ~30x speedup in Gibbs sampling compared to the original MATLAB implementation (averaged across large-scale benchmarks).
  • Biological Directionality: Classifies inferred circuits as activators (+) or repressors (-) by analyzing continuous regression weights.

Documentation

For detailed information on setup, biological methodology, and validation, please refer to the following guides:

Installation

For users (from PyPI)

Install pymagical in one step with pip (or uv pip):

pip install pymagical

For the interactive HTML report (pymagical viz), install the optional viz extra:

pip install "pymagical[viz]"

Requires Python ≥ 3.10 and a C compiler (Numba needs one for its JIT kernels).

For developers (from source)

Clone the repository and sync the environment with uv; this creates a .venv and installs the package (editable) plus the dev dependency group (pytest, plotting, and the viz libraries):

git clone https://github.com/csun0/pymagical.git
cd pymagical
uv sync

Then run commands inside the environment with uv run:

uv run pymagical --help     # CLI
uv run pytest               # test suite

The package version is derived from git tags via hatch-vcs. A full clone (or a release tarball) builds fine; if you build from a source tree with no git history the version falls back to 0.0.0.

Quick Start

1. Command Line Usage

Once installed, run the circuit inference directly from your terminal. Use --use-numba for maximum performance:

# Run with default data for 500 iterations using Numba
pymagical run --main-dir path/to/data --cell-dir astrocytes --iter 500 --use-numba --outdir results/

# Generate an interactive HTML visualization report (requires [viz] extra)
pymagical viz results/magical_py_500.txt

Run pymagical --help to see all available flags and subcommands.

2. Programmatic Usage

from pymagical import run_magical

run_magical(
    cand_gene_file="genes.txt",
    cand_peak_file="peaks.txt",
    # ... other file paths ...
    iteration_num=2000,
    use_numba=True,
    output_file="my_results.txt"
)

Citation

If you use MAGICAL in your research, please cite:

@article{chen_mapping_2023,
	title = {Mapping disease regulatory circuits at cell-type resolution from single-cell multiomics data},
	author = {Chen, Xi and Wang, Yuan and Cappuccio, Antonio and Cheng, Wan-Sze and Zamojski, Frederique Ruf and Nair, Venugopalan D. and Miller, Clare M. and Rubenstein, Aliza B. and Nudelman, German and Tadych, Alicja and Theesfeld, Chandra L. and Vornholt, Alexandria and George, Mary-Catherine and Ruffin, Felicia and Dagher, Michael and Chawla, Daniel G. and Soares-Schanoski, Alessandra and Spurbeck, Rachel R. and Ndhlovu, Lishomwa C. and Sebra, Robert and Kleinstein, Steven H. and Letizia, Andrew G. and Ramos, Irene and Fowler, Vance G. and Woods, Christopher W. and Zaslavsky, Elena and Troyanskaya, Olga G. and Sealfon, Stuart C.},
	journal = {Nature Computational Science},
	year = {2023},
	month = jul,
	doi = {10.1038/s43588-023-00476-5},
	url = {https://www.nature.com/articles/s43588-023-00476-5},
}

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

pymagical-1.5.0.tar.gz (413.6 kB view details)

Uploaded Source

Built Distribution

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

pymagical-1.5.0-py3-none-any.whl (423.7 kB view details)

Uploaded Python 3

File details

Details for the file pymagical-1.5.0.tar.gz.

File metadata

  • Download URL: pymagical-1.5.0.tar.gz
  • Upload date:
  • Size: 413.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pymagical-1.5.0.tar.gz
Algorithm Hash digest
SHA256 b685291c66fc03f233c82bd8c5eb038fdf15ea86726d4e9df30822fc29b499c9
MD5 90555edba0f654ff9219c7b433b3fd2a
BLAKE2b-256 ade726475c77118aa056af868c6d3a5459ec9d7e93095d194f930917a4610c83

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymagical-1.5.0.tar.gz:

Publisher: python-publish.yml on csun0/pymagical

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

File details

Details for the file pymagical-1.5.0-py3-none-any.whl.

File metadata

  • Download URL: pymagical-1.5.0-py3-none-any.whl
  • Upload date:
  • Size: 423.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pymagical-1.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 84a01ff769114f2be2941e6e59c8bbbfd138d490b39844c18be7ea4afbd4b860
MD5 c73288d3036059b220d133f1c52107db
BLAKE2b-256 5849515c069c2f33ce08ad83a91fbee4ef8696dc063ae97028d42d7bab5f8e6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymagical-1.5.0-py3-none-any.whl:

Publisher: python-publish.yml on csun0/pymagical

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