X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=alignment.cpp;h=9ab17004bc146bc97168373995c98b932dcb9c3f;hp=235216e8e59c82be596004559445c021312acb40;hb=050a3ff02473a3d4c0980964e1a9ebe52e55d6b8;hpb=e4c80376cc4533f66c8dfc18f3e1a86a60ac17fe diff --git a/alignment.cpp b/alignment.cpp index 235216e..9ab1700 100644 --- a/alignment.cpp +++ b/alignment.cpp @@ -15,7 +15,7 @@ /**************************************************************************************************/ -Alignment::Alignment() { /* do nothing */ } +Alignment::Alignment() { m = MothurOut::getInstance(); /* do nothing */ } /**************************************************************************************************/ @@ -53,7 +53,8 @@ void Alignment::resize(int A) { void Alignment::traceBack(){ // This traceback routine is used by the dynamic programming algorithms try { - // to fill the values of seqAaln and seqBaln + BBaseMap.clear(); + ABaseMap.clear(); // to fill the values of seqAaln and seqBaln seqAaln = ""; seqBaln = ""; int row = lB-1; @@ -65,31 +66,51 @@ void Alignment::traceBack(){ // This traceback routine is used by the dynamic // matrix if(currentCell.prevCell == 'x'){ seqAaln = seqBaln = "NOALIGNMENT"; }//If there's an 'x' in the bottom- - else{ // right corner bail out because it means nothing got aligned + else{ // right corner bail out because it means nothing got aligned + int count = 0; while(currentCell.prevCell != 'x'){ // while the previous cell isn't an 'x', keep going... if(currentCell.prevCell == 'u'){ // if the pointer to the previous cell is 'u', go up in the seqAaln = '-' + seqAaln; // matrix. this indicates that we need to insert a gap in seqBaln = seqB[row] + seqBaln; // seqA and a base in seqB + BBaseMap[row] = count; currentCell = alignment[--row][column]; } else if(currentCell.prevCell == 'l'){ // if the pointer to the previous cell is 'l', go to the left seqBaln = '-' + seqBaln; // in the matrix. this indicates that we need to insert a gap seqAaln = seqA[column] + seqAaln; // in seqB and a base in seqA + ABaseMap[column] = count; currentCell = alignment[row][--column]; } else{ seqAaln = seqA[column] + seqAaln; // otherwise we need to go diagonally up and to the left, seqBaln = seqB[row] + seqBaln; // here we add a base to both alignments + BBaseMap[row] = count; + ABaseMap[column] = count; currentCell = alignment[--row][--column]; } + count++; } } - pairwiseLength = seqAaln.length(); + + pairwiseLength = seqAaln.length(); seqAstart = 1; seqAend = 0; seqBstart = 1; seqBend = 0; - + //flip maps since we now know the total length + map newAMap; + for (map::iterator it = ABaseMap.begin(); it != ABaseMap.end(); it++) { + int spot = it->second; + newAMap[pairwiseLength-spot-1] = it->first-1; + } + ABaseMap = newAMap; + map newBMap; + for (map::iterator it = BBaseMap.begin(); it != BBaseMap.end(); it++) { + int spot = it->second; + newBMap[pairwiseLength-spot-1] = it->first-1; + } + BBaseMap = newBMap; + for(int i=0;i Alignment::getSeqAAlnBaseMap(){ + return ABaseMap; +} +/**************************************************************************************************/ +map Alignment::getSeqBAlnBaseMap(){ + return BBaseMap; +} /**************************************************************************************************/ int Alignment::getTemplateEndPos(){