R/ancestry_split.R
split_haplotype_multi.RdGeneralises split_haplotype to an arbitrary number of ancestries.
Each haplotype's allele is routed to the dosage pool whose code matches its
local ancestry call. Haplotypes with unrecognised codes contribute 0 to
all pools. NA genotypes are treated as 0 (reference allele).
split_haplotype_multi(
gt_hap0,
gt_hap1,
anc_hap0,
anc_hap1,
pop_codes = c(AFR = 0L, EUR = 1L)
)Integer matrix (variants x samples) of haplotype-0 alleles (0/1).
Integer matrix (variants x samples) of haplotype-1 alleles (0/1).
Integer matrix (variants x samples) of haplotype-0 ancestry codes.
Integer matrix (variants x samples) of haplotype-1 ancestry codes.
Named integer vector mapping population label to ancestry code,
e.g. c(AFR = 0L, EUR = 1L, NAT = 2L). Codes must match those used
in the MSP file (RFMix default: 0-based integers).
Named list of K numeric matrices (variants x samples), one per
entry in pop_codes, in the same order. List names equal the
names of pop_codes.
For the two-population case split_haplotype_multi and split_haplotype
are equivalent; prefer split_haplotype_multi for new code that may later
be extended to three or more ancestries.
split_haplotype for the two-population convenience wrapper,
split_diploid for unphased (diploid-code) splitting.
# Three-population panel: AFR=0, EUR=1, NAT=2
gt0 <- matrix(c(1L, 0L, 0L, 1L, 1L, 0L), nrow = 3, ncol = 2)
gt1 <- matrix(c(0L, 1L, 1L, 0L, 0L, 1L), nrow = 3, ncol = 2)
a0 <- matrix(c(0L, 1L, 2L, 0L, 1L, 2L), nrow = 3, ncol = 2)
a1 <- matrix(c(1L, 2L, 0L, 2L, 0L, 1L), nrow = 3, ncol = 2)
out <- split_haplotype_multi(gt0, gt1, a0, a1, c(AFR = 0L, EUR = 1L, NAT = 2L))
names(out) # "AFR" "EUR" "NAT"
#> [1] "AFR" "EUR" "NAT"
out$NAT # native-ancestry dosage matrix
#> [,1] [,2]
#> [1,] 0 0
#> [2,] 1 0
#> [3,] 0 0