CalcLikeForCandidates<-function(p,G,candidates,Gcandidates,Alleles,Probs){
LikeFromGenPop<-rep(0,length(Gpool2[,1,1]))
for(i in 1:length(Alleles)){
tmp<-OffspringGenotypeProb(Probs[[i]],Probs[[i]])
for(j in 1:length(LikeFromGenPop)){
tmpallele1<-which(Alleles[[i]]==Gpool2[j,1,i])
tmpallele2<-which(Alleles[[i]]==Gpool2[j,2,i])
tmp2<-log(tmp[min(tmpallele1,tmpallele2)[1],max(tmpallele1,tmpallele2)[1]],10)
LikeFromGenPop[j]<-LikeFromGenPop[j]+tmp2
}
}
BaseLike<-CalcLikeZ(p,G2,nucs,Alleles,Probs)
SearchPattern<-MakeSearchPattern(searched)
ret<-NULL
ret2<-NULL
ret3<-NULL
counter<-1
for(i in 1:length(SearchPattern$X)){
spx<-as.matrix(SearchPattern$X[[i]])
for(j in 1:length(spx[,1])){
ToTestCurrent<-spx[j,]
tmpG2<-G
numtested<-length(ToTestCurrent)
tmpcandidates<-list()
if(numtested>0){
for(k in 1:numtested){
selectedToBeTested<-which(searched==ToTestCurrent[k])
tmpcandidates[[k]]<-candidates[[selectedToBeTested]]
}
}
tmpTestPattern<-MakeTestPattern(tmpcandidates)
for(k in 1:length(tmpTestPattern[,1])){
tmpG2<-G
tmpG2[ToTestCurrent,,]<-Gpool2[tmpTestPattern[k,],,]
LoutTmp<-CalcLikeZ(p,tmpG2,nucs,Alleles,Probs)
ret[[counter]]<-LoutTmp-BaseLike-sum(LikeFromGenPop[tmpTestPattern[k,]])
ret2[[counter]]<-list(ToTestCurrent)
ret3[[counter]]<-list(tmpTestPattern[k,])
counter<-counter+1
}
}
}
list(LogLike=ret,SearchedID=ret2,CandidateID=ret3)
}
printTAPout2<-function(tap){
n<-length(tap$LogLike)
for(i in 1:n){
if(tap$LogLike[[i]]!=-Inf){
tmp<-paste("LogLike",tap$LogLike[[i]],"Prob",10^(tap$LogLike[[i]]),"SearchedID",c(tap$SearchedID[[i]]),"CandidateID",c(tap$CandidateID[[i]]))
print(tmp)
}
}
}
clfcout<-CalcLikeForCandidates(p,G,candidates,Gcandidates,Alleles,Probs)
printTAPout2(clfcout)