PG-SUI
Population Genomic Supervised and Unsupervised Imputation.
About PG-SUI
PG-SUI is a Python 3 API that uses machine learning to impute missing values from population genomic SNP data. The CLI and experimental desktop GUI offer four neural models and two deterministic baselines. Two experimental supervised wrappers are available through Python.
Start with the imputation tutorial or compare validation results on 30 diploid datasets.
How PG-SUI works
PG-SUI fills missing SNP genotypes using unsupervised neural networks, experimental supervised models, or deterministic methods. Its neural models learn to reconstruct genotype calls using observed values as training targets. To evaluate an imputer, PG-SUI temporarily masks some observed genotypes, predicts them, and compares the predictions with their known values. After fitting, it fills the genotypes that were missing in the original input. Those calls have no known truth, so they are excluded from accuracy scores.
The following schematic animation illustrates the variational autoencoder (VAE) genotype imputation workflow. Its predictions are illustrative, not measured results.
Unsupervised Imputation Methods
Unsupervised imputers include four neural network models:
- Variational Autoencoder (VAE) 1
- Encodes genotypes as a latent distribution, then decodes them to reconstruct observed calls. Training excludes originally missing calls from the reconstruction loss; the trained model predicts those calls.
- Autoencoder 2
- Learns a lower-dimensional representation of the genotypes and reconstructs observed calls. Its predictions fill originally missing positions.
- Nonlinear PCA (NLPCA)
- Learns per-sample latent representations and a decoder network to reconstruct genotypes.
- Unsupervised backpropagation (UBP)
- Initializes sample representations with PCA, then refines the decoder and representations in stages.
The animations below show the four neural imputation workflows.
Experimental supervised imputation methods
Supervised methods use scikit-learn's IterativeImputer, which is based on multivariate imputation by chained equations (MICE) 3. It predicts missing genotypes at each SNP site using other sites as features. Users can configure how many other SNP features are considered for each prediction. PG-SUI supports these classifiers:
- ImputeRandomForest
- ImputeHistGradientBoosting
See the scikit-learn documentation for more information on IterativeImputer and each of the classifiers.
The animations below illustrate the supervised imputation models.
Non-Machine Learning (Deterministic) Methods
We also include several deterministic options for imputing missing data, including:
- Per-population mode per SNP site
- Overall mode per SNP site
- Reference allele (REF genotype)
The animations below illustrate each deterministic model.
Installing PG-SUI
PG-SUI supports both pip and conda distributions. Both are kept current with up-to-date releases.
Installation with Pip
To install PG-SUI with pip, do the following. It is strongly recommended to install pg-sui in a virtual environment.
python3 -m venv .pgsui-venv
source .pgsui-venv/bin/activate
pip install pg-sui
Installation with Anaconda
To install PG-SUI with Anaconda, do the following:
conda create -n pgsui-env --strict-channel-priority --override-channels \
-c btmartin721 -c conda-forge -c bioconda \
python=3.12 pg-sui
conda activate pgsui-env
Docker Container
We also maintain a Docker image that comes with PG-SUI preinstalled. This can be useful for automated workflows such as Nextflow or Snakemake.
docker pull btmartin721/pg-sui:latest
docker run -it --rm btmartin721/pg-sui:latest pg-sui --help
Experimental desktop GUI for macOS
The GUI is in development. The v1.8.8 tag and Python distributions omit the Electron interface HTML. Use the CLI for released installations. The desktop guide documents the controls and setup for developers with a complete interface checkout. Experimental desktop guide
Input Data
You can read your input files as a GenotypeData object from the SNPio package. SNPio supports the VCF, PHYLIP, STRUCTURE, and GENEPOP input file formats.
# Import snpio. Automatically installed with pg-sui.
from snpio import VCFReader
# Read in VCF alignment.
# SNPio also supports PHYLIP, STRUCTURE, and GENEPOP input file formats.
data = VCFReader(
filename="pgsui/example_data/vcf_files/phylogen_subset14K.vcf.gz",
popmapfile="pgsui/example_data/popmaps/phylogen_nomx.popmap", # optional
force_popmap=True, # optional
)
Supported Imputation Methods
There are several supported algorithms PG-SUI uses to impute missing data. Each one can be run by calling the corresponding class. You must provide a GenotypeData instance as the first positional argument.
You can import all the supported methods with the following:
from pgsui import ImputeVAE, ImputeAutoencoder, ImputeRefAllele, ImputeMostFrequent, MostFrequentConfig
Unsupervised Imputers
The four unsupervised imputers can be run by initializing them with the SNPio GenotypeData object and then calling fit() and transform().
# Initialize the models, then fit and impute
vae = ImputeVAE(data) # Variational autoencoder
vae.fit()
vae_imputed = vae.transform()
ae = ImputeAutoencoder(data) # standard autoencoder
ae.fit()
ae_imputed = ae.transform()
The *_imputed objects are NumPy arrays of IUPAC single-character codes that are compatible with SNPio's GenotypeData objects.
Experimental supervised imputers
ImputeRandomForest and ImputeHistGradientBoosting wrap scikit-learn’s iterative imputer. In v1.8.8, the stock supervised configuration lacks the ploidy field required by fit(). See the experimental Python API guide.
Non-machine learning methods
The following deterministic methods are supported. ImputeMostFrequent supports the mode-per-population or overall (global) mode options to inform imputation.
# Per-population, per-locus mode
cfg = MostFrequentConfig.from_preset("fast")
cfg.algo.by_populations = True
pop_mode = ImputeMostFrequent(data, config=cfg)
pop_mode.fit()
imputed_pop_mode = pop_mode.transform()
# Per-locus mode
mode = ImputeMostFrequent(data, config=MostFrequentConfig.from_preset("fast"))
mode.fit()
imputed_mode = mode.transform()
Or, always replace missing values with the reference allele.
ref = ImputeRefAllele(data)
ref.fit()
imputed_ref = ref.transform()
Command-Line Interface
Run the PG-SUI CLI with pg-sui (installed alongside the library). The CLI follows the same precedence model as the Python API:
code defaults < preset (--preset) < YAML (--config) < explicit CLI flags < --set key=value.
Recent releases add explicit switches for the simulated-missingness workflow shared by the neural and deterministic models:
--sim-strategyselects one ofrandom,random_weighted,random_weighted_inv,nonrandom,nonrandom_weighted.--sim-propsets the proportion of observed calls to temporarily mask when building the evaluation set.
Example:
pg-sui \
--input data.vcf.gz \
--popmap pops.popmap \
--models ImputeVAE ImputeAutoencoder \
--preset balanced \
--sim-strategy random_weighted_inv \
--sim-prop 0.3 \
--prefix ae_and_vae \
--n-jobs 4 \
--tune-n-trials 100 \
--set tune.enabled=True
CLI overrides cascade into every selected model, so a single invocation can evaluate multiple imputers with a consistent simulation strategy and output prefix.
STRUCTURE inputs accept a few extra flags for parsing metadata:
pg-sui \
--input data.str \
--format structure \
--structure-has-popids \
--structure-allele-start-col 2 \
--structure-allele-encoding '{"1":"A","2":"C","3":"G","4":"T","-9":"N"}'
References
-
Kingma, D.P. & Welling, M. (2013). Auto-encoding variational bayes. In: Proceedings of the International Conference on Learning Representations (ICLR). arXiv:1312.6114 [stat.ML].
-
Hinton, G.E., & Salakhutdinov, R.R. (2006). Reducing the dimensionality of data with neural networks. Science, 313(5786), 504-507.
-
Stef van Buuren, Karin Groothuis-Oudshoorn (2011). mice: Multivariate Imputation by Chained Equations in R. Journal of Statistical Software 45: 1-67.
Metadata
Release files for pg-sui 1.8.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pg_sui-1.8.8.tar.gz | 44.0 MB | Without provenance | Details for pg_sui-1.8.8.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pg_sui-1.8.8-py3-none-any.whl | Python 3 | none | any | Details for pg_sui-1.8.8-py3-none-any.whl |
Total release size: 52.9 MB
Release files / pg_sui-1.8.8.tar.gz
| Download URL | pg_sui-1.8.8.tar.gz |
|---|---|
| Size | 44.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6717e521feaca168a2f7df39c54971c103d27809a4ca1a3fd9e97d44701a6377
|
|
BLAKE2b-256 checksum How to use checksums |
47f18c4ed6453aa6a7d742ec100fe4aadcd13906c8ead7cab29b6fd99f1b9055
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.16
|
Release files / pg_sui-1.8.8-py3-none-any.whl
| Download URL | pg_sui-1.8.8-py3-none-any.whl |
|---|---|
| Size | 8.9 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
59869a9b51970bfeb68944ebd49a14e15950110c440c327384653a352e6847ab
|
|
BLAKE2b-256 checksum How to use checksums |
9a0eca0aa92d9c550d7b446a6ed10cb0d1faed8e63fb251fa4cce548854d0d67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.16
|
Security for pg-sui 1.8.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.