1 #include "NucleotideMatrix.h" 2 #include <climits> 3 NucleotideMatrix(const char * scoringMatrixFileName,float bitFactor,float scoreBias)4NucleotideMatrix::NucleotideMatrix(const char* scoringMatrixFileName, float bitFactor, float scoreBias) 5 : SubstitutionMatrix(scoringMatrixFileName, bitFactor, scoreBias) { 6 setupLetterMapping(); 7 reverseLookup = new int[alphabetSize]; 8 // TODO think about making the matrix dynamic 9 reverseLookup[aa2num[static_cast<int>('A')]] = aa2num[static_cast<int>('T')]; 10 reverseLookup[aa2num[static_cast<int>('G')]] = aa2num[static_cast<int>('C')]; 11 reverseLookup[aa2num[static_cast<int>('C')]] = aa2num[static_cast<int>('G')]; 12 reverseLookup[aa2num[static_cast<int>('T')]] = aa2num[static_cast<int>('A')]; 13 reverseLookup[aa2num[static_cast<int>('X')]] = aa2num[static_cast<int>('X')]; 14 } 15 16 setupLetterMapping()17void NucleotideMatrix::setupLetterMapping(){ 18 for(int letter = 0; letter < UCHAR_MAX; letter++){ 19 char upperLetter = toupper(static_cast<char>(letter)); 20 /* 21 * R.................A or G 22 * Y.................C or T 23 * S.................G or C 24 * W.................A or T 25 * K.................G or T 26 * M.................A or C 27 * B.................C or G or T 28 * D.................A or G or T 29 * H.................A or C or T 30 * V.................A or C or G 31 */ 32 switch(upperLetter){ 33 case 'A': 34 case 'T': 35 case 'G': 36 case 'C': 37 this->aa2num[static_cast<int>(letter)] = this->aa2num[static_cast<int>(upperLetter)]; 38 break; 39 case 'U': 40 case 'W': 41 this->aa2num[static_cast<int>(letter)] = this->aa2num[static_cast<int>('T')]; 42 break; 43 case 'K': 44 case 'B': 45 case 'D': 46 case 'V': 47 case 'R': 48 case 'S': 49 this->aa2num[static_cast<int>(letter)] = this->aa2num[static_cast<int>('G')]; 50 break; 51 case 'M': 52 case 'Y': 53 case 'H': 54 this->aa2num[static_cast<int>(letter)] = this->aa2num[static_cast<int>('C')]; 55 break; 56 default: 57 this->aa2num[static_cast<int>(letter)] = this->aa2num[static_cast<int>('X')]; 58 break; 59 } 60 } 61 } 62 63 ~NucleotideMatrix()64NucleotideMatrix::~NucleotideMatrix(){ 65 delete [] reverseLookup; 66 } 67 68