How hakyimlab/metaxcan works
1. What this repository is
MetaXcan is a Python 3 command-line toolkit for transcriptome/TWAS-style association analysis. The repo is centered on running association methods over three kinds of input data: prediction model databases, genotype or GWAS data, and precomputed covariance/summary products.
2. Top-level architectural split
The software/ directory is the executable and library layer. The root README.md, papers/, and DevNotes.Rmd are documentation/support. software/tests/ is a fairly extensive fixture-driven test suite with synthetic and GTEx-like data. software/setup.py, requirements.txt, and conda_env.yaml define packaging and runtime dependencies.
3. Primary entrypoints
The main user-facing tools are SPrediXcan.py, PrediXcan.py, MulTiXcan.py, and SMulTiXcan.py. These are the core pipeline entrypoints: S-PrediXcan consumes GWAS summary statistics; PrediXcan consumes individual-level genotypes and phenotypes; MultiXcan/SMultiXcan aggregate across tissues or models. MetaXcanUI.py and the metax/ GUI-related modules are ancillary.
4. Core library boundary
Most computation lives under software/metax/. This package is the internal domain layer: it contains reusable code for data parsing, matrices, model handling, GWAS handling, genotype handling, and association algorithms. The scripts at the top of software/ are thin orchestration wrappers around these library modules.
5. Domain model and shared abstractions
The metax/ package defines the main objects and helpers used across the pipeline: DataSet, DataSetSNP, Person, Gene, PredictionModel, MatrixManager, KeyedDataSet, and Constants/Formats/NamingConventions. These represent the repository’s internal contract for “who/what is being analyzed” and standardize how SNPs, genes, samples, and matrices are keyed and aligned.
6. Input adapters by data type
Input handling is split by modality:
- metax/genotype/ reads individual-level genotype from BGEN, VCF, dosage, and GTEx-like formats.
- metax/gwas/ reads summary-statistic GWAS inputs and special-case formats.
- metax/expression/ reads expression matrices from plain text or HDF5.
These adapters isolate file-format complexity from the association logic.
7. Association computation layer
The central analysis code is under metax/metaxcan/ and metax/predixcan/. metaxcan/AssociationCalculation.py performs the S-PrediXcan-style gene-level statistic from GWAS summary data plus model weights and SNP covariance. predixcan/PrediXcanAssociation.py and predixcan/MultiPrediXcanAssociation.py implement the individual-level PrediXcan and multi-tissue logic. This is the main “engine” boundary in the repo.
8. Multi-tissue and cross-model analysis
MulTiXcan.py / SMulTiXcan.py depend on tissue-level predicted expression correlation structure and singular-value decomposition-style reduction. The supporting code in metax/cross_model/JointAnalysis.py and metax/predixcan/MultiPrediXcanAssociation.py combines correlated tissue predictions into a smaller number of independent components before association testing. HDF5 support in metax/expression/HDF5Expression.py exists specifically to make this cross-tissue access efficient.
9. Preprocessing and model-building pipeline
Several scripts prepare the derived inputs needed by the association engines: BuildExpressionProduct.py, CovarianceBuilder.py, ToHDF5.py, Predict.py, and the M00_–M04_ scripts. These generate or transform model databases, covariance matrices, betas, and z-scores. Conceptually, this is an offline preparation layer that feeds the runtime association tools.
10. Data flow from inputs to results
The canonical flow is: prediction model database + SNP covariance + GWAS summary stats or genotype/phenotype data → library loaders/adapters → aligned SNP/gene matrices → association engine → tabular CSV/TSV results. For MultiXcan, an additional intermediate product is per-tissue predicted expression, often stored as HDF5 or text, which is then aggregated across tissues/models.
11. External data and ecosystem dependencies
The repository assumes externally produced model and reference data from PredictDB / predictdb.org and often GTEx / 1000 Genomes-derived assets. Runtime dependencies include NumPy, SciPy, Pandas, HDF5, and for some genotype readers BGEN and VCF libraries (bgen_reader, cyvcf2). R is optional for some statistics/plots, but not the core computation path.
12. Testing and fixture strategy
software/tests/_td/ contains representative compressed fixture data for GWAS, covariance, db files, dosage, VCF, and GTEx-like expression. Tests cover both low-level abstractions and end-to-end behavior, which indicates the repo treats format parsing and mathematical correctness as first-class architectural concerns.
13. Packaging and deployment model
The project is packaged as an installable Python distribution, with setup.py, setup.cfg, MANIFEST.in, and __init__.py files exposing the library and command-line scripts. The architecture is therefore primarily a local batch-computation toolkit, not a service application: users install it into a Python environment and run the scripts against local files.
Main entry points: metax metax · software Software · AssociationCalculation.py S-PrediXcan engine · tests Tests
Components 22
Docs & support
Repository documentation and packaging support.
Runtime toolkit
Executable scripts and the shared Python library used to run analyses.
- Software · Installable Python package containing CLI tools and library code.
software - PrediXcan · Individual-level genotype/phenotype association entrypoint.
software/PrediXcan.py - S-PrediXcan · Summary-statistic association entrypoint.
software/SPrediXcan.py - MulTiXcan · Multi-tissue aggregation entrypoint.
software/MulTiXcan.py - SMulTiXcan · Summary-statistic multi-tissue entrypoint.
software/SMulTiXcan.py - Predict · Offline prediction and model-transform utility.
software/Predict.py - Covariance · Builds SNP covariance and related derived products.
software/CovarianceBuilder.py - Expr Product · Builds expression products for downstream analysis.
software/BuildExpressionProduct.py - To HDF5 · Converts expression and related data into HDF5.
software/ToHDF5.py - metax · Shared domain objects, constants, utilities, and orchestration support.
software/metax - Domain model · Datasets, samples, genes, models, and keyed alignment primitives.
software/metax/DataSet.py - Genotype I/O · Readers and helpers for BGEN, VCF, dosage, and GTEx-like genotype data.
software/metax/genotype - GWAS I/O · Summary-statistic parsers and special-case GWAS handling.
software/metax/gwas - Expression I/O · Plain-text and HDF5 expression readers.
software/metax/expression - S-PrediXcan engine · Gene-level statistics from GWAS summary data plus model weights and covariance.
software/metax/metaxcan/AssociationCalculation.py - PrediXcan engine · Individual-level association and multi-prediction testing.
software/metax/predixcan/PrediXcanAssociation.py - Cross-model analysis · Combines correlated tissue/model predictions into independent components.
software/metax/cross_model/JointAnalysis.py - Packaging · setup.py, requirements, and environment definitions for installation.
software/setup.py
Connections 33
- README → Software: describes · Documentation explains how to install and run the toolkit.
- Papers → Software: supports · Method papers document the analysis workflows.
- Software → PrediXcan: exposes · Package installs the main CLI entrypoints.
- Software → S-PrediXcan: exposes · Package installs the main CLI entrypoints.
- Software → MulTiXcan: exposes · Package installs the main CLI entrypoints.
- Software → SMulTiXcan: exposes · Package installs the main CLI entrypoints.
- Software → Predict: exposes · Package installs preprocessing utilities.
- Software → Covariance: exposes · Package installs preprocessing utilities.
- Software → Expr Product: exposes · Package installs preprocessing utilities.
- Software → To HDF5: exposes · Package installs preprocessing utilities.
- PrediXcan → metax: uses · CLI orchestration delegates to the shared library.
- S-PrediXcan → metax: uses · CLI orchestration delegates to the shared library.
- MulTiXcan → metax: uses · CLI orchestration delegates to the shared library.
- SMulTiXcan → metax: uses · CLI orchestration delegates to the shared library.
- metax → Domain model: defines · Shared objects and alignment abstractions.
- metax → Genotype I/O: routes · Core library coordinates genotype loading.
- metax → GWAS I/O: routes · Core library coordinates GWAS loading.
- metax → Expression I/O: routes · Core library coordinates expression loading.
- metax → S-PrediXcan engine: contains · Association calculation lives in the metaxcan engine.
- metax → PrediXcan engine: contains · Individual-level association lives in the predixcan engine.
- metax → Cross-model analysis: contains · Cross-tissue/model reduction and aggregation logic.
- MulTiXcan → Cross-model analysis: depends on · Multi-tissue workflows require component reduction.
- SMulTiXcan → S-PrediXcan engine: depends on · Summary-statistic multi-tissue workflow builds on gene-level association.
- S-PrediXcan → S-PrediXcan engine: depends on · Summary-statistic workflow calls the S-PrediXcan engine.
- PrediXcan → PrediXcan engine: depends on · Individual-level workflow calls the PrediXcan engine.
- Predict → Expression I/O: prepares · Transforms outputs into expression products.
- Covariance → S-PrediXcan engine: feeds · Produces covariance inputs needed by association calculation.
- Expr Product → Expression I/O: feeds · Creates intermediate expression products for downstream tools.
- To HDF5 → Expression I/O: feeds · Builds HDF5-backed expression access for efficient reuse.
- Tests → Fixtures: uses · Tests are driven by representative compressed fixtures.
- Tests → metax: verifies · Tests cover the shared data model and utilities.
- Tests → S-PrediXcan engine: verifies · Tests cover association math and end-to-end behavior.
- Tests → PrediXcan engine: verifies · Tests cover individual-level association behavior.