/***************************************************************************** * * (C) Copyright 2005 The Board of Trustees of the * University of Illinois * All Rights Reserved * ******************************************************************************/ /***************************************************************************** * RCS INFORMATION: * * $RCSfile: sequenceQR.cpp,v $ * $Author: erobert3 $ $Locker: $ $State: Exp $ * $Revision: 1.1.2.7 $ $Date: 2005/02/10 23:16:20 $ * ******************************************************************************/ // $Id: sequenceQR.cpp,v 1.1.2.7 2005/02/10 23:16:20 erobert3 Exp $ #include #include #include "symbol.h" #include "sequence.h" #include "alignedSequence.h" #include "sequenceAlignment.h" #include "sequenceQR.h" // Constructor SequenceQR::SequenceQR(SequenceAlignment *alignment, float identityCutoff, int preserveCount, int performGapScaling, float gapScaleParameter) { this->alignment = alignment; this->identityCutoff = identityCutoff; this->preserveCount = preserveCount; this->performGapScaling = performGapScaling; this->gapScaleParameter = gapScaleParameter; cMi = alignment->getLength(); cMj = 24; cMk = alignment->getSequenceCount(); //Create a matrix containing the data representing this alignment. matrix = new float**[cMi]; for (int i=0; igetSequence(k); //Fill in the value for the matrix element. switch (j) { case 0: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'A')?1:0; break; case 1: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'B')?1:0; break; case 2: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'C')?1:0; break; case 3: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'D')?1:0; break; case 4: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'E')?1:0; break; case 5: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'F')?1:0; break; case 6: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'G')?1:0; break; case 7: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'H')?1:0; break; case 8: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'I')?1:0; break; case 9: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'K')?1:0; break; case 10: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'L')?1:0; break; case 11: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'M')?1:0; break; case 12: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'N')?1:0; break; case 13: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'P')?1:0; break; case 14: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'Q')?1:0; break; case 15: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'R')?1:0; break; case 16: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'S')?1:0; break; case 17: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'T')?1:0; break; case 18: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'V')?1:0; break; case 19: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'W')?1:0; break; case 20: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'X')?1:0; break; case 21: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'Y')?1:0; break; case 22: matrix[i][j][k] = (sequence->getSymbol(i)->getOne() == 'Z')?1:0; break; case 23: matrix[i][j][k] = sequence->getAlphabet()->isGap(sequence->getSymbol(i))?1:0; break; } } } } //Fill in the initial sequence ordering list. columnList = new int[cMk]; for (int k=0; k= preserveCount) permuteColumns(k); householder(k); //If we have exceeded the percent identity cutoff value, we are done. if (identityCutoff < 1.0 && isSequenceAboveIdentityCutoff(k)) break; } //Copy the profile into a new sequence alignment. int kMax = k; SequenceAlignment* profile = new SequenceAlignment(alignment->getLength(), alignment->getSequenceCount()); for (k=0; kaddSequence(alignment->getSequence(columnList[k])); } return profile; } // householder // void SequenceQR::householder(int currentColumn) { int i,j,k; float sign, alpha, beta, gamma; float * hhVector; // Loop over coordinate dimensions (x,y,z,gap) for (j=0; j= 0) ? 1.0 : -1.0; alpha = -sign * sqrt(alpha); hhVector = new float[cMi]; for (i=0; igetSequence(k1)->getPercentIdentity(alignment->getSequence(k2))); } //If this is the least percent identity we ahve yet encountered, save it. if (min < 0.0 || value < min) { min = value; maxCol = k1; } } } //Otherwise, use the frobenius norm to figure out which column to switch. else { float *norms = new float[cMk]; float maxNorm = 0.0; for (int k=0; k maxNorm) { maxCol = k; maxNorm = norms[k]; } } delete norms; } /* //Print the norms. printf("Norms for %d:", currentColumn); for (int k=0; kgetSequence(columnList[currentColumn]); for (int k=0; kgetSequence(columnList[k]); if (currentSequence->getPercentIdentity(sequence) >= identityCutoff) { return 1; } } return 0; } // frobeniusNormSeq // Get the frobenius norm for the matrix corresponding // to the data for one sequence // frobeniusNorm(A) = sqrt( sum( all Aij ) ); float SequenceQR::frobeniusNormByK(int k, int currentRow) { float fNorm = 0; for (int i=currentRow; i