Portfolio › Ancestry estimation
Population Structure · LEA

Population Structure and Ancestry Estimation in Barley Using LEA

Use LEA's sNMF algorithm in R to evaluate candidate ancestry cluster numbers, compare cross-entropy, and visualize estimated ancestry proportions from a barley SNP panel.

LEAsNMFCross-entropyQ matrix

Admixture analysis estimates each individual's ancestry proportions under a specified number of ancestral clusters, (K). Here, LEA's sNMF algorithm is used to evaluate candidate values of (K) with cross-entropy and to extract a Q matrix for a selected run.

The lowest cross-entropy value is a useful model-selection criterion, but it should not be interpreted as definitive proof of the biological number of populations. Repeat runs and biological context matter.

01

Analysis workflow

VCF conversion → sNMF → cross-entropy → Q matrix

VCF
Genotypes
→
.geno
LEA input
→
sNMF
K = 1–5
→
Q matrix
Ancestry
R

R code

Run candidate K values and extract a Q matrix

R · LEA / sNMF
library(LEA)

# Convert VCF genotypes to LEA's .geno format
vcf2geno(vcf_file, output = geno_file)

# Fit multiple repetitions for candidate K values
project <- snmf(geno_file, K = 1:5, entropy = TRUE,
                repetitions = 10, project = "new")

# Inspect cross-entropy to compare candidate K values
plot(project, col = "#2d5c42", pch = 19, type = "b",
     xlab = "Number of ancestral clusters (K)",
     ylab = "Cross-entropy")

# We will select K = 2 for this analysis
selected_K <- 2
ce <- cross.entropy(project, K = selected_K)
best_run <- which.min(ce)

# Extract estimated ancestry proportions
qmatrix <- Q(project, K = selected_K, run = best_run)
q_df <- as.data.frame(qmatrix)
names(q_df) <- paste0("Ancestry_", seq_len(ncol(q_df)))

# Preserve individual IDs separately from the Q matrix.
# Confirm row order against the genotype samples before joining!
write.csv(q_df, "barley_Q_matrix.csv", row.names = FALSE)

# Ancestry bar plot from the selected LEA run
my_colors <- c("#2d5c42", "#c8a84b")
barchart(project, K = selected_K, run = best_run,
         border = NA, space = 0, col = my_colors,
         sort.by.Q = TRUE,
         xlab = "Individuals (sorted by ancestry)",
         ylab = "Ancestry proportions",
         main = paste("Barley population structure (K =", selected_K, ")"))
FIG

Model selection and ancestry results

Cross-entropy and the K = 2 ancestry bar plot

Cross-entropy by candidate number of ancestral populations K from 1 to 5
Cross-entropy across the candidate values of K tested in this project. Select K based on the lowest cross-entropy supported by repeated-run stability and biological interpretability. Since the displayed curve continues to decrease through K = 5, it does not by itself support selecting K = 2; consider testing a wider K range before finalizing the model.
Estimated ancestry proportions for barley individuals under K equals 2
Illustrative ancestry proportions from the displayed K = 2 LEA run. Each vertical bar represents an individual and coloured segments represent estimated ancestry components. Treat this as the output for the selected run, not proof that K = 2 is optimal; confirm the chosen K from cross-entropy, run stability, and biological context.
02

Interpretation

Reading the Q matrix responsibly

  • Each row of the Q matrix represents one individual; each column is an estimated ancestry component.
  • Values across a row should sum approximately to 1.
  • Mixed proportions suggest assignment across inferred components under the fitted model; they are not direct estimates of pedigree percentages.
  • For GWAS, align Q rows to genotype and phenotype identifiers explicitly. Never assume row order is unchanged after filtering.
REF

Reproducibility notes

⚠️
Track sample order

The LEA Q matrix does not automatically carry the VCF sample names as a regular data-frame column. Save the sample IDs in the same order as the rows used to build the .geno file, then validate that mapping before using ancestry covariates in GAPIT.