# NOT RUN {
#################################################
# Example 1: Advanced OCS using pedigree data #
# Objective: maximize genetic gain #
# Constraints: #
# - mean kinship #
# - mean kinship at native alleles #
# - genetic contributions from other breeds #
#################################################
data(PedigWithErrors)
data(Phen)
keep <- Phen$Indiv
Pedig <- prePed(PedigWithErrors, keep=keep, thisBreed="Hinterwaelder", lastNative=1970)
Pedig$MC <- 1-pedBreedComp(Pedig, thisBreed="Hinterwaelder")$native
Phen <- merge(Pedig, Phen[,c("Indiv", "BV")], by="Indiv")
Kin <- kinlist(pKin = pedIBD(Pedig, keep.only=keep),
pKinatN = pedIBDatN(Pedig, thisBreed="Hinterwaelder", keep.only=keep))
head(Phen)
cor(Phen$MC, Phen$BV)
help.opticont(Kin, Phen)
# Compute offspring parameters for unselected population
noSel <- opticont(method="min.pKin", K=Kin, phen=Phen, con=list(ub=c(M=-1, F=-1)))
noSel.s <- summary(noSel)
round(noSel.s[,c("pKin","pKinatN", "meanMC", "meanBV")],4)
meanMC <- noSel.s$meanMC
meanKin <- noSel.s$pKin
meanKinatN <- noSel.s$pKinatN
meanBV <- noSel.s$meanBV
# Define Constraints
Ne <- 100
con <- list(ub=c(M=NA, F=-1))
con$ub.pKin <- meanKin + (1-meanKin )*(1/(2*Ne))
con$ub.pKinatN <- meanKinatN + (1-meanKinatN)*(1/(2*Ne))
con$ub.MC <- 0.97*meanMC
# Compute the genetic progress achievable
maxBV <- opticont("max.BV", K=Kin, phen=Phen, con=con)
maxBV.s <- summary(maxBV)
maxBV.s$meanBV
# [1] 0.5428925
# Get optimum contributions of sires
Sire <- maxBV$parent[maxBV$parent$Sex=="male",]
ord <- order(Sire$oc, decreasing=TRUE)
head(Sire[ord,])
#################################################
# Example 2: Advanced OCS using genotype data #
# Objective: minimize inbreeding #
# Constraints: #
# - breeding values #
# - mean kinship at native alleles #
# - genetic contributions from other breeds #
#################################################
data(map)
data(Cattle)
dir <- system.file("extdata", package = "optiSel")
files <- paste(dir, "/Chr", 1:2, ".phased", sep="")
Kin <- kinlist(sKin = segIBD(files, map, minSNP=20, minL=2.0),
sKinatN = segIBDatN(files, Cattle, map, thisBreed="Angler",
ubFreq=0.01, minSNP=20, minL=2.0))
Haplo <- haplofreq(files, Cattle, map, thisBreed="Angler",
minSNP=20, minL=2.0, ubFreq=0.01, what="match")
Comp <- segBreedComp(Haplo$match, map)
Comp$MC <- 1-Comp$native
Phen <- merge(Cattle, Comp[,c("Indiv", "MC")], by="Indiv", all=FALSE)
help.opticont(Kin, Phen)
cor(Phen$MC, Phen$BV,use="complete.obs")
#[1] 0.5033714
# Compute offspring parameters for unselected population
noSel <- opticont(method="min.sKin", K=Kin, phen=Phen, con=list(ub=c(M=-1, F=-1)))
noSel.s <- summary(noSel)
round(noSel.s[,c("sKin","sKinatN", "meanMC", "meanBV")],4)
meanMC <- noSel.s$meanMC
meanKin <- noSel.s$sKin
meanKinatN <- noSel.s$sKinatN
meanBV <- noSel.s$meanBV
# Define Constraints
Ne <- 100
con <- list(ub=c(M=NA, F=-1))
con$ub.sKinatN <- meanKinatN + (1-meanKinatN)*(1/(2*Ne))
con$ub.MC <- 0.97*meanMC
con$lb.BV <- meanBV
# Compute the smallest mean kinship achievable
minKin <- opticont("min.sKin", K=Kin, phen=Phen, con=con)
minKin.s <- summary(minKin)
minKin.s$sKin
# [1] 0.03881304
# Get optimum contributions of sires
Sire <- minKin$parent[minKin$parent$Sex=="male",]
ord <- order(Sire$oc, decreasing=TRUE)
head(Sire[ord,])
# }
Run the code above in your browser using DataLab