Next version of JABA
[jabaws.git] / binaries / src / muscle / glbalign.cpp
1 #include "muscle.h"\r
2 #include "pwpath.h"\r
3 #include "timing.h"\r
4 #include "textfile.h"\r
5 #include "msa.h"\r
6 #include "profile.h"\r
7 \r
8 #if     !VER_3_52\r
9 \r
10 #define COMPARE_SIMPLE  0\r
11 \r
12 #if     TIMING\r
13 TICKS g_ticksDP = 0;\r
14 #endif\r
15 \r
16 #if     1\r
17 extern bool g_bKeepSimpleDP;\r
18 SCORE NWSmall(const ProfPos *PA, unsigned uLengthA, const ProfPos *PB,\r
19   unsigned uLengthB, PWPath &Path);\r
20 SCORE NWDASmall(const ProfPos *PA, unsigned uLengthA, const ProfPos *PB,\r
21   unsigned uLengthB, PWPath &Path);\r
22 SCORE NWDASimple(const ProfPos *PA, unsigned uLengthA, const ProfPos *PB,\r
23   unsigned uLengthB, PWPath &Path);\r
24 SCORE NWDASimple2(const ProfPos *PA, unsigned uLengthA, const ProfPos *PB,\r
25   unsigned uLengthB, PWPath &Path);\r
26 SCORE GlobalAlignSimple(const ProfPos *PA, unsigned uLengthA, const ProfPos *PB,\r
27   unsigned uLengthB, PWPath &Path);\r
28 \r
29 SCORE GlobalAlignNoDiags(const ProfPos *PA, unsigned uLengthA, const ProfPos *PB,\r
30   unsigned uLengthB, PWPath &Path)\r
31         {\r
32         return GlobalAlign(PA, uLengthA, PB, uLengthB, Path);\r
33         }\r
34 \r
35 #if     COMPARE_SIMPLE\r
36 \r
37 SCORE GlobalAlign(const ProfPos *PA, unsigned uLengthA, const ProfPos *PB,\r
38   unsigned uLengthB, PWPath &Path)\r
39         {\r
40 #if     TIMING\r
41         TICKS t1 = GetClockTicks();\r
42 #endif\r
43         g_bKeepSimpleDP = true;\r
44         PWPath SimplePath;\r
45         GlobalAlignSimple(PA, uLengthA, PB, uLengthB, SimplePath);\r
46 \r
47         SCORE Score = NWSmall(PA, uLengthA, PB, uLengthB, Path);\r
48 \r
49         if (!Path.Equal(SimplePath))\r
50                 {\r
51                 Log("Simple:\n");\r
52                 SimplePath.LogMe();\r
53                 Log("Small:\n");\r
54                 Path.LogMe();\r
55                 Quit("Paths differ");\r
56                 }\r
57 \r
58 #if     TIMING\r
59         TICKS t2 = GetClockTicks();\r
60         g_ticksDP += (t2 - t1);\r
61 #endif\r
62         return Score;\r
63         }\r
64 \r
65 #else // COMPARE_SIMPLE\r
66 \r
67 SCORE GlobalAlign(const ProfPos *PA, unsigned uLengthA, const ProfPos *PB,\r
68   unsigned uLengthB, PWPath &Path)\r
69         {\r
70 #if     TIMING\r
71         TICKS t1 = GetClockTicks();\r
72 #endif\r
73         SCORE Score = NWSmall(PA, uLengthA, PB, uLengthB, Path);\r
74 #if     TIMING\r
75         TICKS t2 = GetClockTicks();\r
76         g_ticksDP += (t2 - t1);\r
77 #endif\r
78         return Score;\r
79         }\r
80 \r
81 #endif\r
82 \r
83 #else // 1\r
84 \r
85 static void AllInserts(PWPath &Path, unsigned uLengthB)\r
86         {\r
87         Path.Clear();\r
88         PWEdge Edge;\r
89         Edge.cType = 'I';\r
90         Edge.uPrefixLengthA = 0;\r
91         for (unsigned uPrefixLengthB = 1; uPrefixLengthB <= uLengthB; ++uPrefixLengthB)\r
92                 {\r
93                 Edge.uPrefixLengthB = uPrefixLengthB;\r
94                 Path.AppendEdge(Edge);\r
95                 }\r
96         }\r
97 \r
98 static void AllDeletes(PWPath &Path, unsigned uLengthA)\r
99         {\r
100         Path.Clear();\r
101         PWEdge Edge;\r
102         Edge.cType = 'D';\r
103         Edge.uPrefixLengthB = 0;\r
104         for (unsigned uPrefixLengthA = 1; uPrefixLengthA <= uLengthA; ++uPrefixLengthA)\r
105                 {\r
106                 Edge.uPrefixLengthA = uPrefixLengthA;\r
107                 Path.AppendEdge(Edge);\r
108                 }\r
109         }\r
110 \r
111 SCORE GlobalAlign(const ProfPos *PA, unsigned uLengthA, const ProfPos *PB,\r
112   unsigned uLengthB, PWPath &Path)\r
113         {\r
114 #if     TIMING\r
115         TICKS t1 = GetClockTicks();\r
116 #endif\r
117         if (0 == uLengthA)\r
118                 {\r
119                 AllInserts(Path, uLengthB);\r
120                 return 0;\r
121                 }\r
122         else if (0 == uLengthB)\r
123                 {\r
124                 AllDeletes(Path, uLengthA);\r
125                 return 0;\r
126                 }\r
127 \r
128         SCORE Score = 0;\r
129         if (g_bDiags)\r
130                 Score = GlobalAlignDiags(PA, uLengthA, PB, uLengthB, Path);\r
131         else\r
132                 Score = GlobalAlignNoDiags(PA, uLengthA, PB, uLengthB, Path);\r
133 #if     TIMING\r
134         TICKS t2 = GetClockTicks();\r
135         g_ticksDP += (t2 - t1);\r
136 #endif\r
137         return Score;\r
138         }\r
139 \r
140 SCORE GlobalAlignNoDiags(const ProfPos *PA, unsigned uLengthA, const ProfPos *PB,\r
141   unsigned uLengthB, PWPath &Path)\r
142         {\r
143         if (g_bDimer)\r
144                 return GlobalAlignDimer(PA, uLengthA, PB, uLengthB, Path);\r
145 \r
146         switch (g_PPScore)\r
147                 {\r
148         case PPSCORE_LE:\r
149                 return GlobalAlignLE(PA, uLengthA, PB, uLengthB, Path);\r
150 \r
151         case PPSCORE_SP:\r
152         case PPSCORE_SV:\r
153                 return GlobalAlignSP(PA, uLengthA, PB, uLengthB, Path);\r
154 \r
155         case PPSCORE_SPN:\r
156                 return GlobalAlignSPN(PA, uLengthA, PB, uLengthB, Path);\r
157                 }\r
158 \r
159         Quit("Invalid PP score (GlobalAlignNoDiags)");\r
160         return 0;\r
161         }\r
162 \r
163 #endif\r
164 \r
165 #endif  // !VER_3_52\r