#include "matrix.h" #include "aaTools.h" // Initializes Matrix Matrix::Matrix(int len) { if(DB) printf("entering Matrix constructor \n"); N = len; cell = new int*[len]; for(int i = 0; i < len; i++) cell[i] = new int[len]; label = new char[len+1]; if(len==20) strcpy(label, "ARNDCQEGHILKMFPSTWYV"); if(len==7) strcpy(label, "BEGHSTC"); if(DB) printf("leaving Matrix constructor \n"); } // Default constructor Matrix::Matrix() { if(DB) printf("entering default Matrix constructor \n"); int len=20; // set by default N = len; cell = new int*[len]; for(int i = 0; i < len; i++) cell[i] = new int[len]; label = new char[len+1]; if(len==20) strcpy(label, "ARNDCQEGHILKMFPSTWYV"); if(len==7) strcpy(label, "BEGHSTC"); if(DB) printf("leaving default Matrix constructor \n"); } // Destructor Matrix::~Matrix() { if(DB) printf("entering Matrix destructor \n"); if(cell!=NULL) for(int i=0; icell[i][j]) minimumCellValue=cell[i][j]; delete[] p; for(int i=0; i-1 && B>-1 && gapP[i]<=maxPGaps) { f[A][B]++; f[B][A]++; } } } else for(k=0; k-1 && B>-1) { f[A][B]++; f[B][A]++; } } } if(DB) printf("leaving Matrix computeFrequencies \n"); } // Loads the Blosum50 Matrix into the Matrix::cell fields void Matrix::computeFromBlosumFile(char *s) { if(DB) printf("entering Matrix computeFromBlosumFile \n"); int i, j; FILE *blosFile; char* temp = new char[100]; char* temp2 = new char[100]; strcpy(temp, BLOSUM_PATH); strcat(temp, s); blosFile = fopen(temp, "r"); // Open input file for(i=0; i<6; i++) fgets(temp, 80+2, blosFile); strcpy(temp2, temp+13); temp2[9]=0; relativeEntropy = charToFloat(temp2); strcpy(temp2, temp+34); temp2[9]=0; expectedValue = charToFloat(temp2); fgets(temp, 80+2, blosFile); for(i=0; imax) max=cell[i][j]; printf("# Matrix made by aaTools\n"); printf("# * column uses minimum score\n"); printf("# Scoring Matrix in 1/%d Bit Units\n",SCALE); printf("# \n"); printf("# \n"); printf("# Entropy = %1.4f, Expected = %1.4f\n", relativeEntropy,expectedValue); printf(" "); for(i=0; imax) max=cell[i][j]; printf("Relative Entropy (H) = %f\n", relativeEntropy); printf("Expected Score (E) = %f\n", expectedValue); printf(" "); for(i=0; imax*2/3) RED else if(cell[j][i]>max*1/3) YEL else if(cell[j][i]>0) GRE else if(cell[j][i]>min*1/3) IND else if(cell[j][i]>min*2/3) BLU else VIO */ if(cell[j][i]>10) RED else if(cell[j][i]>5) YEL else if(cell[j][i]>0) GRE else if(cell[j][i]>-5) IND else if(cell[j][i]>-10) BLU else VIO printf("%3d", cell[j][i]); BLK } printf("\n"); } BLK if(DB) printf("leaving Matrix::print\n"); } // Maps each character in a set to consecutive integers int Matrix::residueCharToInt(char residue) { for(int i=0; i=N) fprintf(stderr,"ERROR: In function int Matrix::getCell(int,int), index i=%d is greater than matrix dimension N=%d\n",i,N); if(j>=N) fprintf(stderr,"ERROR: In function int Matrix::getCell(int,int), index j=%d is greater than matrix dimension N=%d\n",j,N); } return -999; } }