2 #include "dpreglist.h"
\r
3 #include "diaglist.h"
\r
10 #define LIST_DIAGS 0
\r
12 static double g_dDPAreaWithoutDiags = 0.0;
\r
13 static double g_dDPAreaWithDiags = 0.0;
\r
15 static void OffsetPath(PWPath &Path, unsigned uOffsetA, unsigned uOffsetB)
\r
17 const unsigned uEdgeCount = Path.GetEdgeCount();
\r
18 for (unsigned uEdgeIndex = 0; uEdgeIndex < uEdgeCount; ++uEdgeIndex)
\r
20 const PWEdge &Edge = Path.GetEdge(uEdgeIndex);
\r
22 // Nasty hack -- poke new values back into path, circumventing class
\r
23 PWEdge &NonConstEdge = (PWEdge &) Edge;
\r
24 NonConstEdge.uPrefixLengthA += uOffsetA;
\r
25 NonConstEdge.uPrefixLengthB += uOffsetB;
\r
29 static void DiagToPath(const Diag &d, PWPath &Path)
\r
32 const unsigned uLength = d.m_uLength;
\r
33 for (unsigned i = 0; i < uLength; ++i)
\r
37 Edge.uPrefixLengthA = d.m_uStartPosA + i + 1;
\r
38 Edge.uPrefixLengthB = d.m_uStartPosB + i + 1;
\r
39 Path.AppendEdge(Edge);
\r
43 static void AppendRegPath(PWPath &Path, const PWPath &RegPath)
\r
45 const unsigned uRegEdgeCount = RegPath.GetEdgeCount();
\r
46 for (unsigned uRegEdgeIndex = 0; uRegEdgeIndex < uRegEdgeCount; ++uRegEdgeIndex)
\r
48 const PWEdge &RegEdge = RegPath.GetEdge(uRegEdgeIndex);
\r
49 Path.AppendEdge(RegEdge);
\r
53 SCORE GlobalAlignDiags(const ProfPos *PA, unsigned uLengthA, const ProfPos *PB,
\r
54 unsigned uLengthB, PWPath &Path)
\r
57 TICKS t1 = GetClockTicks();
\r
62 if (ALPHA_Amino == g_Alpha)
\r
63 FindDiags(PA, uLengthA, PB, uLengthB, DL);
\r
64 else if (ALPHA_DNA == g_Alpha || ALPHA_RNA == g_Alpha)
\r
65 FindDiagsNuc(PA, uLengthA, PB, uLengthB, DL);
\r
67 Quit("GlobalAlignDiags: bad alpha");
\r
70 Log("GlobalAlignDiags, diag list:\n");
\r
75 DL.DeleteIncompatible();
\r
78 Log("After DeleteIncompatible:\n");
\r
85 Log("After MergeDiags:\n");
\r
90 DiagListToDPRegionList(DL, RL, uLengthA, uLengthB);
\r
93 Log("RegionList:\n");
\r
99 TICKS t2 = GetClockTicks();
\r
100 unsigned uArea = RL.GetDPArea();
\r
101 Log("ticks=%ld\n", (long) (t2 - t1));
\r
102 Log("area=%u\n", uArea);
\r
106 g_dDPAreaWithoutDiags += uLengthA*uLengthB;
\r
108 double dDPAreaWithDiags = 0.0;
\r
109 const unsigned uRegionCount = RL.GetCount();
\r
110 for (unsigned uRegionIndex = 0; uRegionIndex < uRegionCount; ++uRegionIndex)
\r
112 const DPRegion &r = RL.Get(uRegionIndex);
\r
115 if (DPREGIONTYPE_Diag == r.m_Type)
\r
117 DiagToPath(r.m_Diag, RegPath);
\r
119 Log("DiagToPath, path=\n");
\r
123 else if (DPREGIONTYPE_Rect == r.m_Type)
\r
125 const unsigned uRegStartPosA = r.m_Rect.m_uStartPosA;
\r
126 const unsigned uRegStartPosB = r.m_Rect.m_uStartPosB;
\r
127 const unsigned uRegLengthA = r.m_Rect.m_uLengthA;
\r
128 const unsigned uRegLengthB = r.m_Rect.m_uLengthB;
\r
129 const ProfPos *RegPA = PA + uRegStartPosA;
\r
130 const ProfPos *RegPB = PB + uRegStartPosB;
\r
132 dDPAreaWithDiags += uRegLengthA*uRegLengthB;
\r
133 GlobalAlignNoDiags(RegPA, uRegLengthA, RegPB, uRegLengthB, RegPath);
\r
135 Log("GlobalAlignNoDiags RegPath=\n");
\r
138 OffsetPath(RegPath, uRegStartPosA, uRegStartPosB);
\r
140 Log("After offset path, RegPath=\n");
\r
145 Quit("GlobalAlignDiags, Invalid region type %u", r.m_Type);
\r
147 AppendRegPath(Path, RegPath);
\r
149 Log("After AppendPath, path=");
\r
156 double dDPAreaWithoutDiags = uLengthA*uLengthB;
\r
157 Log("DP area with diags %.3g without %.3g pct saved %.3g %%\n",
\r
158 dDPAreaWithDiags, dDPAreaWithoutDiags, (1.0 - dDPAreaWithDiags/dDPAreaWithoutDiags)*100.0);
\r
161 g_dDPAreaWithDiags += dDPAreaWithDiags;
\r
165 void ListDiagSavings()
\r
167 if (!g_bVerbose || !g_bDiags)
\r
169 double dAreaSaved = g_dDPAreaWithoutDiags - g_dDPAreaWithDiags;
\r
170 double dPct = dAreaSaved*100.0/g_dDPAreaWithoutDiags;
\r
171 Log("DP area saved by diagonals %-4.1f%%\n", dPct);
\r