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