| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#include <p7_config.h> |
| 15 |
|
| 16 |
#include <stdlib.h> |
| 17 |
#include <math.h> |
| 18 |
|
| 19 |
#include "hmmer.h" |
| 20 |
#include "p7_gmxchk.h" |
| 21 |
|
| 22 |
|
| 23 |
static int set_row_layout (P7_GMXCHK *gxc, int allocL, int maxR); |
| 24 |
static void set_full (P7_GMXCHK *gxc, int L); |
| 25 |
static void set_checkpointed(P7_GMXCHK *gxc, int L, int R); |
| 26 |
static void set_redlined (P7_GMXCHK *gxc, int L, double minR); |
| 27 |
|
| 28 |
static double minimum_rows (int L); |
| 29 |
static double checkpointed_rows(int L, int R); |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
P7_GMXCHK * |
| 68 |
p7_gmxchk_Create(int M, int L, int64_t ramlimit) |
| 69 |
{ |
| 70 |
P7_GMXCHK *gxc = NULL; |
| 71 |
int maxR; |
| 72 |
int r; |
| 73 |
int status; |
| 74 |
|
| 75 |
|
| 76 |
ESL_DASSERT1( (M <= 100000) ); |
| 77 |
ESL_DASSERT1( (L <= 100000) ); |
| 78 |
|
| 79 |
|
| 80 |
ESL_ALLOC(gxc, sizeof(P7_GMXCHK)); |
| 81 |
gxc->dp = NULL; |
| 82 |
gxc->dp_mem = NULL; |
| 83 |
|
| 84 |
|
| 85 |
gxc->R0 = 3; |
| 86 |
gxc->allocW = (M+1) * p7G_NSCELLS + p7GC_NXCELLS; |
| 87 |
gxc->ncell_limit = ramlimit / sizeof(float); |
| 88 |
maxR = (int) (gxc->ncell_limit / (int64_t) gxc->allocW); |
| 89 |
set_row_layout(gxc, L, maxR); |
| 90 |
gxc->allocR = gxc->R0 + gxc->Ra + gxc->Rb + gxc->Rc; |
| 91 |
gxc->validR = gxc->allocR; |
| 92 |
|
| 93 |
|
| 94 |
gxc->ncells = gxc->allocR * gxc->allocW; |
| 95 |
ESL_ALLOC( gxc->dp_mem, sizeof(float) * gxc->ncells); |
| 96 |
ESL_ALLOC( gxc->dp, sizeof(float *) * gxc->allocR); |
| 97 |
for (r = 0; r < gxc->allocR; r++) |
| 98 |
gxc->dp[r] = gxc->dp_mem + (r * gxc->allocW); |
| 99 |
|
| 100 |
#if eslDEBUGLEVEL > 0 |
| 101 |
gxc->do_debugging = FALSE; |
| 102 |
gxc->dfp = NULL; |
| 103 |
gxc->dbg_width = 9; |
| 104 |
gxc->dbg_precision = 4; |
| 105 |
gxc->dbg_flags = p7_DEFAULT; |
| 106 |
#endif |
| 107 |
|
| 108 |
gxc->M = 0; |
| 109 |
gxc->L = 0; |
| 110 |
gxc->R = 0; |
| 111 |
return gxc; |
| 112 |
|
| 113 |
ERROR: |
| 114 |
if (gxc) p7_gmxchk_Destroy(gxc); |
| 115 |
return NULL; |
| 116 |
} |
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
int |
| 143 |
p7_gmxchk_GrowTo(P7_GMXCHK *gxc, int M, int L) |
| 144 |
{ |
| 145 |
int W = (M+1)*p7G_NSCELLS + p7GC_NXCELLS; |
| 146 |
int minR_chk = (int) ceil(minimum_rows(L)) + gxc->R0; |
| 147 |
int reset_dp_ptrs = FALSE; |
| 148 |
int maxR; |
| 149 |
int r; |
| 150 |
int status; |
| 151 |
|
| 152 |
|
| 153 |
if (W <= gxc->allocW && gxc->ncells <= gxc->ncell_limit) |
| 154 |
{ |
| 155 |
if (L + gxc->R0 <= gxc->validR) { set_full (gxc, L); return eslOK; } |
| 156 |
else if (minR_chk <= gxc->validR) { set_checkpointed(gxc, L, gxc->validR); return eslOK; } |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
if ( W > gxc->allocW) |
| 161 |
{ |
| 162 |
gxc->allocW = W; |
| 163 |
gxc->validR = (int) (gxc->ncells / (int64_t) gxc->allocW); |
| 164 |
reset_dp_ptrs = TRUE; |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
maxR = (int) (gxc->ncell_limit / (int64_t) gxc->allocW); |
| 169 |
if ( (gxc->ncells > gxc->ncell_limit && minR_chk <= maxR) || |
| 170 |
minR_chk > gxc->validR) |
| 171 |
{ |
| 172 |
set_row_layout(gxc, L, maxR); |
| 173 |
gxc->validR = gxc->R0 + gxc->Ra + gxc->Rb + gxc->Rc; |
| 174 |
gxc->ncells = gxc->validR * gxc->allocW; |
| 175 |
ESL_REALLOC(gxc->dp_mem, sizeof(float) * gxc->ncells); |
| 176 |
reset_dp_ptrs = TRUE; |
| 177 |
} |
| 178 |
else |
| 179 |
{ |
| 180 |
if (L+gxc->R0 <= gxc->validR) set_full(gxc, L); |
| 181 |
else set_checkpointed(gxc, L, gxc->validR); |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
if (gxc->validR > gxc->allocR) |
| 186 |
{ |
| 187 |
ESL_REALLOC(gxc->dp, sizeof(float *) * gxc->validR); |
| 188 |
gxc->allocR = gxc->validR; |
| 189 |
reset_dp_ptrs = TRUE; |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
if (reset_dp_ptrs) |
| 194 |
for (r = 0; r < gxc->validR; r++) |
| 195 |
gxc->dp[r] = gxc->dp_mem + (r * gxc->allocW); |
| 196 |
|
| 197 |
gxc->M = 0; |
| 198 |
gxc->L = 0; |
| 199 |
gxc->R = 0; |
| 200 |
return eslOK; |
| 201 |
|
| 202 |
ERROR: |
| 203 |
return status; |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
size_t |
| 211 |
p7_gmxchk_Sizeof(const P7_GMXCHK *gxc) |
| 212 |
{ |
| 213 |
size_t n = 0; |
| 214 |
|
| 215 |
n += sizeof(P7_GMXCHK); |
| 216 |
n += gxc->ncells * sizeof(float); |
| 217 |
n += gxc->allocR * sizeof(float *); |
| 218 |
return n; |
| 219 |
} |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
int |
| 237 |
p7_gmxchk_Reuse(P7_GMXCHK *gxc) |
| 238 |
{ |
| 239 |
gxc->M = 0; |
| 240 |
gxc->L = 0; |
| 241 |
gxc->R = 0; |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
gxc->R0 = 3; |
| 246 |
gxc->Ra = 0; |
| 247 |
gxc->Rb = 0; |
| 248 |
gxc->Rc = 0; |
| 249 |
gxc->La = 0; |
| 250 |
gxc->Lb = 0; |
| 251 |
gxc->Lc = 0; |
| 252 |
|
| 253 |
return eslOK; |
| 254 |
} |
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
void |
| 264 |
p7_gmxchk_Destroy(P7_GMXCHK *gxc) |
| 265 |
{ |
| 266 |
if (gxc) |
| 267 |
{ |
| 268 |
if (gxc->dp_mem) free(gxc->dp_mem); |
| 269 |
if (gxc->dp) free(gxc->dp); |
| 270 |
free(gxc); |
| 271 |
} |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
#if eslDEBUGLEVEL > 0 |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
int |
| 301 |
p7_gmxchk_Dump(FILE *ofp, P7_GMXCHK *gxc, int flags) |
| 302 |
{ |
| 303 |
int kstart = 0; |
| 304 |
int kend = gxc->M; |
| 305 |
int i, r, b, w; |
| 306 |
int status; |
| 307 |
|
| 308 |
p7_gmxchk_DumpHeader(ofp, gxc, kstart, kend, flags); |
| 309 |
|
| 310 |
for (i = 0, r = gxc->R0-1; i <= gxc->La; i++, r++) |
| 311 |
if ((status = p7_gmxchk_DumpRow(ofp, gxc, gxc->dp[r], i, kstart, kend, flags)) != eslOK) return status; |
| 312 |
|
| 313 |
for (b = gxc->Rb + gxc->Rc, w = gxc->Lb; i <= gxc->L; i++) |
| 314 |
{ |
| 315 |
if (!(--w)) { |
| 316 |
w = b--; |
| 317 |
if ((status = p7_gmxchk_DumpRow(ofp, gxc, gxc->dp[r], i, kstart, kend, flags)) != eslOK) return status; |
| 318 |
r++; |
| 319 |
} |
| 320 |
} |
| 321 |
return eslOK; |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
int |
| 353 |
p7_gmxchk_SetDumpMode(P7_GMXCHK *gxc, FILE *ofp, int flags) |
| 354 |
{ |
| 355 |
if (ofp) { |
| 356 |
gxc->do_debugging = TRUE; |
| 357 |
gxc->dfp = ofp; |
| 358 |
gxc->dbg_flags = flags; |
| 359 |
} else { |
| 360 |
gxc->do_debugging = FALSE; |
| 361 |
gxc->dfp = NULL; |
| 362 |
gxc->dbg_flags = 0; |
| 363 |
} |
| 364 |
return eslOK; |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
int |
| 392 |
p7_gmxchk_DumpHeader(FILE *ofp, P7_GMXCHK *gxc, int kstart, int kend, int flags) |
| 393 |
{ |
| 394 |
int width = gxc->dbg_width; |
| 395 |
int k,x; |
| 396 |
|
| 397 |
fprintf(ofp, " "); |
| 398 |
for (k = kstart; k <= kend; k++) fprintf(ofp, "%*d ", width, k); |
| 399 |
if (! (flags & p7_HIDE_SPECIALS)) fprintf(ofp, "%*s %*s %*s %*s %*s %*s %*s\n", width, "E", width, "N", width, "JJ", width, "J", width, "B", width, "CC", width, "C"); |
| 400 |
fprintf(ofp, " "); |
| 401 |
for (k = kstart; k <= kend; k++) fprintf(ofp, "%*.*s ", width, width, "----------"); |
| 402 |
if (! (flags & p7_HIDE_SPECIALS)) |
| 403 |
for (x = 0; x < 5; x++) fprintf(ofp, "%*.*s ", width, width, "----------"); |
| 404 |
fprintf(ofp, "\n"); |
| 405 |
return eslOK; |
| 406 |
} |
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
int |
| 430 |
p7_gmxchk_DumpRow(FILE *ofp, P7_GMXCHK *gxc, float *dpc, int i, int kstart, int kend, int flags) |
| 431 |
{ |
| 432 |
int width = gxc->dbg_width; |
| 433 |
int precision = gxc->dbg_precision; |
| 434 |
float val; |
| 435 |
int k, x; |
| 436 |
int xoffset = (gxc->M+1)*p7G_NSCELLS; |
| 437 |
|
| 438 |
fprintf(ofp, "%3d M ", i); |
| 439 |
for (k = kstart; k <= kend; k++) |
| 440 |
{ |
| 441 |
val = dpc[k * p7G_NSCELLS + p7G_M]; |
| 442 |
if (flags & p7_SHOW_LOG) val = log(val); |
| 443 |
fprintf(ofp, "%*.*f ", width, precision, val); |
| 444 |
} |
| 445 |
|
| 446 |
if (! (flags & p7_HIDE_SPECIALS)) |
| 447 |
{ |
| 448 |
for (x = 0; x < p7GC_NXCELLS; x++) |
| 449 |
{ |
| 450 |
val = dpc[xoffset + x]; |
| 451 |
if (flags & p7_SHOW_LOG) val = log(val); |
| 452 |
fprintf(ofp, "%*.*f ", width, precision, val); |
| 453 |
} |
| 454 |
} |
| 455 |
fprintf(ofp, "\n"); |
| 456 |
|
| 457 |
fprintf(ofp, "%3d I ", i); |
| 458 |
for (k = kstart; k <= kend; k++) |
| 459 |
{ |
| 460 |
val = dpc[k * p7G_NSCELLS + p7G_I]; |
| 461 |
if (flags & p7_SHOW_LOG) val = log(val); |
| 462 |
fprintf(ofp, "%*.*f ", width, precision, val); |
| 463 |
} |
| 464 |
fprintf(ofp, "\n"); |
| 465 |
|
| 466 |
fprintf(ofp, "%3d D ", i); |
| 467 |
for (k = kstart; k <= kend; k++) |
| 468 |
{ |
| 469 |
val = dpc[k * p7G_NSCELLS + p7G_D]; |
| 470 |
if (flags & p7_SHOW_LOG) val = log(val); |
| 471 |
fprintf(ofp, "%*.*f ", width, precision, val); |
| 472 |
} |
| 473 |
fprintf(ofp, "\n\n"); |
| 474 |
return eslOK; |
| 475 |
} |
| 476 |
#endif |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
static int |
| 516 |
set_row_layout(P7_GMXCHK *gxc, int allocL, int maxR) |
| 517 |
{ |
| 518 |
double Rbc = minimum_rows(allocL); |
| 519 |
int minR_chk = gxc->R0 + (int) ceil(Rbc); |
| 520 |
int minR_all = gxc->R0 + allocL; |
| 521 |
|
| 522 |
if (minR_all <= maxR) set_full (gxc, allocL); |
| 523 |
else if (minR_chk <= maxR) set_checkpointed(gxc, allocL, maxR); |
| 524 |
else set_redlined (gxc, allocL, Rbc); |
| 525 |
|
| 526 |
return eslOK; |
| 527 |
} |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
static void |
| 532 |
set_full(P7_GMXCHK *gxc, int L) |
| 533 |
{ |
| 534 |
gxc->Ra = L; |
| 535 |
gxc->Rb = 0; |
| 536 |
gxc->Rc = 0; |
| 537 |
gxc->La = L; |
| 538 |
gxc->Lb = 0; |
| 539 |
gxc->Lc = 0; |
| 540 |
} |
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
static void |
| 550 |
set_checkpointed(P7_GMXCHK *gxc, int L, int R) |
| 551 |
{ |
| 552 |
double Rbc = checkpointed_rows(L, R-gxc->R0); |
| 553 |
double Rc = floor(Rbc); |
| 554 |
|
| 555 |
gxc->Rc = (int) Rc; |
| 556 |
gxc->Rb = (Rbc > Rc ? 1 : 0); |
| 557 |
gxc->Ra = R - gxc->Rb - gxc->Rc - gxc->R0; |
| 558 |
gxc->Lc = ((gxc->Rc + 2) * (gxc->Rc + 1)) / 2 - 1; |
| 559 |
gxc->La = gxc->Ra; |
| 560 |
gxc->Lb = L - gxc->La - gxc->Lc; |
| 561 |
} |
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
static void |
| 568 |
set_redlined(P7_GMXCHK *gxc, int L, double minR) |
| 569 |
{ |
| 570 |
double Rc = floor(minR); |
| 571 |
|
| 572 |
gxc->Rc = (int) Rc; |
| 573 |
gxc->Rb = (minR > Rc ? 1 : 0); |
| 574 |
gxc->Ra = 0; |
| 575 |
gxc->Lc = ((gxc->Rc + 2) * (gxc->Rc + 1)) / 2 - 1; |
| 576 |
gxc->La = 0; |
| 577 |
gxc->Lb = L - gxc->La - gxc->Lc; |
| 578 |
} |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
static double |
| 595 |
minimum_rows(int L) |
| 596 |
{ |
| 597 |
return (sqrt(9. + 8. * (double) L) - 3.) / 2.; |
| 598 |
} |
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
static double |
| 614 |
checkpointed_rows(int L, int R) |
| 615 |
{ |
| 616 |
return (sqrt(1. + 8. * (double) (L - R)) - 1.) / 2.; |
| 617 |
} |
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
#ifdef p7GMXCHK_TESTDRIVE |
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
static void |
| 638 |
utest_testpattern(P7_GMXCHK *gxc, int M, int L) |
| 639 |
{ |
| 640 |
char msg[] = "testpattern failed"; |
| 641 |
int n; |
| 642 |
int ntot; |
| 643 |
int b, w, i, k, s, r; |
| 644 |
float *dpc; |
| 645 |
|
| 646 |
if (L != gxc->La + gxc->Lb + gxc->Lc) esl_fatal(msg); |
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
ntot = (gxc->R0+gxc->Ra+gxc->Rb+gxc->Rc) * ( (M+1)*p7G_NSCELLS + p7GC_NXCELLS); |
| 652 |
n = 0; |
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
for (r = 0; r < gxc->R0; r++) |
| 657 |
{ |
| 658 |
dpc = gxc->dp[r]; |
| 659 |
for (k = 0; k <= M; k++) |
| 660 |
for (s = 0; s < p7G_NSCELLS; s++) { *dpc = n++; dpc++; } |
| 661 |
for (s = 0; s < p7GC_NXCELLS; s++) { *dpc = n++; dpc++; } |
| 662 |
} |
| 663 |
|
| 664 |
|
| 665 |
for (i = 1, gxc->R = 0; i <= gxc->La; i++) |
| 666 |
{ |
| 667 |
dpc = gxc->dp[gxc->R0+gxc->R]; gxc->R++; |
| 668 |
for (k = 0; k <= M; k++) |
| 669 |
for (s = 0; s < p7G_NSCELLS; s++) { *dpc = n++; dpc++; } |
| 670 |
for (s = 0; s < p7GC_NXCELLS; s++) { *dpc = n++; dpc++; } |
| 671 |
} |
| 672 |
if (gxc->R != gxc->Ra) esl_fatal(msg); |
| 673 |
|
| 674 |
|
| 675 |
for (b = gxc->Rb + gxc->Rc, w = (gxc->Rb ? gxc->Lb : gxc->Rc+1); i <= L; i++) |
| 676 |
{ |
| 677 |
if (! (--w)) |
| 678 |
{ |
| 679 |
dpc = gxc->dp[gxc->R0+gxc->R]; gxc->R++; |
| 680 |
w = b--; |
| 681 |
|
| 682 |
|
| 683 |
for (k = 0; k <= M; k++) |
| 684 |
for (s = 0; s < p7G_NSCELLS; s++) { *dpc = n++; dpc++; } |
| 685 |
for (s = 0; s < p7GC_NXCELLS; s++) { *dpc = n++; dpc++; } |
| 686 |
} |
| 687 |
} |
| 688 |
if (i != L+1) esl_fatal(msg); |
| 689 |
if (gxc->R != gxc->Ra+gxc->Rb+gxc->Rc) esl_fatal(msg); |
| 690 |
if (n != ntot) esl_fatal(msg); |
| 691 |
|
| 692 |
|
| 693 |
n = ntot; |
| 694 |
for (i = L, b = 1; b <= gxc->Rb + gxc->Rc; b++) |
| 695 |
{ |
| 696 |
w = (b <= gxc->Rc ? b+1 : gxc->Lb); |
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
gxc->R--; |
| 702 |
dpc = gxc->dp[gxc->R0+gxc->R] + (M+1)*p7G_NSCELLS + p7GC_NXCELLS - 1; |
| 703 |
for (s = p7GC_NXCELLS-1; s >= 0; s--) { if (*dpc != --n) esl_fatal(msg); dpc--; } |
| 704 |
for (k = M; k >= 0; k--) |
| 705 |
for (s = p7G_NSCELLS-1; s >= 0; s--) { if (*dpc != --n) esl_fatal(msg); dpc--; } |
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
i -= w; |
| 716 |
} |
| 717 |
if (i != gxc->La) esl_fatal(msg); |
| 718 |
|
| 719 |
|
| 720 |
for ( ; i >= 1; i--) |
| 721 |
{ |
| 722 |
gxc->R--; |
| 723 |
dpc = gxc->dp[gxc->R0+gxc->R] + (M+1)*p7G_NSCELLS + p7GC_NXCELLS - 1; |
| 724 |
for (s = p7GC_NXCELLS-1; s >= 0; s--) { if (*dpc != --n) esl_fatal(msg); dpc--; } |
| 725 |
for (k = M; k >= 0; k--) |
| 726 |
for (s = p7G_NSCELLS-1; s >= 0; s--) { if (*dpc != --n) esl_fatal(msg); dpc--; } |
| 727 |
} |
| 728 |
|
| 729 |
|
| 730 |
for (r = gxc->R0-1; r >= 0; r--) |
| 731 |
{ |
| 732 |
dpc = gxc->dp[r] + (M+1)*p7G_NSCELLS + p7GC_NXCELLS - 1; |
| 733 |
for (s = p7GC_NXCELLS-1; s >= 0; s--) { if (*dpc != --n) esl_fatal(msg); dpc--; } |
| 734 |
for (k = M; k >= 0; k--) |
| 735 |
for (s = p7G_NSCELLS-1; s >= 0; s--) { if (*dpc != --n) esl_fatal(msg); dpc--; } |
| 736 |
} |
| 737 |
} |
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
static void |
| 745 |
utest_GrowTo(void) |
| 746 |
{ |
| 747 |
int M, L; |
| 748 |
P7_GMXCHK *gxc = NULL; |
| 749 |
|
| 750 |
M = 20; L = 20; gxc = p7_gmxchk_Create(M, L, 0); utest_testpattern(gxc, M, L); |
| 751 |
M = 40; L = 20; p7_gmxchk_GrowTo(gxc, M, L); utest_testpattern(gxc, M, L); |
| 752 |
M = 40; L = 40; p7_gmxchk_GrowTo(gxc, M, L); utest_testpattern(gxc, M, L); |
| 753 |
M = 80; L = 10; p7_gmxchk_GrowTo(gxc, M, L); utest_testpattern(gxc, M, L); |
| 754 |
M = 10; L = 80; p7_gmxchk_GrowTo(gxc, M, L); utest_testpattern(gxc, M, L); |
| 755 |
M = 100; L = 100; p7_gmxchk_GrowTo(gxc, M, L); utest_testpattern(gxc, M, L); |
| 756 |
p7_gmxchk_Destroy(gxc); |
| 757 |
|
| 758 |
M = 20; L = 20; gxc = p7_gmxchk_Create(M, L, ESL_MBYTES(32)); utest_testpattern(gxc, M, L); |
| 759 |
M = 40; L = 20; p7_gmxchk_GrowTo(gxc, M, L); utest_testpattern(gxc, M, L); |
| 760 |
M = 40; L = 40; p7_gmxchk_GrowTo(gxc, M, L); utest_testpattern(gxc, M, L); |
| 761 |
M = 80; L = 10; p7_gmxchk_GrowTo(gxc, M, L); utest_testpattern(gxc, M, L); |
| 762 |
M = 10; L = 80; p7_gmxchk_GrowTo(gxc, M, L); utest_testpattern(gxc, M, L); |
| 763 |
M = 100; L = 100; p7_gmxchk_GrowTo(gxc, M, L); utest_testpattern(gxc, M, L); |
| 764 |
p7_gmxchk_Destroy(gxc); |
| 765 |
} |
| 766 |
|
| 767 |
#endif |
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
#ifdef p7GMXCHK_TESTDRIVE |
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
#include <p7_config.h> |
| 779 |
|
| 780 |
#include <stdio.h> |
| 781 |
#include <math.h> |
| 782 |
|
| 783 |
#include "easel.h" |
| 784 |
#include "esl_getopts.h" |
| 785 |
#include "esl_random.h" |
| 786 |
#include "esl_randomseq.h" |
| 787 |
|
| 788 |
#include "hmmer.h" |
| 789 |
#include "p7_gmxchk.h" |
| 790 |
|
| 791 |
static ESL_OPTIONS options[] = { |
| 792 |
|
| 793 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show help and usage", 0}, |
| 794 |
{ "-s", eslARG_INT, "42", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 }, |
| 795 |
{ "-L", eslARG_INT, "40", NULL, NULL, NULL, NULL, NULL, "length of sampled sequences", 0 }, |
| 796 |
{ "-M", eslARG_INT, "40", NULL, NULL, NULL, NULL, NULL, "length of sampled test profile", 0 }, |
| 797 |
{ 0,0,0,0,0,0,0,0,0,0}, |
| 798 |
}; |
| 799 |
static char usage[] = "[-options]"; |
| 800 |
static char banner[] = "test driver for p7_gmxchk.c"; |
| 801 |
|
| 802 |
int |
| 803 |
main(int argc, char **argv) |
| 804 |
{ |
| 805 |
char *msg = "p7_gmxchk unit test driver failed"; |
| 806 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 0, argc, argv, banner, usage); |
| 807 |
ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s")); |
| 808 |
ESL_ALPHABET *abc = esl_alphabet_Create(eslAMINO); |
| 809 |
P7_BG *bg = p7_bg_Create(abc); |
| 810 |
P7_HMM *hmm = NULL; |
| 811 |
P7_PROFILE *gm = NULL; |
| 812 |
int M = esl_opt_GetInteger(go, "-M"); |
| 813 |
int L = esl_opt_GetInteger(go, "-L"); |
| 814 |
|
| 815 |
p7_FLogsumInit(); |
| 816 |
|
| 817 |
if (p7_hmm_Sample(r, M, abc, &hmm) != eslOK) esl_fatal(msg); |
| 818 |
if ((gm = p7_profile_Create(hmm->M, abc)) == NULL) esl_fatal(msg); |
| 819 |
if (p7_bg_SetLength(bg, L) != eslOK) esl_fatal(msg); |
| 820 |
if (p7_ProfileConfig(hmm, bg, gm, L, p7_LOCAL) != eslOK) esl_fatal(msg); |
| 821 |
|
| 822 |
utest_GrowTo(); |
| 823 |
|
| 824 |
esl_getopts_Destroy(go); |
| 825 |
esl_randomness_Destroy(r); |
| 826 |
esl_alphabet_Destroy(abc); |
| 827 |
p7_bg_Destroy(bg); |
| 828 |
p7_hmm_Destroy(hmm); |
| 829 |
p7_profile_Destroy(gm); |
| 830 |
return eslOK; |
| 831 |
} |
| 832 |
#endif |
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|