Learn R Programming

tidypopgen (version 0.4.3)

gt_pcadapt: 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)

Value

An object of subclass gt_pcadapt, a subclass of mhtest.

Arguments

x

A gen_tibble object.

pca

a gt_pca object, as returned by gt_pca_partialSVD() or gt_pca_randomSVD().

k

Number of principal components to use in the analysis.

n_cores

Number of cores to use.

Details

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

References

Luu, K., Bazin, E., Blum, M. G. B., & François, O. (2017). pcadapt: an R package for genome scans for selection based on principal component analysis. Molecular Ecology Resources, 17(1), 67–77.

See Also

bigsnpr::snp_pcadapt() which this function wraps.

Examples

Run this code
if (FALSE) { # all(rlang::is_installed(c("RhpcBLASctl", "data.table")))
# \dontshow{
data.table::setDTthreads(2)
RhpcBLASctl::blas_set_num_threads(2)
RhpcBLASctl::omp_set_num_threads(2)
# }
# 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 and impute
lobsters <- lobsters %>% select_loci_if(loci_maf(genotypes) > 0)
lobsters <- gt_impute_simple(lobsters, method = "mode")

# Create PCA object
pca <- gt_pca_partialSVD(lobsters)

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

Run the code above in your browser using DataLab