Given a data frame D in the format of long_markers, this function creates the matrix X_l for each locus, given all the values of kappa supplied as rows in a matrix like that in kappas. The rows and columns refer to genotypes that are in the order given in the function index_ab.

long_markers_to_X_l_list(D, kappa_matrix, allele_separator = " / ")

Arguments

D

a data frame in the format of long_markers. Monomorphic loci should have been removed and the whole thing run through reindex_markers before passing it to this function.

kappa_matrix

A matrix like that in the supplied data kappas. It should have three columns, and rownames giving the abbreviated name of the pairwise relationship. Each row is a three-vector which are the Cotterman coefficients for the relationship. The first element is the probability that the pair shares 0 gene copies IBD, the second is the prob that they share 1 gene copy IBD, and the third is the prob that they share 2 gene copies IBD, all assuming no inbreeding.

allele_separator

This string is used to separate allele names in the names of genotypes. By default it is " / ". This should not get confused by any elements in actual allele names, as long as the allele names don't have any spaces in them. This gets used to parse the genotype names down the road.

Value

This returns a named list. The names of the components are the Chrom.Locus.Pos of the marker in D. The contents of each list component is a list that includes the allele frequencies (as a vector named with the Allele names), and also another list of matrices with nA * (nA+1) / 2 rows and columns. The rows and columns of this matrix are named by the genotypes.

Examples

data(kappas)
lm_example <- long_markers_to_X_l_list(long_markers[1:18,], kappa_matrix = kappas)
mh_example <- long_markers_to_X_l_list(microhaps, kappa_matrix = kappas)