]> git.donarmstrong.com Git - mothur.git/blobdiff - gotohoverlap.cpp
changes while testing
[mothur.git] / gotohoverlap.cpp
index e3be6c31c83ceff26c027546f5fc8f2ebf572ce5..ea27df07068a5e2060d3a1be4220a9b2de57822c 100644 (file)
 
 /**************************************************************************************************/
 
-GotohOverlap::GotohOverlap(float gO, float gE, float m, float mm, int r) :
-       gapOpen(gO), gapExtend(gE), match(m), mismatch(mm), Alignment(r) {
+GotohOverlap::GotohOverlap(float gO, float gE, float f, float mm, int r) :
+       gapOpen(gO), gapExtend(gE), match(f), mismatch(mm), Alignment(r) {
        
-       for(int i=1;i<nCols;i++){                               //      we initialize the dynamic programming matrix by setting the pointers in
-               alignment[0][i].prevCell = 'l';         //      the first row to the left
-               alignment[0][i].cValue = 0;
-               alignment[0][i].dValue = 0;
+       try {
+               for(int i=1;i<nCols;i++){                               //      we initialize the dynamic programming matrix by setting the pointers in
+                       alignment[0][i].prevCell = 'l';         //      the first row to the left
+                       alignment[0][i].cValue = 0;
+                       alignment[0][i].dValue = 0;
+               }
+               
+               for(int i=1;i<nRows;i++){                               //      we initialize the dynamic programming matrix by setting the pointers in
+                       alignment[i][0].prevCell = 'u';         //      the first column upward
+                       alignment[i][0].cValue = 0;
+                       alignment[i][0].iValue = 0;
+               }
+               
        }
-       
-       for(int i=1;i<nRows;i++){                               //      we initialize the dynamic programming matrix by setting the pointers in
-               alignment[i][0].prevCell = 'u';         //      the first column upward
-               alignment[i][0].cValue = 0;
-               alignment[i][0].iValue = 0;
+       catch(exception& e) {
+               m->errorOut(e, "GotohOverlap", "GotohOverlap");
+               exit(1);
        }
 }
 
 /**************************************************************************************************/
 
 void GotohOverlap::align(string A, string B){
-       
-       seqA = ' ' + A; lA = seqA.length();             //      the algorithm requires that the first character be a dummy value
-       seqB = ' ' + B; lB = seqB.length();             //      the algorithm requires that the first character be a dummy value
-       
-       for(int i=1;i<lB;i++){                                  //      the recursion here is shown in Webb and Miller, Fig. 1A.  Note that 
-               for(int j=1;j<lA;j++){                          //      if we need to conserve on space we should see Fig. 1B, which is linear
-                                                                                       //      in space, which I think is unnecessary
-                       float diagonal;
-                       if(seqB[i] == seqA[j])  {       diagonal = alignment[i-1][j-1].cValue + match;          }
-                       else                                    {       diagonal = alignment[i-1][j-1].cValue + mismatch;       }
-                       
-                       alignment[i][j].iValue = max(alignment[i][j-1].iValue, alignment[i][j-1].cValue + gapOpen) + gapExtend;
-                       alignment[i][j].dValue = max(alignment[i-1][j].dValue, alignment[i-1][j].cValue + gapOpen) + gapExtend;
-                       
-                       if(alignment[i][j].iValue > alignment[i][j].dValue){
-                               if(alignment[i][j].iValue > diagonal){
-                                       alignment[i][j].cValue = alignment[i][j].iValue;
-                                       alignment[i][j].prevCell = 'l';
+       try {
+               seqA = ' ' + A; lA = seqA.length();             //      the algorithm requires that the first character be a dummy value
+               seqB = ' ' + B; lB = seqB.length();             //      the algorithm requires that the first character be a dummy value
+               
+               for(int i=1;i<lB;i++){                                  //      the recursion here is shown in Webb and Miller, Fig. 1A.  Note that 
+                       for(int j=1;j<lA;j++){                          //      if we need to conserve on space we should see Fig. 1B, which is linear
+                               //      in space, which I think is unnecessary
+                               float diagonal;
+                               if(seqB[i] == seqA[j])  {       diagonal = alignment[i-1][j-1].cValue + match;          }
+                               else                                    {       diagonal = alignment[i-1][j-1].cValue + mismatch;       }
+                               
+                               alignment[i][j].iValue = max(alignment[i][j-1].iValue, alignment[i][j-1].cValue + gapOpen) + gapExtend;
+                               alignment[i][j].dValue = max(alignment[i-1][j].dValue, alignment[i-1][j].cValue + gapOpen) + gapExtend;
+                               
+                               if(alignment[i][j].iValue > alignment[i][j].dValue){
+                                       if(alignment[i][j].iValue > diagonal){
+                                               alignment[i][j].cValue = alignment[i][j].iValue;
+                                               alignment[i][j].prevCell = 'l';
+                                       }
+                                       else{
+                                               alignment[i][j].cValue = diagonal;
+                                               alignment[i][j].prevCell = 'd';
+                                       }
                                }
                                else{
-                                       alignment[i][j].cValue = diagonal;
-                                       alignment[i][j].prevCell = 'd';
+                                       if(alignment[i][j].dValue > diagonal){
+                                               alignment[i][j].cValue = alignment[i][j].dValue;
+                                               alignment[i][j].prevCell = 'u';
+                                       }
+                                       else{
+                                               alignment[i][j].cValue = diagonal;
+                                               alignment[i][j].prevCell = 'd';
+                                       }
                                }
+                               
                        }
-                       else{
-                               if(alignment[i][j].dValue > diagonal){
-                                       alignment[i][j].cValue = alignment[i][j].dValue;
-                                       alignment[i][j].prevCell = 'u';
-                               }
-                               else{
-                                       alignment[i][j].cValue = diagonal;
-                                       alignment[i][j].prevCell = 'd';
-                               }
-                       }
-                       
                }
+               Overlap over;
+               over.setOverlap(alignment, lA, lB, 0);  //      Fix the gaps at the ends of the sequences
+               traceBack();                                                    //      Construct the alignment and set seqAaln and seqBaln
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "GotohOverlap", "align");
+               exit(1);
        }
-       Overlap over;
-       over.setOverlap(alignment, lA, lB, 0);  //      Fix the gaps at the ends of the sequences
-       traceBack();                                                    //      Construct the alignment and set seqAaln and seqBaln
 }
 
 /**************************************************************************************************/