]> git.donarmstrong.com Git - mothur.git/blobdiff - nast.cpp
changed random forest output filename
[mothur.git] / nast.cpp
index 90c8383f2a8a6fb23467d6b662879dfde5fd8f49..647e0e4f1e17e205c183c78615a966b7a98545cc 100644 (file)
--- a/nast.cpp
+++ b/nast.cpp
@@ -25,8 +25,10 @@ Nast::Nast(Alignment* method, Sequence* cand, Sequence* temp) : alignment(method
        try {
                m = MothurOut::getInstance();
                maxInsertLength = 0;
+       
                pairwiseAlignSeqs();    //      This is part A in Fig. 2 of DeSantis et al.
                regapSequences();               //      This is parts B-F in Fig. 2 of DeSantis et al.
+               
        }
        catch(exception& e) {
                m->errorOut(e, "Nast", "Nast");
@@ -43,7 +45,7 @@ void Nast::pairwiseAlignSeqs(){       //      Here we call one of the pairwise alignment me
 
                string candAln = alignment->getSeqAAln();
                string tempAln = alignment->getSeqBAln();
-
+       
                if(candAln == ""){
 
                        candidateSeq->setPairwise("");
@@ -76,6 +78,7 @@ void Nast::pairwiseAlignSeqs(){       //      Here we call one of the pairwise alignment me
 
                candidateSeq->setPairwise(candAln);                                     //      set the pairwise sequences in the Sequence objects for
                templateSeq->setPairwise(tempAln);                                      //      the candidate and template sequences
+
        }
        catch(exception& e) {
                m->errorOut(e, "Nast", "pairwiseAlignSeqs");
@@ -89,11 +92,6 @@ void Nast::removeExtraGaps(string& candAln, string tempAln, string newTemplateAl
 
 //     here we do steps C-F of Fig. 2 from DeSantis et al.
        try {
-       
-               //cout << candAln << endl;
-               //cout << tempAln << endl;
-               //cout << newTemplateAlign << endl;
-               //cout << endl;
                
                int longAlignmentLength = newTemplateAlign.length();    
        
@@ -141,24 +139,22 @@ void Nast::removeExtraGaps(string& candAln, string tempAln, string newTemplateAl
                                                        string leftCandidateString = candAln.substr(0,(leftIndex-insertLength+1));
                                                        string rightCandidateString = candAln.substr((leftIndex+1));
                                                        candAln = leftCandidateString + rightCandidateString;
-               
-                                               }
-                                               else{                                                                   //      not enough room to the left, have to steal some space to
+                                                       
+                                               }else{                                                                  //      not enough room to the left, have to steal some space to the right
                                                
                        //cout << "in else lr newTemplateAlign = " << newTemplateAlign.length() << '\t' << i << '\t' << insertLength << endl;
-                                                       string leftTemplateString = newTemplateAlign.substr(0,i);       //      the right
+                                                       string leftTemplateString = newTemplateAlign.substr(0,i);       
                                                        string rightTemplateString = newTemplateAlign.substr((i+insertLength));
                                                        newTemplateAlign = leftTemplateString + rightTemplateString;
                                                        longAlignmentLength = newTemplateAlign.length();
-                       //cout << " in else lr candAln = " << candAln.length() << '\t' << " leftIndex = " << leftIndex << " leftroom = " << leftRoom << " rightIndex = " << rightIndex << '\t' << endl;                                 
+                       //cout << " in else lr candAln = " << candAln.length() << '\t' << " leftIndex = " << leftIndex << " leftroom = " << leftRoom << " rightIndex = " << rightIndex << '\t' << " rightroom = " << rightRoom << '\t' << endl;                                 
                                                        string leftCandidateString = candAln.substr(0,(leftIndex-leftRoom+1));
                                                        string insertString = candAln.substr((leftIndex+1),(rightIndex-leftIndex-1));
                                                        string rightCandidateString = candAln.substr((rightIndex+(insertLength-leftRoom)));
                                                        candAln = leftCandidateString + insertString + rightCandidateString;
                                
                                                }
-                                       }
-                                       else{                                                                           //      the right gap is closer - > move stuff right there's
+                                       }else{                                                                          //      the right gap is closer - > move stuff right there's
                                                if(rightRoom >= insertLength){                  //      enough room to the right to move
                        //cout << "rr newTemplateAlign = " << newTemplateAlign.length() << '\t' << i << '\t' << i+insertLength << endl;
                                                        string leftTemplateString = newTemplateAlign.substr(0,i);
@@ -186,8 +182,9 @@ void Nast::removeExtraGaps(string& candAln, string tempAln, string newTemplateAl
                                                                        
                                                }
                                        }
-                                       i -= insertLength;
-       //if (i < 0) { cout << " we have a negative i = " << i << endl; }
+                                       
+                                       if ((i - insertLength) < 0) {  i = 0; }
+                                       else { i -= insertLength; }
 
                                }
                                else{
@@ -208,6 +205,9 @@ void Nast::removeExtraGaps(string& candAln, string tempAln, string newTemplateAl
                                }
                        
 //                             i -= insertLength;
+                               
+                               //if i is negative, we want to remove the extra gaps to the right
+                               if (i < 0) { m->mothurOut("i is negative"); m->mothurOutEndLine(); } 
                        } 
                }
        }
@@ -221,7 +221,7 @@ void Nast::removeExtraGaps(string& candAln, string tempAln, string newTemplateAl
 
 void Nast::regapSequences(){   //This is essentially part B in Fig 2. of DeSantis et al.
        try { 
-       
+       //cout << candidateSeq->getName() << endl;
                string candPair = candidateSeq->getPairwise();
                string candAln = "";
                
@@ -250,6 +250,7 @@ void Nast::regapSequences(){        //This is essentially part B in Fig 2. of DeSantis
                string lastLoop = "";
                
                while(pairwiseAlignIndex<pairwiseLength){
+       //cout << pairwiseAlignIndex << '\t' << fullAlignIndex << '\t' << pairwiseLength << endl;
                        if(isalpha(tempPair[pairwiseAlignIndex]) && isalpha(tempAln[fullAlignIndex])
                           && isalpha(candPair[pairwiseAlignIndex])){
                                //  the template and candidate pairwise and template aligned have characters
@@ -356,6 +357,7 @@ void Nast::regapSequences(){        //This is essentially part B in Fig 2. of DeSantis
                }                                                                                               //      2 of Desantis et al.
 
                candidateSeq->setAligned(candAln);
+       //cout << "here" << endl;
        }
        catch(exception& e) {
                m->errorOut(e, "Nast", "regapSequences");