MyNixOS website logo
Description

Estimate Kinship and FST under Arbitrary Population Structure.

Provides functions to estimate the kinship matrix of individuals from a large set of biallelic SNPs, and extract inbreeding coefficients and the generalized FST (Wright's fixation index). Method described in Ochoa and Storey (2021) <doi:10.1371/journal.pgen.1009241>.

popkin popkin

The popkin ("population kinship") R package estimates the kinship matrix of individuals and FST from their biallelic genotypes. Our estimation framework is the first to be practically unbiased under arbitrary population structures.

Installation

The stable version of the package is now on CRAN and can be installed using

install.packages("popkin")

The current development version can be installed from the GitHub repository using devtools:

install.packages("devtools") # if needed
library(devtools)
install_github('StoreyLab/popkin', build_vignettes = TRUE)

You can see the package vignette, which has more detailed documentation, by typing this into your R session:

vignette('popkin')

Examples

Input data

The examples below assume the following R data variables are present for n individuals and m loci:

  • The m-by-n genotype matrix X, containing only unphased biallelic variants encoded as 0,1,2 counting a given reference allele per locus.
  • The length-n vector subpops that assigns each individual to a subpopulation.

The subpops vector is not required, but its use is recommended to improve estimation of the baseline kinship value treated as zero.

If your data is in BED format, popkin will process it efficiently using BEDMatrix. If file is the path to the BED file (excluding .bed extension):

library(BEDMatrix)
X <- BEDMatrix(file) # load genotype matrix object

popkin functions

This is a quick overview of every popkin function, covering estimation and visualization of kinship and FST from a genotype matrix.

First estimate the kinship matrix from the genotypes X. All downstream analysis require kinship, none use X after this

library(popkin)
kinship <- popkin(X, subpops) # calculate kinship from X and optional subpop labels

Plot the kinship matrix, marking the subpopulations. Note inbr_diag replaces the diagonal of kinship with inbreeding coefficients

plot_popkin( inbr_diag(kinship), labs = subpops )

Extract inbreeding coefficients from kinship

inbreeding <- inbr(kinship)

Estimate FST

weights <- weights_subpops(subpops) # weigh individuals so subpopulations are balanced
Fst <- fst(kinship, weights) # use kinship matrix and weights to calculate fst
Fst <- fst(inbreeding, weights) # estimate more directly from inbreeding vector (same result)

Estimate and visualize the pairwise FST matrix

pairwise_fst <- pwfst(kinship) # estimated matrix
leg_title <- expression(paste('Pairwise ', F[ST])) # fancy legend label
plot_popkin(pairwise_fst, labs = subpops, leg_title = leg_title) # NOTE no need for inbr_diag() here!

Rescale the kinship matrix using different subpopulations (implicitly changes the most recent common ancestor population used as reference)

kinship2 <- rescale_popkin(kinship, subpops2)

Estimate the coancestry matrix from a matrix of allele frequencies P (useful when P comes from an admixture inference model)

coancestry <- popkin_af( P )

Please see the popkin R vignette for a description of the key parameters and more detailed examples, including complex plots with multiple kinship matrices and multi-level subpopulation labeling.

Citations

Alejandro Ochoa, John D Storey. 2021. "Estimating FST and kinship for arbitrary population structures." PLoS Genet 17(1): e1009241. PubMed ID 33465078. doi:10.1371/journal.pgen.1009241. bioRxiv doi:10.1101/083923 2016-10-27.

Alejandro Ochoa, John D Storey. 2019. "New kinship and FST estimates reveal higher levels of differentiation in the global human population." bioRxiv doi:10.1101/653279.

Alejandro Ochoa, John D Storey. 2016. "FST And Kinship for Arbitrary Population Structures I: Generalized Definitions." bioRxiv doi:10.1101/083915.

Metadata

Version

1.3.23

License

Unknown

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows