Build Multi-allelic Additive Genomic Relationship Matrix

Build Multi-allelic Additive Genomic Relationship Matrix

Description

Constructs the multi-allelic additive genomic relationship matrix following Da (2015). Uses multi-allelic haplotype block coding (\(W_{ah}\)) that captures haplotype diversity beyond what bi-allelic SNPs can represent. The resulting matrix can be used in masreml() or gwablup() via the G argument.

Usage

build_G_mh(mh_list, ref_mh = NULL, ids = NULL)

Arguments

mh_list

list of data.frames (one per chromosome) or integer matrix (n x n_blocks2). Two input modes are supported:

  • List of data.frames: First column = individual IDs, remaining columns = paired haplotype allele codes per block (strand1_block1, strand2_block1, …). Allele codes must be 0-based sequential integers.

  • Haplotype matrix: integer matrix (n x n_blocks

2), columns alternate strand1/strand2 per block. Allele codes can be any integer (sparse, non-sequential) — re-encoded internally to sequential 0-based using training reference (ref_mh). Example matrix format (50 blocks → 100 columns):

  hap_block_all  # n x (n_blocks*2), cols: s1_b1, s2_b1, s1_b2, s2_b2, ...
  
ref_mh reference haplotype data for training-based allele frequencies. Same format as mh_list. If provided, allele frequencies and dropped allele (most frequent) are estimated from ref_mh only, avoiding data leakage from test individuals. If NULL, frequencies are computed from all individuals in mh_list.
ids character vector of individual IDs for alignment. Required when mh_list is a haplotype matrix without rownames.

Details

Multi-allelic additive GRM (Da, 2015). For individual \(i\) with phased alleles \((A_i, A_j)\) at haplotype block \(h\), the column corresponding to non-baseline allele \(k\) (with population frequency \(p_k\)) is coded as:

Homozygous (\(A_i = A_j = k\)):
\(W_{\alpha h}^{(k)} = -2(1 - p_k)\)
Heterozygous (\(A_i = k\) or \(A_j = k\)):
\(W_{\alpha h}^{(k)} = -(1 - 2p_k)\)
Absent (\(A_i \neq k\) and \(A_j \neq k\)):
\(W_{\alpha h}^{(k)} = 2p_k\)

Rare alleles receive larger absolute deviations; common alleles receive smaller deviations. The population column-mean is zero by construction, ensuring the additive effects sum to zero across individuals.

The additive multi-allelic GRM is then:

A_{gh} = , k_{ah} =

where \(n\) is the number of individuals and \(k_{ah}\) scales the matrix so that diagonal elements average approximately 1.

Value

numeric matrix (n x n) of microhaplotype-based genomic relationships. Same interpretation as SNP additive G matrix but based on haplotype block diversity.

References

Da, Y. (2015) Multi-allelic haplotype model based on genetic partition for genomic prediction and variance component estimation using SNP markers. BMC Genetics 16:144. doi:10.1186/s12863-015-0301-1

See Also

build_G_snp, masreml, run_gwas

Examples

Code
library("masreml")

d <- load_data("small")
# d$mh is a haplotype matrix consumable directly via auto-detection.
G_mh <- build_G_mh(d$mh)
dim(G_mh)
# Diagonal ~ 1 + inbreeding coefficient
round(summary(diag(G_mh)), 3)

# Train-only G with leakage-safe full-set G for prediction
G_mh_full <- build_G_mh(
  mh_list = d$mh,
  ref_mh  = d$mh[d$train_idx, ],
  ids     = d$pheno$id
)
dim(G_mh_full)