Portfolio › GAPIT GWAS
Association Mapping · R

Genome-Wide Association Analysis of Barley Leaf-Rust Resistance Using GAPIT3 in R

Analyze seedling and adult-plant leaf-rust resistance using GAPIT3 in R, with aligned phenotype, genotype, marker-map, and covariate inputs.

GAPITMLMFarmCPUBLINKSNP QC

This project runs a multi-trait GWAS workflow using a filtered SNP matrix and four barley leaf-rust phenotypes: SRT_MRC, SRT_SAT, APR_SAT17, and APR_SAT19. The code is organized around GAPIT's input conventions: phenotype table (Y), genotype dosage table (GD), marker map (GM), and optional covariates (CV).

The example follows the supplied analysis structure, but sample matching and Q-matrix row alignment must be checked before the model is run. The scripts must be tested against the installed GAPIT version and local input files.

01

Analysis workflow

Quality control → synchronized inputs → multi-model GWAS

VCF + traits
Import
→
SNP QC
MAF / missing
→
GD + GM + Y
Align taxa
→
GAPIT
Compare models
R

R code

Prepare GAPIT inputs from a vcfR object

R · GAPIT
library(vcfR)
library(dplyr)
library(stringr)
library(GAPIT)

# # # # 1. Import phenotypes
pheno <- read.csv("pheno.csv", sep = ";", stringsAsFactors = FALSE)


traits <- c("SRT_MRC", "SRT_SAT", "APR_SAT17", "APR_SAT19")
required_cols <- c("Taxa", "RowType", traits)

# 2. Read the actual VCF as a vcfR object
geno <- read.vcfR("5OK_AM17.vcf", verbose = FALSE)
stopifnot(inherits(geno, "vcfR"))

gt <- extract.gt(geno, element = "GT")
gt_numeric <- ifelse(gt %in% c("0/0", "0|0"), 0,
              ifelse(gt %in% c("0/1", "1/0", "0|1", "1|0"), 1,
              ifelse(gt %in% c("1/1", "1|1"), 2, NA_real_)))
gt_numeric <- matrix(as.numeric(gt_numeric), nrow = nrow(gt),
                     ncol = ncol(gt), dimnames = dimnames(gt))
genotype_taxa_all <- colnames(gt_numeric)

map <- data.frame(
  SNP = geno@fix[, "ID"],
  Chromosome = geno@fix[, "CHROM"],
  Position = as.numeric(geno@fix[, "POS"]),
  stringsAsFactors = FALSE
)

# 3. SNP QC: MAF >= 0.05 and missingness <= 0.10
maf <- apply(gt_numeric, 1, function(x) {
  p <- mean(x, na.rm = TRUE) / 2
  min(p, 1 - p)
})
snp_missing <- rowMeans(is.na(gt_numeric))
keep_snp <- is.finite(maf) & maf >= 0.05 & snp_missing <= 0.10
gt_qc <- gt_numeric[keep_snp, , drop = FALSE]
map_qc <- map[keep_snp, , drop = FALSE]

# 4. Filter individuals by missingness
keep_ind <- colMeans(is.na(gt_qc)) <= 0.10
gt_qc <- gt_qc[, keep_ind, drop = FALSE]
genotype_taxa <- colnames(gt_qc)

# 5. Synchronize phenotype and genotype IDs
common_taxa <- genotype_taxa[genotype_taxa %in% pheno$Taxa]
stopifnot(length(common_taxa) > 0)
pheno_gwas <- pheno[match(common_taxa, pheno$Taxa), , drop = FALSE]
stopifnot(identical(pheno_gwas$Taxa, common_taxa))
gt_qc <- gt_qc[, common_taxa, drop = FALSE]

# 6. Mean-impute missing SNP dosages after QC
for (i in seq_len(nrow(gt_qc))) {
  missing_i <- is.na(gt_qc[i, ])
  if (any(missing_i)) {
    gt_qc[i, missing_i] <- mean(gt_qc[i, ], na.rm = TRUE)
  }
}

# 7. Build GAPIT Y, GD and GM tables
my_Y <- pheno_gwas[, c("Taxa", traits), drop = FALSE]
my_GD <- as.data.frame(t(gt_qc), check.names = FALSE)
my_GD <- cbind(Taxa = rownames(my_GD), my_GD)
rownames(my_GD) <- NULL
my_GM <- map_qc
colnames(my_GM) <- c("SNP", "Chromosome", "Position")

# 8. Import the LEA sNMF ancestry estimates and align them to sample IDs.
#    The Q-matrix rows must follow the original VCF genotype-sample order.
q_df <- read.csv("barley_Q_matrix.csv", stringsAsFactors = FALSE)
stopifnot(nrow(q_df) == length(genotype_taxa_all))
my_CV <- data.frame(
  Taxa = common_taxa,
  Ancestry_1 = q_df$Ancestry_1[match(common_taxa, genotype_taxa_all)]
)
stopifnot(!anyNA(my_CV$Ancestry_1))

# 9. Execute multi-model GAPIT analysis
myGAPIT <- GAPIT(
  Y = my_Y,                            # Phenotype dataframe (Taxa + Traits)
  GD = my_GD,                          # Genotype dataframe (Taxa + SNPs)
  GM = my_GM,                          # SNP Map dataframe (SNP + Chrom + Pos)
  CV = my_CV,                          # Fixed Covariates (sNMF Q1 column only) calculated with LEA package
  model = c("MLM", "FarmCPU", "Blink"), # High-performance GWAS models
  PCA.total = 0,                       # Set to 0 because we explicitly provide sNMF structure via CV
  Multiple_analysis = TRUE,            # Enables seamless loop across all 4 traits
  file.output = TRUE                   # Save Manhattan/QQ plots directly to your setwd()
)
FIG

GWAS results: Manhattan plots

GAPIT association results across four leaf-rust traits

The following figures are the association plots supplied for this GAPIT-in-R project: APR-SAT17, APR-SAT19, SRT-MRC, and SRT-SAT. Confirm the trait labels, model used to generate each plot, and the significance threshold against the analysis outputs before describing any marker as significant.

Manhattan plot for APR-SAT17
APR-SAT17 — adult-plant resistance phenotype from the 2016–2017 field season.
Manhattan plot for APR-SAT19
APR-SAT19 — adult-plant resistance phenotype from the 2018–2019 field season.
GAPIT Manhattan plot for seedling resistance to the SRT-MRC isolate
SRT-MRC — seedling resistance to the MRC isolate. The image filename is retained for compatibility with the existing project asset.
Manhattan plot for SRT-SAT
SRT-SAT — seedling resistance to the SAT isolate.
02

Model interpretation

Use complementary models, not just the smallest p-value

  • MLM: accounts for relatedness through a kinship matrix; model configuration should be checked for the installed GAPIT version.
  • FarmCPU and BLINK: multi-locus approaches that can complement the mixed model.
  • Review QQ plots, Manhattan plots, effect sizes, marker quality, and consistency across traits/models.
  • Control multiple testing and distinguish exploratory associations from independently validated markers.
REF

Reproducibility notes

⚠️
Important scientific checks

This GAPIT workflow uses LEA sNMF ancestry estimates as a population-structure covariate. Align every Q-matrix row to the genotype and phenotype sample IDs explicitly. Also verify GT encoding, multiallelic variants, chromosome labels, marker-map positions, and GAPIT input columns for your installed version.