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 infers functional regulatory circuits (triads of Transcription Factors, cis-regulatory elements or Peaks, and target Genes) from paired 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: Caches large sparse matrices and genomic metadata into PyArrow-backed Parquet and NumPy formats for near-instant subsequent loads (~15x faster than re-parsing text).
  • Numba-Accelerated Sampling: JIT-compiled kernels give ~28x faster Gibbs sampling than the original MATLAB implementation (astrocytes, 2000 iterations).
  • Biological Directionality: Classifies inferred circuits as activators (+) or repressors (-) from the 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

run_magical takes individual file paths (all required); see the tutorial for the full argument list.

from pymagical import run_magical

run_magical(
    cand_gene_file="genes.txt",
    cand_peak_file="peaks.txt",
    # ... remaining RNA/ATAC/motif/TAD/refseq file paths (all required) ...
    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.1.tar.gz (414.1 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.1-py3-none-any.whl (424.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pymagical-1.5.1.tar.gz
  • Upload date:
  • Size: 414.1 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.1.tar.gz
Algorithm Hash digest
SHA256 6d6110af975076222e3650d1e604e9cc8049593d8ca287b2dae09f537a1d3c50
MD5 e3be66b9f35733c7d348c160cb96ab51
BLAKE2b-256 444af2117f78523a4783a9bcfe6a0090daa8c33003af4bc3d04ab97bd91f03d5

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pymagical-1.5.1-py3-none-any.whl
  • Upload date:
  • Size: 424.1 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 33555fde159db18097d5fa19e1f8ad53a3413989fece49371a9b61c93389f077
MD5 04abd7d4c716d88dc13045da7f0158a9
BLAKE2b-256 493227f8f8f4012f20e810f83bab455954cbd32d7e46f3fb42994e7cd5bbe14a

See more details on using hashes here.

Provenance

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