BaseUtilities.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "BaseUtilities.h"
00019 #include <ctype.h>
00020 #include "BaseAsciiMap.h"
00021
00022
00023 bool BaseUtilities::isAmbiguous(char base)
00024 {
00025 switch(base)
00026 {
00027 case 'N':
00028 case 'n':
00029 case '.':
00030 return(true);
00031 break;
00032 default:
00033 break;
00034 };
00035
00036
00037 return(false);
00038 }
00039
00040 bool BaseUtilities::areEqual(char base1, char base2)
00041 {
00042
00043 if(base1 == base2)
00044 {
00045 return(true);
00046 }
00047
00048 if((base1 == '=') || (base2 == '='))
00049 {
00050 return(true);
00051 }
00052
00053
00054 if(toupper(base1) == toupper(base2))
00055 {
00056
00057 return(true);
00058 }
00059
00060
00061 return(false);
00062 }
00063
00064
00065
00066 uint8_t BaseUtilities::getPhredBaseQuality(char charQuality)
00067 {
00068 if(charQuality == UNKNOWN_QUALITY_CHAR)
00069 {
00070 return(UNKNOWN_QUALITY_INT);
00071 }
00072
00073 return(charQuality - 33);
00074 }
00075
00076
00077 char BaseUtilities::getAsciiQuality(uint8_t phredQuality)
00078 {
00079 if(phredQuality == UNKNOWN_QUALITY_INT)
00080 {
00081 return(UNKNOWN_QUALITY_CHAR);
00082 }
00083 return(phredQuality + 33);
00084 }
00085
00086
00087 void BaseUtilities::reverseComplement(std::string& sequence)
00088 {
00089 int start = 0;
00090 int end = sequence.size() - 1;
00091 char tempChar;
00092
00093 while(start < end)
00094 {
00095 tempChar = sequence[start];
00096 sequence[start] = BaseAsciiMap::base2complement[(int)(sequence[end])];
00097 sequence[end] = BaseAsciiMap::base2complement[(int)tempChar];
00098
00099 ++start;
00100 --end;
00101 }
00102
00103
00104 if(start == end)
00105 {
00106 tempChar = sequence[start];
00107 sequence[start] = BaseAsciiMap::base2complement[(int)tempChar];
00108 }
00109 }