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
)

Arguments

path

Character. Path to the folder containing PLINK files.

prefix

Character. File prefix (without extension). The function will look for `<prefix>.bed`, `<prefix>.bim`, and `<prefix>.fam` in `path`.

admixture_path

Character. Path to the ADMIXTURE executable, or "admixture" if in system PATH. Default is "admixture".

K

Integer. Number of ancestral populations to estimate.

supervised

Logical. If TRUE, runs ADMIXTURE in supervised mode (requires pop_assignments). Default is FALSE.

pop_assignments

Character vector. Population assignments for each individual (length equal to number of individuals in `.fam`). Use NA or "-" for missing. Required if supervised = TRUE.

extra_args

Character vector. Additional arguments to pass to ADMIXTURE (e.g., other flags). Default is NULL.

out_prefix

Character. Optional prefix for renaming output files (.Q, .P, .log) after the run completes. Default is NULL.

cv

Integer. Number of folds for cross-validation (e.g., 5 or 10). If provided, adds --cv=cv. Default is NULL.

Value

No value returned. Runs ADMIXTURE as a side effect. Generates output files in the specified directory. Messages indicate progress and output file names.

Details

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.

Examples

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"
)
} # }