⚠️ Development statusPostHoc is currently under active development. The core pipeline is functional, but the project is not yet considered production-ready or suitable for drawing scientific conclusions. Additional attribution methods, validation experiments, benchmarking, and documentation are planned.
PostHoc is a Python toolkit for post-hoc variant attribution on GWAS-scale genotype data. It trains neural models on PLINK2 genotype matrices and produces PLINK-like output tables that can be compared or merged with standard GWAS pipelines.
PostHoc builds upon the neural-network attribution framework introduced by Yelmen et al. [1] for identifying genome-wide association signals from artificial neural networks. In particular, PostHoc implements and extends the PAL (Post-hoc Attribution Loci) analysis described in that work within a modular, command-line framework designed for reproducible analysis of genotype data.
The project currently includes:
- phenotype simulation on real genotype matrices
- baseline sparse logistic regression benchmarking
- integrated gradients SNP attribution
- PAL (Post-hoc Attribution Loci) discovery with null-model significance testing
- PLINK2-compatible genotype input and GWAS-style outputs
- repeated-model analysis for robust locus discovery
You can find full documentation here
- On PostHoc
- Relationship to prior work
- Installation
- Input data expectations
- Command-line interface
- Outputs
- Typical workflow
- Development
- Project layout
- License
- Citation
Traditional GWAS tools report association statistics from predefined linear or logistic models. PostHoc explores a complementary approach:
- train flexible predictive models (currently MLP)
- compute feature attribution scores for SNPs
- convert those attributions into GWAS-friendly tabular outputs
- identify robust loci across repeated model fits (PAL)
This is useful for exploring non-linear or interaction-heavy genetic architectures, especially with simulated phenotypes where ground truth is available.
PostHoc builds upon the attribution-based framework introduced by Yelmen et al. [1]:
Yelmen, B., Alver, M., Estonian Biobank Research Team, Jay, F., & Milani, L. (2024). Interpreting artificial neural networks to detect genome-wide association signals for complex traits. arXiv:2407.18811.
The PAL/AMAS methodology implemented in PostHoc is based on this prior work. PostHoc is intended as a modular and extensible software framework around this methodology, with PLINK2-native genotype input, phenotype simulation, configurable neural models, attribution analysis, GWAS-style outputs, and command-line workflows.
- Python 3.10+
pip- PLINK2 on
PATHif you use--indep-pairwiseQC pruning
git clone https://github.com/Nifdi01/posthoc.git
cd posthoc
pip install -e .# development tools
pip install -e .[dev]
# genotype ecosystem extras (pgenlib/pandas-plink)
pip install -e .[genotype]Commands that read genotype data expect a PLINK2 prefix with these files:
<prefix>.pgen<prefix>.pvar<prefix>.psam
A whitespace-delimited PLINK-style phenotype table with sample IDs and at least one phenotype column.
- accepted sample ID column names:
IIDor#IID - phenotype defaults to first non-ID column unless
--pheno-nameis provided - for logistic tasks, labels must be either
0/1or PLINK-style1/2(automatically recoded to0/1)
Optional whitespace-delimited table with IID/#IID plus one or more numeric covariate columns.
Samples are aligned by ID across genotype/phenotype/covariates, and samples with missing required values are dropped.
After installation, use:
posthoc --help
posthoc <command> --helpAvailable commands:
simulate-phenobaselineattributepal
Simulate a phenotype from real genotypes using additive/dominant/recessive and interaction effects.
Example:
posthoc simulate-pheno \
--pfile datasets/data/processed/chr22_subset \
--additive 10 0.6 \
--additive 25 -0.4 \
--interaction2 10 25 0.8 \
--logistic \
--heritability 0.5 \
--prevalence 0.1 \
--out outputs/simulated.phenoThis writes:
- phenotype file at
--out - causal variant IDs at
<out>.causal.txt
Run an L1-style logistic regression baseline (with QC and optional covariates) and print train/validation metrics for several regularization values.
Example:
posthoc baseline \
--pfile datasets/data/processed/chr22_subset \
--pheno outputs/simulated.pheno \
--pheno-name PHENO1 \
--maf 0.01 \
--geno 0.05 \
--val-fraction 0.2 \
--seed 42Train an MLP and compute per-SNP integrated gradients attribution.
Example:
posthoc attribute \
--pfile datasets/data/processed/chr22_subset \
--pheno outputs/simulated.pheno \
--pheno-name PHENO1 \
--logistic \
--hidden-dims 256,64 \
--epochs 200 \
--patience 15 \
--n-steps 50 \
--ig-baseline mean \
--out outputs/ig_results.glmRun repeated-model PAL analysis:
- train
n_modelson real labels - train
n_null_modelson permuted labels - derive PAL_Common and PAL_AMAS loci
- estimate PAL_AMAS p-values from null distribution bootstrapping
Example:
posthoc pal \
--pfile datasets/data/processed/chr22_subset \
--pheno outputs/simulated.pheno \
--pheno-name PHENO1 \
--logistic \
--n-models 10 \
--n-null-models 10 \
--theta-percentile 99.99 \
--n-bootstrap 100 \
--out outputs/pal.tsvColumns:
#CHROM,POS,ID,REF,ALTA1TESTIMPORTANCEP_PERMP_CORRECTEDN
The first five columns are intentionally PLINK-join friendly.
Columns:
#CHROM,POS,ID,REF,ALTMUAMASIN_PAL_COMMONIN_PAL_AMASP_VALUEN_MODELS
- Prepare or subset PLINK2 genotype data (see
scripts/prepare_data.shfor one example). - Simulate phenotype with known causal structure (
simulate-pheno). - Train/inspect baseline model performance (
baseline). - Run integrated gradients attribution (
attribute). - Run robust multi-model locus detection (
pal). - Compare discovered loci against
<simulated>.causal.txtground truth.
Install dev dependencies:
pip install -e .[dev]Run tests:
python -m pytestposthoc/commands/— CLI entrypointsposthoc/io/— genotype/phenotype/covariate readers and output writersposthoc/models/— MLP model and training utilitiesposthoc/attribution/— integrated gradients, PAL, significance logicposthoc/simulation/— phenotype simulation frameworkposthoc/qc/— MAF/missingness/LD-pruning filterstests/— unit tests
Apache (see LICENSE).
If you use PostHoc in your research, please cite the PostHoc software as well as the methodological work on which its PAL/AMAS analysis builds.
@software{guliyev2026posthoc,
author = {Guliyev, Nifdi},
title = {PostHoc: Post-hoc variant attribution for neural networks in GWAS},
year = {2026},
url = {https://github.com/Nifdi01/posthoc}
}@misc{yelmen_interpreting_2024,
title = {Interpreting artificial neural networks to detect genome-wide association signals for complex traits},
author = {Yelmen, Burak and Alver, Maris and Team, Estonian Biobank Research and Jay, Flora and Milani, Lili},
year = {2024},
month = jul,
publisher = {arXiv},
eprint = {2407.18811},
archivePrefix = {arXiv},
primaryClass = {cs, q-bio},
url = {https://arxiv.org/abs/2407.18811}
}