Development

Setup

git clone https://github.com/Nifdi01/posthoc.git
cd posthoc
pip install -e ".[dev,genotype]"

This installs pytest, pytest-cov, black, and ruff alongside the core and genotype-I/O dependencies.

Running tests

python -m pytest

Tests live under tests/ and cover genotype/phenotype/covariate readers, QC filters, model training, and output writers. tests/conftest.py defines shared fixtures; tests/plink_ref.PHENO1.glm.logistic.hybrid is a reference PLINK2 output used to cross-check PostHoc’s output format.

Project layout

Path

Contents

posthoc/commands/

CLI entrypoints (one module per subcommand), thin orchestration over the modules below.

posthoc/io/

Genotype/phenotype/covariate readers and output writers.

posthoc/models/

The MLP model and training utilities.

posthoc/attribution/

Integrated Gradients, PAL, and significance-testing logic.

posthoc/simulation/

Phenotype simulation framework.

posthoc/qc/

MAF / missingness / LD-pruning filters.

tests/

Unit tests.

scripts/prepare_data.sh

Example script that downloads and QC-filters a chromosome 22 region for use in the Quickstart.

Building the documentation locally

This documentation is built with Sphinx and hosted on Read the Docs, configured via .readthedocs.yaml at the repository root. To build it locally:

pip install -e ".[genotype]"
pip install -r docs/requirements.txt
sphinx-build -b html docs docs/_build/html

The Python API reference pages under Python API reference use sphinx.ext.autodoc and therefore import posthoc at build time — the genotype extra must be installed (or at least pgenlib) for posthoc.io.genotype_reader to import successfully.

Coding conventions

  • Formatting: black.

  • Linting: ruff.

  • Type hints are used throughout; most dataclasses (e.g. TrainConfig, PALConfig) act as the de facto configuration schema for their corresponding function.

Contributing

Issues and pull requests are welcome on the GitHub repository. If you’re adding a new model or attribution method, note that the CLI currently gates --model/--attribution behind click.Choice allow-lists (see attribute) — extending those is the natural entry point.