+++ /dev/null
-// IntMath.h: Header for doing fractional math with integers for speed.\r
-\r
-#ifndef IntMath_h\r
-#define IntMath_h\r
-\r
-typedef float BASETYPE;\r
-//typedef double BASETYPE;\r
-\r
-// Scaling factor used to store certain floating point\r
-// values as integers to a few significant figures.\r
-//const int INTSCALE = 1000;\r
-const int INTSCALE = 1;\r
-\r
-// Type for a probability in range 0.0 to 1.0.\r
-typedef BASETYPE PROB;\r
-\r
-// Type for an log-odds integer score.\r
-// Stored as log2(PROB)*INTSCALE.\r
-//typedef int SCORE;\r
-typedef BASETYPE SCORE;\r
-\r
-// Type for a weight.\r
-// Stored as w*INTSCALE where w is in range 0.0 to 1.0.\r
-//typedef unsigned WEIGHT;\r
-typedef BASETYPE WEIGHT;\r
-\r
-// Type for a fractional weighted count stored as n*WEIGHT/N\r
-// where n=measured count (integer >= 0) and N is total for\r
-// the distribution (e.g., n=number of residues of a given\r
-// type in a column, N=number of residues in the column).\r
-// Hence values in an FCOUNT variable range from 0..INTSCALE\r
-// as an integer, representing "true" values 0.0 to 1.0.\r
-//typedef unsigned FCOUNT;\r
-typedef BASETYPE FCOUNT;\r
-\r
-// Representation of -infinity. Value should\r
-// be large and negative, but not so large\r
-// that adding a few of them overflows.\r
-// TODO: Multiplied by 10 to work around bug\r
-// when aligning Bali 1ckaA in ref4, which is\r
-// so long that B->Mmax got to -infinity, causing\r
-// traceback to fail.\r
-//const int MINUS_INFINITY = -10000000;\r
-const BASETYPE MINUS_INFINITY = (BASETYPE) -1e37;\r
-const BASETYPE PLUS_INFINITY = (BASETYPE) 1e37;\r
-\r
-// Probability relative to a null model\r
-typedef double RPROB;\r
-\r
-PROB ScoreToProb(SCORE Score);\r
-SCORE ProbToScore(PROB Prob);\r
-SCORE DoubleToScore(double d);\r
-WEIGHT DoubleToWeight(double d);\r
-double WeightToDouble(WEIGHT w);\r
-SCORE MulScoreWeight(SCORE Score, WEIGHT Weight);\r
-bool ScoreEq(SCORE s1, SCORE s2);\r
-bool BTEq(double b1, double b2);\r
-\r
-static double ScoreToDouble(SCORE Score)\r
- {\r
- return (double) Score / (double) INTSCALE;\r
- }\r
-\r
-#if 0\r
-// In-line assembler for Result = (x*y)/z\r
-// Note that imul and idiv will do 64-bit arithmetic\r
-// on 32-bit operands, so this shouldn't overflow\r
-// Can't write this efficiently in C/C++ (would\r
-// often overlow 32 bits).\r
-#define MulDivAssign(Result, x, y, z) \\r
- { \\r
- int X = (x); \\r
- int Y = (y); \\r
- int Z = (z); \\r
- _asm mov eax,X \\r
- _asm imul Y \\r
- _asm mov ecx,Z \\r
- _asm idiv ecx \\r
- _asm mov Result,eax \\r
- }\r
-#else\r
-#define MulDivAssign(Result, x, y, z) Result = (((x)*(y))/(z))\r
-#endif\r
-\r
-#define MulScoreWeight(r, s, w) MulDivAssign(r, s, w, INTSCALE)\r
-#define MulWeightWCount(r, wt, wc) MulDivAssign(r, wt, wc, INTSCALE)\r
-#define MulFCountScore(r, fc, sc) MulDivAssign(r, fc, sc, INTSCALE)\r
-\r
-#if _DEBUG\r
-\r
-static inline SCORE Add2(SCORE a, SCORE b)\r
- {\r
- if (MINUS_INFINITY == a)\r
- return MINUS_INFINITY;\r
- if (MINUS_INFINITY == b)\r
- return MINUS_INFINITY;\r
- SCORE sum = a + b;\r
- if (sum < MINUS_INFINITY)\r
- return MINUS_INFINITY;\r
-// assert(sum < OVERFLOW_WARN);\r
- return sum;\r
- }\r
-\r
-static inline SCORE Add3(SCORE a, SCORE b, SCORE c)\r
- {\r
- return Add2(Add2(a, b), c);\r
- }\r
-\r
-static inline SCORE Add4(SCORE a, SCORE b, SCORE c, SCORE d)\r
- {\r
- return Add2(Add2(a, b), Add2(c, d));\r
- }\r
-\r
-static inline SCORE Add5(SCORE a, SCORE b, SCORE c, SCORE d, SCORE e)\r
- {\r
- return Add3(Add2(a, b), Add2(c, d), e);\r
- }\r
-\r
-static inline SCORE Add6(SCORE a, SCORE b, SCORE c, SCORE d, SCORE e, SCORE f)\r
- {\r
- return Add3(Add2(a, b), Add2(c, d), Add2(e, f));\r
- }\r
-\r
-static inline SCORE Add7(SCORE a, SCORE b, SCORE c, SCORE d, SCORE e, SCORE f, SCORE g)\r
- {\r
- return Add4(Add2(a, b), Add2(c, d), Add2(e, f), g);\r
- }\r
-\r
-static inline SCORE Mul2(SCORE a, SCORE b)\r
- {\r
- if (MINUS_INFINITY == a)\r
- return MINUS_INFINITY;\r
- if (MINUS_INFINITY == b)\r
- return MINUS_INFINITY;\r
- //__int64 prod = (__int64) a * (__int64) b;\r
- //assert((SCORE) prod == prod);\r
- //return (SCORE) prod;\r
- return a*b;\r
- }\r
-\r
-static inline SCORE Sub2(SCORE a, SCORE b)\r
- {\r
- if (MINUS_INFINITY == a)\r
- return MINUS_INFINITY;\r
- if (MINUS_INFINITY == b)\r
- return MINUS_INFINITY;\r
- SCORE diff = a - b;\r
- if (diff < MINUS_INFINITY)\r
- return MINUS_INFINITY;\r
-// assert(diff < OVERFLOW_WARN);\r
- return diff;\r
- }\r
-\r
-static inline SCORE Div2(SCORE a, int b)\r
- {\r
- if (MINUS_INFINITY == a)\r
- return MINUS_INFINITY;\r
- return a/b;\r
- }\r
-\r
-//static inline SCORE MulScoreWeight(SCORE s, WEIGHT w)\r
-// {\r
-// SCORE Prod = s*(SCORE) w;\r
-// assert(Prod < OVERFLOW_WARN);\r
-// extern void Log(const char Format[], ...);\r
-// if (Prod/(SCORE) w != s)\r
-// Log("**WARRNING MulScoreWeight Prod=%d w=%d Prod/w=%d s=%d\n",\r
-// Prod,\r
-// w,\r
-// Prod/(SCORE) w,\r
-// s);\r
-// assert(Prod/ (SCORE) w == s);\r
-// return Prod/INTSCALE;\r
-// }\r
-//\r
-//static inline WCOUNT MulWeightWCount(WEIGHT wt, WCOUNT wc)\r
-// {\r
-// return (wt*wc)/INTSCALE;\r
-// }\r
-\r
-#else\r
-#define Add2(a, b) ((a) + (b))\r
-#define Sub2(a, b) ((MINUS_INFINITY == (a)) ? MINUS_INFINITY : ((a) - (b)))\r
-#define Div2(a, b) ((MINUS_INFINITY == (a)) ? MINUS_INFINITY : ((a) / (b)))\r
-#define Add3(a, b, c) ((a) + (b) + (c))\r
-#define Add4(a, b, c, d) ((a) + (b) + (c) + (d))\r
-#define Add5(a, b, c, d, e) ((a) + (b) + (c) + (d) + (e))\r
-#define Add6(a, b, c, d, e, f) ((a) + (b) + (c) + (d) + (e) + (f))\r
-#define Add7(a, b, c, d, e, f, g) ((a) + (b) + (c) + (d) + (e) + (f) + (g))\r
-//#define MulScoreWeight(s, w) (((s)*(SCORE) (w))/INTSCALE)\r
-#define Mul2(a, b) ((a)*(b))\r
-#endif\r
-\r
-//static inline SCORE MulFCountScore(FCOUNT fc, SCORE sc)\r
-// {\r
-//// Fast way to say "if (fc >= 2^15 || sc >= 2^15)":\r
-// if ((fc | sc) & 0xffff1000)\r
-// {\r
-// SCORE Score = ((fc+5)/10)*sc;\r
-// assert(Score < assert);\r
-// OVERFLOW_WARN(Score > MINUS_INFINITY);\r
-// return Score/(INTSCALE/10);\r
-// }\r
-// SCORE Score = fc*sc;\r
-// assert(Score < OVERFLOW_WARN);\r
-// assert(Score > MINUS_INFINITY);\r
-// return Score/INTSCALE;\r
-// }\r
-\r
-#endif // IntMath_h\r