]> git.donarmstrong.com Git - mothur.git/blob - uchime_src/hsp.h
changes while testing
[mothur.git] / uchime_src / hsp.h
1 #ifndef hsp_h\r
2 #define hsp_h   1\r
3 \r
4 struct HSPData\r
5         {\r
6         unsigned Loi;\r
7         unsigned Loj;\r
8         unsigned Leni;\r
9         unsigned Lenj;\r
10         float Score;\r
11         unsigned User;\r
12 \r
13         unsigned GetLength() const\r
14                 {\r
15                 if (Leni != Lenj)\r
16                         Die("HSP::GetLength(): Leni %u, Lenj %u, Loi %u, Loj %u, Score %.1f",\r
17                           Leni, Lenj, Loi, Loj, Score);\r
18 \r
19                 return Leni;\r
20                 }\r
21 \r
22         unsigned GetHii() const\r
23                 {\r
24                 assert(Leni > 0);\r
25                 return Loi + Leni - 1;\r
26                 }\r
27 \r
28         unsigned GetHij() const\r
29                 {\r
30                 assert(Lenj > 0);\r
31                 return Loj + Lenj - 1;\r
32                 }\r
33 \r
34         bool LeftA() const\r
35                 {\r
36                 return Loi == 0;\r
37                 }\r
38 \r
39         bool LeftB() const\r
40                 {\r
41                 return Loj == 0;\r
42                 }\r
43 \r
44         bool RightA(unsigned LA) const\r
45                 {\r
46                 return Loi + Leni == LA;\r
47                 }\r
48 \r
49         bool RightB(unsigned LB) const\r
50                 {\r
51                 return Loj + Lenj == LB;\r
52                 }\r
53 \r
54         unsigned GetIdCount(const byte *A, const byte *B) const\r
55                 {\r
56                 unsigned Count = 0;\r
57                 unsigned K = GetLength();\r
58                 for (unsigned k = 0; k < K; ++k)\r
59                         {\r
60                         byte a = A[Loi+k];\r
61                         byte b = B[Loj+k];\r
62                         if (toupper(a) == toupper(b))\r
63                                 Count++;\r
64                         }\r
65                 return Count;\r
66                 }\r
67 \r
68         double OverlapFract(const HSPData &HSP) const\r
69                 {\r
70                 if (Leni == 0 || Lenj == 0)\r
71                         return 0.0;\r
72 \r
73                 unsigned MaxLoi = max(Loi, HSP.Loi);\r
74                 unsigned MaxLoj = max(Loj, HSP.Loj);\r
75                 unsigned MinHii = min(GetHii(), HSP.GetHii());\r
76                 unsigned MinHij = min(GetHij(), HSP.GetHij());\r
77 \r
78                 unsigned Ovi = (MinHii < MaxLoi) ? 0 : MinHii - MaxLoi;\r
79                 unsigned Ovj = (MinHij < MaxLoj) ? 0 : MinHij - MaxLoj;\r
80 \r
81                 asserta(Ovi <= Leni && Ovj <= Lenj);\r
82                 return double(Ovi*Ovj)/double(Leni*Lenj);\r
83                 }\r
84 \r
85         bool operator<(const HSPData &rhs) const\r
86                 {\r
87                 return Loi < rhs.Loi;\r
88                 }\r
89 \r
90         void LogMe() const\r
91                 {\r
92                 Log("Loi=%u Loj=%u Li=%u Lj=%u Score=%.1f\n", Loi, Loj, Leni, Lenj, Score);\r
93                 }\r
94 \r
95         void LogMe2() const\r
96                 {\r
97                 Log("(%u-%u,%u-%u/%.1f)", Loi, GetHii(), Loj, GetHij(), Score);\r
98                 }\r
99         };\r
100 \r
101 // Bendpoint\r
102 struct BPData\r
103         {\r
104         unsigned Pos;\r
105         bool IsLo;\r
106         unsigned Index;\r
107 \r
108         void LogMe() const\r
109                 {\r
110                 Log("BP%s Pos %u Ix %u", (IsLo ? "lo" : "hi"), Pos, Index);\r
111                 }\r
112         };\r
113 \r
114 #endif // hsp_h\r