| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#include <p7_config.h> |
| 19 |
|
| 20 |
#include <stdio.h> |
| 21 |
#include <math.h> |
| 22 |
|
| 23 |
#ifndef __APPLE_ALTIVEC__ |
| 24 |
#include <altivec.h> |
| 25 |
#endif |
| 26 |
|
| 27 |
#include "easel.h" |
| 28 |
#include "esl_vmx.h" |
| 29 |
#include "esl_gumbel.h" |
| 30 |
|
| 31 |
#include "hmmer.h" |
| 32 |
#include "impl_vmx.h" |
| 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 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
int |
| 75 |
p7_MSVFilter(const ESL_DSQ *dsq, int L, const P7_OPROFILE *om, P7_OMX *ox, float *ret_sc) |
| 76 |
{ |
| 77 |
vector unsigned char mpv; |
| 78 |
vector unsigned char xEv; |
| 79 |
vector unsigned char xBv; |
| 80 |
vector unsigned char sv; |
| 81 |
vector unsigned char biasv; |
| 82 |
uint8_t xJ; |
| 83 |
int i; |
| 84 |
int q; |
| 85 |
int Q = p7O_NQB(om->M); |
| 86 |
vector unsigned char *dp; |
| 87 |
vector unsigned char *rsc; |
| 88 |
vector unsigned char zerov; |
| 89 |
vector unsigned char xJv; |
| 90 |
vector unsigned char tjbmv; |
| 91 |
vector unsigned char tecv; |
| 92 |
vector unsigned char basev; |
| 93 |
vector unsigned char ceilingv; |
| 94 |
vector unsigned char tempv; |
| 95 |
|
| 96 |
|
| 97 |
if (Q > ox->allocQ16) ESL_EXCEPTION(eslEINVAL, "DP matrix allocated too small"); |
| 98 |
ox->M = om->M; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
dp = ox->dpb[0]; |
| 103 |
for (q = 0; q < Q; q++) dp[q] = vec_splat_u8(0); |
| 104 |
xJ = 0; |
| 105 |
|
| 106 |
biasv = esl_vmx_set_u8(om->bias_b); |
| 107 |
zerov = vec_splat_u8(0); |
| 108 |
|
| 109 |
|
| 110 |
tempv = vec_splat_u8(1); |
| 111 |
ceilingv = (vector unsigned char)vec_cmpeq(biasv, biasv); |
| 112 |
ceilingv = vec_subs(ceilingv, biasv); |
| 113 |
ceilingv = vec_subs(ceilingv, tempv); |
| 114 |
|
| 115 |
basev = esl_vmx_set_u8((int8_t) om->base_b); |
| 116 |
|
| 117 |
tecv = esl_vmx_set_u8((int8_t) om->tec_b); |
| 118 |
tjbmv = esl_vmx_set_u8((int8_t) om->tjb_b + (int8_t) om->tbm_b); |
| 119 |
|
| 120 |
xJv = vec_subs(biasv, biasv); |
| 121 |
xBv = vec_subs(basev, tjbmv); |
| 122 |
|
| 123 |
#if eslDEBUGLEVEL > 0 |
| 124 |
if (ox->debugging) |
| 125 |
{ |
| 126 |
unsigned char xB; |
| 127 |
vec_ste(xBv, 0, &xB); |
| 128 |
vec_ste(xJv, 0, &xJ); |
| 129 |
p7_omx_DumpMFRow(ox, 0, 0, 0, xJ, xB, xJ); |
| 130 |
} |
| 131 |
#endif |
| 132 |
|
| 133 |
for (i = 1; i <= L; i++) |
| 134 |
{ |
| 135 |
rsc = om->rbv[dsq[i]]; |
| 136 |
xEv = vec_splat_u8(0); |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
mpv = vec_sld(zerov, dp[Q-1], 15); |
| 144 |
for (q = 0; q < Q; q++) |
| 145 |
{ |
| 146 |
|
| 147 |
sv = vec_max(mpv, xBv); |
| 148 |
sv = vec_adds(sv, biasv); |
| 149 |
sv = vec_subs(sv, *rsc); rsc++; |
| 150 |
xEv = vec_max(xEv, sv); |
| 151 |
|
| 152 |
mpv = dp[q]; |
| 153 |
dp[q] = sv; |
| 154 |
} |
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
tempv = vec_sld(xEv, xEv, 1); |
| 161 |
xEv = vec_max(xEv, tempv); |
| 162 |
tempv = vec_sld(xEv, xEv, 2); |
| 163 |
xEv = vec_max(xEv, tempv); |
| 164 |
tempv = vec_sld(xEv, xEv, 4); |
| 165 |
xEv = vec_max(xEv, tempv); |
| 166 |
tempv = vec_sld(xEv, xEv, 8); |
| 167 |
xEv = vec_max(xEv, tempv); |
| 168 |
|
| 169 |
|
| 170 |
if (vec_any_gt(xEv, ceilingv)) |
| 171 |
{ |
| 172 |
*ret_sc = eslINFINITY; |
| 173 |
return eslERANGE; |
| 174 |
} |
| 175 |
|
| 176 |
xEv = vec_subs(xEv, tecv); |
| 177 |
xJv = vec_max(xJv,xEv); |
| 178 |
|
| 179 |
xBv = vec_max(basev, xJv); |
| 180 |
xBv = vec_subs(xBv, tjbmv); |
| 181 |
|
| 182 |
#if eslDEBUGLEVEL > 0 |
| 183 |
if (ox->debugging) |
| 184 |
{ |
| 185 |
unsigned char xB, xE; |
| 186 |
vec_ste(xBv, 0, &xB); |
| 187 |
vec_ste(xEv, 0, &xE); |
| 188 |
vec_ste(xJv, 0, &xJ); |
| 189 |
p7_omx_DumpMFRow(ox, i, xE, 0, xJ, xB, xJ); |
| 190 |
} |
| 191 |
#endif |
| 192 |
} |
| 193 |
|
| 194 |
|
| 195 |
vec_ste(xJv, 0, &xJ); |
| 196 |
*ret_sc = ((float) (xJ - om->tjb_b) - (float) om->base_b); |
| 197 |
*ret_sc /= om->scale_b; |
| 198 |
*ret_sc -= 3.0; |
| 199 |
|
| 200 |
return eslOK; |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 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 |
int |
| 248 |
p7_SSVFilter_longtarget(const ESL_DSQ *dsq, int L, P7_OPROFILE *om, P7_OMX *ox, const P7_SCOREDATA *ssvdata, |
| 249 |
P7_BG *bg, double P, P7_HMM_WINDOWLIST *windowlist) |
| 250 |
{ |
| 251 |
|
| 252 |
vector unsigned char mpv; |
| 253 |
vector unsigned char xEv; |
| 254 |
vector unsigned char xBv; |
| 255 |
vector unsigned char sv; |
| 256 |
vector unsigned char biasv; |
| 257 |
int i; |
| 258 |
int q; |
| 259 |
int Q = p7O_NQB(om->M); |
| 260 |
vector unsigned char *dp = ox->dpb[0]; |
| 261 |
vector unsigned char *rsc; |
| 262 |
vector unsigned char zerov; |
| 263 |
vector unsigned char tjbmv; |
| 264 |
vector unsigned char basev; |
| 265 |
union { vector unsigned char v; uint8_t b[16]; } u; |
| 266 |
int k; |
| 267 |
int n; |
| 268 |
int end; |
| 269 |
int rem_sc; |
| 270 |
int start; |
| 271 |
int target_end; |
| 272 |
int target_start; |
| 273 |
int max_end; |
| 274 |
int max_sc; |
| 275 |
int sc; |
| 276 |
int pos_since_max; |
| 277 |
float ret_sc; |
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
float nullsc; |
| 299 |
float invP = esl_gumbel_invsurv(P, om->evparam[p7_MMU], om->evparam[p7_MLAMBDA]); |
| 300 |
vector unsigned char sc_threshv; |
| 301 |
int sc_thresh; |
| 302 |
|
| 303 |
|
| 304 |
if (Q > ox->allocQ16) ESL_EXCEPTION(eslEINVAL, "DP matrix allocated too small"); |
| 305 |
ox->M = om->M; |
| 306 |
|
| 307 |
|
| 308 |
p7_bg_SetLength(bg, om->max_length); |
| 309 |
p7_oprofile_ReconfigMSVLength(om, om->max_length); |
| 310 |
p7_bg_NullOne (bg, dsq, om->max_length, &nullsc); |
| 311 |
|
| 312 |
sc_thresh = (int) ceil( ( ( nullsc + (invP * eslCONST_LOG2) + 3.0 ) * om->scale_b ) + om->base_b + om->tec_b + om->tjb_b ); |
| 313 |
sc_threshv = esl_vmx_set_u8( (int8_t)sc_thresh - 1); |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
biasv = esl_vmx_set_u8(om->bias_b); |
| 318 |
for (q = 0; q < Q; q++) dp[q] = vec_splat_u8(0); |
| 319 |
zerov = vec_splat_u8(0); |
| 320 |
basev = esl_vmx_set_u8((int8_t) om->base_b); |
| 321 |
tjbmv = esl_vmx_set_u8((int8_t) om->tjb_b + (int8_t) om->tbm_b); |
| 322 |
xBv = vec_subs(basev, tjbmv); |
| 323 |
|
| 324 |
for (i = 1; i <= L; i++) |
| 325 |
{ |
| 326 |
rsc = om->rbv[dsq[i]]; |
| 327 |
xEv = vec_splat_u8(0); |
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
mpv = vec_sld(zerov, dp[Q-1], 15); |
| 333 |
for (q = 0; q < Q; q++) |
| 334 |
{ |
| 335 |
|
| 336 |
sv = vec_max(mpv, xBv); |
| 337 |
sv = vec_adds(sv, biasv); |
| 338 |
sv = vec_subs(sv, *rsc); rsc++; |
| 339 |
xEv = vec_max(xEv, sv); |
| 340 |
|
| 341 |
mpv = dp[q]; |
| 342 |
dp[q] = sv; |
| 343 |
} |
| 344 |
|
| 345 |
|
| 346 |
if (vec_any_gt(xEv, sc_threshv) ) |
| 347 |
{ |
| 348 |
|
| 349 |
end = -1; |
| 350 |
rem_sc = -1; |
| 351 |
for (q = 0; q < Q; q++) |
| 352 |
{ |
| 353 |
u.v = dp[q]; |
| 354 |
for (k = 0; k < 16; k++) |
| 355 |
{ |
| 356 |
|
| 357 |
if (u.b[k] >= sc_thresh && u.b[k] > rem_sc && (q+Q*k+1) <= om->M) |
| 358 |
{ |
| 359 |
end = (q+Q*k+1); |
| 360 |
rem_sc = u.b[k]; |
| 361 |
} |
| 362 |
} |
| 363 |
dp[q] = vec_splat_u8(0); |
| 364 |
} |
| 365 |
|
| 366 |
|
| 367 |
start = end; |
| 368 |
target_end = target_start = i; |
| 369 |
sc = rem_sc; |
| 370 |
while (rem_sc > om->base_b - om->tjb_b - om->tbm_b) |
| 371 |
{ |
| 372 |
rem_sc -= om->bias_b - ssvdata->ssv_scores[start*om->abc->Kp + dsq[target_start]]; |
| 373 |
--start; |
| 374 |
--target_start; |
| 375 |
|
| 376 |
} |
| 377 |
start++; |
| 378 |
target_start++; |
| 379 |
|
| 380 |
|
| 381 |
k = end+1; |
| 382 |
n = target_end+1; |
| 383 |
max_end = target_end; |
| 384 |
max_sc = sc; |
| 385 |
pos_since_max = 0; |
| 386 |
while (k<om->M && n<=L) |
| 387 |
{ |
| 388 |
sc += om->bias_b - ssvdata->ssv_scores[k*om->abc->Kp + dsq[n]]; |
| 389 |
if (sc >= max_sc) |
| 390 |
{ |
| 391 |
max_sc = sc; |
| 392 |
max_end = n; |
| 393 |
pos_since_max=0; |
| 394 |
} |
| 395 |
else |
| 396 |
{ |
| 397 |
pos_since_max++; |
| 398 |
if (pos_since_max == 5) |
| 399 |
break; |
| 400 |
} |
| 401 |
k++; |
| 402 |
n++; |
| 403 |
} |
| 404 |
|
| 405 |
end += (max_end - target_end); |
| 406 |
target_end = max_end; |
| 407 |
|
| 408 |
ret_sc = ((float) (max_sc - om->tjb_b) - (float) om->base_b); |
| 409 |
ret_sc /= om->scale_b; |
| 410 |
ret_sc -= 3.0; |
| 411 |
|
| 412 |
p7_hmmwindow_new( windowlist, |
| 413 |
0, |
| 414 |
target_start, |
| 415 |
0, |
| 416 |
end, |
| 417 |
end-start+1 , |
| 418 |
ret_sc, |
| 419 |
p7_NOCOMPLEMENT, |
| 420 |
L); |
| 421 |
|
| 422 |
i = target_end; |
| 423 |
} |
| 424 |
} |
| 425 |
|
| 426 |
return eslOK; |
| 427 |
} |
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
#ifdef p7MSVFILTER_BENCHMARK |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
#include <p7_config.h> |
| 465 |
|
| 466 |
#include "easel.h" |
| 467 |
#include "esl_alphabet.h" |
| 468 |
#include "esl_getopts.h" |
| 469 |
#include "esl_random.h" |
| 470 |
#include "esl_randomseq.h" |
| 471 |
#include "esl_stopwatch.h" |
| 472 |
|
| 473 |
#include "hmmer.h" |
| 474 |
#include "impl_vmx.h" |
| 475 |
|
| 476 |
static ESL_OPTIONS options[] = { |
| 477 |
|
| 478 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 479 |
{ "-c", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "-x", "compare scores to generic implementation (debug)", 0 }, |
| 480 |
{ "-s", eslARG_INT, "42", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 }, |
| 481 |
{ "-x", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "-c", "equate scores to trusted implementation (debug)", 0 }, |
| 482 |
{ "-L", eslARG_INT, "400", NULL, "n>0", NULL, NULL, NULL, "length of random target seqs", 0 }, |
| 483 |
{ "-N", eslARG_INT, "50000", NULL, "n>0", NULL, NULL, NULL, "number of random target seqs", 0 }, |
| 484 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 485 |
}; |
| 486 |
static char usage[] = "[-options] <hmmfile>"; |
| 487 |
static char banner[] = "benchmark driver for MSVFilter() implementation"; |
| 488 |
|
| 489 |
int |
| 490 |
main(int argc, char **argv) |
| 491 |
{ |
| 492 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 1, argc, argv, banner, usage); |
| 493 |
char *hmmfile = esl_opt_GetArg(go, 1); |
| 494 |
ESL_STOPWATCH *w = esl_stopwatch_Create(); |
| 495 |
ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s")); |
| 496 |
ESL_ALPHABET *abc = NULL; |
| 497 |
P7_HMMFILE *hfp = NULL; |
| 498 |
P7_HMM *hmm = NULL; |
| 499 |
P7_BG *bg = NULL; |
| 500 |
P7_PROFILE *gm = NULL; |
| 501 |
P7_OPROFILE *om = NULL; |
| 502 |
P7_OMX *ox = NULL; |
| 503 |
P7_GMX *gx = NULL; |
| 504 |
int L = esl_opt_GetInteger(go, "-L"); |
| 505 |
int N = esl_opt_GetInteger(go, "-N"); |
| 506 |
ESL_DSQ *dsq = malloc(sizeof(ESL_DSQ) * (L+2)); |
| 507 |
int i; |
| 508 |
float sc1, sc2; |
| 509 |
double base_time, bench_time, Mcs; |
| 510 |
|
| 511 |
if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile); |
| 512 |
if (p7_hmmfile_Read(hfp, &abc, &hmm) != eslOK) p7_Fail("Failed to read HMM"); |
| 513 |
|
| 514 |
bg = p7_bg_Create(abc); |
| 515 |
p7_bg_SetLength(bg, L); |
| 516 |
gm = p7_profile_Create(hmm->M, abc); |
| 517 |
p7_ProfileConfig(hmm, bg, gm, L, p7_LOCAL); |
| 518 |
om = p7_oprofile_Create(gm->M, abc); |
| 519 |
p7_oprofile_Convert(gm, om); |
| 520 |
p7_oprofile_ReconfigLength(om, L); |
| 521 |
|
| 522 |
if (esl_opt_GetBoolean(go, "-x")) p7_profile_SameAsMF(om, gm); |
| 523 |
|
| 524 |
ox = p7_omx_Create(gm->M, 0, 0); |
| 525 |
gx = p7_gmx_Create(gm->M, L); |
| 526 |
|
| 527 |
|
| 528 |
esl_stopwatch_Start(w); |
| 529 |
for (i = 0; i < N; i++) |
| 530 |
esl_rsq_xfIID(r, bg->f, abc->K, L, dsq); |
| 531 |
esl_stopwatch_Stop(w); |
| 532 |
base_time = w->user; |
| 533 |
|
| 534 |
esl_stopwatch_Start(w); |
| 535 |
for (i = 0; i < N; i++) |
| 536 |
{ |
| 537 |
esl_rsq_xfIID(r, bg->f, abc->K, L, dsq); |
| 538 |
p7_MSVFilter (dsq, L, om, ox, &sc1); |
| 539 |
|
| 540 |
|
| 541 |
if (esl_opt_GetBoolean(go, "-c")) |
| 542 |
{ |
| 543 |
p7_GMSV (dsq, L, gm, gx, 2.0, &sc2); |
| 544 |
printf("%.4f %.4f\n", sc1, sc2); |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
if (esl_opt_GetBoolean(go, "-x")) |
| 549 |
{ |
| 550 |
p7_GViterbi(dsq, L, gm, gx, &sc2); |
| 551 |
sc2 /= om->scale_b; |
| 552 |
if (om->mode == p7_UNILOCAL) sc2 -= 2.0; |
| 553 |
else if (om->mode == p7_LOCAL) sc2 -= 3.0; |
| 554 |
printf("%.4f %.4f\n", sc1, sc2); |
| 555 |
} |
| 556 |
} |
| 557 |
esl_stopwatch_Stop(w); |
| 558 |
bench_time = w->user - base_time; |
| 559 |
Mcs = (double) N * (double) L * (double) gm->M * 1e-6 / (double) bench_time; |
| 560 |
esl_stopwatch_Display(stdout, w, "# CPU time: "); |
| 561 |
printf("# M = %d\n", gm->M); |
| 562 |
printf("# %.1f Mc/s\n", Mcs); |
| 563 |
|
| 564 |
free(dsq); |
| 565 |
p7_omx_Destroy(ox); |
| 566 |
p7_gmx_Destroy(gx); |
| 567 |
p7_oprofile_Destroy(om); |
| 568 |
p7_profile_Destroy(gm); |
| 569 |
p7_bg_Destroy(bg); |
| 570 |
p7_hmm_Destroy(hmm); |
| 571 |
p7_hmmfile_Close(hfp); |
| 572 |
esl_alphabet_Destroy(abc); |
| 573 |
esl_stopwatch_Destroy(w); |
| 574 |
esl_randomness_Destroy(r); |
| 575 |
esl_getopts_Destroy(go); |
| 576 |
return 0; |
| 577 |
} |
| 578 |
#endif |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
#ifdef p7MSVFILTER_TESTDRIVE |
| 588 |
#include "esl_random.h" |
| 589 |
#include "esl_randomseq.h" |
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
static void |
| 601 |
utest_msv_filter(ESL_RANDOMNESS *r, ESL_ALPHABET *abc, P7_BG *bg, int M, int L, int N) |
| 602 |
{ |
| 603 |
P7_HMM *hmm = NULL; |
| 604 |
P7_PROFILE *gm = NULL; |
| 605 |
P7_OPROFILE *om = NULL; |
| 606 |
ESL_DSQ *dsq = malloc(sizeof(ESL_DSQ) * (L+2)); |
| 607 |
P7_OMX *ox = p7_omx_Create(M, 0, 0); |
| 608 |
P7_GMX *gx = p7_gmx_Create(M, L); |
| 609 |
float sc1, sc2; |
| 610 |
|
| 611 |
p7_oprofile_Sample(r, abc, bg, M, L, &hmm, &gm, &om); |
| 612 |
p7_profile_SameAsMF(om, gm); |
| 613 |
#if 0 |
| 614 |
p7_oprofile_Dump(stdout, om); |
| 615 |
p7_omx_SetDumpMode(stdout, ox, TRUE); |
| 616 |
#endif |
| 617 |
|
| 618 |
while (N--) |
| 619 |
{ |
| 620 |
esl_rsq_xfIID(r, bg->f, abc->K, L, dsq); |
| 621 |
p7_MSVFilter(dsq, L, om, ox, &sc1); |
| 622 |
p7_GViterbi (dsq, L, gm, gx, &sc2); |
| 623 |
#if 0 |
| 624 |
p7_gmx_Dump(stdout, gx, p7_DEFAULT); |
| 625 |
#endif |
| 626 |
|
| 627 |
sc2 = sc2 / om->scale_b - 3.0f; |
| 628 |
if (fabs(sc1-sc2) > 0.001) esl_fatal("msv filter unit test failed: scores differ (%.2f, %.2f)", sc1, sc2); |
| 629 |
} |
| 630 |
|
| 631 |
free(dsq); |
| 632 |
p7_hmm_Destroy(hmm); |
| 633 |
p7_omx_Destroy(ox); |
| 634 |
p7_gmx_Destroy(gx); |
| 635 |
p7_profile_Destroy(gm); |
| 636 |
p7_oprofile_Destroy(om); |
| 637 |
} |
| 638 |
#endif |
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
#ifdef p7MSVFILTER_TESTDRIVE |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
#include <p7_config.h> |
| 653 |
|
| 654 |
#include "easel.h" |
| 655 |
#include "esl_alphabet.h" |
| 656 |
#include "esl_getopts.h" |
| 657 |
|
| 658 |
#include "hmmer.h" |
| 659 |
#include "impl_vmx.h" |
| 660 |
|
| 661 |
static ESL_OPTIONS options[] = { |
| 662 |
|
| 663 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 664 |
{ "-s", eslARG_INT, "42", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 }, |
| 665 |
{ "-v", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "be verbose", 0 }, |
| 666 |
{ "-L", eslARG_INT, "200", NULL, NULL, NULL, NULL, NULL, "size of random sequences to sample", 0 }, |
| 667 |
{ "-M", eslARG_INT, "145", NULL, NULL, NULL, NULL, NULL, "size of random models to sample", 0 }, |
| 668 |
{ "-N", eslARG_INT, "100", NULL, NULL, NULL, NULL, NULL, "number of random sequences to sample", 0 }, |
| 669 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 670 |
}; |
| 671 |
static char usage[] = "[-options]"; |
| 672 |
static char banner[] = "test driver for the VMX MSVFilter() implementation"; |
| 673 |
|
| 674 |
int |
| 675 |
main(int argc, char **argv) |
| 676 |
{ |
| 677 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 0, argc, argv, banner, usage); |
| 678 |
ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s")); |
| 679 |
ESL_ALPHABET *abc = NULL; |
| 680 |
P7_BG *bg = NULL; |
| 681 |
int M = esl_opt_GetInteger(go, "-M"); |
| 682 |
int L = esl_opt_GetInteger(go, "-L"); |
| 683 |
int N = esl_opt_GetInteger(go, "-N"); |
| 684 |
|
| 685 |
|
| 686 |
if ((abc = esl_alphabet_Create(eslDNA)) == NULL) esl_fatal("failed to create alphabet"); |
| 687 |
if ((bg = p7_bg_Create(abc)) == NULL) esl_fatal("failed to create null model"); |
| 688 |
|
| 689 |
if (esl_opt_GetBoolean(go, "-v")) printf("MSVFilter() tests, DNA\n"); |
| 690 |
utest_msv_filter(r, abc, bg, M, L, N); |
| 691 |
utest_msv_filter(r, abc, bg, 1, L, 10); |
| 692 |
utest_msv_filter(r, abc, bg, M, 1, 10); |
| 693 |
|
| 694 |
esl_alphabet_Destroy(abc); |
| 695 |
p7_bg_Destroy(bg); |
| 696 |
|
| 697 |
if ((abc = esl_alphabet_Create(eslAMINO)) == NULL) esl_fatal("failed to create alphabet"); |
| 698 |
if ((bg = p7_bg_Create(abc)) == NULL) esl_fatal("failed to create null model"); |
| 699 |
|
| 700 |
if (esl_opt_GetBoolean(go, "-v")) printf("MSVFilter() tests, protein\n"); |
| 701 |
utest_msv_filter(r, abc, bg, M, L, N); |
| 702 |
utest_msv_filter(r, abc, bg, 1, L, 10); |
| 703 |
utest_msv_filter(r, abc, bg, M, 1, 10); |
| 704 |
|
| 705 |
esl_alphabet_Destroy(abc); |
| 706 |
p7_bg_Destroy(bg); |
| 707 |
|
| 708 |
esl_getopts_Destroy(go); |
| 709 |
esl_randomness_Destroy(r); |
| 710 |
return eslOK; |
| 711 |
} |
| 712 |
#endif |
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
#ifdef p7MSVFILTER_EXAMPLE |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
#include <p7_config.h> |
| 728 |
|
| 729 |
#include "easel.h" |
| 730 |
#include "esl_alphabet.h" |
| 731 |
#include "esl_getopts.h" |
| 732 |
#include "esl_gumbel.h" |
| 733 |
#include "esl_sq.h" |
| 734 |
#include "esl_sqio.h" |
| 735 |
|
| 736 |
#include "hmmer.h" |
| 737 |
#include "impl_vmx.h" |
| 738 |
|
| 739 |
static ESL_OPTIONS options[] = { |
| 740 |
|
| 741 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 742 |
{ "-1", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "output in one line awkable format", 0 }, |
| 743 |
{ "-P", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "output in profmark format", 0 }, |
| 744 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 745 |
}; |
| 746 |
static char usage[] = "[-options] <hmmfile> <seqfile>"; |
| 747 |
static char banner[] = "example of MSV filter algorithm"; |
| 748 |
|
| 749 |
int |
| 750 |
main(int argc, char **argv) |
| 751 |
{ |
| 752 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 2, argc, argv, banner, usage); |
| 753 |
char *hmmfile = esl_opt_GetArg(go, 1); |
| 754 |
char *seqfile = esl_opt_GetArg(go, 2); |
| 755 |
ESL_ALPHABET *abc = NULL; |
| 756 |
P7_HMMFILE *hfp = NULL; |
| 757 |
P7_HMM *hmm = NULL; |
| 758 |
P7_BG *bg = NULL; |
| 759 |
P7_PROFILE *gm = NULL; |
| 760 |
P7_OPROFILE *om = NULL; |
| 761 |
P7_OMX *ox = NULL; |
| 762 |
P7_GMX *gx = NULL; |
| 763 |
ESL_SQ *sq = NULL; |
| 764 |
ESL_SQFILE *sqfp = NULL; |
| 765 |
int format = eslSQFILE_UNKNOWN; |
| 766 |
float msvraw, nullsc, msvscore; |
| 767 |
float graw, gscore; |
| 768 |
double P, gP; |
| 769 |
int status; |
| 770 |
|
| 771 |
|
| 772 |
if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile); |
| 773 |
if (p7_hmmfile_Read(hfp, &abc, &hmm) != eslOK) p7_Fail("Failed to read HMM"); |
| 774 |
|
| 775 |
|
| 776 |
sq = esl_sq_CreateDigital(abc); |
| 777 |
status = esl_sqfile_Open(seqfile, format, NULL, &sqfp); |
| 778 |
if (status == eslENOTFOUND) p7_Fail("No such file."); |
| 779 |
else if (status == eslEFORMAT) p7_Fail("Format unrecognized."); |
| 780 |
else if (status == eslEINVAL) p7_Fail("Can't autodetect stdin or .gz."); |
| 781 |
else if (status != eslOK) p7_Fail("Open failed, code %d.", status); |
| 782 |
|
| 783 |
|
| 784 |
bg = p7_bg_Create(abc); |
| 785 |
p7_bg_SetLength(bg, sq->n); |
| 786 |
gm = p7_profile_Create(hmm->M, abc); |
| 787 |
p7_ProfileConfig(hmm, bg, gm, sq->n, p7_LOCAL); |
| 788 |
om = p7_oprofile_Create(gm->M, abc); |
| 789 |
p7_oprofile_Convert(gm, om); |
| 790 |
|
| 791 |
|
| 792 |
ox = p7_omx_Create(gm->M, 0, 0); |
| 793 |
gx = p7_gmx_Create(gm->M, sq->n); |
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
p7_omx_SetDumpMode(stdout, ox, TRUE); |
| 802 |
|
| 803 |
while ((status = esl_sqio_Read(sqfp, sq)) == eslOK) |
| 804 |
{ |
| 805 |
p7_oprofile_ReconfigLength(om, sq->n); |
| 806 |
p7_ReconfigLength(gm, sq->n); |
| 807 |
p7_bg_SetLength(bg, sq->n); |
| 808 |
p7_omx_GrowTo(ox, om->M, 0, sq->n); |
| 809 |
p7_gmx_GrowTo(gx, gm->M, sq->n); |
| 810 |
|
| 811 |
p7_MSVFilter (sq->dsq, sq->n, om, ox, &msvraw); |
| 812 |
p7_bg_NullOne (bg, sq->dsq, sq->n, &nullsc); |
| 813 |
msvscore = (msvraw - nullsc) / eslCONST_LOG2; |
| 814 |
P = esl_gumbel_surv(msvscore, om->evparam[p7_MMU], om->evparam[p7_MLAMBDA]); |
| 815 |
|
| 816 |
p7_GMSV(sq->dsq, sq->n, gm, gx, 2.0, &graw); |
| 817 |
gscore = (graw - nullsc) / eslCONST_LOG2; |
| 818 |
gP = esl_gumbel_surv(gscore, gm->evparam[p7_MMU], gm->evparam[p7_MLAMBDA]); |
| 819 |
|
| 820 |
if (esl_opt_GetBoolean(go, "-1")) |
| 821 |
{ |
| 822 |
printf("%-30s %-20s %9.2g %7.2f %9.2g %7.2f\n", sq->name, hmm->name, P, msvscore, gP, gscore); |
| 823 |
} |
| 824 |
else if (esl_opt_GetBoolean(go, "-P")) |
| 825 |
{ |
| 826 |
printf("%g %.2f %s %s\n", P, msvscore, sq->name, hmm->name); |
| 827 |
} |
| 828 |
else |
| 829 |
{ |
| 830 |
printf("target sequence: %s\n", sq->name); |
| 831 |
printf("msv filter raw score: %.2f nats\n", msvraw); |
| 832 |
printf("null score: %.2f nats\n", nullsc); |
| 833 |
printf("per-seq score: %.2f bits\n", msvscore); |
| 834 |
printf("P-value: %g\n", P); |
| 835 |
printf("GMSV raw score: %.2f nats\n", graw); |
| 836 |
printf("GSMV per-seq score: %.2f bits\n", gscore); |
| 837 |
printf("GSMV P-value: %g\n", gP); |
| 838 |
} |
| 839 |
|
| 840 |
esl_sq_Reuse(sq); |
| 841 |
} |
| 842 |
|
| 843 |
|
| 844 |
esl_sq_Destroy(sq); |
| 845 |
esl_sqfile_Close(sqfp); |
| 846 |
p7_omx_Destroy(ox); |
| 847 |
p7_gmx_Destroy(gx); |
| 848 |
p7_oprofile_Destroy(om); |
| 849 |
p7_profile_Destroy(gm); |
| 850 |
p7_bg_Destroy(bg); |
| 851 |
p7_hmm_Destroy(hmm); |
| 852 |
p7_hmmfile_Close(hfp); |
| 853 |
esl_alphabet_Destroy(abc); |
| 854 |
esl_getopts_Destroy(go); |
| 855 |
return 0; |
| 856 |
} |
| 857 |
#endif |
| 858 |
|
| 859 |
|