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

The recommended way to install pymagical is via PyPI:

pip install pymagical

For interactive HTML reports and visualization features, install the viz extra:

pip install "pymagical[viz]"

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.4.0.tar.gz (413.0 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.4.0-py3-none-any.whl (423.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pymagical-1.4.0.tar.gz
Algorithm Hash digest
SHA256 c44c6730dce4c715c48dfd0dfad49d96e5f4e16772a8ab13581447f2bc66d09d
MD5 ffa14c712b28997e850bf6fb3f6dc25c
BLAKE2b-256 5528974d7a40d6a97daf0da6d0c14749768bb9b16db8373f0fd022640e23df20

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymagical-1.4.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.4.0-py3-none-any.whl.

File metadata

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

File hashes

Hashes for pymagical-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6c2558336fccca58dc928c20341124983c86ef3c54f4646813b32618c432403
MD5 e6ab852d4161b73b09eb43777abe4df7
BLAKE2b-256 9372d7d7ebc928937e66ca6e92228fa6defd0d08ec8ea5811175d02e77ddc2c3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pymagical-1.4.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