The basis of genetic likeness
Overview
We will learn how to compute an additive relationship matrix from pedigree using the tabular method.
Reading file
Use the function read_excel
in the readxl
package to read the pedigree file (Simdata.xlsx) in a data frame format.
install.packages("readxl")
library(readxl)
dat <- read_excel(file.choose())
dim(dat)
head(dat)
synbreed package
The synbreed package includes the function kin
for computing a relationship matrix. Learn more about the Synbreed project. The kin
function requires the object of class gpData for inputs.
install.packages("synbreed")
library(synbreed)
gp.ped <- create.pedigree(ID=dat$Animal, Par1=dat$Sire, Par2=dat$Dam, unknown = "0")
head(gp.ped)
gpData<- create.gpData(pedigree = gp.ped)
class(gpData)
We can obtain an additive relationship matrix by setting the argument ret
equals to add
.
A1 <- kin(gpData, ret = "add")
dim(A1)
table(colnames(A1) == rownames(A1))
One thing we need to be cautious of is that the kin
function does not retrain the original order.
head(colnames(A1))
head(dat$Animal)
This brings up a problem when we want to link phenotypic values to the A matrix because animals appear in a different order. So let’s keep the original order of animal IDs in the dat
object.
index <- match(dat$Animal, rownames(A1))
A <- A1[index, index]
dim(A)
The A
object is a reordered A matrix where animals appear in the same order as that of the dat
object.
head(rownames(A))
head(dat$Animal)
table(dat$Animal == rownames(A))
table(dat$Animal == colnames(A))
Exercise 1
Compute the inbreeding coefficients of animals and report the average of inbreeding coefficients. Use the function diag
.
kinship2 package
Alternatively, we can use the kinship2
package to compute a relationship matrix. The kinship
function returns the coefficient of kinship.
install.packages("kinship2")
library(kinship2)
A2 <- kinship(dat$Animal, dat$Sire, dat$Dam)
dim(A2)
table(colnames(A2) == rownames(A2))
table(dat$Animal == rownames(A2))
Exercise 2
Recall that the additive genetic relationship between a pair of individuals is equal to twice their coefficient of kinship. Verify this by comparing the last five animals in the A2
and A3
objects.
Save R object
Save the object A
so that we can reuse in the next class.
save(A, file = "A.Rda")