Framework for haplotype clustering in phased genotype data
Project description
hapla (v0.12)
hapla is a framework for performing window-based haplotype clustering in phased genotype data. The inferred haplotype cluster alleles can be used to infer fine-scale population structure, perform polygenic prediction and haplotype cluster based association studies.
Citation
Installation
# Build and install via PyPI
pip install hapla
# or download source and install via pip
git clone https://github.com/Rosemeis/hapla.git
cd hapla
pip install .
# or download source and install in new Conda environment
git clone https://github.com/Rosemeis/hapla.git
conda env create -f environment.yml
conda activate hapla
# The "hapla" main caller will now be available
Quick start
hapla contains the following subcommands at this moment:
- cluster
- struct
- predict
- admix
- fatash
Haplotype clustering
hapla cluster
Window-based haplotype clustering in a phased VCF/BCF.
# Cluster haplotypes in a chromosome with fixed window size (8 SNPs)
hapla cluster --bcf data.chr1.bcf --fixed 8 --threads 16 --out hapla.chr1
# Saves inferred haplotype cluster assignments in binary hapla format
# - hapla.chr1.bca
# - hapla.chr1.ids
# - hapla.chr1.win
hapla cluster
outputs three files. A .bca-file (binary cluster assignments), which stores the cluster assignments as unsigned chars, a .ids-file with sample names and a .win-file with information about the genomic windows.
# Cluster haplotypes in a chromosome with fixed size and overlapping windows (step size 4)
hapla cluster --bcf data.chr1.bcf --fixed 8 --step 4 --threads 16 --out hapla.chr1
# Cluster haplotypes in all chromosomes and save output path in a filelist
for c in {1..22}
do
hapla cluster --bcf data.chr${c}.bcf --fixed 8 --threads 16 --out hapla.chr${c}
realpath hapla.chr${c} >> hapla.filelist
done
Optionally, the haplotype cluster alleles can be saved in binary PLINK format (.bed, .bim, .fam) for ease of use with other software. Note that window information needs to be inferred from .bim-file for downstream analyses in this case.
hapla cluster --bcf data.chr1.bcf --threads 16 --out hapla.chr1 --plink
# Saves inferred haplotype cluster alleles in a binary PLINK format
# - hapla.chr1.bed
# - hapla.chr1.bim
# - hapla.chr1.fam
GRM estimation and population structure inference
hapla struct
Estimate genome-wide relationship matrix (GRM) and infer population structure using the haplotype cluster alleles.
# Construct genome-wide relationship matrix (GRM)
hapla struct --filelist hapla.filelist --threads 16 --grm --out hapla
# Saves the GRM in binary GCTA format (float)
# - hapla.grm.bin
# - hapla.grm.N.bin
# - hapla.grm.id
# Perform PCA on all chromosomes (genome-wide) using filelist and extract top 20 eigenvectors
hapla struct --filelist hapla.filelist --threads 16 --pca 20 --out hapla
# Saves eigenvalues and eigenvectors in text-format
# - hapla.eigenvecs
# - hapla.eigenvals
# Or perform PCA on a single chromosome and extract top 20 eigenvectors
hapla struct --clusters hapla.chr1 --threads 16 --pca 20 --out hapla.chr1
# Saves eigenvalues and eigenvectors in text-format
# - hapla.chr1.eigenvecs
# - hapla.chr1.eigenvals
# A faster randomized SVD approach can also be utilized for large datasets (>5,000 individuals)
hapla struct --filelist hapla.filelist --threads 16 --pca 20 --randomized --out hapla
Predict haplotype cluster assignments
hapla predict
Predict haplotype cluster assignments using pre-computed cluster medians in new haplotypes. All SNPs must be overlapping.
# Cluster haplotypes in a chromosome with 'hapla cluster' and save cluster medians (--medians)
hapla cluster --bcf ref.chr1.bcf --fixed 8 --threads 16 --out ref.chr1 --medians
# Saves haplotype cluster medians (besides standard binary hapla format)
# - ref.chr1.bcm
# - ref.chr1.wix
# - ref.chr1.hcc
# Predict assignments in a set of new haplotypes using haplotype cluster medians
hapla predict --bcf new.chr1.bcf --threads 16 --out new.chr1 --ref ref.chr1
# Saves predicted haplotype cluster assignments in binary hapla format
# - new.chr1.bca
# - new.chr1.ids
# - new.chr1.win
Using --medians
in hapla cluster
outputs three extra files. A .bcm-file (binary cluster medians), which stores the cluster medians as unsigned chars, a .wix-file with window index information and a .hcc-file with haplotype cluster counts. All files are needed to predict haplotype clusters in a new set of haplotypes.
Admixture estimation
hapla admix
Estimate ancestry proportions and ancestral haplotype cluster frequencies with a pre-specified number of sources (K). Using a modified ADMIXTURE model for haplotype clusters.
# Estimate ancestry proportions assuming K=3 ancestral sources for a single chromosome
hapla admix --clusters hapla.chr1 --K 3 --seed 1 --threads 16 --out hapla.chr1
# Saves Q matrix and P matrix in a text-file format
# - hapla.chr1.K3.s1.Q
# - hapla.chr1.K3.s1.P
# Estimate ancestry proportions assuming K=3 ancestral sources using filelist with all chromosomes
hapla admix --filelist hapla.filelist --K 3 --seed 1 --threads 16 --out hapla
# Saves Q matrix in a text-file and separate text-files of P matrices for each file
# - hapla.K3.s1.Q
# - hapla.K3.s1.file{1..22}.P
Local ancestry inference
hapla fatash
Infer local ancestry tracts using the admixture estimation in a hidden markov model. Using a modified fastPHASE model for haplotype clusters.
# Infer local ancestry tracts for a single chromosome (posterior decoding)
hapla fatash --clusters hapla.chr1 --qfile hapla.chr1.K3.s1.Q --pfile hapla.chr1.K3.s1.P --threads 16 --out hapla.chr1
# Saves posterior decoding path in text-format
# - hapla.chr1.path
# Infer local ancestry tracts using filelist with all chromosomes (Viterbi decoding)
for c in {1..22}; do realpath hapla.chr1.K3.s1.file${c}.P >> hapla.K3.s1.pfilelist; done
hapla fatash --filelist hapla.filelist --qfile hapla.K3.s1.Q --pfilelist hapla.K3.s1.pfilelist --threads 16 --out hapla --viterbi
# Saves Viterbi decoding paths in text-files
# - hapla.file{1..22}.path
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file hapla-0.12.tar.gz
.
File metadata
- Download URL: hapla-0.12.tar.gz
- Upload date:
- Size: 971.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6f7b9bfe3cd52820591bd995d22f72839a456e87248b4a173846034857bcf62 |
|
MD5 | 8e1e8e07a7cfbf4de821a877c96f4481 |
|
BLAKE2b-256 | c673ec40280dcd6bfc1c81ecb7deffe3dd652233fce87150a08656ff181b1595 |
File details
Details for the file hapla-0.12-cp311-cp311-macosx_11_0_arm64.whl
.
File metadata
- Download URL: hapla-0.12-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 515.6 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24da48e018f6306c65d125ba1cda3bc4ac191a08049c23fe917b9253f8392bfe |
|
MD5 | 44fbd7279abee5cbe8805ad552867ed2 |
|
BLAKE2b-256 | 5f002a684de684c2a84228b0c3cecfa87282de0972ae03ca010e399836291222 |