Population structure from 1KGP
Example that uses 150 real samples from five 1000 Genomes populations on chromosome 22, then estimates pairwise Hudson FST. The chromosome-22 estimates are illustrative rather than genome-wide. The first run downloads and caches about 206 MB.
import snputils as su
from snputils.processing import embedding_dataframe_from_model
from snputils.stats import fst
populations = ["YRI", "CEU", "GIH", "CHB", "PEL"]
snp = su.load_dataset(
"1kgp",
resource="phase3",
chromosomes=22,
populations=populations,
samples_per_population=30,
max_variants=15_000,
maf=0.05,
require_complete=True,
snv_only=True,
)
# Or load your own VCF, BCF, PGEN, BED, or BGEN with:
# snp = su.read_snp("cohort.vcf.gz")
pca = su.PCA(snp, n_components=2, fitting="exact")
coords = embedding_dataframe_from_model(pca)
coords["population"] = snp.sample_fid
su.viz.plot_embedding(coords, hue="population", show=True)
fst_results = fst(snp, sample_labels=snp.sample_fid, block_size=1_000)
fst_results.rename(columns={
"pop1": "population 1", "pop2": "population 2",
"est": "FST estimate", "se": "standard error",
}).round(3).head()
| population 1 | population 2 | FST estimate | standard error |
|---|---|---|---|
| CEU | CHB | 0.108 | 0.014 |
| CEU | GIH | 0.031 | 0.006 |
| CEU | PEL | 0.094 | 0.014 |
| CEU | YRI | 0.137 | 0.012 |
| CHB | GIH | 0.072 | 0.009 |