Type: | Package |
Title: | Pedigree Functions |
Version: | 1.4.2 |
Date: | 2022-08-13 |
Depends: | Matrix |
Imports: | methods,HaploSim (≥ 1.8.4),reshape |
Description: | Pedigree related functions. |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
Author: | Albart Coster [aut, cre] |
Maintainer: | Albart Coster <albart@dairyconsult.nl> |
NeedsCompilation: | yes |
Packaged: | 2022-08-13 20:25:52 UTC; Gebruiker |
Repository: | CRAN |
Date/Publication: | 2022-08-13 20:50:02 UTC |
Package to deal with pedigree data
Description
Package with functions to analyse and transform pedigree data. A
pedigree is a data.frame
where the first column contains an
ID, and the second and third columns contain ID of first and second parent.
Author(s)
Albart Coster: <albart.coster@wur.nl>
See Also
trimPed
orderPed
countGen
makeA
makeAinv
calcInbreeding
add.Inds
Function to add missing individuals to a pedigree
Description
Function add.Inds() adds missing individuals to a pedigree and returns the
complete pedigree as a data.frame with the same headers as the
original pedigree. Remeber to check for errors beforehand with
function errors.ped
. Unknown parents should be coded as NA.
Usage
add.Inds(ped)
Arguments
ped |
|
Value
data.frame of three columns with identical header as input.
Author(s)
Albart Coster, Albart.Coster@wur.nl
See Also
Examples
ID <- 3:5
DAM <- c(1,1,3)
SIRE <- c(2,2,4)
pedigree <- data.frame(ID,DAM,SIRE)
pedigree <- add.Inds(pedigree)
Function to calculate breeding values using an animal model
Description
Fit an animal model to data, use a given variance ratio
(\alpha = \frac{\sigma^2_e}{\sigma^ 2_a}
). Calculate inverse of the
additive genetic relationship matrix using function makeInv()
of this package.
Usage
blup(formula, ped, alpha,trim = FALSE)
Arguments
formula |
formula of the model, do not include the random effect due to animal (generally ID). |
ped |
|
alpha |
Variance ratio ( |
trim |
If |
Value
Vector of solutions to the model, including random animal effects.
See Also
SamplePedigree
, gblup
,
makeAinv
,blup
Examples
example(gblup)
sol <- blup(P~1,ped = ped,alpha = 1/h2 - 1)
Function to calculate a relationship matrix from marker data (usually allele count data), G matrix.
Description
Function to calculate a relationship matrix from marker data. Option
to return the inverse of matrix. Inverse calculated using
Matrix
package.
Usage
calcG(M, data = NULL,solve = FALSE)
Arguments
M |
Matrix of marker genotypes, usually the count of one of the two SNP alleles at each markers (0, 1, or 2). |
data |
Optional logical vector which can tell of which individuals we have phenotypes. |
solve |
Logic, if TRUE then function returns the inverse of the relationship matrix. |
Value
Matrix of class dgeMatrix
.
See Also
SamplePedigree
, gblup
,
makeAinv
,blup
Examples
example(gblup)
G <- calcG(M)
Ginv <- calcG(M,solve = TRUE)
Calculates inbreeding coefficients for individuals in a pedigree.
Description
Calculates inbreeding coefficients of individuals in a pedigree.
Usage
calcInbreeding(ped)
Arguments
ped |
|
Value
Logical.
Examples
id <- 1:6
dam <- c(0,0,1,1,4,4)
sire <- c(0,0,2,2,3,5)
ped <- data.frame(id,dam,sire)
(F <- calcInbreeding(ped))
Count generation number for each individual in a pedigree.
Description
Counts generation number for individuals in a pedigreee.
Usage
countGen(ped)
Arguments
ped |
|
Value
Numeric vector
Examples
id <- 1:5
dam <- c(0,0,1,1,4)
sire <- c(0,0,2,2,3)
ped <- data.frame(id,dam,sire)
(gens <- countGen(ped))
Function that counts the number of offspring (and following generations for each individual in a pedigree.
Description
Function to count the number of offspring for each individual in a pedigree. With loops, offspring of later generations will be counted several times.
Usage
countOff(ped)
Arguments
ped |
|
Value
Numeric vector with number of offspring for each individual in the pedigree.
Author(s)
Albart Coster
Examples
example(countGen)
countOff(ped)
Function to calculate breeding values using an animal model and a relationship matrix calculated from the markers (G matrix)
Description
Fit an animal model to data, use a given variance ratio
(\alpha = \frac{\sigma^2_e}{\sigma^ 2_a}
). Calculate genetic
relationship matrix using the function calcG
of this package.
Usage
gblup(formula, data, M, lambda)
Arguments
formula |
formula of the model, do not include the random effect due to animal (generally ID). |
data |
|
M |
Matrix of marker genotypes, usually the count of one of the two SNP alleles at each markers (0, 1, or 2). |
lambda |
Variance ratio ( |
Value
Vector of solutions to the model, including random animal effects.
See Also
SamplePedigree
, gblup
,
makeAinv
,blup
Examples
## Example Code from SampleHaplotypes
hList <- HaploSim::SampleHaplotypes(nHaplotypes = 20,genDist =
1,nDec = 3,nLoc = 20) ## create objects
h <- HaploSim::SampleHaplotype(H0 = hList[[1]],H1 = hList[[2]],genDist =
1,nDec = 3)
## code from the Example SamplePedigree
ID <- 1:10
pID0 <- c(rep(0,5),1,1,3,3,5)
pID1 <- c(rep(0,4),2,2,2,4,4,6)
ped <- data.frame(ID,pID0,pID1)
phList <- HaploSim::SamplePedigree(orig = hList,ped = ped)
## own code
h2 <- 0.5
ped <- phList$ped
hList <- phList$hList
qtlList <- HaploSim::ListQTL(hList = hList,frqtl = 0.1,sigma2qtl = 1)
qtl <- tapply(unlist(qtlList),list(rep(names(qtlList),times = unlist(lapply(qtlList,length))),
unlist(lapply(qtlList,function(x)seq(1,length(x))))),mean,na.rm = TRUE)
qtl <- reshape::melt(qtl)
names(qtl) <- c("POS","TRAIT","a")
HH <- HaploSim::getAll(hList,translatePos = FALSE)
rownames(HH) <- sapply(hList,function(x)x@hID)
QQ <- HH[,match(qtl$POS,colnames(HH))]
g <- QQ
ped$G <- with(ped,g[match(hID0,rownames(g))]+g[match(hID1,rownames(g))])
sigmae <- sqrt(var(ped$G)/h2 - var(ped$G))
ped$P <- ped$G + rnorm(nrow(ped),0,sigmae)
M <- with(ped,HH[match(hID0,rownames(HH)),] + HH[match(hID1,rownames(HH)),])
rownames(M) <- ped$ID
sol <- gblup(P~1,data = ped[,c('ID','P')],M = M,lambda = 1/h2 - 1)
Makes the A matrix for a part of a pedigree
Description
Makes the A matrix for a part of a pedigree and stores it in a file called
A.txt
.
Usage
makeA(ped,which)
Arguments
ped |
|
which |
Logical vector specifying between which indiduals additive genetic relationship is required. Goes back through the whole pedigree but only for subset of individuals. |
Value
Logical.
Examples
id <- 1:6
dam <- c(0,0,1,1,4,4)
sire <- c(0,0,2,2,3,5)
ped <- data.frame(id,dam,sire)
makeA(ped,which = c(rep(FALSE,4),rep(TRUE,2)))
A <- read.table("A.txt")
if(file.exists("A.txt"))
file.remove("A.txt")
Makes inverted A matrix for a pedigree
Description
Makes inverted A matrix for a pedigree and stores it in a file called
Ainv.txt
.
Usage
makeAinv(ped)
Arguments
ped |
|
Value
Logical.
Examples
id <- 1:6
dam <- c(0,0,1,1,4,4)
sire <- c(0,0,2,2,3,5)
ped <- data.frame(id,dam,sire)
makeAinv(ped)
Ai <- read.table('Ainv.txt')
nInd <- nrow(ped)
Ainv <- matrix(0,nrow = nInd,ncol = nInd)
Ainv[as.matrix(Ai[,1:2])] <- Ai[,3]
dd <- diag(Ainv)
Ainv <- Ainv + t(Ainv)
diag(Ainv) <- dd
if(file.exists("Ainv.txt"))
file.remove("Ainv.txt")
Orders a pedigree
Description
Orders a pedigree so that offspring follow parents.
Usage
orderPed(ped)
Arguments
ped |
|
Value
numerical vector
Examples
id <- 1:6
dam <- c(0,0,1,1,4,4)
sire <- c(0,0,2,2,3,5)
pedigree <- data.frame(id,dam,sire)
(ord <- orderPed(pedigree))
pedigree <- pedigree[6:1,]
(ord <- orderPed(pedigree))
pedigree <- pedigree[order(ord),]
pwrong <- pedigree
pwrong[1,2] <- pwrong[6,1]
Function to trim a pedigree based on available data
Description
Trims a pedigree given a vector of data. Branches without data are trimmed off the pedigree.
Usage
trimPed(ped, data,ngenback = NULL)
Arguments
ped |
|
data |
TRUE-FALSE vector. Specifies if data for an individual is available. |
ngenback |
Number of generations back. Specifies the number of generations to keep before the individuals with data. |
Value
Logical vector specifying if an individual should stay in the pedigree.
Examples
id <- 1:5
dam <- c(0,0,1,1,4)
sire <- c(0,0,2,2,3)
data <- c(FALSE,FALSE,TRUE,FALSE,FALSE)
ped <- data.frame(id,dam,sire)
yn <- trimPed(ped,data)
ped <- ped[yn,]