eXpress “1.5”
|
00001 #ifndef MAIN_H 00002 #define MAIN_H 00003 00012 #include "config.h" 00013 #include "logger.h" 00014 #include <algorithm> 00015 #include <limits> 00016 #include <boost/foreach.hpp> 00017 #include <cmath> 00018 #include <cassert> 00019 #include <limits> 00020 00021 #define foreach BOOST_FOREACH 00022 00023 class MapParser; 00024 class TargetTable; 00025 class BiasBoss; 00026 class MismatchTable; 00027 class LengthDistribution; 00028 00029 extern Logger logger; 00034 extern bool running; 00040 extern bool burned_out; 00044 extern bool edit_detect; 00048 extern size_t max_indel_size; 00059 enum Direction { FR, RF, R, F, BOTH }; 00064 extern Direction direction; 00068 extern size_t max_read_len; 00072 const size_t NUM_NUCS = 4; 00076 const char NUCS[] = {'A','C','G','T'}; 00080 const double LOG_0 = HUGE_VAL; 00084 const double LOG_1 = 0; 00088 const double LOG_QUARTER = log(0.25); 00092 const double EPSILON = 0.000001; 00093 const double LOG_EPSILON = log(EPSILON); 00094 const double LOG_MAX = log(std::numeric_limits<double>::max()); 00095 00105 inline bool approx_eq(double a, double b, double eps=EPSILON) { 00106 return fabs(a-b) <= eps; 00107 } 00108 00116 inline double log_add(double x, double y) { 00117 if (fabs(x) == LOG_0) { 00118 return y; 00119 } 00120 if (fabs(y) == LOG_0) { 00121 return x; 00122 } 00123 00124 if (y > x) { 00125 std::swap(x,y); 00126 } 00127 00128 double sum = x+log(1+exp(y-x)); 00129 return sum; 00130 } 00138 inline double log_sub(double x, double y) { 00139 if (fabs(y) == LOG_0) { 00140 return x; 00141 } 00142 00143 // Have to be careful of numerical issues, so we allow y to be slightly 00144 // greater than x. 00145 if (x <= y) { 00146 assert(approx_eq(x, y)); 00147 return LOG_0; 00148 } 00149 00150 00151 double diff = x+log(1-exp(y-x)); 00152 return diff; 00153 } 00159 inline double islzero(double x) 00160 { 00161 return (fabs(x) == LOG_0); 00162 } 00163 00169 inline double sexp(double x) 00170 { 00171 if (islzero(x)) { 00172 return 0.0; 00173 } 00174 return exp(x); 00175 } 00176 00177 #endif