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,
pymagicalautomatically 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 python main.py --iter 500 --outdir results/
# Run with custom data and dump weight history
uv run python main.py
--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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pymagical-1.0.3.tar.gz.
File metadata
- Download URL: pymagical-1.0.3.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c2ff1efd9a574ef7b8dc04d0fc150feef4333eaeb44b89aa9e515ab0c2e9268c
|
|
| MD5 |
60e0ad75d6cf2b5f4447e5cbf8d28ea4
|
|
| BLAKE2b-256 |
2005a86ce91e42c1232380e23cc4998ecc8694686fdbaaf1f76b5329d51ebfd8
|
Provenance
The following attestation bundles were made for pymagical-1.0.3.tar.gz:
Publisher:
python-publish.yml on csun0/pymagical
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pymagical-1.0.3.tar.gz -
Subject digest:
c2ff1efd9a574ef7b8dc04d0fc150feef4333eaeb44b89aa9e515ab0c2e9268c - Sigstore transparency entry: 1004310986
- Sigstore integration time:
-
Permalink:
csun0/pymagical@9798f3971cff586fe659d521b5249b4b7d5c8315 -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/csun0
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9798f3971cff586fe659d521b5249b4b7d5c8315 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pymagical-1.0.3-py3-none-any.whl.
File metadata
- Download URL: pymagical-1.0.3-py3-none-any.whl
- Upload date:
- Size: 15.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc95141ac7875b43d89ce0d50cad17ab347cded12033d6610b959ba415ecb96c
|
|
| MD5 |
4b913a8a31289bf6a7d9e721495fd0e6
|
|
| BLAKE2b-256 |
31a0f9f865db0bd40fb6daf40e79c5c41c2b121468a8a871c7dfeebf655c65c9
|
Provenance
The following attestation bundles were made for pymagical-1.0.3-py3-none-any.whl:
Publisher:
python-publish.yml on csun0/pymagical
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pymagical-1.0.3-py3-none-any.whl -
Subject digest:
dc95141ac7875b43d89ce0d50cad17ab347cded12033d6610b959ba415ecb96c - Sigstore transparency entry: 1004311000
- Sigstore integration time:
-
Permalink:
csun0/pymagical@9798f3971cff586fe659d521b5249b4b7d5c8315 -
Branch / Tag:
refs/tags/v1.0.3 - Owner: https://github.com/csun0
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@9798f3971cff586fe659d521b5249b4b7d5c8315 -
Trigger Event:
release
-
Statement type: