Skip to main content

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},
}

Metadata

Release files for pymagical 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 pymagical 1.0
File Size Uploaded Provenance Actions
pymagical-1.0.tar.gz 415.2 kB With provenance Details for pymagical-1.0.tar.gz

Built distribution (wheel)

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

Total release size: 840.6 kB

Release files / pymagical-1.0.tar.gz

Download URL pymagical-1.0.tar.gz
Size 415.2 kB
Tags Source
SHA-256 checksum
How to use checksums
1eeeb442a0f120990325cdb8fba552a179431a624d52c9085910c28dbe6822bc
BLAKE2b-256 checksum
How to use checksums
af4579409cbbb655021ccf23a837c4d0d76a16b68ebc8d6e65a88ab0964af448
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 Oct 5, 2026.

Transparency log

Release files / pymagical-1.0-py3-none-any.whl

Download URL pymagical-1.0-py3-none-any.whl
Size 425.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f75f5cb9e5ca11f31d4f287aebc0784d59aaca09f07c34cb222c7bf0b8acef45
BLAKE2b-256 checksum
How to use checksums
0627ec45550c8d451d60d64f79e08588102c9bea179fa523f6634d814969a31f
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 Oct 5, 2026.

Transparency log

Security for pymagical 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 pymagical-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 Oct 5, 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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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