This function runs the ADMIXTURE program on a set of PLINK files (.bed/.bim/.fam) located in a specified directory, using a given file prefix. It supports both unsupervised and supervised analyses, optional cross-validation, and custom output file prefixes to avoid overwriting results.
run_admixture(
path,
prefix,
admixture_path = "admixture",
K,
supervised = FALSE,
pop_assignments = NULL,
extra_args = NULL,
out_prefix = NULL,
cv = NULL
)Character. Path to the folder containing PLINK files.
Character. File prefix (without extension). The function will look for `<prefix>.bed`, `<prefix>.bim`, and `<prefix>.fam` in `path`.
Character. Path to the ADMIXTURE executable, or "admixture" if in system PATH. Default is "admixture".
Integer. Number of ancestral populations to estimate.
Logical. If TRUE, runs ADMIXTURE in supervised mode (requires pop_assignments). Default is FALSE.
Character vector. Population assignments for each individual (length equal to number of individuals in `.fam`). Use NA or "-" for missing. Required if supervised = TRUE.
Character vector. Additional arguments to pass to ADMIXTURE (e.g., other flags). Default is NULL.
Character. Optional prefix for renaming output files (.Q, .P, .log) after the run completes. Default is NULL.
Integer. Number of folds for cross-validation (e.g., 5 or 10). If provided, adds --cv=cv. Default is NULL.
No value returned. Runs ADMIXTURE as a side effect. Generates output files in the specified directory. Messages indicate progress and output file names.
When supervised = TRUE, a `.pop` file is automatically created in the specified directory.
Each line in this file corresponds to one individual, containing the population name or "-" for missing assignments.
If out_prefix is provided, the function renames the standard ADMIXTURE output files
(e.g., `<prefix>.3.Q`) to use this prefix (e.g., `myrun.Q`).
The function only works on Linux or macOS systems.
if (FALSE) { # \dontrun{
# Requires the external ADMIXTURE binary and PLINK files prepared beforehand.
work_dir <- file.path(tempdir(), "admixture_demo")
run_admixture(
path = work_dir,
prefix = "plink_data",
admixture_path = "admixture",
K = 3,
out_prefix = "run1_k3"
)
pop_vec <- c("A", "A", "B", "B", "-", "-", "A", "B", "A", "-")
run_admixture(
path = work_dir,
prefix = "plink_data",
admixture_path = "admixture",
K = 3,
supervised = TRUE,
pop_assignments = pop_vec,
cv = 10,
out_prefix = "supervised_k3_cv10"
)
} # }