| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
#include <p7_config.h> |
| 12 |
|
| 13 |
#include <stdio.h> |
| 14 |
#include <math.h> |
| 15 |
|
| 16 |
#ifndef __APPLE_ALTIVEC__ |
| 17 |
#include <altivec.h> |
| 18 |
#endif |
| 19 |
|
| 20 |
#include "easel.h" |
| 21 |
#include "esl_vmx.h" |
| 22 |
|
| 23 |
#include "hmmer.h" |
| 24 |
#include "impl_vmx.h" |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 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 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
int |
| 75 |
p7_Decoding(const P7_OPROFILE *om, const P7_OMX *oxf, P7_OMX *oxb, P7_OMX *pp) |
| 76 |
{ |
| 77 |
vector float *ppv; |
| 78 |
vector float *fv; |
| 79 |
vector float *bv; |
| 80 |
vector float totrv; |
| 81 |
vector float zerov; |
| 82 |
int L = oxf->L; |
| 83 |
int M = om->M; |
| 84 |
int Q = p7O_NQF(M); |
| 85 |
int i,q; |
| 86 |
float scaleproduct = 1.0 / oxb->xmx[p7X_N]; |
| 87 |
|
| 88 |
pp->M = M; |
| 89 |
pp->L = L; |
| 90 |
|
| 91 |
zerov = (vector float) vec_splat_u32(0); |
| 92 |
|
| 93 |
ppv = pp->dpf[0]; |
| 94 |
for (q = 0; q < Q; q++) { |
| 95 |
*ppv = (vector float) vec_splat_u32(0); ppv++; |
| 96 |
*ppv = (vector float) vec_splat_u32(0); ppv++; |
| 97 |
*ppv = (vector float) vec_splat_u32(0); ppv++; |
| 98 |
} |
| 99 |
pp->xmx[p7X_E] = 0.0; |
| 100 |
pp->xmx[p7X_N] = 0.0; |
| 101 |
pp->xmx[p7X_J] = 0.0; |
| 102 |
pp->xmx[p7X_C] = 0.0; |
| 103 |
pp->xmx[p7X_B] = 0.0; |
| 104 |
|
| 105 |
for (i = 1; i <= L; i++) |
| 106 |
{ |
| 107 |
ppv = pp->dpf[i]; |
| 108 |
fv = oxf->dpf[i]; |
| 109 |
bv = oxb->dpf[i]; |
| 110 |
|
| 111 |
totrv = esl_vmx_set_float(scaleproduct * oxf->xmx[i*p7X_NXCELLS+p7X_SCALE]); |
| 112 |
|
| 113 |
for (q = 0; q < Q; q++) |
| 114 |
{ |
| 115 |
|
| 116 |
*ppv = vec_madd(*fv, *bv, zerov); |
| 117 |
*ppv = vec_madd(*ppv, totrv, zerov); |
| 118 |
ppv++; fv++; bv++; |
| 119 |
|
| 120 |
|
| 121 |
*ppv = (vector float) vec_splat_u32(0); |
| 122 |
ppv++; fv++; bv++; |
| 123 |
|
| 124 |
|
| 125 |
*ppv = vec_madd(*fv, *bv, zerov); |
| 126 |
*ppv = vec_madd(*ppv, totrv, zerov); |
| 127 |
ppv++; fv++; bv++; |
| 128 |
} |
| 129 |
pp->xmx[i*p7X_NXCELLS+p7X_E] = 0.0; |
| 130 |
pp->xmx[i*p7X_NXCELLS+p7X_N] = oxf->xmx[(i-1)*p7X_NXCELLS+p7X_N] * oxb->xmx[i*p7X_NXCELLS+p7X_N] * om->xf[p7O_N][p7O_LOOP] * scaleproduct; |
| 131 |
pp->xmx[i*p7X_NXCELLS+p7X_J] = oxf->xmx[(i-1)*p7X_NXCELLS+p7X_J] * oxb->xmx[i*p7X_NXCELLS+p7X_J] * om->xf[p7O_J][p7O_LOOP] * scaleproduct; |
| 132 |
pp->xmx[i*p7X_NXCELLS+p7X_C] = oxf->xmx[(i-1)*p7X_NXCELLS+p7X_C] * oxb->xmx[i*p7X_NXCELLS+p7X_C] * om->xf[p7O_C][p7O_LOOP] * scaleproduct; |
| 133 |
pp->xmx[i*p7X_NXCELLS+p7X_B] = 0.0; |
| 134 |
|
| 135 |
if (oxb->has_own_scales) scaleproduct *= oxf->xmx[i*p7X_NXCELLS+p7X_SCALE] / oxb->xmx[i*p7X_NXCELLS+p7X_SCALE]; |
| 136 |
} |
| 137 |
|
| 138 |
if (isinf(scaleproduct)) return eslERANGE; |
| 139 |
else return eslOK; |
| 140 |
} |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
int |
| 163 |
p7_DomainDecoding(const P7_OPROFILE *om, const P7_OMX *oxf, const P7_OMX *oxb, P7_DOMAINDEF *ddef) |
| 164 |
{ |
| 165 |
int L = oxf->L; |
| 166 |
float scaleproduct = 1.0 / oxb->xmx[p7X_N]; |
| 167 |
float njcp; |
| 168 |
int i; |
| 169 |
|
| 170 |
ddef->btot[0] = 0.0; |
| 171 |
ddef->etot[0] = 0.0; |
| 172 |
ddef->mocc[0] = 0.0; |
| 173 |
for (i = 1; i <= L; i++) |
| 174 |
{ |
| 175 |
|
| 176 |
ddef->btot[i] = ddef->btot[i-1] + |
| 177 |
(oxf->xmx[(i-1)*p7X_NXCELLS+p7X_B] * oxb->xmx[(i-1)*p7X_NXCELLS+p7X_B] * oxf->xmx[(i-1)*p7X_NXCELLS+p7X_SCALE] * scaleproduct); |
| 178 |
|
| 179 |
if (oxb->has_own_scales) scaleproduct *= oxf->xmx[(i-1)*p7X_NXCELLS+p7X_SCALE] / oxb->xmx[(i-1)*p7X_NXCELLS+p7X_SCALE]; |
| 180 |
|
| 181 |
|
| 182 |
ddef->etot[i] = ddef->etot[i-1] + |
| 183 |
(oxf->xmx[i*p7X_NXCELLS+p7X_E] * oxb->xmx[i*p7X_NXCELLS+p7X_E] * oxf->xmx[i*p7X_NXCELLS+p7X_SCALE] * scaleproduct); |
| 184 |
|
| 185 |
njcp = oxf->xmx[(i-1)*p7X_NXCELLS+p7X_N] * oxb->xmx[i*p7X_NXCELLS+p7X_N] * om->xf[p7O_N][p7O_LOOP] * scaleproduct; |
| 186 |
njcp += oxf->xmx[(i-1)*p7X_NXCELLS+p7X_J] * oxb->xmx[i*p7X_NXCELLS+p7X_J] * om->xf[p7O_J][p7O_LOOP] * scaleproduct; |
| 187 |
njcp += oxf->xmx[(i-1)*p7X_NXCELLS+p7X_C] * oxb->xmx[i*p7X_NXCELLS+p7X_C] * om->xf[p7O_C][p7O_LOOP] * scaleproduct; |
| 188 |
ddef->mocc[i] = 1. - njcp; |
| 189 |
} |
| 190 |
ddef->L = oxf->L; |
| 191 |
|
| 192 |
if (isinf(scaleproduct)) return eslERANGE; |
| 193 |
else return eslOK; |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
#ifdef p7DECODING_BENCHMARK |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
#include <p7_config.h> |
| 213 |
|
| 214 |
#include "easel.h" |
| 215 |
#include "esl_alphabet.h" |
| 216 |
#include "esl_getopts.h" |
| 217 |
#include "esl_random.h" |
| 218 |
#include "esl_randomseq.h" |
| 219 |
#include "esl_stopwatch.h" |
| 220 |
|
| 221 |
#include "hmmer.h" |
| 222 |
#include "impl_vmx.h" |
| 223 |
|
| 224 |
static ESL_OPTIONS options[] = { |
| 225 |
|
| 226 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 227 |
{ "-s", eslARG_INT, "42", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 }, |
| 228 |
{ "-L", eslARG_INT, "400", NULL, "n>0", NULL, NULL, NULL, "length of random target seqs", 0 }, |
| 229 |
{ "-N", eslARG_INT, "50000", NULL, "n>0", NULL, NULL, NULL, "number of random target seqs", 0 }, |
| 230 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 231 |
}; |
| 232 |
static char usage[] = "[-options] <hmmfile>"; |
| 233 |
static char banner[] = "benchmark driver for posterior residue decoding, VMX version"; |
| 234 |
|
| 235 |
int |
| 236 |
main(int argc, char **argv) |
| 237 |
{ |
| 238 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 1, argc, argv, banner, usage); |
| 239 |
char *hmmfile = esl_opt_GetArg(go, 1); |
| 240 |
ESL_STOPWATCH *w = esl_stopwatch_Create(); |
| 241 |
ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s")); |
| 242 |
ESL_ALPHABET *abc = NULL; |
| 243 |
P7_HMMFILE *hfp = NULL; |
| 244 |
P7_HMM *hmm = NULL; |
| 245 |
P7_BG *bg = NULL; |
| 246 |
P7_PROFILE *gm = NULL; |
| 247 |
P7_OPROFILE *om = NULL; |
| 248 |
P7_OMX *fwd = NULL; |
| 249 |
P7_OMX *bck = NULL; |
| 250 |
P7_OMX *pp = NULL; |
| 251 |
int L = esl_opt_GetInteger(go, "-L"); |
| 252 |
int N = esl_opt_GetInteger(go, "-N"); |
| 253 |
ESL_DSQ *dsq = malloc(sizeof(ESL_DSQ) * (L+2)); |
| 254 |
int i; |
| 255 |
float fsc, bsc; |
| 256 |
double Mcs; |
| 257 |
|
| 258 |
if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile); |
| 259 |
if (p7_hmmfile_Read(hfp, &abc, &hmm) != eslOK) p7_Fail("Failed to read HMM"); |
| 260 |
|
| 261 |
bg = p7_bg_Create(abc); p7_bg_SetLength(bg, L); |
| 262 |
gm = p7_profile_Create(hmm->M, abc); p7_ProfileConfig(hmm, bg, gm, L, p7_LOCAL); |
| 263 |
om = p7_oprofile_Create(gm->M, abc); p7_oprofile_Convert(gm, om); |
| 264 |
p7_oprofile_ReconfigLength(om, L); |
| 265 |
|
| 266 |
fwd = p7_omx_Create(gm->M, L, L); |
| 267 |
bck = p7_omx_Create(gm->M, L, L); |
| 268 |
pp = p7_omx_Create(gm->M, L, L); |
| 269 |
|
| 270 |
esl_rsq_xfIID(r, bg->f, abc->K, L, dsq); |
| 271 |
p7_Forward (dsq, L, om, fwd, &fsc); |
| 272 |
p7_Backward(dsq, L, om, fwd, bck, &bsc); |
| 273 |
|
| 274 |
esl_stopwatch_Start(w); |
| 275 |
for (i = 0; i < N; i++) |
| 276 |
p7_Decoding(om, fwd, bck, pp); |
| 277 |
esl_stopwatch_Stop(w); |
| 278 |
|
| 279 |
Mcs = (double) N * (double) L * (double) gm->M * 1e-6 / (double) w->user; |
| 280 |
esl_stopwatch_Display(stdout, w, "# CPU time: "); |
| 281 |
printf("# M = %d\n", gm->M); |
| 282 |
printf("# %.1f Mc/s\n", Mcs); |
| 283 |
|
| 284 |
free(dsq); |
| 285 |
p7_omx_Destroy(fwd); |
| 286 |
p7_omx_Destroy(bck); |
| 287 |
p7_omx_Destroy(pp); |
| 288 |
p7_oprofile_Destroy(om); |
| 289 |
p7_profile_Destroy(gm); |
| 290 |
p7_bg_Destroy(bg); |
| 291 |
p7_hmm_Destroy(hmm); |
| 292 |
p7_hmmfile_Close(hfp); |
| 293 |
esl_alphabet_Destroy(abc); |
| 294 |
esl_stopwatch_Destroy(w); |
| 295 |
esl_randomness_Destroy(r); |
| 296 |
esl_getopts_Destroy(go); |
| 297 |
return eslOK; |
| 298 |
} |
| 299 |
#endif |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
#ifdef p7DECODING_TESTDRIVE |
| 309 |
#include "esl_random.h" |
| 310 |
#include "esl_randomseq.h" |
| 311 |
|
| 312 |
|
| 313 |
static void |
| 314 |
utest_decoding(ESL_RANDOMNESS *r, ESL_ALPHABET *abc, P7_BG *bg, int M, int L, int N, float tolerance) |
| 315 |
{ |
| 316 |
char *msg = "decoding unit test failed"; |
| 317 |
P7_HMM *hmm = NULL; |
| 318 |
P7_PROFILE *gm = NULL; |
| 319 |
P7_OPROFILE *om = NULL; |
| 320 |
ESL_DSQ *dsq = malloc(sizeof(ESL_DSQ) * (L+2)); |
| 321 |
P7_OMX *fwd = p7_omx_Create(M, L, L); |
| 322 |
P7_OMX *bck = p7_omx_Create(M, L, L); |
| 323 |
P7_OMX *pp = p7_omx_Create(M, L, L); |
| 324 |
P7_GMX *gxf = p7_gmx_Create(M, L); |
| 325 |
P7_GMX *gxb = p7_gmx_Create(M, L); |
| 326 |
P7_GMX *gxp1 = p7_gmx_Create(M, L); |
| 327 |
P7_GMX *gxp2 = p7_gmx_Create(M, L); |
| 328 |
float fsc1, fsc2; |
| 329 |
float bsc1, bsc2; |
| 330 |
|
| 331 |
if (p7_oprofile_Sample(r, abc, bg, M, L, &hmm, &gm, &om) != eslOK) esl_fatal(msg); |
| 332 |
while (N--) |
| 333 |
{ |
| 334 |
if (esl_rsq_xfIID(r, bg->f, abc->K, L, dsq) != eslOK) esl_fatal(msg); |
| 335 |
if (p7_Forward (dsq, L, om, fwd, &fsc1) != eslOK) esl_fatal(msg); |
| 336 |
if (p7_Backward (dsq, L, om, fwd, bck, &bsc1) != eslOK) esl_fatal(msg); |
| 337 |
if (p7_Decoding(om, fwd, bck, pp) != eslOK) esl_fatal(msg); |
| 338 |
if (p7_omx_FDeconvert(pp, gxp1) != eslOK) esl_fatal(msg); |
| 339 |
|
| 340 |
if (p7_GForward (dsq, L, gm, gxf, &fsc2) != eslOK) esl_fatal(msg); |
| 341 |
if (p7_GBackward(dsq, L, gm, gxb, &bsc2) != eslOK) esl_fatal(msg); |
| 342 |
if (p7_GDecoding(gm, gxf, gxb, gxp2) != eslOK) esl_fatal(msg); |
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
if (p7_gmx_Compare(gxp1, gxp2, tolerance) != eslOK) esl_fatal(msg); |
| 348 |
} |
| 349 |
|
| 350 |
p7_gmx_Destroy(gxp1); |
| 351 |
p7_gmx_Destroy(gxp2); |
| 352 |
p7_gmx_Destroy(gxf); |
| 353 |
p7_gmx_Destroy(gxb); |
| 354 |
p7_omx_Destroy(fwd); |
| 355 |
p7_omx_Destroy(bck); |
| 356 |
p7_omx_Destroy(pp); |
| 357 |
free(dsq); |
| 358 |
p7_oprofile_Destroy(om); |
| 359 |
p7_profile_Destroy(gm); |
| 360 |
p7_hmm_Destroy(hmm); |
| 361 |
} |
| 362 |
#endif |
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
#ifdef p7DECODING_TESTDRIVE |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
#include <p7_config.h> |
| 378 |
|
| 379 |
#include <stdio.h> |
| 380 |
#include <math.h> |
| 381 |
|
| 382 |
#include "easel.h" |
| 383 |
#include "esl_getopts.h" |
| 384 |
#include "esl_random.h" |
| 385 |
#include "esl_randomseq.h" |
| 386 |
|
| 387 |
#include "hmmer.h" |
| 388 |
#include "impl_vmx.h" |
| 389 |
|
| 390 |
static ESL_OPTIONS options[] = { |
| 391 |
|
| 392 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show help and usage", 0}, |
| 393 |
{ "-s", eslARG_INT, "42", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 }, |
| 394 |
{ "-t", eslARG_REAL, "0.01", NULL, NULL, NULL, NULL, NULL, "floating point comparison tolerance", 0 }, |
| 395 |
{ "-L", eslARG_INT, "40", NULL, NULL, NULL, NULL, NULL, "length of sampled sequences", 0 }, |
| 396 |
{ "-M", eslARG_INT, "40", NULL, NULL, NULL, NULL, NULL, "length of sampled test profile", 0 }, |
| 397 |
{ "-N", eslARG_INT, "10", NULL, NULL, NULL, NULL, NULL, "number of sampled test sequences", 0 }, |
| 398 |
{ 0,0,0,0,0,0,0,0,0,0}, |
| 399 |
}; |
| 400 |
static char usage[] = "[-options]"; |
| 401 |
static char banner[] = "test driver for VMX posterior decoding"; |
| 402 |
|
| 403 |
int |
| 404 |
main(int argc, char **argv) |
| 405 |
{ |
| 406 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 0, argc, argv, banner, usage); |
| 407 |
ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s")); |
| 408 |
ESL_ALPHABET *abc = esl_alphabet_Create(eslAMINO); |
| 409 |
P7_BG *bg = p7_bg_Create(abc); |
| 410 |
int M = esl_opt_GetInteger(go, "-M"); |
| 411 |
int L = esl_opt_GetInteger(go, "-L"); |
| 412 |
int N = esl_opt_GetInteger(go, "-N"); |
| 413 |
float tol = esl_opt_GetReal (go, "-t"); |
| 414 |
|
| 415 |
p7_FLogsumInit(); |
| 416 |
|
| 417 |
utest_decoding(r, abc, bg, M, L, N, tol); |
| 418 |
|
| 419 |
esl_getopts_Destroy(go); |
| 420 |
esl_randomness_Destroy(r); |
| 421 |
esl_alphabet_Destroy(abc); |
| 422 |
p7_bg_Destroy(bg); |
| 423 |
return eslOK; |
| 424 |
} |
| 425 |
#endif |
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|