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 an automated pipeline for inferring functional regulatory circuits—triads of Transcription Factors (TFs), cis-regulatory elements (Peaks), and target Genes—from paired single-cell RNA-seq and ATAC-seq data.

Key Features

  • Fast & Optimized: Significantly faster than the original MATLAB implementation (~1.9x speedup in sampling, up to 15x speedup in data loading).
  • Intelligent IO Caching: Automatically caches large sparse matrices and genomic metadata into PyArrow-backed Parquet and NumPy formats for near-instant subsequent loads.
  • Biological Directionality: Unlike the original version, pymagical automatically classifies inferred circuits as activators (+) or repressors (-) by analyzing the continuous regression weights calculated during Gibbs sampling.
  • HPC Ready: Includes built-in support for high-memory Slurm environments and allows for detailed weight-history dumping for downstream statistical distribution analysis.

Installation

This project uses uv for environment management.

# Clone the repository
git clone <repo-url>
cd pymagical

# Sync the environment
uv sync

Quick Start

1. Command Line Usage

Run the circuit inference directly from your terminal:

# Run with default demo data (astrocytes) for 500 iterations
uv run pymagical --iter 500 --outdir results/

# Run with custom data and dump weight history
uv run pymagical \
    --iter 1000 \
    --prefix my_sample \
    --rna-counts path/to/rna.txt \
    --atac-counts path/to/atac.txt \
    --dump-weights

2. Programmatic Usage

Integrate pymagical into your own Python pipelines:

from pymagical import run_magical

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

Output Notation

The final triad list includes a biological effect annotation for every identified TF:

TF_Name (Confidence_Probability, Overall_Effect [L_dir, B_dir])

  • Overall Effect: + (Activator) or - (Repressor).
  • L_dir (Looping): Direction of Peak-to-Gene effect.
  • B_dir (Binding): Direction of TF-to-Peak effect.

Example: STAT5B (0.85, + [+,+]) indicates an 85% confident activator that opens a peak which subsequently increases gene expression.

Documentation

Evaluation and Comparison

The eval/ directory contains tools for comparing pymagical against the original MATLAB implementation and profiling performance.

  • eval/tests/compare_results.py: Compare fidelity and performance across implementations.
  • eval/benchmarks/profile_run.py: Profile the runtime of different execution stages.

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.1.0.tar.gz (16.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.1.0-py3-none-any.whl (18.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pymagical-1.1.0.tar.gz
  • Upload date:
  • Size: 16.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.1.0.tar.gz
Algorithm Hash digest
SHA256 9ef4175dcb36248cdf9ca0eb1ebc1e4d4cc1fe7dceb304b43fe9735b4ded9ad9
MD5 51367db83dd6d150d0113bb0e25b4e78
BLAKE2b-256 ee272b08a6c69aa44c7dcdf907c75f152b10fe2c6a44e00a5cde4a77cd2e525c

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pymagical-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.5 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7a233a4fef41df8c3f14637aaabdba3aeb3a8744a2646d29702af5580eec4723
MD5 ca3ec8515a2ebed470fa7d2eaeb7a33c
BLAKE2b-256 5b594f7c7b28d9267d2ec342c9ffd2146fd64f8696a41be3675563a8eac49823

See more details on using hashes here.

Provenance

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