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