BaseAsciiMap.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _BASE_ASCII_MAP_H
00019 #define _BASE_ASCII_MAP_H
00020
00021 #include "StringBasics.h"
00022
00023 class BaseAsciiMap
00024 {
00025 public:
00026 static const int baseAIndex = 000;
00027 static const int baseTIndex = 001;
00028 static const int baseCIndex = 002;
00029 static const int baseGIndex = 003;
00030 static const int baseNIndex = 004;
00031 static const int baseXIndex = 005;
00032
00033
00034
00035
00036
00037 static const char int2base[];
00038 static const char int2colorSpace[];
00039 static unsigned char base2complement[];
00040
00041 enum SPACE_TYPE {UNKNOWN, BASE_SPACE, COLOR_SPACE};
00042
00043 public:
00044 BaseAsciiMap();
00045 ~BaseAsciiMap();
00046
00047
00048 inline void setBaseMapType(SPACE_TYPE spaceType)
00049 {
00050 resetPrimerCount();
00051
00052 switch (spaceType)
00053 {
00054 case BASE_SPACE:
00055
00056 myBase2IntMapPtr = base2int;
00057 break;
00058 case COLOR_SPACE:
00059
00060 myBase2IntMapPtr = color2int;
00061 break;
00062 default:
00063
00064 myBase2IntMapPtr = NULL;
00065 break;
00066 }
00067 };
00068
00069
00070 inline int getBaseIndex(const char& letter)
00071 {
00072 if (myBase2IntMapPtr == NULL)
00073 {
00074
00075 if (myPrimerCount < myNumPrimerBases)
00076 {
00077
00078
00079 ++myPrimerCount;
00080 return(base2int[(int)letter]);
00081 }
00082
00083
00084
00085
00086
00087 setBaseMapType(letter);
00088
00089
00090
00091 if (myBase2IntMapPtr == NULL)
00092 {
00093 return(baseXIndex);
00094 }
00095 }
00096
00097
00098 if ((myBase2IntMapPtr == color2int) && (myPrimerCount < myNumPrimerBases))
00099 {
00100
00101
00102 ++myPrimerCount;
00103 return(base2int[(int)letter]);
00104 }
00105
00106 return myBase2IntMapPtr[(int)letter];
00107 }
00108
00109 inline SPACE_TYPE getSpaceType()
00110 {
00111 if (myBase2IntMapPtr == base2int)
00112 {
00113 return(BASE_SPACE);
00114 }
00115 else if (myBase2IntMapPtr == color2int)
00116 {
00117 return(COLOR_SPACE);
00118 }
00119 else
00120 {
00121 return(UNKNOWN);
00122 }
00123 }
00124
00125 void setNumPrimerBases(int numPrimerBases)
00126 {
00127 myNumPrimerBases = numPrimerBases;
00128 }
00129
00130 void resetPrimerCount()
00131 {
00132 myPrimerCount = 0;
00133 };
00134 void resetBaseMapType()
00135 {
00136 myBase2IntMapPtr = NULL;
00137 resetPrimerCount();
00138 };
00139
00140 private:
00141
00142
00143
00144 inline void setBaseMapType(const char& letter)
00145 {
00146
00147 if (base2int[(int)letter] != baseXIndex)
00148 {
00149
00150 myBase2IntMapPtr = base2int;
00151 }
00152 else if (color2int[(int)letter] != baseXIndex)
00153 {
00154
00155 myBase2IntMapPtr = color2int;
00156 }
00157 else
00158 {
00159
00160 myBase2IntMapPtr = NULL;
00161 }
00162 };
00163
00164
00165
00166 unsigned int myNumPrimerBases;
00167
00168
00169
00170 unsigned int myPrimerCount;
00171
00172 unsigned char* myBase2IntMapPtr;
00173 static unsigned char baseColor2int[256+1];
00174 static unsigned char base2int[256+1];
00175 static unsigned char color2int[256+1];
00176 };
00177
00178 #endif