Nast::Nast(Alignment* method, Sequence* cand, Sequence* temp) : alignment(method), candidateSeq(cand), templateSeq(temp) {
try {
Nast::Nast(Alignment* method, Sequence* cand, Sequence* temp) : alignment(method), candidateSeq(cand), templateSeq(temp) {
try {
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.
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.
void Nast::pairwiseAlignSeqs(){ // Here we call one of the pairwise alignment methods to align our unaligned candidate
// and template sequences
try {
void Nast::pairwiseAlignSeqs(){ // Here we call one of the pairwise alignment methods to align our unaligned candidate
// and template sequences
try {
if(tempAln[0] == '-'){
int pairwiseAlignmentLength = tempAln.length(); // we need to make sure that the candidate sequence alignment
for(int i=0;i<pairwiseAlignmentLength;i++){ // starts where the template sequence alignment starts, if it
if(tempAln[0] == '-'){
int pairwiseAlignmentLength = tempAln.length(); // we need to make sure that the candidate sequence alignment
for(int i=0;i<pairwiseAlignmentLength;i++){ // starts where the template sequence alignment starts, if it
int pairwiseAlignmentLength = tempAln.length();
if(tempAln[pairwiseAlignmentLength-1] == '-'){ // we need to make sure that the candidate sequence alignment
for(int i=pairwiseAlignmentLength-1; i>=0; i--){// ends where the template sequence alignment ends, if it runs
int pairwiseAlignmentLength = tempAln.length();
if(tempAln[pairwiseAlignmentLength-1] == '-'){ // we need to make sure that the candidate sequence alignment
for(int i=pairwiseAlignmentLength-1; i>=0; i--){// ends where the template sequence alignment ends, if it runs
candidateSeq->setPairwise(candAln); // set the pairwise sequences in the Sequence objects for
templateSeq->setPairwise(tempAln); // the candidate and template sequences
candidateSeq->setPairwise(candAln); // set the pairwise sequences in the Sequence objects for
templateSeq->setPairwise(tempAln); // the candidate and template sequences
for(int i=0; i<longAlignmentLength; i++){ // use the long alignment as the standard
int rightIndex, rightRoom, leftIndex, leftRoom;
for(int i=0; i<longAlignmentLength; i++){ // use the long alignment as the standard
int rightIndex, rightRoom, leftIndex, leftRoom;
rightRoom = 0; leftRoom = 0;
// Part D of Fig. 2 from DeSantis et al. // template sequence and the official template sequence
rightRoom = 0; leftRoom = 0;
// Part D of Fig. 2 from DeSantis et al. // template sequence and the official template sequence
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++; }
break;
}
}
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++; }
break;
}
}
for(rightIndex=i+1;rightIndex<longAlignmentLength-1;rightIndex++){
if(!isalpha(candAln[rightIndex])){
rightRoom = 1; //count how far it is to the nearest gap on the RIGHT side of the anomaly
for(rightIndex=i+1;rightIndex<longAlignmentLength-1;rightIndex++){
if(!isalpha(candAln[rightIndex])){
rightRoom = 1; //count how far it is to the nearest gap on the RIGHT side of the anomaly
int insertLength = 0; // figure out how long the anomaly is
while(!isalpha(newTemplateAlign[i + insertLength])) { insertLength++; }
if(insertLength > maxInsertLength){ maxInsertLength = insertLength; }
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
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;
string leftTemplateString = newTemplateAlign.substr(0,i);
string rightTemplateString = newTemplateAlign.substr(i+insertLength);
newTemplateAlign = leftTemplateString + rightTemplateString;
}
else{ // the right gap is closer - > move stuff right there's
if(rightRoom >= insertLength){ // enough room to the right to move
}
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;
string leftTemplateString = newTemplateAlign.substr(0,i);
string rightTemplateString = newTemplateAlign.substr(i+insertLength);
newTemplateAlign = leftTemplateString + rightTemplateString;
// space to the left lets move left and then right...
string leftTemplateString = newTemplateAlign.substr(0,i);
string rightTemplateString = newTemplateAlign.substr(i+insertLength);
// space to the left lets move left and then right...
string leftTemplateString = newTemplateAlign.substr(0,i);
string rightTemplateString = newTemplateAlign.substr(i+insertLength);
- // 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();
string rightTemplateString = newTemplateAlign.substr(i+leftRoom+rightRoom);
newTemplateAlign = leftTemplateString + rightTemplateString;
longAlignmentLength = newTemplateAlign.length();
string insertString = candAln.substr(leftIndex+1,rightIndex-leftIndex-1);
string rightCandidateString = candAln.substr(rightIndex+rightRoom);
candAln = leftCandidateString + insertString + rightCandidateString;
string insertString = candAln.substr(leftIndex+1,rightIndex-leftIndex-1);
string rightCandidateString = candAln.substr(rightIndex+rightRoom);
candAln = leftCandidateString + insertString + rightCandidateString;
int fullAlignIndex = 0;
int pairwiseAlignIndex = 0;
string newTemplateAlign = ""; // this is going to be messy so we want a temporary template
int fullAlignIndex = 0;
int pairwiseAlignIndex = 0;
string newTemplateAlign = ""; // this is going to be messy so we want a temporary template
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
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
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.
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.