4 //unsigned g_MaxL = 0;
\r
6 static bool *g_IsChar = g_IsAminoChar;
\r
8 // Term gaps allowed in query (A) only
\r
9 static double GetFractIdGivenPathDerep(const byte *A, const byte *B, const char *Path,
\r
15 sprintf(ptrDesc, "(term gap in Query)");
\r
19 const char *LastM = 0;
\r
20 for (const char *p = Path; *p; ++p)
\r
29 for (const char *p = Path; *p && p != LastM; ++p)
\r
35 byte a = toupper(A[PosA]);
\r
36 byte b = toupper(B[PosB]);
\r
37 if (g_IsChar[a] && g_IsChar[b])
\r
47 if (c == 'D' || c == 'I')
\r
49 if (c == 'M' || c == 'D')
\r
51 if (c == 'M' || c == 'I')
\r
55 double FractId = (Cols == 0 ? 0.0 : 1.0 - double(Diffs)/double(Cols));
\r
57 sprintf(ptrDesc, "(ids=%u/cols=%u)", Ids, Cols);
\r
61 static double GetFractIdGivenPathAllDiffs(const byte *A, const byte *B, const char *Path,
\r
69 for (const char *p = Path; *p; ++p)
\r
75 byte a = toupper(A[PosA]);
\r
76 byte b = toupper(B[PosB]);
\r
77 if (g_IsChar[a] && g_IsChar[b])
\r
87 if (c == 'D' || c == 'I')
\r
89 if (c == 'M' || c == 'D')
\r
91 if (c == 'M' || c == 'I')
\r
95 double FractId = (Cols == 0 ? 0.0 : 1.0 - double(Diffs)/double(Cols));
\r
97 sprintf(ptrDesc, "(ids=%u/cols=%u)", Ids, Cols);
\r
101 static double GetFractIdGivenPathInternalDiffs(const byte *A, const byte *B,
\r
102 const char *Path, char *ptrDesc)
\r
105 unsigned FirstM = UINT_MAX;
\r
106 unsigned LastM = UINT_MAX;
\r
107 for (const char *p = Path; *p; ++p)
\r
111 if (FirstM == UINT_MAX)
\r
117 if (FirstM == UINT_MAX)
\r
120 strcpy(ptrDesc, "(no matches)");
\r
127 unsigned Diffs = 0;
\r
129 for (unsigned i = 0; i < FirstM; ++i)
\r
132 if (c == 'M' || c == 'D')
\r
134 if (c == 'M' || c == 'I')
\r
138 for (unsigned i = FirstM; i <= LastM; ++i)
\r
144 byte a = toupper(A[PosA]);
\r
145 byte b = toupper(B[PosB]);
\r
146 if (g_IsChar[a] && g_IsChar[b])
\r
156 if (c == 'D' || c == 'I')
\r
158 if (c == 'M' || c == 'D')
\r
160 if (c == 'M' || c == 'I')
\r
164 double FractId = (Cols == 0 ? 0.0 : 1.0 - double(Diffs)/double(Cols));
\r
166 sprintf(ptrDesc, "(ids=%u/cols=%u)", Ids, Cols);
\r
170 static double GetFractIdGivenPathMBL(const byte *A, const byte *B, const char *Path,
\r
175 unsigned Mismatches = 0;
\r
177 for (const char *p = Path; *p; ++p)
\r
180 if (c == 'M' && toupper(A[PosA]) != toupper(B[PosB]))
\r
182 if (c == 'D' || c == 'I' && (p == Path || p[-1] == 'M'))
\r
184 if (c == 'M' || c == 'D')
\r
186 if (c == 'M' || c == 'I')
\r
189 unsigned Diffs = Gaps + Mismatches;
\r
190 double FractDiffs = (PosB == 0 ? 0.0 : double(Diffs)/double(PosB));
\r
192 sprintf(ptrDesc, "Gap opens %u, Id=1 - [(diffs=%u)/(target_length=%u)]",
\r
193 Gaps, Diffs, PosB);
\r
194 double FractId = 1.0 - FractDiffs;
\r
200 static double GetFractIdGivenPathBLAST(const byte *A, const byte *B, const char *Path,
\r
206 unsigned Wilds = 0;
\r
208 for (const char *p = Path; *p; ++p)
\r
214 byte a = toupper(A[PosA]);
\r
215 byte b = toupper(B[PosB]);
\r
216 if (g_IsChar[a] && g_IsChar[b])
\r
224 if (c == 'M' || c == 'D')
\r
226 if (c == 'M' || c == 'I')
\r
229 asserta(Cols >= Wilds);
\r
231 double FractId = Cols == 0 ? 0.0f : float(Ids)/float(Cols);
\r
233 sprintf(ptrDesc, "(ids=%u/cols=%u)", Ids, Cols);
\r
237 static double GetFractIdGivenPathDefault(const byte *A, const byte *B, const char *Path,
\r
243 unsigned Wilds = 0;
\r
244 for (const char *p = Path; *p; ++p)
\r
249 byte a = toupper(A[PosA]);
\r
250 byte b = toupper(B[PosB]);
\r
251 if (g_IsChar[a] && g_IsChar[b])
\r
259 if (c == 'M' || c == 'D')
\r
261 if (c == 'M' || c == 'I')
\r
264 unsigned MinLen = min(PosA, PosB) - Wilds;
\r
265 double FractId = (MinLen == 0 ? 0.0 : double(Ids)/double(MinLen));
\r
267 sprintf(ptrDesc, "(ids=%u/shorter_length=%u)", Ids, MinLen);
\r
271 double GetFractIdGivenPath(const byte *A, const byte *B, const char *Path,
\r
272 bool Nucleo, char *ptrDesc, unsigned IdDef)
\r
275 g_IsChar = g_IsACGTU;
\r
277 g_IsChar = g_IsAminoChar;
\r
282 strcpy(ptrDesc, "(NULL path)");
\r
286 unsigned ColCount = (unsigned) strlen(Path);
\r
292 if (Path[0] != 'M' || Path[ColCount-1] == 'D')
\r
295 strcpy(ptrDesc, "(leftjust)");
\r
302 if (Path[0] == 'D' || Path[ColCount-1] != 'M')
\r
305 strcpy(ptrDesc, "(rightjust)");
\r
310 double FractId = 0.0;
\r
311 //if (opt_idprefix > 0)
\r
313 // for (unsigned i = 0; i < opt_idprefix; ++i)
\r
315 // char c = Path[i];
\r
316 // if (c != 'M' || toupper(A[i]) != toupper(B[i]))
\r
318 // if (ptrDesc != 0)
\r
319 // sprintf(ptrDesc, "Prefix ids %u < idprefix(%u)",
\r
320 // i, opt_idprefix);
\r
326 //if (opt_idsuffix > 0)
\r
328 // unsigned Cols = strlen(Path);
\r
329 // for (unsigned i = 0; i < opt_idsuffix && i > Cols; ++i)
\r
331 // unsigned k = Cols - 1 - i;
\r
332 // char c = Path[k];
\r
333 // if (c != 'M' || toupper(A[k]) != toupper(B[k]))
\r
335 // if (ptrDesc != 0)
\r
336 // sprintf(ptrDesc, "Suffix ids %u < idsuffix(%u)",
\r
337 // i, opt_idsuffix);
\r
343 if (opt_maxqgap > 0 || opt_maxtgap > 0)
\r
346 const char *LastM = 0;
\r
347 for (const char *p = Path; *p; ++p)
\r
352 for (const char *p = Path; *p && p != LastM; ++p)
\r
362 if (L > opt_maxtgap)
\r
365 sprintf(ptrDesc, "(maxtgap)");
\r
369 else if (p[-1] == 'I')
\r
371 if (L > opt_maxqgap)
\r
374 sprintf(ptrDesc, "(maxqgap)");
\r
400 FractId = GetFractIdGivenPathDefault(A, B, Path, ptrDesc);
\r
404 FractId = GetFractIdGivenPathAllDiffs(A, B, Path, ptrDesc);
\r
408 FractId = GetFractIdGivenPathInternalDiffs(A, B, Path, ptrDesc);
\r
412 FractId = GetFractIdGivenPathMBL(A, B, Path, ptrDesc);
\r
416 FractId = GetFractIdGivenPathBLAST(A, B, Path, ptrDesc);
\r
420 FractId = GetFractIdGivenPathDerep(A, B, Path, ptrDesc);
\r
424 Die("--iddef %u invalid", opt_iddef);
\r
430 double GetFractIdGivenPath(const byte *A, const byte *B, const char *Path,
\r
431 bool Nucleo, char *ptrDesc)
\r
433 return GetFractIdGivenPath(A, B, Path, Nucleo, ptrDesc, opt_iddef);
\r
436 double GetFractIdGivenPath(const byte *A, const byte *B, const char *Path, bool Nucleo)
\r
438 return GetFractIdGivenPath(A, B, Path, Nucleo, (char *) 0);
\r
441 double GetFractIdGivenPath(const byte *A, const byte *B, const string &Path)
\r
443 return GetFractIdGivenPath(A, B, Path.c_str(), true);
\r
446 double GetFractIdGivenPath(const byte *A, const byte *B, const char *Path)
\r
448 return GetFractIdGivenPath(A, B, Path, true);
\r