# mickey mouse example
Q=matrix(sample(0:1,32,replace = TRUE),nrow=4,ncol=8) # possible solutions
SNP=matrix(sample(0:2,80,replace = TRUE),nrow=8,ncol=10) # SNPs of 8 individuals with 10 markers
solution = matrix(rnorm(10)) # marker effects
ocsFunC(SNP=SNP,Q=Q, solution=solution) # sum of frequency of positive alleles
if (FALSE) {
# using the function in an optimal contribution
data(DT_technow, package="enhancer")
DT <- DT_technow
DT$occ <- 1; DT$occ[1]=0
Md <- apply(Md_technow,2,as.numeric)
rownames(Md) <- rownames(Md_technow)
Mf <- apply(Mf_technow,2,as.numeric)
rownames(Mf) <- rownames(Mf_technow)
M <- rbind(Md,Mf)
A <- A.matr(M)
A <- A[DT$hy,DT$hy]
library(rrBLUP)
mixm = mixed.solve(y=DT$GY, Z=M)
solution = matrix(mixm$u[colnames(M)])
sum(freqPosAllele(M,solution[,1])) # starting frequencies
# run the genetic algorithm
# we assig a weight to x'Dx of (20*pi)/180=0.34
res<-evolafit(formula = c(GY, occ)~hy,
dt= DT,
# constraints: if sum is greater than this ignore
constraintsUB = c(Inf,100),
# constraints: if sum is smaller than this ignore
constraintsLB= c(-Inf,-Inf),
# weight the traits for the selection
b = c(1,0),
# population parameters
nCrosses = 100, nProgeny = 10,
recombGens=1, nChr=1, mutRateAllele=0,
# coancestry parameters
D=A, lambda= (20*pi)/180 , nQtlStart = 90,
# selection parameters
propSelBetween = 0.5, propSelWithin =0.5,
fitnessf = ocsFunC,
SNP=M, solution=solution,
nGenerations = 20)
Q <- pullQtlGeno(res$pop, simParam = res$simParam, trait=1); Q <- Q/2
best = bestSol(res$pop)[,"fitness"]
qa = (Q %*% DT$GY)[best,]; qa
qAq = Q[best,] %*% A %*% Q[best,]; qAq
sum(Q[best,]) # total # of inds selected
sum(freqPosAllele(diag(Q[best,])%*%M,solution[,1]))
evolmonitor(res)
plot(DT$GY, col=as.factor(Q[best,]),
pch=(Q[best,]*19)+1)
pareto(res)
}
Run the code above in your browser using DataLab