FitchLikelihooder(int numNodes,int numAlpha,Alphabet &alpha, MultSeqAlignment &A,int column,RootNode *root,int order) : A(A), numNodes(numNodes), numAlpha(numAlpha), alpha(alpha), L(numNodes,numAlpha), column(column), order(order), root(root), likelihood(NEGATIVE_INFINITY), gapSymbols(A.getGapSymbols()), V(numAlpha) { L.setAllTo(NEGATIVE_INFINITY); V.setAllTo(NEGATIVE_INFINITY); }
int Application::main(int argc,char *argv[]) { // Process command line CommandLine cmd(argc,argv,""); if(cmd.numArgs()!=2) throw String("train-3state <alignment-file> <outfile>"); String infile=cmd.arg(0); String outfile=cmd.arg(1); // Initialization transCounts.resize(4,4); emitCounts.resize(4,nAlpha,nAlpha); transCounts.setAllTo(0); emitCounts.setAllTo(0); // Process all alignments (pairs of sequences in fasta file) FastaReader reader(infile,alphabet); String def1, seq1, def2, seq2; while(reader.nextSequence(def1,seq1) && reader.nextSequence(def2,seq2)) { Sequence S1(seq1,alphabet), S2(seq2,alphabet); updateCounts(S1,S2); } // Compute HMM parameters PairHMM hmm(alphabet,gapSymbol,4); hmm.setStateType(INSERTION_STATE,PHMM_INSERT); hmm.setStateType(DELETION_STATE,PHMM_DELETE); hmm.setStateType(MATCH_STATE,PHMM_MATCH); hmm.setStateType(0,PHMM_OTHER); for(STATE i=0 ; i<4 ; ++i) { double sum=0; for(STATE j=0 ; j<4 ; ++j) sum+=transCounts[i][j]; for(STATE j=0 ; j<4 ; ++j) hmm.setTransP(i,j,transCounts[i][j]/sum); } for(STATE k=0 ; k<4 ; ++k) { double sum=0; for(Symbol i=0 ; i<nAlpha ; ++i) for(Symbol j=0 ; j<nAlpha ; ++j) sum+=emitCounts(k,i,j); if(sum==0) sum=1; for(Symbol i=0 ; i<nAlpha ; ++i) for(Symbol j=0 ; j<nAlpha ; ++j) hmm.setEmitP(k,i,j,emitCounts(k,i,j)/sum); } // Save HMM hmm.save(outfile); return 0; }
void reinit(int col) { L.setAllTo(NEGATIVE_INFINITY); column=col; }