# 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)
# Run clustering on the first 10 PCs
gt_cluster_pca(
x = pca,
n_pca = 10,
k_clusters = c(1, 5),
method = "kmeans",
n_iter = 1e5,
n_start = 10,
quiet = FALSE
)
# Alternatively, use method "ward"
gt_cluster_pca(
x = pca,
n_pca = 10,
k_clusters = c(1, 5),
method = "ward",
quiet = FALSE
)
Run the code above in your browser using DataLab