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.

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 path/to/data/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. Run the Downloadable Demo

From the cloned repository root, run uv sync as described above, then download and extract the demo inputs (about 353 MB compressed, 1.5 GB extracted):

curl --fail --location --retry 3 --continue-at - \
  --output magical_demo_input_files.tar.gz \
  https://github.com/csun0/pymagical/releases/download/data-v1.0/magical_demo_input_files.tar.gz
tar -xzf magical_demo_input_files.tar.gz

The CLI defaults match the demo filenames. All files are in the same folder, so use --cell-dir Demo_input_files with --main-dir Demo_input_files. Both directory options resolve independently from the working directory. The bundled hg38_Refseq.txt is header-free and ready to use. Start with a short smoke run:

uv run pymagical run \
  --main-dir Demo_input_files --cell-dir Demo_input_files \
  --iter 10 --use-numba \
  --prefix demo_smoke --outdir outputs/demo_smoke

After the smoke run succeeds, rerun the same command with --iter 2000, --prefix demo, and --outdir outputs/demo. The main result will be outputs/demo/demo_py_2000.txt, alongside B/L matrices and timing statistics. Keep Demo_input_files/.magical_cache/ to reuse parsed inputs on subsequent runs. Sampling starts a new chain each time; it does not resume from the smoke run.

3. 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.5.3

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.5.3
File Size Uploaded Provenance Actions
pymagical-1.5.3.tar.gz 416.0 kB With provenance Details for pymagical-1.5.3.tar.gz

Built distribution (wheel)

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

Total release size: 842.3 kB

Release files / pymagical-1.5.3.tar.gz

Download URL pymagical-1.5.3.tar.gz
Size 416.0 kB
Tags Source
SHA-256 checksum
How to use checksums
861a0b9dcce7e771a30bba2c5f84a9fade3a1c8df032bcfd5bebc8c621c86226
BLAKE2b-256 checksum
How to use checksums
cc8fc242cfc3986f6e96dd47b31141099d1d5763c1cf96080f256dd68a217adc
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 6, 2026.

Transparency log

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

Download URL pymagical-1.5.3-py3-none-any.whl
Size 426.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea6d1cd61b3874577f9207e3e4bf1fca9b6ed36680934cd339c434d9fecabbbc
BLAKE2b-256 checksum
How to use checksums
c9ba6bd6b5b496b999be9c02f0d286cd83d71fe41aa1b7c0484b911e16d04f84
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 6, 2026.

Transparency log

Security for pymagical 1.5.3

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.5.3.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 6, 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