include/scoreMatrix.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

scoreMatrix scoreMatrix_load (char *filename)
scoreMatrix scoreMatrix_create (int2 match, int2 mismatch)
void scoreMatrix_print (struct scoreMatrix scoreMatrix)
void scoreMatrix_free (struct scoreMatrix scoreMatrix)


Function Documentation

struct scoreMatrix scoreMatrix_create ( int2  match,
int2  mismatch 
) [read]

Definition at line 197 of file scoreMatrix.c.

References constants_sentinalScore, encoding_numCodes, encoding_numRegularLetters, encoding_sentinalCode, encoding_wildcards, global_malloc(), scoreMatrix::highestValue, int2, int4, scoreMatrix::lowestValue, scoreMatrix::matrix, and wildcard::numCodes.

Referenced by main().

00198 {
00199     struct scoreMatrix scoreMatrix;
00200         char *tempAddress;
00201         int4 x, y, numXcodes, numYcodes, count, xCode, yCode, total;
00202 
00203         scoreMatrix.highestValue = match;
00204         scoreMatrix.lowestValue = mismatch;
00205 
00206         // Declare memory used by scoreMatrix
00207         scoreMatrix.matrix = (int2**)global_malloc(sizeof(int2*) * encoding_numCodes
00208                        + sizeof(int2) * encoding_numCodes * encoding_numCodes);
00209     tempAddress = (char*)scoreMatrix.matrix;
00210 
00211     // For each row in the matrix
00212     x = 0;
00213         while (x < encoding_numCodes)
00214         {
00215         // Initialize memory
00216                 scoreMatrix.matrix[x] = (int2*)(tempAddress + sizeof(int2*) * encoding_numCodes +
00217                                              sizeof(int2) * encoding_numCodes * x);
00218 
00219         // For each column, determine value
00220                 y = 0;
00221                 while (y < encoding_numCodes)
00222                 {
00223                 // If either is the sentinal code, use sentinal score
00224                 if (x == encoding_sentinalCode || y == encoding_sentinalCode)
00225             {
00226                                 scoreMatrix.matrix[x][y] = constants_sentinalScore;
00227             }
00228             // If both characters are wilds, calculate score for match
00229             else if (x >= encoding_numRegularLetters && y >= encoding_numRegularLetters)
00230             {
00231                 // For each possible letter for x
00232                 total = 0; count = 0;
00233                 xCode = 0;
00234                 numXcodes = encoding_wildcards[x].numCodes;
00235                 while (xCode < numXcodes)
00236                 {
00237                         // For each possible letter for y
00238                     yCode = 0;
00239                     numYcodes = encoding_wildcards[y].numCodes;
00240                     while (yCode < numYcodes)
00241                     {
00242                                                 // If the letters match
00243                         if (encoding_wildcards[x].replacementCodes[xCode] ==
00244                             encoding_wildcards[y].replacementCodes[yCode])
00245                         {
00246                                 count++;
00247                         }
00248                         total++;
00249                         yCode++;
00250                     }
00251                     xCode++;
00252                 }
00253 
00254                 // Calculate frequency of the letters matching and probably score
00255                 scoreMatrix.matrix[x][y] = (int4)ceilf(((float)match * (float)count / (float)total) +
00256                                            ((float)mismatch * (float)(total - count) / (float)total));
00257             }
00258             // If the characters match
00259             else if (x == y)
00260             {
00261                                 scoreMatrix.matrix[x][y] = match;
00262             }
00263             // Mismatch
00264             else
00265             {
00266                                 scoreMatrix.matrix[x][y] = mismatch;
00267 
00268                 // If y is in x's list of ambigious codes
00269                 count = 0;
00270                 numXcodes = encoding_wildcards[x].numCodes;
00271                 while (count < numXcodes)
00272                 {
00273                         if (encoding_wildcards[x].replacementCodes[count] == y)
00274                     {
00275                         // Give score based on probability of a match
00276                                                 scoreMatrix.matrix[x][y] = (int4)ceilf(((float)match / (float)numXcodes) +
00277                                 ((float)mismatch * (float)(numXcodes - 1) / (float)numXcodes));
00278                     }
00279                     count++;
00280                 }
00281 
00282                 // Similarly if x is in y's list of ambigious codes
00283                 count = 0;
00284                 numYcodes = encoding_wildcards[y].numCodes;
00285                 while (count < numYcodes)
00286                 {
00287                         if (encoding_wildcards[y].replacementCodes[count] == x)
00288                     {
00289                         // Give score based on probability of a match
00290                                                 scoreMatrix.matrix[x][y] = (int4)ceilf(((float)match / (float)numYcodes) +
00291                                 ((float)mismatch * (float)(numYcodes - 1) / (float)numYcodes));
00292                     }
00293                     count++;
00294                 }
00295             }
00296 
00297                         y++;
00298                 }
00299         x++;
00300         }
00301 
00302     return scoreMatrix;
00303 }

Here is the call graph for this function:

Here is the caller graph for this function:

void scoreMatrix_free ( struct scoreMatrix  scoreMatrix  ) 

Definition at line 346 of file scoreMatrix.c.

References scoreMatrix::matrix.

Referenced by main().

00347 {
00348         free(scoreMatrix.matrix);
00349 }

Here is the caller graph for this function:

struct scoreMatrix scoreMatrix_load ( char *  filename  )  [read]

Definition at line 16 of file scoreMatrix.c.

References scoreMatrix::averageMatchScore, constants_sentinalScore, encoding_aaStartWildcards, encoding_getCode(), encoding_numCodes, encoding_numLetters, encoding_sentinalCode, global_malloc(), scoreMatrix::highestValue, int2, int4, scoreMatrix::lowestValue, scoreMatrix::matrix, Robinson_prob, clusterWildcard::scoreMatrixRow, wildcards_clusterWildcards, and wildcards_numClusterWildcards.

Referenced by main().

00017 {
00018         FILE* matrixFile;
00019         int4 MAXLINELENGTH = 8096;
00020         int4 lineNumber = 0;
00021         int4 tokenCount;
00022         char line[MAXLINELENGTH];
00023         char *token, *tempAddress;
00024         unsigned char columnHeadings[24];
00025         unsigned char rowHeadings[24];
00026         int2 value;
00027     struct scoreMatrix scoreMatrix;
00028         int4 x, y;
00029 
00030         scoreMatrix.highestValue = 0;
00031         scoreMatrix.lowestValue = 0;
00032 
00033         // Declare memory used by scoreMatrix
00034         scoreMatrix.matrix = (int2**)global_malloc(sizeof(int2*) * encoding_numCodes
00035                        + sizeof(int2) * encoding_numCodes * encoding_numCodes);
00036     tempAddress = (char*)scoreMatrix.matrix;
00037         x = 0;
00038         while (x < encoding_numCodes)
00039         {
00040                 scoreMatrix.matrix[x] = (int2*)(tempAddress + sizeof(int2*) * encoding_numCodes +
00041                                              sizeof(int2) * encoding_numCodes * x);
00042         // Initialize the score matrix, by setting all values to sentinal score
00043                 y = 0;
00044                 while (y < encoding_numCodes)
00045                 {
00046                         scoreMatrix.matrix[x][y] = constants_sentinalScore;
00047                         y++;
00048                 }
00049         x++;
00050         }
00051 
00052     // Open file for reading
00053         if ((matrixFile = fopen(filename, "r")) == NULL)
00054         {
00055         fprintf(stderr, "%s\n", strerror(errno));
00056                 fprintf(stderr, "Error opening matrix file %s for reading\n", filename);
00057                 exit(-1);
00058         }
00059 
00060         // Read each line in turn
00061         while (fgets(line, MAXLINELENGTH, matrixFile) != NULL)
00062         {
00063                 // Check we didn't max out the buffer
00064                 if (strlen(line) >= MAXLINELENGTH - 1)
00065                 {
00066                 fprintf(stderr, "%s\n", strerror(errno));
00067                         fprintf(stderr, "Error reading file %s: maximum line length %d exceeded\n",
00068                                 filename, MAXLINELENGTH);
00069                         exit(-1);
00070                 }
00071                 // Check not a comment or blank line
00072                 if (line[0] != '\0' && line[0] != '#' && lineNumber < 25)
00073                 {
00074                         // Read each of the space seperated tokens from the line
00075                         tokenCount = 0;
00076                         token = strtok(line, " \n");
00077                         while (token != NULL && tokenCount < 25)
00078                         {
00079                                 // First line - tokens are column headings
00080                                 if (lineNumber == 0)
00081                                 {
00082                                         columnHeadings[tokenCount] = token[0];
00083                                 }
00084                                 // Subsequent lines, first token is row heading
00085                                 else if (tokenCount == 0) 
00086                                 {
00087                                         rowHeadings[lineNumber - 1] = token[0];
00088                                 }
00089                                 // Subsequent lines, subsequent tokens are array values
00090                                 else
00091                                 {
00092                         // Get integer value of token
00093                         value = atoi(token);
00094 
00095                     // Add to scoring matrix
00096                     scoreMatrix.matrix[encoding_getCode(rowHeadings[lineNumber - 1])]
00097                                       [encoding_getCode(columnHeadings[tokenCount - 1])] = value;
00098 
00099                     // Determine the highest and lowest values in the matrix
00100                     if (value > scoreMatrix.highestValue)
00101                     {
00102                         scoreMatrix.highestValue = value;
00103                     }
00104                     if (value < scoreMatrix.lowestValue)
00105                     {
00106                         scoreMatrix.lowestValue = value;
00107                     }
00108                                 }
00109 
00110                                 token = strtok(NULL, " \n");
00111                                 tokenCount++;
00112                         }
00113 
00114                         lineNumber++;
00115                 }
00116         }
00117 
00118     fclose(matrixFile);
00119 
00120     // For cells in the score matrix that did not recieve a score, use 1 and
00121     // lowestValue instead
00122         x = 0;
00123         while (x < encoding_numCodes)
00124         {
00125                 y = 0;
00126                 while (y < encoding_numCodes)
00127                 {
00128                 if (scoreMatrix.matrix[x][y] == constants_sentinalScore)
00129             {
00130                 if (x == y)
00131                 {
00132                         scoreMatrix.matrix[x][y] = 1;
00133                 }
00134                 else
00135                 {
00136                         scoreMatrix.matrix[x][y] = scoreMatrix.lowestValue;
00137                 }
00138             }
00139                         y++;
00140                 }
00141         x++;
00142         }
00143 
00144     // Every letter scores well against the wildcard
00145         x = 0;
00146         while (x < encoding_numCodes)
00147         {
00148                 scoreMatrix.matrix[x][encoding_aaStartWildcards] = 1;
00149                 scoreMatrix.matrix[encoding_aaStartWildcards][x] = 1;
00150                 x++;
00151         }
00152 
00153     // Every letter scores poorly against the sentinal code
00154         x = 0;
00155         while (x < encoding_numCodes)
00156         {
00157                 scoreMatrix.matrix[x][encoding_sentinalCode] = constants_sentinalScore;
00158                 scoreMatrix.matrix[encoding_sentinalCode][x] = constants_sentinalScore;
00159                 x++;
00160         }
00161 
00162     // Process wildcard scores
00163     y = 0;
00164     while (y < wildcards_numClusterWildcards)
00165     {
00166         x = 0;
00167         while (x < encoding_numLetters)
00168         {
00169                         scoreMatrix.matrix[y + encoding_aaStartWildcards][x]
00170                 = wildcards_clusterWildcards[y].scoreMatrixRow[x];
00171                         scoreMatrix.matrix[x][y + encoding_aaStartWildcards]
00172                 = wildcards_clusterWildcards[y].scoreMatrixRow[x];
00173             x++;
00174         }
00175         y++;
00176         }
00177 
00178     // Calculate average match score for two residues
00179     scoreMatrix.averageMatchScore = 0;
00180     y = 0;
00181     while (y < encoding_numLetters)
00182     {
00183         x = 0;
00184         while (x < encoding_numLetters)
00185         {
00186                 scoreMatrix.averageMatchScore += scoreMatrix.matrix[y][x] * Robinson_prob[x] * Robinson_prob[y];
00187             x++;
00188         }
00189         y++;
00190         }
00191     scoreMatrix.averageMatchScore /= 1000000;
00192 
00193     return scoreMatrix;
00194 }

Here is the call graph for this function:

Here is the caller graph for this function:

void scoreMatrix_print ( struct scoreMatrix  scoreMatrix  ) 

Definition at line 306 of file scoreMatrix.c.

References constants_sentinalScore, encoding_getLetter(), encoding_numCodes, int4, and scoreMatrix::matrix.

00307 {
00308         int4 x, y;
00309 
00310     // Print column headers
00311     printf("   ");
00312         y = 0;
00313         while (y < encoding_numCodes)
00314         {
00315         printf(" %c ", encoding_getLetter(y));
00316         y++;
00317         }
00318     printf("\n");
00319 
00320     // Iterate through each row
00321         x = 0;
00322         while (x < encoding_numCodes)
00323         {
00324         // Print row header
00325         printf(" %c ", encoding_getLetter(x));
00326 
00327                 // For each cell in the row
00328                 y = 0;
00329                 while (y < encoding_numCodes)
00330                 {
00331                         // Print value
00332                         if (scoreMatrix.matrix[x][y] == constants_sentinalScore)
00333                                 printf(" X ");
00334                         else if (scoreMatrix.matrix[x][y] >= 0 && scoreMatrix.matrix[x][y] <= 9)
00335                                 printf(" %d ", scoreMatrix.matrix[x][y]);
00336                         else
00337                                 printf("%d ", scoreMatrix.matrix[x][y]);
00338                         y++;
00339                 }
00340                 printf("\n");
00341                 x++;
00342         }
00343 }

Here is the call graph for this function:


Generated on Wed Dec 19 20:51:45 2007 for fsa-blast by  doxygen 1.5.2