| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
#include <p7_config.h> |
| 36 |
|
| 37 |
#include <math.h> |
| 38 |
#include <string.h> |
| 39 |
|
| 40 |
#include "easel.h" |
| 41 |
#include "esl_random.h" |
| 42 |
#include "esl_sq.h" |
| 43 |
#include "esl_vectorops.h" |
| 44 |
|
| 45 |
#include "hmmer.h" |
| 46 |
|
| 47 |
static int is_multidomain_region (P7_DOMAINDEF *ddef, int i, int j); |
| 48 |
static int region_trace_ensemble (P7_DOMAINDEF *ddef, const P7_OPROFILE *om, const ESL_DSQ *dsq, int ireg, int jreg, const P7_OMX *fwd, P7_OMX *wrk, int *ret_nc); |
| 49 |
static int rescore_isolated_domain(P7_DOMAINDEF *ddef, P7_OPROFILE *om, const ESL_SQ *sq, const ESL_SQ *ntsq, P7_OMX *ox1, P7_OMX *ox2, |
| 50 |
int i, int j, int null2_is_done, P7_BG *bg, int long_target, P7_BG *bg_tmp, float *scores_arr, float *fwd_emissions_arr); |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
P7_DOMAINDEF * |
| 70 |
p7_domaindef_Create(ESL_RANDOMNESS *r) |
| 71 |
{ |
| 72 |
P7_DOMAINDEF *ddef = NULL; |
| 73 |
int Lalloc = 512; |
| 74 |
int nalloc = 32; |
| 75 |
int status; |
| 76 |
|
| 77 |
|
| 78 |
ESL_ALLOC(ddef, sizeof(P7_DOMAINDEF)); |
| 79 |
ddef->mocc = ddef->btot = ddef->etot = NULL; |
| 80 |
ddef->n2sc = NULL; |
| 81 |
ddef->sp = NULL; |
| 82 |
ddef->tr = NULL; |
| 83 |
ddef->dcl = NULL; |
| 84 |
|
| 85 |
|
| 86 |
ESL_ALLOC(ddef->mocc, sizeof(float) * (Lalloc+1)); |
| 87 |
ESL_ALLOC(ddef->btot, sizeof(float) * (Lalloc+1)); |
| 88 |
ESL_ALLOC(ddef->etot, sizeof(float) * (Lalloc+1)); |
| 89 |
ESL_ALLOC(ddef->n2sc, sizeof(float) * (Lalloc+1)); |
| 90 |
ddef->mocc[0] = ddef->etot[0] = ddef->btot[0] = 0.; |
| 91 |
ddef->n2sc[0] = 0.; |
| 92 |
ddef->Lalloc = Lalloc; |
| 93 |
ddef->L = 0; |
| 94 |
|
| 95 |
|
| 96 |
ESL_ALLOC(ddef->dcl, sizeof(P7_DOMAIN) * nalloc); |
| 97 |
ddef->nalloc = nalloc; |
| 98 |
ddef->ndom = 0; |
| 99 |
|
| 100 |
ddef->nexpected = 0.0; |
| 101 |
ddef->nregions = 0; |
| 102 |
ddef->nclustered = 0; |
| 103 |
ddef->noverlaps = 0; |
| 104 |
ddef->nenvelopes = 0; |
| 105 |
|
| 106 |
|
| 107 |
ddef->rt1 = 0.25; |
| 108 |
ddef->rt2 = 0.10; |
| 109 |
ddef->rt3 = 0.20; |
| 110 |
ddef->nsamples = 200; |
| 111 |
ddef->min_overlap = 0.8; |
| 112 |
ddef->of_smaller = TRUE; |
| 113 |
ddef->max_diagdiff = 4; |
| 114 |
ddef->min_posterior = 0.25; |
| 115 |
ddef->min_endpointp = 0.02; |
| 116 |
|
| 117 |
|
| 118 |
ddef->sp = p7_spensemble_Create(1024, 64, 32); |
| 119 |
ddef->tr = p7_trace_CreateWithPP(); |
| 120 |
ddef->gtr = p7_trace_Create(); |
| 121 |
|
| 122 |
|
| 123 |
ddef->r = r; |
| 124 |
ddef->do_reseeding = TRUE; |
| 125 |
return ddef; |
| 126 |
|
| 127 |
ERROR: |
| 128 |
p7_domaindef_Destroy(ddef); |
| 129 |
return NULL; |
| 130 |
} |
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
int |
| 149 |
p7_domaindef_GrowTo(P7_DOMAINDEF *ddef, int L) |
| 150 |
{ |
| 151 |
void *p; |
| 152 |
int status; |
| 153 |
|
| 154 |
if (L <= ddef->Lalloc) return eslOK; |
| 155 |
|
| 156 |
ESL_RALLOC(ddef->mocc, p, sizeof(float) * (L+1)); |
| 157 |
ESL_RALLOC(ddef->btot, p, sizeof(float) * (L+1)); |
| 158 |
ESL_RALLOC(ddef->etot, p, sizeof(float) * (L+1)); |
| 159 |
ESL_RALLOC(ddef->n2sc, p, sizeof(float) * (L+1)); |
| 160 |
ddef->Lalloc = L; |
| 161 |
return eslOK; |
| 162 |
|
| 163 |
ERROR: |
| 164 |
return status; |
| 165 |
} |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
int |
| 185 |
p7_domaindef_Reuse(P7_DOMAINDEF *ddef) |
| 186 |
{ |
| 187 |
int status; |
| 188 |
int d; |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
if (ddef->dcl == NULL) |
| 195 |
ESL_ALLOC(ddef->dcl, sizeof(P7_DOMAIN) * ddef->nalloc); |
| 196 |
else |
| 197 |
{ |
| 198 |
for (d = 0; d < ddef->ndom; d++) { |
| 199 |
p7_alidisplay_Destroy(ddef->dcl[d].ad); ddef->dcl[d].ad = NULL; |
| 200 |
free(ddef->dcl[d].scores_per_pos); ddef->dcl[d].scores_per_pos = NULL; |
| 201 |
} |
| 202 |
|
| 203 |
} |
| 204 |
ddef->ndom = 0; |
| 205 |
ddef->L = 0; |
| 206 |
|
| 207 |
ddef->nexpected = 0.0; |
| 208 |
ddef->nregions = 0; |
| 209 |
ddef->nclustered = 0; |
| 210 |
ddef->noverlaps = 0; |
| 211 |
ddef->nenvelopes = 0; |
| 212 |
|
| 213 |
p7_spensemble_Reuse(ddef->sp); |
| 214 |
p7_trace_Reuse(ddef->tr); |
| 215 |
p7_trace_Reuse(ddef->gtr); |
| 216 |
return eslOK; |
| 217 |
|
| 218 |
ERROR: |
| 219 |
return status; |
| 220 |
} |
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
int |
| 251 |
p7_domaindef_DumpPosteriors(FILE *ofp, P7_DOMAINDEF *ddef) |
| 252 |
{ |
| 253 |
int i; |
| 254 |
|
| 255 |
for (i = 1; i <= ddef->L; i++) |
| 256 |
fprintf(ofp, "%d %f\n", i, ddef->mocc[i]); |
| 257 |
fprintf(ofp, "&\n"); |
| 258 |
|
| 259 |
for (i = 1; i <= ddef->L; i++) |
| 260 |
fprintf(ofp, "%d %f\n", i, ddef->btot[i]); |
| 261 |
fprintf(ofp, "&\n"); |
| 262 |
|
| 263 |
for (i = 1; i <= ddef->L; i++) |
| 264 |
fprintf(ofp, "%d %f\n", i, ddef->etot[i]); |
| 265 |
fprintf(ofp, "&\n"); |
| 266 |
|
| 267 |
for (i = 1; i <= ddef->L; i++) |
| 268 |
fprintf(ofp, "%d %f\n", i, ddef->n2sc[i]); |
| 269 |
fprintf(ofp, "&\n"); |
| 270 |
|
| 271 |
return eslOK; |
| 272 |
} |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
void |
| 283 |
p7_domaindef_Destroy(P7_DOMAINDEF *ddef) |
| 284 |
{ |
| 285 |
int d; |
| 286 |
if (ddef == NULL) return; |
| 287 |
|
| 288 |
if (ddef->mocc != NULL) free(ddef->mocc); |
| 289 |
if (ddef->btot != NULL) free(ddef->btot); |
| 290 |
if (ddef->etot != NULL) free(ddef->etot); |
| 291 |
if (ddef->n2sc != NULL) free(ddef->n2sc); |
| 292 |
|
| 293 |
if (ddef->dcl != NULL) { |
| 294 |
for (d = 0; d < ddef->ndom; d++) { |
| 295 |
if (ddef->dcl[d].scores_per_pos) free(ddef->dcl[d].scores_per_pos); |
| 296 |
p7_alidisplay_Destroy(ddef->dcl[d].ad); |
| 297 |
} |
| 298 |
free(ddef->dcl); |
| 299 |
} |
| 300 |
|
| 301 |
p7_spensemble_Destroy(ddef->sp); |
| 302 |
p7_trace_Destroy(ddef->tr); |
| 303 |
p7_trace_Destroy(ddef->gtr); |
| 304 |
free(ddef); |
| 305 |
return; |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
#if 0 |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
int |
| 331 |
p7_domaindef_ByViterbi(P7_PROFILE *gm, const ESL_SQ *sq, const ESL_SQ *ntsq, P7_GMX *gx1, P7_GMX *gx2, P7_DOMAINDEF *ddef) |
| 332 |
{ |
| 333 |
int d; |
| 334 |
int saveL = gm->L; |
| 335 |
int save_mode = gm->mode; |
| 336 |
|
| 337 |
p7_domaindef_GrowTo(ddef, sq->n); |
| 338 |
p7_GTrace (sq->dsq, sq->n, gm, gx1, ddef->gtr); |
| 339 |
p7_trace_Index(ddef->gtr); |
| 340 |
|
| 341 |
p7_ReconfigUnihit(gm, 0); |
| 342 |
|
| 343 |
for (d = 0; d < ddef->gtr->ndom; d++) |
| 344 |
rescore_isolated_domain(ddef, gm, sq, ntsq, gx1, gx2, ddef->gtr->sqfrom[d], ddef->gtr->sqto[d], FALSE, NULL, FALSE, NULL, NULL, NULL); |
| 345 |
|
| 346 |
|
| 347 |
if (p7_IsMulti(save_mode)) p7_ReconfigMultihit(gm, saveL); |
| 348 |
else p7_ReconfigUnihit( gm, saveL); |
| 349 |
return eslOK; |
| 350 |
} |
| 351 |
#endif |
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
int |
| 384 |
p7_domaindef_ByPosteriorHeuristics(const ESL_SQ *sq, const ESL_SQ *ntsq, P7_OPROFILE *om, |
| 385 |
P7_OMX *oxf, P7_OMX *oxb, P7_OMX *fwd, P7_OMX *bck, |
| 386 |
P7_DOMAINDEF *ddef, P7_BG *bg, int long_target, |
| 387 |
P7_BG *bg_tmp, float *scores_arr, float *fwd_emissions_arr) |
| 388 |
{ |
| 389 |
int i, j; |
| 390 |
int triggered; |
| 391 |
int d; |
| 392 |
int i2,j2; |
| 393 |
int last_j2; |
| 394 |
int nc; |
| 395 |
int saveL = om->L; |
| 396 |
int save_mode = om->mode; |
| 397 |
int status; |
| 398 |
|
| 399 |
if ((status = p7_domaindef_GrowTo(ddef, sq->n)) != eslOK) return status; |
| 400 |
if ((status = p7_DomainDecoding(om, oxf, oxb, ddef)) != eslOK) return status; |
| 401 |
|
| 402 |
esl_vec_FSet(ddef->n2sc, sq->n+1, 0.0); |
| 403 |
ddef->nexpected = ddef->btot[sq->n]; |
| 404 |
|
| 405 |
p7_oprofile_ReconfigUnihit(om, saveL); |
| 406 |
i = -1; |
| 407 |
triggered = FALSE; |
| 408 |
|
| 409 |
for (j = 1; j <= sq->n; j++) |
| 410 |
{ |
| 411 |
|
| 412 |
if (! triggered) |
| 413 |
{ |
| 414 |
if (ddef->mocc[j] - (ddef->btot[j] - ddef->btot[j-1]) < ddef->rt2) i = j; |
| 415 |
else if (i == -1) i = j; |
| 416 |
if (ddef->mocc[j] >= ddef->rt1) triggered = TRUE; |
| 417 |
} |
| 418 |
else if (ddef->mocc[j] - (ddef->etot[j] - ddef->etot[j-1]) < ddef->rt2) |
| 419 |
{ |
| 420 |
|
| 421 |
p7_omx_GrowTo(fwd, om->M, j-i+1, j-i+1); |
| 422 |
p7_omx_GrowTo(bck, om->M, j-i+1, j-i+1); |
| 423 |
ddef->nregions++; |
| 424 |
if (is_multidomain_region(ddef, i, j)) |
| 425 |
{ |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
ddef->nclustered++; |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
p7_oprofile_ReconfigMultihit(om, saveL); |
| 439 |
p7_Forward(sq->dsq+i-1, j-i+1, om, fwd, NULL); |
| 440 |
|
| 441 |
region_trace_ensemble(ddef, om, sq->dsq, i, j, fwd, bck, &nc); |
| 442 |
p7_oprofile_ReconfigUnihit(om, saveL); |
| 443 |
|
| 444 |
|
| 445 |
last_j2 = 0; |
| 446 |
for (d = 0; d < nc; d++) { |
| 447 |
p7_spensemble_GetClusterCoords(ddef->sp, d, &i2, &j2, NULL, NULL, NULL); |
| 448 |
if (i2 <= last_j2) ddef->noverlaps++; |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
ddef->nenvelopes++; |
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
if (rescore_isolated_domain(ddef, om, sq, ntsq, fwd, bck, i2, j2, TRUE, bg, long_target, bg_tmp, scores_arr, fwd_emissions_arr) == eslOK) |
| 472 |
last_j2 = j2; |
| 473 |
} |
| 474 |
p7_spensemble_Reuse(ddef->sp); |
| 475 |
p7_trace_Reuse(ddef->tr); |
| 476 |
} |
| 477 |
else |
| 478 |
{ |
| 479 |
|
| 480 |
ddef->nenvelopes++; |
| 481 |
rescore_isolated_domain(ddef, om, sq, ntsq, fwd, bck, i, j, FALSE, bg, long_target, bg_tmp, scores_arr, fwd_emissions_arr); |
| 482 |
} |
| 483 |
i = -1; |
| 484 |
triggered = FALSE; |
| 485 |
} |
| 486 |
} |
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
if (p7_IsMulti(save_mode)) p7_oprofile_ReconfigMultihit(om, saveL); |
| 491 |
else p7_oprofile_ReconfigUnihit (om, saveL); |
| 492 |
return eslOK; |
| 493 |
} |
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
static int |
| 531 |
is_multidomain_region(P7_DOMAINDEF *ddef, int i, int j) |
| 532 |
{ |
| 533 |
int z; |
| 534 |
float max; |
| 535 |
float expected_n; |
| 536 |
|
| 537 |
max = -1.0; |
| 538 |
for (z = i; z <= j; z++) |
| 539 |
{ |
| 540 |
expected_n = ESL_MIN( (ddef->etot[z] - ddef->etot[i-1]), (ddef->btot[j] - ddef->btot[z-1])); |
| 541 |
max = ESL_MAX(max, expected_n); |
| 542 |
} |
| 543 |
|
| 544 |
return ( (max >= ddef->rt3) ? TRUE : FALSE); |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
static int |
| 597 |
region_trace_ensemble(P7_DOMAINDEF *ddef, const P7_OPROFILE *om, const ESL_DSQ *dsq, int ireg, int jreg, |
| 598 |
const P7_OMX *fwd, P7_OMX *wrk, int *ret_nc) |
| 599 |
{ |
| 600 |
int Lr = jreg-ireg+1; |
| 601 |
int t, d, d2; |
| 602 |
int nov, n; |
| 603 |
int nc; |
| 604 |
int pos; |
| 605 |
float null2[p7_MAXCODE]; |
| 606 |
|
| 607 |
esl_vec_FSet(ddef->n2sc+ireg, Lr, 0.0); |
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
if (ddef->do_reseeding) |
| 613 |
esl_randomness_Init(ddef->r, esl_randomness_GetSeed(ddef->r)); |
| 614 |
|
| 615 |
|
| 616 |
for (t = 0; t < ddef->nsamples; t++) |
| 617 |
{ |
| 618 |
p7_StochasticTrace(ddef->r, dsq+ireg-1, Lr, om, fwd, ddef->tr); |
| 619 |
p7_trace_Index(ddef->tr); |
| 620 |
|
| 621 |
pos = 1; |
| 622 |
for (d = 0; d < ddef->tr->ndom; d++) |
| 623 |
{ |
| 624 |
p7_spensemble_Add(ddef->sp, t, ddef->tr->sqfrom[d]+ireg-1, ddef->tr->sqto[d]+ireg-1, ddef->tr->hmmfrom[d], ddef->tr->hmmto[d]); |
| 625 |
|
| 626 |
p7_Null2_ByTrace(om, ddef->tr, ddef->tr->tfrom[d], ddef->tr->tto[d], wrk, null2); |
| 627 |
|
| 628 |
|
| 629 |
for (; pos <= ddef->tr->sqfrom[d]; pos++) ddef->n2sc[ireg+pos-1] += 1.0; |
| 630 |
|
| 631 |
|
| 632 |
for (; pos <= ddef->tr->sqto[d]; pos++) ddef->n2sc[ireg+pos-1] += null2[dsq[ireg+pos-1]]; |
| 633 |
} |
| 634 |
|
| 635 |
for (; pos <= Lr; pos++) ddef->n2sc[ireg+pos-1] += 1.0; |
| 636 |
|
| 637 |
p7_trace_Reuse(ddef->tr); |
| 638 |
} |
| 639 |
|
| 640 |
|
| 641 |
for (pos = ireg; pos <= jreg; pos++) |
| 642 |
ddef->n2sc[pos] = logf(ddef->n2sc[pos] / (float) ddef->nsamples); |
| 643 |
|
| 644 |
|
| 645 |
p7_spensemble_Cluster(ddef->sp, ddef->min_overlap, ddef->of_smaller, ddef->max_diagdiff, ddef->min_posterior, ddef->min_endpointp, &nc); |
| 646 |
|
| 647 |
|
| 648 |
for (d = 0; d < nc; d++) |
| 649 |
ddef->sp->assignment[d] = 0; |
| 650 |
|
| 651 |
|
| 652 |
for (d = 0; d < nc; d++) |
| 653 |
{ |
| 654 |
for (d2 = d+1; d2 < nc; d2++) |
| 655 |
{ |
| 656 |
nov = ESL_MIN(ddef->sp->sigc[d].j, ddef->sp->sigc[d2].j) - ESL_MAX(ddef->sp->sigc[d].i, ddef->sp->sigc[d2].i) + 1; |
| 657 |
if (nov == 0) break; |
| 658 |
n = ESL_MIN(ddef->sp->sigc[d].j - ddef->sp->sigc[d].i + 1, ddef->sp->sigc[d2].j - ddef->sp->sigc[d2].i + 1); |
| 659 |
if ((float) nov / (float) n >= 0.8) |
| 660 |
{ |
| 661 |
if (ddef->sp->sigc[d].prob > ddef->sp->sigc[d2].prob) ddef->sp->assignment[d2] = 1; |
| 662 |
else ddef->sp->assignment[d] = 1; |
| 663 |
} |
| 664 |
} |
| 665 |
} |
| 666 |
|
| 667 |
|
| 668 |
d = 0; |
| 669 |
for (d2 = 0; d2 < nc; d2++) |
| 670 |
{ |
| 671 |
if (ddef->sp->assignment[d2]) continue; |
| 672 |
if (d != d2) memcpy(ddef->sp->sigc + d, ddef->sp->sigc + d2, sizeof(struct p7_spcoord_s)); |
| 673 |
d++; |
| 674 |
} |
| 675 |
ddef->sp->nc = d; |
| 676 |
*ret_nc = d; |
| 677 |
return eslOK; |
| 678 |
} |
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
static int |
| 717 |
reparameterize_model (P7_BG *bg, P7_OPROFILE *om, const ESL_SQ *sq, int start, int L, float *fwd_emissions, float *bgf_arr, float *sc_arr) { |
| 718 |
int K = om->abc->K; |
| 719 |
int i; |
| 720 |
float tmp; |
| 721 |
int status; |
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
float bg_smooth = 1.; |
| 727 |
|
| 728 |
if (sq != NULL) { |
| 729 |
|
| 730 |
bg_smooth = 25.0 / (ESL_MIN(100,ESL_MAX(50,sq->n))); |
| 731 |
|
| 732 |
esl_vec_FSet (bgf_arr, om->abc->K, 0); |
| 733 |
status = esl_sq_CountResidues(sq, start, L, bgf_arr); |
| 734 |
if (status != eslOK) p7_Fail("Invalid sequence range in reparameterize_model()\n"); |
| 735 |
esl_vec_FNorm(bgf_arr, om->abc->K); |
| 736 |
|
| 737 |
for (i=0; i<K; i++) { |
| 738 |
tmp = bg->f[i]; |
| 739 |
bg->f[i] = (bg_smooth*bg->f[i]) + ( (1.0-bg_smooth) * bgf_arr[i]) ; |
| 740 |
bgf_arr[i] = tmp; |
| 741 |
} |
| 742 |
} else { |
| 743 |
|
| 744 |
esl_vec_FCopy(bgf_arr, K, bg->f); |
| 745 |
} |
| 746 |
|
| 747 |
p7_oprofile_UpdateFwdEmissionScores(om, bg, fwd_emissions, sc_arr); |
| 748 |
|
| 749 |
return eslOK; |
| 750 |
} |
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
static int |
| 814 |
rescore_isolated_domain(P7_DOMAINDEF *ddef, P7_OPROFILE *om, const ESL_SQ *sq, const ESL_SQ *ntsq, |
| 815 |
P7_OMX *ox1, P7_OMX *ox2, int i, int j, int null2_is_done, P7_BG *bg, int long_target, |
| 816 |
P7_BG *bg_tmp, float *scores_arr, float *fwd_emissions_arr) |
| 817 |
{ |
| 818 |
P7_DOMAIN *dom = NULL; |
| 819 |
int Ld = j-i+1; |
| 820 |
float domcorrection = 0.0; |
| 821 |
float envsc, oasc; |
| 822 |
int z; |
| 823 |
int pos; |
| 824 |
float null2[p7_MAXCODE]; |
| 825 |
int status; |
| 826 |
int max_env_extra = 20; |
| 827 |
int orig_L; |
| 828 |
|
| 829 |
|
| 830 |
if (long_target) { |
| 831 |
|
| 832 |
|
| 833 |
orig_L = om->L; |
| 834 |
p7_oprofile_ReconfigRestLength(om, j-i+1); |
| 835 |
} |
| 836 |
|
| 837 |
if (long_target && scores_arr!=NULL) { |
| 838 |
|
| 839 |
|
| 840 |
reparameterize_model (bg, om, sq, i, j-i+1, fwd_emissions_arr, bg_tmp->f, scores_arr); |
| 841 |
} |
| 842 |
|
| 843 |
p7_Forward (sq->dsq + i-1, Ld, om, ox1, &envsc); |
| 844 |
p7_Backward(sq->dsq + i-1, Ld, om, ox1, ox2, NULL); |
| 845 |
|
| 846 |
status = p7_Decoding(om, ox1, ox2, ox2); |
| 847 |
if (status == eslERANGE) { |
| 848 |
if (long_target && scores_arr) |
| 849 |
reparameterize_model(bg, om, NULL, 0, 0, fwd_emissions_arr, bg_tmp->f, scores_arr); |
| 850 |
status = eslFAIL; |
| 851 |
goto ERROR; |
| 852 |
} |
| 853 |
|
| 854 |
|
| 855 |
p7_OptimalAccuracy(om, ox2, ox1, &oasc); |
| 856 |
p7_OATrace (om, ox2, ox1, ddef->tr); |
| 857 |
|
| 858 |
|
| 859 |
for (z = 0; z < ddef->tr->N; z++) |
| 860 |
if (ddef->tr->i[z] > 0) ddef->tr->i[z] += i-1; |
| 861 |
|
| 862 |
|
| 863 |
if (ddef->ndom == ddef->nalloc) { |
| 864 |
ESL_REALLOC(ddef->dcl, sizeof(P7_DOMAIN) * (ddef->nalloc*2)); |
| 865 |
ddef->nalloc *= 2; |
| 866 |
} |
| 867 |
dom = &(ddef->dcl[ddef->ndom]); |
| 868 |
dom->ad = p7_alidisplay_Create(ddef->tr, 0, om, sq, ntsq); |
| 869 |
dom->scores_per_pos = NULL; |
| 870 |
|
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
if (long_target) { |
| 878 |
|
| 879 |
if ( i < dom->ad->sqfrom-max_env_extra |
| 880 |
|| j > dom->ad->sqto+max_env_extra |
| 881 |
) { |
| 882 |
|
| 883 |
|
| 884 |
i = ESL_MAX(i,dom->ad->sqfrom-max_env_extra); |
| 885 |
j = ESL_MIN(j,dom->ad->sqto+max_env_extra); |
| 886 |
Ld = j - i + 1; |
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
p7_oprofile_ReconfigRestLength(om, j-i+1); |
| 891 |
|
| 892 |
if (scores_arr!=NULL) { |
| 893 |
|
| 894 |
reparameterize_model (bg, om, NULL, 0, 0, fwd_emissions_arr, bg_tmp->f, scores_arr); |
| 895 |
reparameterize_model (bg, om, sq, i, Ld, fwd_emissions_arr, bg_tmp->f, scores_arr); |
| 896 |
} |
| 897 |
|
| 898 |
p7_Forward (sq->dsq + i-1, Ld, om, ox1, &envsc); |
| 899 |
p7_Backward(sq->dsq + i-1, Ld, om, ox1, ox2, NULL); |
| 900 |
|
| 901 |
status = p7_Decoding(om, ox1, ox2, ox2); |
| 902 |
if (status == eslERANGE) { |
| 903 |
reparameterize_model(bg, om, NULL, 0, 0, fwd_emissions_arr, bg_tmp->f, scores_arr); |
| 904 |
status = eslFAIL; |
| 905 |
goto ERROR; |
| 906 |
} |
| 907 |
|
| 908 |
|
| 909 |
p7_OptimalAccuracy(om, ox2, ox1, &oasc); |
| 910 |
p7_trace_Reuse(ddef->tr); |
| 911 |
p7_OATrace (om, ox2, ox1, ddef->tr); |
| 912 |
|
| 913 |
|
| 914 |
for (z = 0; z < ddef->tr->N; z++) |
| 915 |
if (ddef->tr->i[z] > 0) ddef->tr->i[z] += i-1; |
| 916 |
|
| 917 |
|
| 918 |
p7_alidisplay_Destroy(dom->ad); |
| 919 |
dom->ad = p7_alidisplay_Create(ddef->tr, 0, om, sq, NULL); |
| 920 |
} |
| 921 |
|
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
domcorrection = envsc; |
| 926 |
if (scores_arr!=NULL) { |
| 927 |
|
| 928 |
reparameterize_model (bg, om, NULL, 0, 0, fwd_emissions_arr, bg_tmp->f, scores_arr); |
| 929 |
p7_Forward (sq->dsq + i-1, Ld, om, ox1, &domcorrection); |
| 930 |
} |
| 931 |
|
| 932 |
p7_oprofile_ReconfigRestLength(om, orig_L); |
| 933 |
|
| 934 |
if (domcorrection < envsc) |
| 935 |
envsc = domcorrection; |
| 936 |
|
| 937 |
dom->domcorrection = domcorrection - envsc; |
| 938 |
|
| 939 |
} else { |
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
if (!null2_is_done) { |
| 949 |
p7_Null2_ByExpectation(om, ox2, null2); |
| 950 |
for (pos = i; pos <= j; pos++) |
| 951 |
ddef->n2sc[pos] = logf(null2[sq->dsq[pos]]); |
| 952 |
} |
| 953 |
for (pos = i; pos <= j; pos++) |
| 954 |
domcorrection += ddef->n2sc[pos]; |
| 955 |
|
| 956 |
dom->domcorrection = domcorrection; |
| 957 |
|
| 958 |
} |
| 959 |
|
| 960 |
|
| 961 |
dom->iali = dom->ad->sqfrom; |
| 962 |
dom->jali = dom->ad->sqto; |
| 963 |
dom->ienv = i; |
| 964 |
dom->jenv = j; |
| 965 |
dom->envsc = envsc; |
| 966 |
dom->oasc = oasc; |
| 967 |
dom->dombias = 0.0; |
| 968 |
dom->bitscore = 0.0; |
| 969 |
dom->lnP = 0.0; |
| 970 |
dom->is_reported = FALSE; |
| 971 |
dom->is_included = FALSE; |
| 972 |
|
| 973 |
|
| 974 |
ddef->ndom++; |
| 975 |
|
| 976 |
p7_trace_Reuse(ddef->tr); |
| 977 |
return eslOK; |
| 978 |
|
| 979 |
ERROR: |
| 980 |
p7_trace_Reuse(ddef->tr); |
| 981 |
return status; |
| 982 |
} |
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
#ifdef p7DOMAINDEF_EXAMPLE |
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
#include <p7_config.h> |
| 997 |
|
| 998 |
#include <stdio.h> |
| 999 |
#include <stdlib.h> |
| 1000 |
|
| 1001 |
#include "easel.h" |
| 1002 |
#include "esl_getopts.h" |
| 1003 |
#include "esl_random.h" |
| 1004 |
#include "esl_alphabet.h" |
| 1005 |
#include "esl_sq.h" |
| 1006 |
#include "esl_sqio.h" |
| 1007 |
#include "hmmer.h" |
| 1008 |
|
| 1009 |
static ESL_OPTIONS options[] = { |
| 1010 |
|
| 1011 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 1012 |
{ "-V", eslARG_NONE, NULL, NULL, NULL, NULL, NULL, NULL, "find domains by Viterbi parsing", 0 }, |
| 1013 |
{ "--occp", eslARG_OUTFILE, NULL, NULL, NULL, NULL, NULL, NULL, "output posterior occupancies for xmgrace to <f>", 0 }, |
| 1014 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1015 |
}; |
| 1016 |
|
| 1017 |
static char usage[] = "[-options] <hmmfile> <seqfile>"; |
| 1018 |
static char banner[] = "example of domain definition by posterior sampling"; |
| 1019 |
|
| 1020 |
int |
| 1021 |
main(int argc, char **argv) |
| 1022 |
{ |
| 1023 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 2, argc, argv, banner, usage); |
| 1024 |
ESL_RANDOMNESS *r = esl_randomness_CreateFast(42); |
| 1025 |
char *hmmfile = esl_opt_GetArg(go, 1); |
| 1026 |
P7_HMMFILE *hfp = NULL; |
| 1027 |
P7_HMM *hmm = NULL; |
| 1028 |
char *seqfile = esl_opt_GetArg(go, 2); |
| 1029 |
int format = eslSQFILE_UNKNOWN; |
| 1030 |
ESL_SQFILE *sqfp = NULL; |
| 1031 |
ESL_SQ *sq = NULL; |
| 1032 |
ESL_ALPHABET *abc = NULL; |
| 1033 |
P7_BG *bg = NULL; |
| 1034 |
P7_PROFILE *gm = NULL; |
| 1035 |
P7_OPROFILE *om = NULL; |
| 1036 |
P7_OMX *oxf = NULL; |
| 1037 |
P7_OMX *oxb = NULL; |
| 1038 |
P7_OMX *fwd = NULL; |
| 1039 |
P7_OMX *bck = NULL; |
| 1040 |
P7_DOMAINDEF *ddef = NULL; |
| 1041 |
char *ofile = NULL; |
| 1042 |
FILE *ofp = NULL; |
| 1043 |
float overall_sc, sc; |
| 1044 |
int d; |
| 1045 |
int status; |
| 1046 |
|
| 1047 |
|
| 1048 |
if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile); |
| 1049 |
if (p7_hmmfile_Read(hfp, &abc, &hmm) != eslOK) p7_Fail("Failed to read HMM"); |
| 1050 |
p7_hmmfile_Close(hfp); |
| 1051 |
|
| 1052 |
|
| 1053 |
sq = esl_sq_CreateDigital(abc); |
| 1054 |
status = esl_sqfile_Open(seqfile, format, NULL, &sqfp); |
| 1055 |
if (status == eslENOTFOUND) p7_Fail("No such file."); |
| 1056 |
else if (status == eslEFORMAT) p7_Fail("Format unrecognized."); |
| 1057 |
else if (status == eslEINVAL) p7_Fail("Can't autodetect stdin or .gz."); |
| 1058 |
else if (status != eslOK) p7_Fail("Open failed, code %d.", status); |
| 1059 |
if (esl_sqio_Read(sqfp, sq) != eslOK) p7_Fail("Failed to read sequence"); |
| 1060 |
esl_sqfile_Close(sqfp); |
| 1061 |
|
| 1062 |
|
| 1063 |
p7_FLogsumInit(); |
| 1064 |
|
| 1065 |
bg = p7_bg_Create(abc); |
| 1066 |
p7_bg_SetLength(bg, sq->n); |
| 1067 |
gm = p7_profile_Create(hmm->M, abc); |
| 1068 |
om = p7_oprofile_Create(hmm->M, abc); |
| 1069 |
p7_ProfileConfig(hmm, bg, gm, sq->n, p7_LOCAL); |
| 1070 |
p7_oprofile_Convert(gm, om); |
| 1071 |
p7_oprofile_ReconfigLength(om, sq->n); |
| 1072 |
|
| 1073 |
|
| 1074 |
ddef = p7_domaindef_Create(r); |
| 1075 |
|
| 1076 |
|
| 1077 |
fwd = p7_omx_Create(gm->M, sq->n, sq->n); |
| 1078 |
bck = p7_omx_Create(gm->M, sq->n, sq->n); |
| 1079 |
|
| 1080 |
oxf = p7_omx_Create(om->M, 0, sq->n); |
| 1081 |
oxb = p7_omx_Create(om->M, 0, sq->n); |
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
p7_Forward (sq->dsq, sq->n, om, fwd, &overall_sc); |
| 1087 |
p7_Backward(sq->dsq, sq->n, om, fwd, bck, &sc); |
| 1088 |
p7_domaindef_ByPosteriorHeuristics(sq, NULL, om, oxf, oxb, fwd, bck, ddef, NULL, FALSE, NULL, NULL, NULL); |
| 1089 |
|
| 1090 |
|
| 1091 |
printf("Overall raw likelihood score: %.2f nats\n", overall_sc); |
| 1092 |
|
| 1093 |
|
| 1094 |
for (d = 0; d < ddef->ndom; d++) |
| 1095 |
{ |
| 1096 |
printf("domain %-4d : %4" PRId64 " %4" PRId64 " %6.2f %6.2f\n", |
| 1097 |
d+1, |
| 1098 |
ddef->dcl[d].ienv, |
| 1099 |
ddef->dcl[d].jenv, |
| 1100 |
ddef->dcl[d].envsc, |
| 1101 |
ddef->dcl[d].domcorrection); |
| 1102 |
|
| 1103 |
p7_alidisplay_Print(stdout, ddef->dcl[d].ad, 50, 120, FALSE); |
| 1104 |
} |
| 1105 |
|
| 1106 |
if ((ofile = esl_opt_GetString(go, "--occp")) != NULL) |
| 1107 |
{ |
| 1108 |
if ((ofp = fopen(ofile, "w")) == NULL) p7_Fail("Failed to open output file %s\n", ofile); |
| 1109 |
p7_domaindef_DumpPosteriors(ofp, ddef); |
| 1110 |
fclose(ofp); |
| 1111 |
} |
| 1112 |
|
| 1113 |
p7_domaindef_Destroy(ddef); |
| 1114 |
p7_omx_Destroy(oxf); |
| 1115 |
p7_omx_Destroy(oxb); |
| 1116 |
p7_omx_Destroy(fwd); |
| 1117 |
p7_omx_Destroy(bck); |
| 1118 |
p7_profile_Destroy(gm); |
| 1119 |
p7_oprofile_Destroy(om); |
| 1120 |
p7_bg_Destroy(bg); |
| 1121 |
p7_hmm_Destroy(hmm); |
| 1122 |
esl_sq_Destroy(sq); |
| 1123 |
esl_alphabet_Destroy(abc); |
| 1124 |
esl_randomness_Destroy(r); |
| 1125 |
esl_getopts_Destroy(go); |
| 1126 |
return 0; |
| 1127 |
} |
| 1128 |
#endif |
| 1129 |
|
| 1130 |
|
| 1131 |
#ifdef p7DOMAINDEF_EXAMPLE2 |
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
#include <p7_config.h> |
| 1136 |
|
| 1137 |
#include <stdio.h> |
| 1138 |
#include <stdlib.h> |
| 1139 |
|
| 1140 |
#include "easel.h" |
| 1141 |
#include "esl_getopts.h" |
| 1142 |
#include "esl_random.h" |
| 1143 |
#include "esl_alphabet.h" |
| 1144 |
#include "esl_stopwatch.h" |
| 1145 |
#include "hmmer.h" |
| 1146 |
|
| 1147 |
static ESL_OPTIONS options[] = { |
| 1148 |
|
| 1149 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 1150 |
{ "-N", eslARG_INT, "1000", NULL, NULL, NULL, NULL, NULL, "number of sampled sequences", 0 }, |
| 1151 |
{ "-L", eslARG_INT, "400", NULL, NULL, NULL, NULL, NULL, "length config for the profile", 0 }, |
| 1152 |
{ "-V", eslARG_NONE, NULL, NULL, NULL, NULL, NULL, NULL, "find domains by Viterbi parsing", 0 }, |
| 1153 |
{ "-b", eslARG_NONE, NULL, NULL, NULL, NULL, NULL, NULL, "baseline timing - no domain processing", 0 }, |
| 1154 |
{ "-v", eslARG_NONE, NULL, NULL, NULL, NULL, NULL, NULL, "be more verbose (show per sequence results)", 0 }, |
| 1155 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 1156 |
}; |
| 1157 |
|
| 1158 |
static char usage[] = "[-options] <hmmfile>"; |
| 1159 |
static char banner[] = "example of domain definition by posterior sampling"; |
| 1160 |
|
| 1161 |
int |
| 1162 |
main(int argc, char **argv) |
| 1163 |
{ |
| 1164 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 1, argc, argv, banner, usage); |
| 1165 |
ESL_RANDOMNESS *r = esl_randomness_CreateFast(42); |
| 1166 |
ESL_STOPWATCH *w = esl_stopwatch_Create(); |
| 1167 |
char *hmmfile = esl_opt_GetArg(go, 1); |
| 1168 |
P7_HMMFILE *hfp = NULL; |
| 1169 |
P7_HMM *hmm = NULL; |
| 1170 |
ESL_SQ *sq = NULL; |
| 1171 |
ESL_ALPHABET *abc = NULL; |
| 1172 |
P7_BG *bg = NULL; |
| 1173 |
P7_PROFILE *gm = NULL; |
| 1174 |
P7_TRACE *tr = NULL; |
| 1175 |
P7_GMX *fwd = NULL; |
| 1176 |
P7_GMX *bck = NULL; |
| 1177 |
P7_OMX *gxf = NULL; |
| 1178 |
P7_OMX *gxb = NULL; |
| 1179 |
|
| 1180 |
P7_DOMAINDEF *ddef = NULL; |
| 1181 |
int N = esl_opt_GetInteger(go, "-N"); |
| 1182 |
int L0 = esl_opt_GetInteger(go, "-L"); |
| 1183 |
int do_vit = esl_opt_GetBoolean(go, "-V"); |
| 1184 |
int do_baseline = esl_opt_GetBoolean(go, "-b"); |
| 1185 |
int be_verbose = esl_opt_GetBoolean(go, "-v"); |
| 1186 |
float overall_sc, sc; |
| 1187 |
int idx; |
| 1188 |
int tot_true, tot_found; |
| 1189 |
|
| 1190 |
|
| 1191 |
if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile); |
| 1192 |
if (p7_hmmfile_Read(hfp, &abc, &hmm) != eslOK) p7_Fail("Failed to read HMM"); |
| 1193 |
p7_hmmfile_Close(hfp); |
| 1194 |
|
| 1195 |
|
| 1196 |
bg = p7_bg_Create(abc); |
| 1197 |
p7_bg_SetLength(bg, L0); |
| 1198 |
gm = p7_profile_Create(hmm->M, abc); |
| 1199 |
p7_ProfileConfig(hmm, bg, gm, L0, p7_LOCAL); |
| 1200 |
|
| 1201 |
|
| 1202 |
sq = esl_sq_CreateDigital(abc); |
| 1203 |
ddef = p7_domaindef_Create(r); |
| 1204 |
fwd = p7_gmx_Create(gm->M, L0); |
| 1205 |
bck = p7_gmx_Create(gm->M, L0); |
| 1206 |
gxf = p7_gmx_Create(gm->M, L0); |
| 1207 |
gxb = p7_gmx_Create(gm->M, L0); |
| 1208 |
tr = p7_trace_Create(); |
| 1209 |
p7_FLogsumInit(); |
| 1210 |
|
| 1211 |
tot_true = tot_found = 0; |
| 1212 |
esl_stopwatch_Start(w); |
| 1213 |
for (idx = 0; idx < N; idx++) |
| 1214 |
{ |
| 1215 |
p7_ReconfigLength(gm, L0); |
| 1216 |
p7_bg_SetLength(bg, L0); |
| 1217 |
p7_ProfileEmit(r, hmm, gm, bg, sq, tr); |
| 1218 |
p7_trace_Index(tr); |
| 1219 |
tot_true += tr->ndom; |
| 1220 |
|
| 1221 |
p7_ReconfigLength(gm, sq->n); |
| 1222 |
p7_bg_SetLength(bg, sq->n); |
| 1223 |
p7_gmx_GrowTo(fwd, gm->M, sq->n); |
| 1224 |
p7_gmx_GrowTo(bck, gm->M, sq->n); |
| 1225 |
|
| 1226 |
if (do_vit) |
| 1227 |
{ |
| 1228 |
p7_GViterbi (sq->dsq, sq->n, gm, fwd, &overall_sc); |
| 1229 |
if (! do_baseline) |
| 1230 |
p7_domaindef_ByViterbi(gm, sq, fwd, bck, ddef); |
| 1231 |
} |
| 1232 |
else |
| 1233 |
{ |
| 1234 |
p7_GForward (sq->dsq, sq->n, gm, fwd, &overall_sc); |
| 1235 |
if (! do_baseline) { |
| 1236 |
p7_GBackward(sq->dsq, sq->n, gm, bck, &sc); |
| 1237 |
p7_domaindef_ByPosteriorHeuristics(sq, gm, fwd, bck, gxf, gxb, ddef, NULL, FALSE, NULL, NULL, NULL); |
| 1238 |
|
| 1239 |
} |
| 1240 |
} |
| 1241 |
|
| 1242 |
tot_found += ddef->ndom; |
| 1243 |
if (be_verbose) |
| 1244 |
printf("true: %d found: %d\n", tr->ndom, ddef->ndom); |
| 1245 |
|
| 1246 |
p7_trace_Reuse(tr); |
| 1247 |
p7_domaindef_Reuse(ddef); |
| 1248 |
} |
| 1249 |
esl_stopwatch_Stop(w); |
| 1250 |
|
| 1251 |
printf("Total domains: %d\n", tot_true); |
| 1252 |
printf("Total found: %d\n", tot_found); |
| 1253 |
printf("Accuracy: %.2f%%\n", 100. * (double) tot_found / (double) tot_true); |
| 1254 |
esl_stopwatch_Display(stdout, w, "CPU time: "); |
| 1255 |
|
| 1256 |
p7_domaindef_Destroy(ddef); |
| 1257 |
p7_gmx_Destroy(fwd); |
| 1258 |
p7_gmx_Destroy(bck); |
| 1259 |
p7_profile_Destroy(gm); |
| 1260 |
p7_trace_Destroy(tr); |
| 1261 |
p7_bg_Destroy(bg); |
| 1262 |
p7_hmm_Destroy(hmm); |
| 1263 |
esl_sq_Destroy(sq); |
| 1264 |
esl_stopwatch_Destroy(w); |
| 1265 |
esl_randomness_Destroy(r); |
| 1266 |
esl_alphabet_Destroy(abc); |
| 1267 |
esl_getopts_Destroy(go); |
| 1268 |
return 0; |
| 1269 |
} |
| 1270 |
#endif |
| 1271 |
|