]> git.donarmstrong.com Git - mothur.git/blobdiff - nast.cpp
added clearcut command
[mothur.git] / nast.cpp
index 294940cd6aabd49f67aca028311d21529f0912ee..4a0b74aa412873b6bf98ee1b9e30e28a9cc8c21f 100644 (file)
--- a/nast.cpp
+++ b/nast.cpp
 
 Nast::Nast(Alignment* method, Sequence* cand, Sequence* temp) : alignment(method), candidateSeq(cand), templateSeq(temp) {
        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) {
-               errorOut(e, "Nast", "Nast");
+               m->errorOut(e, "Nast", "Nast");
                exit(1);
        }
-
 }
 
 /**************************************************************************************************/
@@ -40,12 +39,12 @@ Nast::Nast(Alignment* method, Sequence* cand, Sequence* temp) : alignment(method
 void Nast::pairwiseAlignSeqs(){        //      Here we call one of the pairwise alignment methods to align our unaligned candidate
                                                                //      and template sequences
        try {
-               
+
                alignment->align(candidateSeq->getUnaligned(), templateSeq->getUnaligned());
-       
+
                string candAln = alignment->getSeqAAln();
                string tempAln = alignment->getSeqBAln();
-
+       
                if(candAln == ""){
 
                        candidateSeq->setPairwise("");
@@ -78,10 +77,9 @@ 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) {
-               errorOut(e, "Nast", "pairwiseAlignSeqs");
+               m->errorOut(e, "Nast", "pairwiseAlignSeqs");
                exit(1);
        }       
 }
@@ -202,7 +200,7 @@ void Nast::removeExtraGaps(string& candAln, string tempAln, string newTemplateAl
                }
        }
        catch(exception& e) {
-               errorOut(e, "Nast", "removeExtraGaps");
+               m->errorOut(e, "Nast", "removeExtraGaps");
                exit(1);
        }       
 }
@@ -226,7 +224,7 @@ void Nast::regapSequences(){        //This is essentially part B in Fig 2. of DeSantis
                        candidateSeq->setAligned(candAln);
                        return;
                }
-               
+       
                int fullAlignIndex = 0;
                int pairwiseAlignIndex = 0;
                string newTemplateAlign = "";                                   //      this is going to be messy so we want a temporary template
@@ -305,14 +303,14 @@ void Nast::regapSequences(){      //This is essentially part B in Fig 2. of DeSantis
                                //      would skip the gaps and not progress through full alignment sequence
                                //      not tested yet
                                
-                               mothurOut("We're into D " + toString(fullAlignIndex) + " " +  toString(pairwiseAlignIndex)); mothurOutEndLine();
+                               m->mothurOut("We're into D " + toString(fullAlignIndex) + " " +  toString(pairwiseAlignIndex)); m->mothurOutEndLine();
                                pairwiseAlignIndex++;
                        }
                        else{
                                //      everything has a gap - not possible
                                //      not tested yet
                                
-                               mothurOut("We're into F " +  toString(fullAlignIndex) + " " +  toString(pairwiseAlignIndex)); mothurOutEndLine();
+                               m->mothurOut("We're into F " +  toString(fullAlignIndex) + " " +  toString(pairwiseAlignIndex)); m->mothurOutEndLine();
                                pairwiseAlignIndex++;
                                fullAlignIndex++;                       
                        }               
@@ -323,7 +321,9 @@ void Nast::regapSequences(){        //This is essentially part B in Fig 2. of DeSantis
                        newTemplateAlign += tempAln[i];//
                }
                
-               int start, end;
+               int start = 0;
+               int end = candAln.length()-1;
+
                for(int i=0;i<candAln.length();i++){
                        if(candAln[i] == 'Z' || !isalnum(candAln[i]))   {       candAln[i] = '.';       }       //      if we padded the alignemnt from
                        else{                   start = i;                      break;          }                                                       //      blast with Z's, change them to
@@ -338,15 +338,15 @@ void Nast::regapSequences(){      //This is essentially part B in Fig 2. of DeSantis
                        candAln[i] = toupper(candAln[i]);                       //      everything is upper case
                }
                
-       
+
                if(candAln.length() != tempAln.length()){               //      if the regapped candidate sequence is longer than the official
                        removeExtraGaps(candAln, tempAln, newTemplateAlign);//  template alignment then we need to do steps C-F in Fig.
                }                                                                                               //      2 of Desantis et al.
-                       
+
                candidateSeq->setAligned(candAln);
        }
        catch(exception& e) {
-               errorOut(e, "Nast", "regapSequences");
+               m->errorOut(e, "Nast", "regapSequences");
                exit(1);
        }       
 }
@@ -381,7 +381,7 @@ float Nast::getSimilarityScore(){
                
        }
        catch(exception& e) {
-               errorOut(e, "Nast", "getSimilarityScore");
+               m->errorOut(e, "Nast", "getSimilarityScore");
                exit(1);
        }       
 }