Title: | Pedigree and Genetic Groups |
---|---|
Description: | Calculates additive and dominance genetic relationship matrices and their inverses, in matrix and tabular-sparse formats. It includes functions for checking and processing pedigree, calculating inbreeding coefficients (Meuwissen & Luo, 1992 <doi:10.1186/1297-9686-24-4-305>), as well as functions to calculate the matrix of genetic group contributions (Q), and adding those contributions to the genetic merit of animals (Quaas (1988) <doi:10.3168/jds.S0022-0302(88)79691-5>). Calculation of Q is computationally extensive. There are computationally optimized functions to calculate Q. |
Authors: | Mohammad Ali Nilforooshan [aut, cre] |
Maintainer: | Mohammad Ali Nilforooshan <[email protected]> |
License: | GPL-3 |
Version: | 2.1.2 |
Built: | 2024-11-18 05:24:06 UTC |
Source: | https://github.com/nilforooshan/ggroups |
This package contains pedigree processing and analyzing functions, including functions for checking and renumbering the pedigree, making the additive and dominance pedigree relationship matrices and their inverses, in matrix and tabular formats, calculating inbreeding coefficients, as well as functions related to genetic groups.
First, it is recommended to check the pedigree data.frame
with the pedcheck
function. Pedigree relationship matrix and its inverse are fundamentals in the conventional and modern animal breeding. The concept of genetic groups stems from the fact that not all the unknown parents are of the same genetic level. The genetic group contribution matrix (Q) is required to weight and add genetic group effects (ĝ) to the genetic merit of animals (û), which is equal to Qĝ + û (Quaas, 1988). Calculating Q is computationally challenging, and for large pedigree, large RAM and long computational time is required. Therefore, the functions qmatL
and its parallel version, qmatXL
are introduced. Overlap between sire and dam genetic groups is supported.
Mohammad Ali Nilforooshan [email protected]
Meuwissen, T. and Luo, Z. 1992. Computing Inbreeding Coefficients in Large Populations. Genet. Sel. Evol., 24:305. <doi:10.1186/1297-9686-24-4-305>
Mrode, R. A. 2005. Linear Models for the Prediction of Animal Breeding Values, 2nd ed. Cambridge, MA: CABI Publishing.
Quaas, R. L. 1988. Additive Genetic Model with Groups and Relationships. J. Dairy Sci., 71:1338-1345. <doi:10.3168.jds.S0022-0302(88)79691-5>
Builds the pedigree-based additive genetic relationship matrix.
buildA(ped)
buildA(ped)
ped |
: |
Relationship matrix
A
ped = data.frame(ID=1:6, SIRE=c(0,0,1,3,1,4), DAM=c(0,0,2,2,2,5)) buildA(ped)
ped = data.frame(ID=1:6, SIRE=c(0,0,1,3,1,4), DAM=c(0,0,2,2,2,5)) buildA(ped)
Builds the pedigree-based dominance relationship matrix.
buildD(ped, A)
buildD(ped, A)
ped |
: |
A |
: Relationship matrix A created by function |
Relationship matrix
D
ped = data.frame(ID=1:6, SIRE=c(0,0,1,3,1,4), DAM=c(0,0,2,2,2,5)) buildD(ped, buildA(ped))
ped = data.frame(ID=1:6, SIRE=c(0,0,1,3,1,4), DAM=c(0,0,2,2,2,5)) buildD(ped, buildA(ped))
This function appends parents that are not available in the first column of the pedigree, to the head of the pedigree, and sorts it. Given a pedigree with all missing parents replaced with the corresponding genetic groups, this functions appends genetic groups to the head of the pedigree.
gghead(ped)
gghead(ped)
ped |
: |
Consider this simple pedigree:
3 0 0
4 3 0
6 4 5
5 0 0
First, unknown parents are replaced with the corresponding genetic groups.
Please note that unknown parent IDs should be smaller than progeny IDs.
3 1 2
4 3 2
6 4 5
5 1 2
Then, gghead
is applied to this pedigree (see the example).
Processed pedigree data.frame
ped = data.frame(ID=c(3,4,6,5), SIRE=c(1,3,4,1), DAM=c(2,2,5,2)) gghead(ped)
ped = data.frame(ID=c(3,4,6,5), SIRE=c(1,3,4,1), DAM=c(2,2,5,2)) gghead(ped)
Calculates inbreeding coefficient for an individual.
inb(ped, id)
inb(ped, id)
ped |
: |
id |
: Numeric ID of an individual |
Inbreeding coefficient of the individual
ped = data.frame(ID=1:7, SIRE=c(0,0,1,1,3,1,5), DAM=c(0,0,0,2,4,4,6)) inb(ped, 7)
ped = data.frame(ID=1:7, SIRE=c(0,0,1,1,3,1,5), DAM=c(0,0,0,2,4,4,6)) inb(ped, 7)
Calculates inbreeding coefficients for all animals in the pedigree.
inbreed(ped)
inbreed(ped)
ped |
: |
Vector of inbreeding coefficients
ped = data.frame(ID=1:7, SIRE=c(0,0,1,1,3,1,5), DAM=c(0,0,0,2,4,4,6)) inbreed(ped)
ped = data.frame(ID=1:7, SIRE=c(0,0,1,1,3,1,5), DAM=c(0,0,0,2,4,4,6)) inbreed(ped)
Converts matrix data to tabular data.
mat2tab(mat)
mat2tab(mat)
mat |
: |
data.frame
with 2 integer (IDs) and 1 numeric (values) columns.
ped = data.frame(ID=1:6, SIRE=c(0,0,1,3,1,4), DAM=c(0,0,2,2,2,5)) mat2tab(buildA(ped))
ped = data.frame(ID=1:6, SIRE=c(0,0,1,3,1,4), DAM=c(0,0,2,2,2,5)) mat2tab(buildA(ped))
Counts and collects progeny and phenotyped progeny of an individual in successive generations. In pedigrees with generation overlap, animals are reported in the 1st generation that they appear in, rather than in multiple generations.
offspring(ped, id, pheno)
offspring(ped, id, pheno)
ped |
: |
id |
: The ID of the individual, for which the descendants to be extracted. |
pheno |
: Vector of phenotyped individuals. |
prgn : list
of progeny per generation.
prgn.ph : list
of phenotyped progeny per generation.
ped = data.frame(V1 = 1:19, V2 = c(0,0,1,1,0,0,0,0,0,4,5,5,7,0,0,9,0,0,12), V3 = c(0,0,0,2,0,2,0,3,3,3,0,6,8,8,8,10,11,11,0)) pheno = 10:18 # Find progeny and phenotyped progeny of individual 1. offspring(ped, 1, pheno) # Find phenotyped progeny of individual 1, in the 2nd generation. offspring(ped, 1, 10:18)$prgn.ph[[2]] # If only interested in finding the progeny of individual 1: offspring(ped, 1, c())$prgn
ped = data.frame(V1 = 1:19, V2 = c(0,0,1,1,0,0,0,0,0,4,5,5,7,0,0,9,0,0,12), V3 = c(0,0,0,2,0,2,0,3,3,3,0,6,8,8,8,10,11,11,0)) pheno = 10:18 # Find progeny and phenotyped progeny of individual 1. offspring(ped, 1, pheno) # Find phenotyped progeny of individual 1, in the 2nd generation. offspring(ped, 1, 10:18)$prgn.ph[[2]] # If only interested in finding the progeny of individual 1: offspring(ped, 1, c())$prgn
Performs basic pedigree checks.
pedcheck(ped)
pedcheck(ped)
ped |
: |
set.seed(127) ped = data.frame(ID=c(1:50,NA,0,1:3), SIRE=c(0, sample(c(0,10:25), 53, replace=TRUE), 51), DAM=c(0, NA, 52, sample(c(0,20:35), 52, replace=TRUE))) pedcheck(ped)
set.seed(127) ped = data.frame(ID=c(1:50,NA,0,1:3), SIRE=c(0, sample(c(0,10:25), 53, replace=TRUE), 51), DAM=c(0, NA, 52, sample(c(0,20:35), 52, replace=TRUE))) pedcheck(ped)
Extracts pedigree downward for one or a group of individuals to find their descendants
peddown(ped, parents, maxgen = c())
peddown(ped, parents, maxgen = c())
ped |
: |
parents |
: Vector of individual ID(s), from which the new pedigree is being extracted. |
maxgen |
: (optional) a positive integer for the maximum number of generations to proceed. If no value is provided, there is no limitation on the maximum number of generations to proceed. |
Extracted pedigree data.frame
ped = data.frame(ID=1:6, SIRE=c(0,0,1,3,1,4), DAM=c(0,0,2,2,2,5)) peddown(ped, c(1,4)) peddown(ped, 1, maxgen=1)
ped = data.frame(ID=1:6, SIRE=c(0,0,1,3,1,4), DAM=c(0,0,2,2,2,5)) peddown(ped, c(1,4)) peddown(ped, 1, maxgen=1)
Extracts pedigree upward for one or a group of individuals to find their ascendants
pedup(ped, progeny, maxgen = c())
pedup(ped, progeny, maxgen = c())
ped |
: |
progeny |
: Vector of individual ID(s), from which the new pedigree is being extracted. |
maxgen |
: (optional) a positive integer for the maximum number of generations (continuing from parents of |
Extracted pedigree data.frame
ped = data.frame(ID=1:6, SIRE=c(0,0,1,3,1,4), DAM=c(0,0,2,2,2,5)) pedup(ped, c(1,4)) pedup(ped, 6, maxgen=1)
ped = data.frame(ID=1:6, SIRE=c(0,0,1,3,1,4), DAM=c(0,0,2,2,2,5)) pedup(ped, c(1,4)) pedup(ped, 6, maxgen=1)
Pruning pedigree in two different modes (strict, loose)
pruneped(ped, pheno, mode)
pruneped(ped, pheno, mode)
ped |
: |
pheno |
: Vector of phenotyped individuals |
mode |
: |
In strict pruning, individuals without progeny and phenotype are recursively deleted from the pedigree, and then individuals without known parent and without progeny (if any) are deleted. Therefore, all uninfluential individuals are deleted. The downside is that individuals without phenotype or phenotyped progeny cannot receive any genetic merit based on the information from their phenotyped relatives. In loose pruning, the pedigree is upward extracted for phenotyped individuals to thier founders, and then the pedigree is downward extracted from the founders.
Pruned pedigree data.frame
ped = data.frame(ID=1:7, SIRE=c(0,0,1,3,1,4,0), DAM=c(0,0,2,2,2,5,0)) pheno = c(1,4) pruneped(ped, pheno, mode="strict") pruneped(ped, pheno, mode="loose")
ped = data.frame(ID=1:7, SIRE=c(0,0,1,3,1,4,0), DAM=c(0,0,2,2,2,5,0)) pheno = c(1,4) pruneped(ped, pheno, mode="strict") pruneped(ped, pheno, mode="loose")
Adds genetic group contributions to the genetic merit of individuals.
Qgpu(Q, sol)
Qgpu(Q, sol)
Q |
|
sol |
: |
Vector of Qĝ + û
ped = data.frame(ID=c(3,4,6,5), SIRE=c(1,3,4,1), DAM=c(2,2,5,2)) Q = qmatL(gghead(ped)) ghat = c(0.1, -0.2) uhat = seq(-1.5, 1.5, 1) sol = data.frame(ID=1:6, EBV=c(ghat, uhat)) Qgpu(Q, sol)
ped = data.frame(ID=c(3,4,6,5), SIRE=c(1,3,4,1), DAM=c(2,2,5,2)) Q = qmatL(gghead(ped)) ghat = c(0.1, -0.2) uhat = seq(-1.5, 1.5, 1) sol = data.frame(ID=1:6, EBV=c(ghat, uhat)) Qgpu(Q, sol)
Creates the genetic group contribution matrix.
qmat(ped2)
qmat(ped2)
ped2 |
: The output |
Q matrix
ped = data.frame(ID=c(3,4,6,5), SIRE=c(1,3,4,1), DAM=c(2,2,5,2)) ped2 = gghead(ped) qmat(ped2)
ped = data.frame(ID=c(3,4,6,5), SIRE=c(1,3,4,1), DAM=c(2,2,5,2)) ped2 = gghead(ped) qmat(ped2)
Creates the genetic group contribution matrix for large pedigrees.
qmatL(ped2)
qmatL(ped2)
ped2 |
: The output |
Q matrix
ped = data.frame(ID=c(3,4,6,5), SIRE=c(1,3,4,1), DAM=c(2,2,5,2)) ped2 = gghead(ped) qmatL(ped2)
ped = data.frame(ID=c(3,4,6,5), SIRE=c(1,3,4,1), DAM=c(2,2,5,2)) ped2 = gghead(ped) qmatL(ped2)
Creates the genetic group contribution matrix for large pedigrees, with parallel processing.
qmatXL(ped2, ncl)
qmatXL(ped2, ncl)
ped2 |
: The output |
ncl |
: User defined number of nodes; if the number of user defined nodes is greater than the number of genetic groups, the number genetic groups is considered as the number of nodes. |
This function is the parallel version of qmatL
. It requires foreach and doParallel packages.
Q matrix
ped = data.frame(ID=c(3,4,6,5), SIRE=c(1,3,4,1), DAM=c(2,2,5,2)) ped2 = gghead(ped) qmatXL(ped2, 2)
ped = data.frame(ID=c(3,4,6,5), SIRE=c(1,3,4,1), DAM=c(2,2,5,2)) ped2 = gghead(ped) qmatXL(ped2, 2)
Renumbering pedigree to numerical IDs, so that progeny's ID is smaller than parents' IDs.
renum(ped)
renum(ped)
ped |
: |
newped : Pedigree data.frame
with renumberred IDs.
xrf : Cross-reference data.frame
with 2 columns for original and renumberred IDs.
ped = data.frame(ID=letters[1:6], SIRE=c(0,0,letters[c(1,3,1,4)]), DAM=c(0,0,letters[c(2,2,2,5)])) renum(ped)$newped renum(ped)$xrf
ped = data.frame(ID=letters[1:6], SIRE=c(0,0,letters[c(1,3,1,4)]), DAM=c(0,0,letters[c(2,2,2,5)])) renum(ped)$newped renum(ped)$xrf
Calculates genetic relationship coefficient between two individuals.
rg(ped, id1, id2)
rg(ped, id1, id2)
ped |
: |
id1 |
: Numeric ID of an individual |
id2 |
: Numeric ID of an individual |
Genetic relationship coefficient between the two individuals
ped = data.frame(ID=1:7, SIRE=c(0,0,1,1,3,1,5), DAM=c(0,0,0,2,4,4,6)) rg(ped, 5, 6)
ped = data.frame(ID=1:7, SIRE=c(0,0,1,1,3,1,5), DAM=c(0,0,0,2,4,4,6)) rg(ped, 5, 6)
Extract sire-maternal grandsire (S-MGS) pedigree from a sire-dam pedigree. Sire and MGS information is extracted for sires of phenotyped individuals.
smgsped(ped, pheno)
smgsped(ped, pheno)
ped |
: |
pheno |
: Vector of phenotyped individuals |
S-MGS pedigree data.frame
ped = data.frame(ID=1:10, SIRE=c(0,0,1,2,0,5,4,4,0,8), DAM=c(0,0,0,3,3,0,6,6,6,0)) smgsped(ped, 7:10)
ped = data.frame(ID=1:10, SIRE=c(0,0,1,2,0,5,4,4,0,8), DAM=c(0,0,0,3,3,0,6,6,6,0)) smgsped(ped, 7:10)
Converts tabular data to matrix data.
tab2mat(tab)
tab2mat(tab)
tab |
: |
Converted data.frame
to matrix
ped = data.frame(ID=1:6, SIRE=c(0,0,1,3,1,4), DAM=c(0,0,2,2,2,5)) tab2mat(tabA(ped))
ped = data.frame(ID=1:6, SIRE=c(0,0,1,3,1,4), DAM=c(0,0,2,2,2,5)) tab2mat(tabA(ped))
Creates the pedigree-based additive genetic relationship data.frame
.
tabA(ped)
tabA(ped)
ped |
: |
Genetic relationship data.frame
ped = data.frame(ID=1:6, SIRE=c(0,0,1,3,1,4), DAM=c(0,0,2,2,2,5)) tabA(ped)
ped = data.frame(ID=1:6, SIRE=c(0,0,1,3,1,4), DAM=c(0,0,2,2,2,5)) tabA(ped)
Creates the data.frame
of the inverse of the pedigree-based genetic relationship matrix.
tabAinv(ped, inbr)
tabAinv(ped, inbr)
ped |
: |
inbr |
: Vector of inbreeding coefficients in the order of individuals in the relationship matrix. |
data.frame
of the inverse of the genetic relationship matrix
ped = data.frame(ID=1:6, SIRE=c(0,0,1,3,1,4), DAM=c(0,0,2,2,2,5)) inbr = c(0, 0, 0, 0.25, 0, 0.25) # or (inbr = diag(buildA(ped)) - 1) # or inbr = tabA(ped); (inbr = inbr[inbr[,1]==inbr[,2],]$a - 1) # or # For individual inbreeding values, use function inb. tabAinv(ped, inbr)
ped = data.frame(ID=1:6, SIRE=c(0,0,1,3,1,4), DAM=c(0,0,2,2,2,5)) inbr = c(0, 0, 0, 0.25, 0, 0.25) # or (inbr = diag(buildA(ped)) - 1) # or inbr = tabA(ped); (inbr = inbr[inbr[,1]==inbr[,2],]$a - 1) # or # For individual inbreeding values, use function inb. tabAinv(ped, inbr)
Creates the pedigree-based dominance relationship data.frame
.
tabD(ped, A)
tabD(ped, A)
ped |
: |
A |
: Relationship matrix A in a tabular format created by function |
Dominance relationship data.frame
ped = data.frame(ID=1:6, SIRE=c(0,0,1,3,1,4), DAM=c(0,0,2,2,2,5)) tabD(ped, tabA(ped))
ped = data.frame(ID=1:6, SIRE=c(0,0,1,3,1,4), DAM=c(0,0,2,2,2,5)) tabD(ped, tabA(ped))
Creates the data.frame
of the inverse of the pedigree-based dominance relationship matrix.
tabDinv(ped, A)
tabDinv(ped, A)
ped |
: |
A |
: Relationship matrix A in a tabular format created by function |
data.frame
of the inverse of the dominance relationship matrix
ped = data.frame(ID=1:6, SIRE=c(0,0,1,3,1,4), DAM=c(0,0,2,2,2,5)) tabDinv(ped, tabA(ped))
ped = data.frame(ID=1:6, SIRE=c(0,0,1,3,1,4), DAM=c(0,0,2,2,2,5)) tabDinv(ped, tabA(ped))