double processInternalChild(Symbol parentSymbol,int parentID,int child, NthOrdSubstMatrix &noPt) { AlignmentSeq &track=A.getIthTrack(parentID); AlignmentSeq &childTrack=A.getIthTrack(child); int contextBegin=column-order; if(contextBegin<0) contextBegin=0; int contextLen=column-contextBegin; Sequence context; track.getSeq().getSubsequence(contextBegin,contextLen,context);//ACO //A.getIthTrack(root->getID()).getSeq().getSubsequence(contextBegin,contextLen,context);//TRCO int pos=MultSeqAlignment::rightmostGapPos(context,gapSymbols); if(pos>=0) { throw "this should not happen (FitchFelsenstein)::processInternalChild"; Sequence temp; context.getSubsequence(pos+1,contextLen-pos-1,temp); context=temp; } SubstitutionMatrix &Pt=*noPt.lookup(context,0,-1); Array2D<double>::RowIn2DArray<double> row=L[child]; Symbol childSym=childTrack.getSeq()[column]; double ll; if(gapSymbols.isMember(childSym)){ V.setAllTo(NEGATIVE_INFINITY); for(Symbol a=0 ; a<numAlpha ; ++a) { if(!gapSymbols.isMember(a)) { V[(int)a]=safeAdd(row[a],Pt(parentSymbol,a)); } } ll=sumLogProbs(V); } else { ll=safeAdd(row[childSym],Pt(parentSymbol,childSym)); } return ll; }
virtual void processNode(RootNode &u) { int id=u.getID(); Symbol a=A.getIthTrack(id)[column]; int childID=u.getChild()->getID(); NthOrdSubstMatrix &Pt=*u.getSubstMatrix(); if(gapSymbols.isMember(a)) likelihood=0; // shouldn't happen... else likelihood=processInternalChild(a,childID,Pt,rootContextCode, rootContextLength); }
virtual void processNode(LeafNode &u) // DO NOT CHANGE THIS FUNCTION { int id=u.getID(); Symbol a=A.getIthTrack(id)[column]; Array2D<double>::RowIn2DArray<double> row=L[id]; if(gapSymbols.isMember(a)) for(Symbol i=0 ; i<numAlpha; ++i) row[i]=0; //=log(1); missing data -- same as Seipel & Haussler else for(Symbol i=0 ; i<numAlpha; ++i) row[i]=(i==a ? 0 : NEGATIVE_INFINITY); }
double processInternalChild(Symbol parentSymbol,int child, NthOrdSubstMatrix &noPt, int contextCode,int contextLength) { SubstitutionMatrix &Pt=*noPt.lookup(contextCode,contextLength); Array2D<double>::RowIn2DArray<double> row=L[child]; Vector<double> V; for(Symbol b=0 ; b<numAlpha ; ++b) if(!gapSymbols.isMember(b)) V.push_back(row[b]+Pt(parentSymbol,b)); // Pt already in log space double ll=sumLogProbs(V); return ll; }
virtual void processNode(InternalNode &u) { int id=u.getID(); NthOrdSubstMatrix &leftPt=*u.getLeftSubstMatrix(); NthOrdSubstMatrix &rightPt=*u.getRightSubstMatrix(); int left=u.getLeft()->getID(), right=u.getRight()->getID(); Array2D<double>::RowIn2DArray<double> row=L[id]; Symbol a=A.getIthTrack(id)[column]; if(gapSymbols.isMember(a)) for(a=0 ; a<numAlpha ; ++a) { if(gapSymbols.isMember(a)) continue; row[a]= processInternalChild(a,id,left,leftPt)+ processInternalChild(a,id,right,rightPt); } else { for(Symbol b=0 ; b<numAlpha ; ++b) row[b]=NEGATIVE_INFINITY; double l=processInternalChild(a,id,left,leftPt); double r=processInternalChild(a,id,right,rightPt); row[a]=l+r; } }
virtual void processNode(InternalNode &u) { int id=u.getID(); int left=u.getLeft()->getID(), right=u.getRight()->getID(); NthOrdSubstMatrix &leftPt=*u.getLeftSubstMatrix(); NthOrdSubstMatrix &rightPt=*u.getRightSubstMatrix(); Array2D<double>::RowIn2DArray<double> row=L[id]; for(Symbol a=0 ; a<numAlpha ; ++a) { if(gapSymbols.isMember(a)) continue; row[a]= processInternalChild(a,left,leftPt,0,0)+ processInternalChild(a,right,rightPt,0,0); } }