| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#include <p7_config.h> |
| 14 |
|
| 15 |
#include <float.h> |
| 16 |
|
| 17 |
#include "easel.h" |
| 18 |
#include "esl_vectorops.h" |
| 19 |
|
| 20 |
#include "hmmer.h" |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
#define MMX(i,k) (dp[(i)][(k) * p7G_NSCELLS + p7G_M]) |
| 27 |
#define IMX(i,k) (dp[(i)][(k) * p7G_NSCELLS + p7G_I]) |
| 28 |
#define DMX(i,k) (dp[(i)][(k) * p7G_NSCELLS + p7G_D]) |
| 29 |
#define XMX(i,s) (xmx[(i) * p7G_NXCELLS + (s)]) |
| 30 |
#define TSCDELTA(s,k) ( (tsc[(k) * p7P_NTRANS + (s)] == -eslINFINITY) ? FLT_MIN : 1.0) |
| 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 |
int |
| 73 |
p7_GOptimalAccuracy(const P7_PROFILE *gm, const P7_GMX *pp, P7_GMX *gx, float *ret_e) |
| 74 |
{ |
| 75 |
int L = pp->L; |
| 76 |
float **dp = gx->dp; |
| 77 |
float *xmx = gx->xmx; |
| 78 |
float const *tsc = gm->tsc; |
| 79 |
int i,k; |
| 80 |
int M = gm->M; |
| 81 |
float esc = p7_profile_IsLocal(gm) ? 1.0 : 0.0; |
| 82 |
float t1, t2; |
| 83 |
|
| 84 |
|
| 85 |
XMX(0,p7G_N) = 0.; |
| 86 |
XMX(0,p7G_B) = 0.; |
| 87 |
XMX(0,p7G_E) = XMX(0,p7G_C) = XMX(0,p7G_J) = -eslINFINITY; |
| 88 |
for (k = 0; k <= M; k++) |
| 89 |
MMX(0,k) = IMX(0,k) = DMX(0,k) = -eslINFINITY; |
| 90 |
|
| 91 |
for (i = 1; i <= L; i++) |
| 92 |
{ |
| 93 |
MMX(i,0) = IMX(i,0) = DMX(i,0) = XMX(i,p7G_E) = -eslINFINITY; |
| 94 |
|
| 95 |
for (k = 1; k < M; k++) |
| 96 |
{ |
| 97 |
MMX(i,k) = ESL_MAX(ESL_MAX(TSCDELTA(p7P_MM, k-1) * (MMX(i-1,k-1) + pp->dp[i][k*p7G_NSCELLS + p7G_M]), |
| 98 |
TSCDELTA(p7P_IM, k-1) * (IMX(i-1,k-1) + pp->dp[i][k*p7G_NSCELLS + p7G_M])), |
| 99 |
ESL_MAX(TSCDELTA(p7P_DM, k-1) * (DMX(i-1,k-1) + pp->dp[i][k*p7G_NSCELLS + p7G_M]), |
| 100 |
TSCDELTA(p7P_BM, k-1) * (XMX(i-1,p7G_B)+ pp->dp[i][k*p7G_NSCELLS + p7G_M]))); |
| 101 |
|
| 102 |
XMX(i,p7G_E) = ESL_MAX(XMX(i,p7G_E), |
| 103 |
esc * MMX(i,k)); |
| 104 |
|
| 105 |
IMX(i,k) = ESL_MAX(TSCDELTA(p7P_MI, k) * (MMX(i-1,k) + pp->dp[i][k*p7G_NSCELLS + p7G_I]), |
| 106 |
TSCDELTA(p7P_II, k) * (IMX(i-1,k) + pp->dp[i][k*p7G_NSCELLS + p7G_I])); |
| 107 |
|
| 108 |
DMX(i,k) = ESL_MAX(TSCDELTA(p7P_MD, k-1) * MMX(i,k-1), |
| 109 |
TSCDELTA(p7P_DD, k-1) * DMX(i,k-1)); |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
MMX(i,M) = ESL_MAX(ESL_MAX(TSCDELTA(p7P_MM, M-1) * (MMX(i-1,M-1) + pp->dp[i][M*p7G_NSCELLS + p7G_M]), |
| 114 |
TSCDELTA(p7P_IM, M-1) * (IMX(i-1,M-1) + pp->dp[i][M*p7G_NSCELLS + p7G_M])), |
| 115 |
ESL_MAX(TSCDELTA(p7P_DM, M-1) * (DMX(i-1,M-1) + pp->dp[i][M*p7G_NSCELLS + p7G_M]), |
| 116 |
TSCDELTA(p7P_BM, M-1) * (XMX(i-1,p7G_B)+ pp->dp[i][M*p7G_NSCELLS + p7G_M]))); |
| 117 |
|
| 118 |
DMX(i,M) = ESL_MAX(TSCDELTA(p7P_MD, M-1) * MMX(i,M-1), |
| 119 |
TSCDELTA(p7P_DD, M-1) * DMX(i,M-1)); |
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
XMX(i,p7G_E) = ESL_MAX(XMX(i,p7G_E), ESL_MAX(MMX(i,M), DMX(i, M))); |
| 125 |
|
| 126 |
|
| 127 |
t1 = ( (gm->xsc[p7P_J][p7P_LOOP] == -eslINFINITY) ? FLT_MIN : 1.0); |
| 128 |
t2 = ( (gm->xsc[p7P_E][p7P_LOOP] == -eslINFINITY) ? FLT_MIN : 1.0); |
| 129 |
XMX(i, p7G_J) = ESL_MAX( t1 * (XMX(i-1,p7G_J) + pp->xmx[i*p7G_NXCELLS + p7G_J]), |
| 130 |
t2 * XMX(i, p7G_E)); |
| 131 |
|
| 132 |
t1 = ( (gm->xsc[p7P_C][p7P_LOOP] == -eslINFINITY) ? FLT_MIN : 1.0); |
| 133 |
t2 = ( (gm->xsc[p7P_E][p7P_MOVE] == -eslINFINITY) ? FLT_MIN : 1.0); |
| 134 |
XMX(i,p7G_C) = ESL_MAX( t1 * (XMX(i-1,p7G_C) + pp->xmx[i*p7G_NXCELLS + p7G_C]), |
| 135 |
t2 * XMX(i, p7G_E)); |
| 136 |
|
| 137 |
t1 = ( (gm->xsc[p7P_N][p7P_LOOP] == -eslINFINITY) ? FLT_MIN : 1.0); |
| 138 |
XMX(i,p7G_N) = t1 * (XMX(i-1,p7G_N) + pp->xmx[i*p7G_NXCELLS + p7G_N]); |
| 139 |
|
| 140 |
t1 = ( (gm->xsc[p7P_N][p7P_MOVE] == -eslINFINITY) ? FLT_MIN : 1.0); |
| 141 |
t2 = ( (gm->xsc[p7P_J][p7P_MOVE] == -eslINFINITY) ? FLT_MIN : 1.0); |
| 142 |
XMX(i,p7G_B) = ESL_MAX( t1 * XMX(i, p7G_N), |
| 143 |
t2 * XMX(i, p7G_J)); |
| 144 |
} |
| 145 |
|
| 146 |
*ret_e = XMX(L,p7G_C); |
| 147 |
return eslOK; |
| 148 |
} |
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
static inline float get_postprob(const P7_GMX *pp, int scur, int sprv, int k, int i); |
| 156 |
|
| 157 |
static inline int select_m(const P7_PROFILE *gm, const P7_GMX *gx, int i, int k); |
| 158 |
static inline int select_d(const P7_PROFILE *gm, const P7_GMX *gx, int i, int k); |
| 159 |
static inline int select_i(const P7_PROFILE *gm, const P7_GMX *gx, int i, int k); |
| 160 |
static inline int select_n(int i); |
| 161 |
static inline int select_c(const P7_PROFILE *gm, const P7_GMX *pp, const P7_GMX *gx, int i); |
| 162 |
static inline int select_j(const P7_PROFILE *gm, const P7_GMX *pp, const P7_GMX *gx, int i); |
| 163 |
static inline int select_e(const P7_PROFILE *gm, const P7_GMX *gx, int i, int *ret_k); |
| 164 |
static inline int select_b(const P7_PROFILE *gm, const P7_GMX *gx, int i); |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
int |
| 196 |
p7_GOATrace(const P7_PROFILE *gm, const P7_GMX *pp, const P7_GMX *gx, P7_TRACE *tr) |
| 197 |
{ |
| 198 |
int i = gx->L; |
| 199 |
int k = 0; |
| 200 |
float postprob; |
| 201 |
int sprv, scur; |
| 202 |
int status; |
| 203 |
|
| 204 |
#if eslDEBUGLEVEL > 0 |
| 205 |
if (tr->N != 0) ESL_EXCEPTION(eslEINVAL, "trace isn't empty: forgot to Reuse()?"); |
| 206 |
#endif |
| 207 |
|
| 208 |
if ((status = p7_trace_AppendWithPP(tr, p7T_T, k, i, 0.0)) != eslOK) return status; |
| 209 |
if ((status = p7_trace_AppendWithPP(tr, p7T_C, k, i, 0.0)) != eslOK) return status; |
| 210 |
|
| 211 |
sprv = p7T_C; |
| 212 |
while (sprv != p7T_S) |
| 213 |
{ |
| 214 |
switch (sprv) { |
| 215 |
case p7T_M: scur = select_m(gm, gx, i, k); k--; i--; break; |
| 216 |
case p7T_D: scur = select_d(gm, gx, i, k); k--; break; |
| 217 |
case p7T_I: scur = select_i(gm, gx, i, k); i--; break; |
| 218 |
case p7T_N: scur = select_n(i); break; |
| 219 |
case p7T_C: scur = select_c(gm, pp, gx, i); break; |
| 220 |
case p7T_J: scur = select_j(gm, pp, gx, i); break; |
| 221 |
case p7T_E: scur = select_e(gm, gx, i, &k); break; |
| 222 |
case p7T_B: scur = select_b(gm, gx, i); break; |
| 223 |
default: ESL_EXCEPTION(eslEINVAL, "bogus state in traceback"); |
| 224 |
} |
| 225 |
if (scur == -1) ESL_EXCEPTION(eslEINVAL, "OA traceback choice failed"); |
| 226 |
|
| 227 |
postprob = get_postprob(pp, scur, sprv, k, i); |
| 228 |
if ((status = p7_trace_AppendWithPP(tr, scur, k, i, postprob)) != eslOK) return status; |
| 229 |
|
| 230 |
|
| 231 |
if ( (scur == p7T_N || scur == p7T_J || scur == p7T_C) && scur == sprv) i--; |
| 232 |
sprv = scur; |
| 233 |
} |
| 234 |
tr->M = gm->M; |
| 235 |
tr->L = gx->L; |
| 236 |
return p7_trace_Reverse(tr); |
| 237 |
} |
| 238 |
|
| 239 |
static inline float |
| 240 |
get_postprob(const P7_GMX *pp, int scur, int sprv, int k, int i) |
| 241 |
{ |
| 242 |
float **dp = pp->dp; |
| 243 |
float *xmx = pp->xmx; |
| 244 |
|
| 245 |
switch (scur) { |
| 246 |
case p7T_M: return MMX(i,k); |
| 247 |
case p7T_I: return IMX(i,k); |
| 248 |
case p7T_N: if (sprv == scur) return XMX(i,p7G_N); |
| 249 |
case p7T_C: if (sprv == scur) return XMX(i,p7G_C); |
| 250 |
case p7T_J: if (sprv == scur) return XMX(i,p7G_J); |
| 251 |
default: return 0.0; |
| 252 |
} |
| 253 |
} |
| 254 |
|
| 255 |
static inline int |
| 256 |
select_m(const P7_PROFILE *gm, const P7_GMX *gx, int i, int k) |
| 257 |
{ |
| 258 |
float **dp = gx->dp; |
| 259 |
float *xmx = gx->xmx; |
| 260 |
float const *tsc = gm->tsc; |
| 261 |
float path[4]; |
| 262 |
int state[4] = { p7T_M, p7T_I, p7T_D, p7T_B }; |
| 263 |
|
| 264 |
path[0] = TSCDELTA(p7P_MM, k-1) * MMX(i-1,k-1); |
| 265 |
path[1] = TSCDELTA(p7P_IM, k-1) * IMX(i-1,k-1); |
| 266 |
path[2] = TSCDELTA(p7P_DM, k-1) * DMX(i-1,k-1); |
| 267 |
path[3] = TSCDELTA(p7P_BM, k-1) * XMX(i-1,p7G_B); |
| 268 |
return state[esl_vec_FArgMax(path, 4)]; |
| 269 |
} |
| 270 |
|
| 271 |
static inline int |
| 272 |
select_d(const P7_PROFILE *gm, const P7_GMX *gx, int i, int k) |
| 273 |
{ |
| 274 |
float **dp = gx->dp; |
| 275 |
float const *tsc = gm->tsc; |
| 276 |
float path[2]; |
| 277 |
|
| 278 |
path[0] = TSCDELTA(p7P_MD, k-1) * MMX(i, k-1); |
| 279 |
path[1] = TSCDELTA(p7P_DD, k-1) * DMX(i, k-1); |
| 280 |
return ((path[0] >= path[1]) ? p7T_M : p7T_D); |
| 281 |
} |
| 282 |
|
| 283 |
static inline int |
| 284 |
select_i(const P7_PROFILE *gm, const P7_GMX *gx, int i, int k) |
| 285 |
{ |
| 286 |
float **dp = gx->dp; |
| 287 |
float const *tsc = gm->tsc; |
| 288 |
float path[2]; |
| 289 |
|
| 290 |
path[0] = TSCDELTA(p7P_MI, k) * MMX(i-1,k); |
| 291 |
path[1] = TSCDELTA(p7P_II, k) * IMX(i-1,k); |
| 292 |
return ((path[0] >= path[1]) ? p7T_M : p7T_I); |
| 293 |
} |
| 294 |
|
| 295 |
static inline int |
| 296 |
select_n(int i) |
| 297 |
{ |
| 298 |
return ((i==0) ? p7T_S : p7T_N); |
| 299 |
} |
| 300 |
|
| 301 |
static inline int |
| 302 |
select_c(const P7_PROFILE *gm, const P7_GMX *pp, const P7_GMX *gx, int i) |
| 303 |
{ |
| 304 |
float t1 = ( (gm->xsc[p7P_C][p7P_LOOP] == -eslINFINITY) ? FLT_MIN : 1.0); |
| 305 |
float t2 = ( (gm->xsc[p7P_E][p7P_MOVE] == -eslINFINITY) ? FLT_MIN : 1.0); |
| 306 |
float *xmx = gx->xmx; |
| 307 |
float path[2]; |
| 308 |
|
| 309 |
path[0] = t1 * (XMX(i-1, p7G_C) + pp->xmx[i*p7G_NXCELLS + p7G_C]); |
| 310 |
path[1] = t2 * XMX(i,p7G_E); |
| 311 |
return ((path[0] > path[1]) ? p7T_C : p7T_E); |
| 312 |
} |
| 313 |
|
| 314 |
static inline int |
| 315 |
select_j(const P7_PROFILE *gm, const P7_GMX *pp, const P7_GMX *gx, int i) |
| 316 |
{ |
| 317 |
float t1 = ( (gm->xsc[p7P_J][p7P_LOOP] == -eslINFINITY) ? FLT_MIN : 1.0); |
| 318 |
float t2 = ( (gm->xsc[p7P_E][p7P_LOOP] == -eslINFINITY) ? FLT_MIN : 1.0); |
| 319 |
float *xmx = gx->xmx; |
| 320 |
float path[2]; |
| 321 |
|
| 322 |
path[0] = t1 * (XMX(i-1,p7G_J) + pp->xmx[i*p7G_NXCELLS + p7G_J]); |
| 323 |
path[1] = t2 * XMX(i,p7G_E); |
| 324 |
return ((path[0] > path[1]) ? p7T_J : p7T_E); |
| 325 |
} |
| 326 |
|
| 327 |
static inline int |
| 328 |
select_e(const P7_PROFILE *gm, const P7_GMX *gx, int i, int *ret_k) |
| 329 |
{ |
| 330 |
float **dp = gx->dp; |
| 331 |
float max = -eslINFINITY; |
| 332 |
int smax = -1; |
| 333 |
int kmax = -1; |
| 334 |
int k; |
| 335 |
|
| 336 |
if (! p7_profile_IsLocal(gm)) |
| 337 |
{ |
| 338 |
*ret_k = gm->M; |
| 339 |
return ((MMX(i,gm->M) >= DMX(i,gm->M)) ? p7T_M : p7T_D); |
| 340 |
} |
| 341 |
|
| 342 |
for (k = 1; k <= gm->M; k++) |
| 343 |
{ |
| 344 |
if (MMX(i,k) >= max) { max = MMX(i,k); smax = p7T_M; kmax = k; } |
| 345 |
if (DMX(i,k) > max) { max = DMX(i,k); smax = p7T_D; kmax = k; } |
| 346 |
} |
| 347 |
*ret_k = kmax; |
| 348 |
return smax; |
| 349 |
} |
| 350 |
|
| 351 |
static inline int |
| 352 |
select_b(const P7_PROFILE *gm, const P7_GMX *gx, int i) |
| 353 |
{ |
| 354 |
float t1 = ( (gm->xsc[p7P_N][p7P_MOVE] == -eslINFINITY) ? FLT_MIN : 1.0); |
| 355 |
float t2 = ( (gm->xsc[p7P_J][p7P_MOVE] == -eslINFINITY) ? FLT_MIN : 1.0); |
| 356 |
float *xmx = gx->xmx; |
| 357 |
float path[2]; |
| 358 |
|
| 359 |
path[0] = t1 * XMX(i, p7G_N); |
| 360 |
path[1] = t2 * XMX(i, p7G_J); |
| 361 |
return ((path[0] > path[1]) ? p7T_N : p7T_J); |
| 362 |
} |
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
#ifdef p7GENERIC_OPTACC_BENCHMARK |
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
#include <p7_config.h> |
| 383 |
|
| 384 |
#include "easel.h" |
| 385 |
#include "esl_alphabet.h" |
| 386 |
#include "esl_getopts.h" |
| 387 |
#include "esl_random.h" |
| 388 |
#include "esl_randomseq.h" |
| 389 |
#include "esl_stopwatch.h" |
| 390 |
|
| 391 |
#include "hmmer.h" |
| 392 |
|
| 393 |
static ESL_OPTIONS options[] = { |
| 394 |
|
| 395 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 396 |
{ "-s", eslARG_INT, "42", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 }, |
| 397 |
{ "-L", eslARG_INT, "400", NULL, "n>0", NULL, NULL, NULL, "length of random target seqs", 0 }, |
| 398 |
{ "-N", eslARG_INT, "5000", NULL, "n>0", NULL, NULL, NULL, "number of random target seqs", 0 }, |
| 399 |
{ "--notrace", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "only benchmark the DP fill stage", 0 }, |
| 400 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 401 |
}; |
| 402 |
static char usage[] = "[-options] <hmmfile>"; |
| 403 |
static char banner[] = "benchmark driver for optimal accuracy alignment, generic version"; |
| 404 |
|
| 405 |
int |
| 406 |
main(int argc, char **argv) |
| 407 |
{ |
| 408 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 1, argc, argv, banner, usage); |
| 409 |
char *hmmfile = esl_opt_GetArg(go, 1); |
| 410 |
ESL_STOPWATCH *w = esl_stopwatch_Create(); |
| 411 |
ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s")); |
| 412 |
ESL_ALPHABET *abc = NULL; |
| 413 |
P7_HMMFILE *hfp = NULL; |
| 414 |
P7_HMM *hmm = NULL; |
| 415 |
P7_BG *bg = NULL; |
| 416 |
P7_PROFILE *gm = NULL; |
| 417 |
P7_GMX *gx1 = NULL; |
| 418 |
P7_GMX *gx2 = NULL; |
| 419 |
P7_TRACE *tr = NULL; |
| 420 |
int L = esl_opt_GetInteger(go, "-L"); |
| 421 |
int N = esl_opt_GetInteger(go, "-N"); |
| 422 |
ESL_DSQ *dsq = malloc(sizeof(ESL_DSQ) * (L+2)); |
| 423 |
int i; |
| 424 |
float fsc, bsc, accscore; |
| 425 |
double Mcs; |
| 426 |
|
| 427 |
p7_FLogsumInit(); |
| 428 |
|
| 429 |
if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile); |
| 430 |
if (p7_hmmfile_Read(hfp, &abc, &hmm) != eslOK) p7_Fail("Failed to read HMM"); |
| 431 |
|
| 432 |
bg = p7_bg_Create(abc); |
| 433 |
p7_bg_SetLength(bg, L); |
| 434 |
gm = p7_profile_Create(hmm->M, abc); |
| 435 |
p7_ProfileConfig(hmm, bg, gm, L, p7_UNILOCAL); |
| 436 |
gx1 = p7_gmx_Create(gm->M, L); |
| 437 |
gx2 = p7_gmx_Create(gm->M, L); |
| 438 |
tr = p7_trace_CreateWithPP(); |
| 439 |
|
| 440 |
esl_rsq_xfIID(r, bg->f, abc->K, L, dsq); |
| 441 |
p7_GForward (dsq, L, gm, gx1, &fsc); |
| 442 |
p7_GBackward(dsq, L, gm, gx2, &bsc); |
| 443 |
p7_GDecoding(gm, gx1, gx2, gx2); |
| 444 |
|
| 445 |
esl_stopwatch_Start(w); |
| 446 |
for (i = 0; i < N; i++) |
| 447 |
{ |
| 448 |
p7_GOptimalAccuracy(gm, gx2, gx1, &accscore); |
| 449 |
|
| 450 |
if (! esl_opt_GetBoolean(go, "--notrace")) |
| 451 |
{ |
| 452 |
p7_GOATrace(gm, gx2, gx1, tr); |
| 453 |
p7_trace_Reuse(tr); |
| 454 |
} |
| 455 |
} |
| 456 |
esl_stopwatch_Stop(w); |
| 457 |
Mcs = (double) N * (double) L * (double) gm->M * 1e-6 / w->user; |
| 458 |
esl_stopwatch_Display(stdout, w, "# CPU time: "); |
| 459 |
printf("# M = %d\n", gm->M); |
| 460 |
printf("# %.1f Mc/s\n", Mcs); |
| 461 |
|
| 462 |
free(dsq); |
| 463 |
p7_trace_Destroy(tr); |
| 464 |
p7_gmx_Destroy(gx1); |
| 465 |
p7_gmx_Destroy(gx2); |
| 466 |
p7_profile_Destroy(gm); |
| 467 |
p7_bg_Destroy(bg); |
| 468 |
p7_hmm_Destroy(hmm); |
| 469 |
p7_hmmfile_Close(hfp); |
| 470 |
esl_alphabet_Destroy(abc); |
| 471 |
esl_stopwatch_Destroy(w); |
| 472 |
esl_randomness_Destroy(r); |
| 473 |
esl_getopts_Destroy(go); |
| 474 |
return 0; |
| 475 |
} |
| 476 |
#endif |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
#ifdef p7GENERIC_OPTACC_TESTDRIVE |
| 484 |
|
| 485 |
#endif |
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
#ifdef p7GENERIC_OPTACC_TESTDRIVE |
| 493 |
|
| 494 |
#endif |
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
#ifdef p7GENERIC_OPTACC_EXAMPLE |
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
#include <p7_config.h> |
| 509 |
|
| 510 |
#include "easel.h" |
| 511 |
#include "esl_alphabet.h" |
| 512 |
#include "esl_getopts.h" |
| 513 |
#include "esl_sq.h" |
| 514 |
#include "esl_sqio.h" |
| 515 |
|
| 516 |
#include "hmmer.h" |
| 517 |
|
| 518 |
static ESL_OPTIONS options[] = { |
| 519 |
|
| 520 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 521 |
{ "-d", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "dump posterior residue decoding matrix", 0 }, |
| 522 |
{ "-m", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "dump OA matrix", 0 }, |
| 523 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 524 |
}; |
| 525 |
static char usage[] = "[-options] <hmmfile> <seqfile>"; |
| 526 |
static char banner[] = "example of optimal accuracy alignment, generic implementation"; |
| 527 |
|
| 528 |
int |
| 529 |
main(int argc, char **argv) |
| 530 |
{ |
| 531 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 2, argc, argv, banner, usage); |
| 532 |
char *hmmfile = esl_opt_GetArg(go, 1); |
| 533 |
char *seqfile = esl_opt_GetArg(go, 2); |
| 534 |
ESL_ALPHABET *abc = NULL; |
| 535 |
P7_HMMFILE *hfp = NULL; |
| 536 |
P7_HMM *hmm = NULL; |
| 537 |
P7_BG *bg = NULL; |
| 538 |
P7_PROFILE *gm = NULL; |
| 539 |
P7_GMX *gx1 = NULL; |
| 540 |
P7_GMX *gx2 = NULL; |
| 541 |
ESL_SQ *sq = NULL; |
| 542 |
ESL_SQFILE *sqfp = NULL; |
| 543 |
P7_TRACE *tr = NULL; |
| 544 |
int format = eslSQFILE_UNKNOWN; |
| 545 |
char errbuf[eslERRBUFSIZE]; |
| 546 |
float fsc, bsc, vsc; |
| 547 |
float accscore; |
| 548 |
int status; |
| 549 |
|
| 550 |
|
| 551 |
if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile); |
| 552 |
if (p7_hmmfile_Read(hfp, &abc, &hmm) != eslOK) p7_Fail("Failed to read HMM"); |
| 553 |
p7_hmmfile_Close(hfp); |
| 554 |
|
| 555 |
|
| 556 |
sq = esl_sq_CreateDigital(abc); |
| 557 |
status = esl_sqfile_OpenDigital(abc, seqfile, format, NULL, &sqfp); |
| 558 |
if (status == eslENOTFOUND) p7_Fail("No such file."); |
| 559 |
else if (status == eslEFORMAT) p7_Fail("Format unrecognized."); |
| 560 |
else if (status == eslEINVAL) p7_Fail("Can't autodetect stdin or .gz."); |
| 561 |
else if (status != eslOK) p7_Fail("Open failed, code %d.", status); |
| 562 |
if (esl_sqio_Read(sqfp, sq) != eslOK) p7_Fail("Failed to read sequence"); |
| 563 |
esl_sqfile_Close(sqfp); |
| 564 |
|
| 565 |
|
| 566 |
bg = p7_bg_Create(abc); |
| 567 |
p7_bg_SetLength(bg, sq->n); |
| 568 |
gm = p7_profile_Create(hmm->M, abc); |
| 569 |
p7_ProfileConfig(hmm, bg, gm, sq->n, p7_LOCAL); |
| 570 |
|
| 571 |
|
| 572 |
gx1 = p7_gmx_Create(gm->M, sq->n); |
| 573 |
gx2 = p7_gmx_Create(gm->M, sq->n); |
| 574 |
tr = p7_trace_CreateWithPP(); |
| 575 |
p7_FLogsumInit(); |
| 576 |
|
| 577 |
|
| 578 |
p7_GForward (sq->dsq, sq->n, gm, gx1, &fsc); |
| 579 |
p7_GBackward(sq->dsq, sq->n, gm, gx2, &bsc); |
| 580 |
p7_GDecoding(gm, gx1, gx2, gx2); |
| 581 |
p7_GOptimalAccuracy(gm, gx2, gx1, &accscore); |
| 582 |
p7_GOATrace(gm, gx2, gx1, tr); |
| 583 |
|
| 584 |
if (esl_opt_GetBoolean(go, "-d")) p7_gmx_Dump(stdout, gx2, p7_DEFAULT); |
| 585 |
if (esl_opt_GetBoolean(go, "-m")) p7_gmx_Dump(stdout, gx1, p7_DEFAULT); |
| 586 |
|
| 587 |
p7_trace_Dump(stdout, tr, gm, sq->dsq); |
| 588 |
if (p7_trace_Validate(tr, abc, sq->dsq, errbuf) != eslOK) p7_Die("trace fails validation:\n%s\n", errbuf); |
| 589 |
|
| 590 |
printf("fwd = %.4f nats\n", fsc); |
| 591 |
printf("bck = %.4f nats\n", bsc); |
| 592 |
printf("acc = %.4f (%.2f%%)\n", accscore, accscore * 100. / (float) sq->n); |
| 593 |
|
| 594 |
p7_trace_Reuse(tr); |
| 595 |
|
| 596 |
p7_GViterbi(sq->dsq, sq->n, gm, gx1, &vsc); |
| 597 |
p7_GTrace (sq->dsq, sq->n, gm, gx1, tr); |
| 598 |
p7_trace_SetPP(tr, gx2); |
| 599 |
p7_trace_Dump(stdout, tr, gm, sq->dsq); |
| 600 |
|
| 601 |
printf("vit = %.4f nats\n", vsc); |
| 602 |
printf("acc = %.4f\n", p7_trace_GetExpectedAccuracy(tr)); |
| 603 |
|
| 604 |
|
| 605 |
esl_sq_Destroy(sq); |
| 606 |
p7_trace_Destroy(tr); |
| 607 |
p7_gmx_Destroy(gx1); |
| 608 |
p7_gmx_Destroy(gx2); |
| 609 |
p7_profile_Destroy(gm); |
| 610 |
p7_bg_Destroy(bg); |
| 611 |
p7_hmm_Destroy(hmm); |
| 612 |
esl_alphabet_Destroy(abc); |
| 613 |
esl_getopts_Destroy(go); |
| 614 |
return 0; |
| 615 |
} |
| 616 |
#endif |
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|