X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=nast.cpp;h=50d3b2440f3a2523257d20faabba51098b345cd4;hb=2a07f8664a7fd1ef0d572b88e8b5bede24cc0b3c;hp=804e3c174d4408c2ae55963ba391098002978c18;hpb=9a339a6b007b23c39b7eb20cc777af66dd2cebef;p=mothur.git diff --git a/nast.cpp b/nast.cpp index 804e3c1..50d3b24 100644 --- a/nast.cpp +++ b/nast.cpp @@ -23,16 +23,15 @@ 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); } } @@ -94,7 +92,7 @@ void Nast::removeExtraGaps(string& candAln, string tempAln, string newTemplateAl try { int longAlignmentLength = newTemplateAlign.length(); - + for(int i=0; i0;leftIndex--){ // then we've got problems... + for(leftIndex=i-1;leftIndex>0;leftIndex--){ // then we've got problems... if(!isalpha(candAln[leftIndex])){ leftRoom = 1; //count how far it is to the nearest gap on the LEFT side of the anomaly while(leftIndex-leftRoom>=0 && !isalpha(candAln[leftIndex-leftRoom])) { leftRoom++; } @@ -119,18 +117,17 @@ void Nast::removeExtraGaps(string& candAln, string tempAln, string newTemplateAl break; } } - + int insertLength = 0; // figure out how long the anomaly is while(!isalpha(newTemplateAlign[i + insertLength])) { insertLength++; } if(insertLength > maxInsertLength){ maxInsertLength = insertLength; } - + if((leftRoom + rightRoom) >= insertLength){ // Parts D & E from Fig. 2 of DeSantis et al. if((i-leftIndex) <= (rightIndex-i)){ // the left gap is closer - > move stuff left there's if(leftRoom >= insertLength){ // enough room to the left to move - string leftTemplateString = newTemplateAlign.substr(0,i); string rightTemplateString = newTemplateAlign.substr(i+insertLength); newTemplateAlign = leftTemplateString + rightTemplateString; @@ -156,7 +153,6 @@ void Nast::removeExtraGaps(string& candAln, string tempAln, string newTemplateAl } else{ // the right gap is closer - > move stuff right there's if(rightRoom >= insertLength){ // enough room to the right to move - string leftTemplateString = newTemplateAlign.substr(0,i); string rightTemplateString = newTemplateAlign.substr(i+insertLength); newTemplateAlign = leftTemplateString + rightTemplateString; @@ -167,7 +163,7 @@ void Nast::removeExtraGaps(string& candAln, string tempAln, string newTemplateAl candAln = leftCandidateString + rightCandidateString; } - else{ // not enough room to the right, have to steal some + else{ // not enough room to the right, have to steal some // space to the left lets move left and then right... string leftTemplateString = newTemplateAlign.substr(0,i); string rightTemplateString = newTemplateAlign.substr(i+insertLength); @@ -181,10 +177,13 @@ void Nast::removeExtraGaps(string& candAln, string tempAln, string newTemplateAl } } + i -= insertLength; + } else{ - // there could be a case where there isn't enough room in - string leftTemplateString = newTemplateAlign.substr(0,i); // either direction to move stuff + // there could be a case where there isn't enough room in either direction to move stuff + + string leftTemplateString = newTemplateAlign.substr(0,i); string rightTemplateString = newTemplateAlign.substr(i+leftRoom+rightRoom); newTemplateAlign = leftTemplateString + rightTemplateString; longAlignmentLength = newTemplateAlign.length(); @@ -193,15 +192,16 @@ void Nast::removeExtraGaps(string& candAln, string tempAln, string newTemplateAl string insertString = candAln.substr(leftIndex+1,rightIndex-leftIndex-1); string rightCandidateString = candAln.substr(rightIndex+rightRoom); candAln = leftCandidateString + insertString + rightCandidateString; - + + i -= (leftRoom + rightRoom); } - - i -= insertLength; + +// i -= insertLength; } } } catch(exception& e) { - errorOut(e, "Nast", "removeExtraGaps"); + m->errorOut(e, "Nast", "removeExtraGaps"); exit(1); } } @@ -225,7 +225,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 @@ -304,14 +304,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++; } @@ -322,7 +322,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;isetAligned(candAln); } catch(exception& e) { - errorOut(e, "Nast", "regapSequences"); + m->errorOut(e, "Nast", "regapSequences"); exit(1); } } @@ -381,7 +382,7 @@ float Nast::getSimilarityScore(){ } catch(exception& e) { - errorOut(e, "Nast", "getSimilarityScore"); + m->errorOut(e, "Nast", "getSimilarityScore"); exit(1); } }