gt_pcadapt: pcadapt analysis on a 'gen_tibble' object

View source: R/gt_pcadapt.R

gt_pcadaptR Documentation

pcadapt analysis on a gen_tibble object

Description

pcadapt is an algorithm that detects genetic markers under selection. It is based on the principal component analysis (PCA) of the genotypes of the individuals. The method is described in Luu et al. (2017). See the R package pcadapt, which provides extensive documentation and examples.

Usage

gt_pcadapt(x, pca, k, n_cores = 1, max_missing = 0.5)

Arguments

x

A gen_tibble object.

pca

a gt_pca object, as returned by gt_pca(), of the individuals of x (see Details for missing genotypes).

k

Number of principal components to use in the analysis.

n_cores

Number of cores to use.

max_missing

the largest fraction of missing genotypes at a locus for it to be tested (see Details); loci with more get NA statistics. Default is 0.5. The fraction is that given by loci_missingness() without imputed genotypes; it is zero when the imputed genotypes are used (with a PCA of complete or imputed genotypes, see Details).

Details

Internally, this function uses the snp_pcadapt function from the bigsnpr package.

The genotypes tested are those that the PCA was computed on:

  • with a PCA of genotypes with missing values (the default method of gt_pca(), which compares individuals over the loci genotyped in both, as PLINK does), the genotypes of x with their missing values; imputed genotypes are not used.

  • with a PCA of complete or imputed genotypes, the imputed genotypes of x if it has any (see gt_impute_simple(); they are used automatically), and otherwise its genotypes with their missing values.

With missing genotypes, each locus is tested on the individuals genotyped at it, as in the pcadapt package. Loci with more than a fraction max_missing of their genotypes missing (by default, more than half), or genotyped in fewer than 3 individuals (the minimum for a t-score), are not tested, and get NA statistics: with few individuals genotyped, their t-scores have heavy tails, which the normal approximation of bigsnpr turns into tiny p-values at the top of the rankings of the loci.

Loci with the same genotype in every individual genotyped can not be tested, and give an error.

Value

An object of subclass gt_pcadapt, a subclass of mhtest.

References

Luu, K., Bazin, E., & Blum, M. G. B. (2017). pcadapt: an R package to perform genome scans for selection based on principal component analysis. Molecular Ecology Resources, 17(1), 67–77. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1111/1755-0998.12592")}

See Also

bigsnpr::snp_pcadapt() which this function wraps.

Examples



# Create a gen_tibble of lobster genotypes
bed_file <-
  system.file("extdata", "lobster", "lobster.bed", package = "tidypopgen")
lobsters <- gen_tibble(bed_file,
  backingfile = tempfile("lobsters"),
  quiet = TRUE
)

# Remove monomorphic loci
lobsters <- lobsters %>% select_loci_if(loci_maf(genotypes) > 0)

# Create PCA object (the lobsters have some missing genotypes, which do not
# need to be imputed)
pca <- gt_pca(lobsters)

# Create a gt_pcadapt object
gt_pcadapt(lobsters, pca, k = 2)


tidypopgen documentation built on Nov. 28, 2026, 1:07 a.m.