| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
#include <p7_config.h> |
| 11 |
|
| 12 |
#include "easel.h" |
| 13 |
|
| 14 |
#include "hmmer.h" |
| 15 |
#include "p7_gmxchk.h" |
| 16 |
#include "p7_gbands.h" |
| 17 |
|
| 18 |
static inline void posterior_decode_row(int rowi, float *fwd, float *bck, int M, float overall_sc, P7_GBANDS *bnd); |
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
static inline void |
| 32 |
forward_row(const ESL_DSQ *dsq, const P7_PROFILE *gm, P7_GMXCHK *gxc, const float *dpp, float *dpc, int i) |
| 33 |
{ |
| 34 |
const float *tsc = gm->tsc; |
| 35 |
const float *rsc = gm->rsc[dsq[i]] + p7P_NR; |
| 36 |
int M = gm->M; |
| 37 |
float esc = p7_profile_IsLocal(gm) ? 0. : -eslINFINITY; |
| 38 |
int k; |
| 39 |
float sc, dc; |
| 40 |
float xB = *(dpp + (M+1)*p7G_NSCELLS + p7GC_B); |
| 41 |
float xE = -eslINFINITY; |
| 42 |
float mvp, ivp, dvp; |
| 43 |
|
| 44 |
*dpc++ = -eslINFINITY; |
| 45 |
*dpc++ = -eslINFINITY; |
| 46 |
*dpc++ = -eslINFINITY; |
| 47 |
dc = -eslINFINITY; |
| 48 |
|
| 49 |
mvp = *dpp++; ivp = *dpp++; dvp = *dpp++; |
| 50 |
|
| 51 |
for (k = 1; k < M; k++) |
| 52 |
{ |
| 53 |
|
| 54 |
*dpc++ = sc = *rsc++ |
| 55 |
+ p7_FLogsum(p7_FLogsum( mvp + *(tsc+p7P_MM), |
| 56 |
ivp + *(tsc+p7P_IM)), |
| 57 |
p7_FLogsum( dvp + *(tsc+p7P_DM), |
| 58 |
xB + *(tsc+p7P_BM))); |
| 59 |
tsc += p7P_NTRANS; |
| 60 |
|
| 61 |
|
| 62 |
mvp = *dpp++; ivp = *dpp++; dvp = *dpp++; |
| 63 |
|
| 64 |
|
| 65 |
*dpc++ = *rsc++ |
| 66 |
+ p7_FLogsum( mvp + *(tsc+p7P_MI), |
| 67 |
ivp + *(tsc+p7P_II)); |
| 68 |
|
| 69 |
|
| 70 |
xE = p7_FLogsum( p7_FLogsum(sc + esc, dc + esc), xE); |
| 71 |
|
| 72 |
|
| 73 |
*dpc++ = dc; |
| 74 |
dc = p7_FLogsum( sc + *(tsc+p7P_MD), |
| 75 |
dc + *(tsc+p7P_DD)); |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
*dpc++ = sc = *rsc++ |
| 80 |
+ p7_FLogsum(p7_FLogsum( mvp + *(tsc + p7P_MM), |
| 81 |
ivp + *(tsc + p7P_IM)), |
| 82 |
p7_FLogsum( dvp + *(tsc + p7P_DM), |
| 83 |
xB + *(tsc + p7P_BM))); |
| 84 |
*dpc++ = -eslINFINITY; |
| 85 |
*dpc++ = dc; |
| 86 |
dpp += 3; |
| 87 |
|
| 88 |
|
| 89 |
dpc[p7GC_E] = p7_FLogsum( p7_FLogsum(sc, dc), xE); |
| 90 |
dpc[p7GC_N] = dpp[p7GC_N] + gm->xsc[p7P_N][p7P_LOOP]; |
| 91 |
dpc[p7GC_JJ] = dpp[p7GC_J] + gm->xsc[p7P_J][p7P_LOOP]; |
| 92 |
dpc[p7GC_J] = p7_FLogsum( dpc[p7GC_JJ], dpc[p7GC_E] + gm->xsc[p7P_E][p7P_LOOP]); |
| 93 |
dpc[p7GC_B] = p7_FLogsum( dpc[p7GC_N] + gm->xsc[p7P_N][p7P_MOVE], dpc[p7GC_J] + gm->xsc[p7P_J][p7P_MOVE]); |
| 94 |
dpc[p7GC_CC] = dpp[p7GC_C] + gm->xsc[p7P_C][p7P_LOOP]; |
| 95 |
dpc[p7GC_C] = p7_FLogsum( dpc[p7GC_CC], dpc[p7GC_E] + gm->xsc[p7P_E][p7P_MOVE]); |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
int |
| 128 |
p7_GForwardCheckpointed(const ESL_DSQ *dsq, int L, const P7_PROFILE *gm, P7_GMXCHK *gxc, float *opt_sc) |
| 129 |
{ |
| 130 |
float *dpc; |
| 131 |
float *dpp; |
| 132 |
int M = gm->M; |
| 133 |
int w; |
| 134 |
int b; |
| 135 |
int i,k; |
| 136 |
|
| 137 |
|
| 138 |
dpc = dpp = gxc->dp[gxc->R0-1]; |
| 139 |
for (k = 0; k < (M+1)*p7G_NSCELLS; k++) |
| 140 |
*dpc++ = -eslINFINITY; |
| 141 |
*dpc++ = -eslINFINITY; |
| 142 |
*dpc++ = 0; |
| 143 |
*dpc++ = -eslINFINITY; |
| 144 |
*dpc++ = -eslINFINITY; |
| 145 |
*dpc++ = gm->xsc[p7P_N][p7P_MOVE]; |
| 146 |
*dpc++ = -eslINFINITY; |
| 147 |
*dpc = -eslINFINITY; |
| 148 |
|
| 149 |
|
| 150 |
for (i = 1; i <= gxc->La; i++) |
| 151 |
{ |
| 152 |
dpc = gxc->dp[gxc->R0+gxc->R]; gxc->R++; |
| 153 |
forward_row(dsq, gm, gxc, dpp, dpc, i); |
| 154 |
dpp = dpc; |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
for (b = gxc->Rb + gxc->Rc, w = (gxc->Rb ? gxc->Lb : gxc->Rc+1); i <= L; i++) |
| 160 |
{ |
| 161 |
if (! (--w)) |
| 162 |
{ |
| 163 |
dpc = gxc->dp[gxc->R0+gxc->R]; gxc->R++; |
| 164 |
w=b; |
| 165 |
b--; |
| 166 |
} |
| 167 |
else |
| 168 |
dpc = gxc->dp[i%2]; |
| 169 |
|
| 170 |
forward_row(dsq, gm, gxc, dpp, dpc, i); |
| 171 |
dpp = dpc; |
| 172 |
} |
| 173 |
|
| 174 |
gxc->M = M; |
| 175 |
gxc->L = L; |
| 176 |
gxc->R = gxc->Ra + gxc->Rb + gxc->Rc; |
| 177 |
if (opt_sc) *opt_sc = gxc->dp[gxc->R0+gxc->R-1][(M+1)*p7G_NSCELLS + p7GC_C] + gm->xsc[p7P_C][p7P_MOVE]; |
| 178 |
return eslOK; |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
static inline void |
| 188 |
backward_row(const ESL_DSQ *dsq, const P7_PROFILE *gm, P7_GMXCHK *gxc, const float *dpp, float *dpc, int i) |
| 189 |
{ |
| 190 |
const float * const tsc = gm->tsc; |
| 191 |
const float * const rsc = gm->rsc[dsq[i+1]]; |
| 192 |
int M = gm->M; |
| 193 |
float esc = p7_profile_IsLocal(gm) ? 0 : -eslINFINITY; |
| 194 |
int k; |
| 195 |
|
| 196 |
XMR(dpc,p7GC_C) = XMR(dpc,p7GC_CC) = XMR(dpp,p7GC_C) + gm->xsc[p7P_C][p7P_LOOP]; |
| 197 |
|
| 198 |
XMR(dpc,p7GC_B) = MMR(dpp,1) + TSC(p7P_BM,0) + MSC(1); |
| 199 |
for (k = 2; k <= M; k++) |
| 200 |
XMR(dpc,p7GC_B) = p7_FLogsum( XMR(dpc,p7GC_B), MMR(dpp,k) + TSC(p7P_BM,k-1) + MSC(k)); |
| 201 |
|
| 202 |
XMR(dpc,p7GC_J) = XMR(dpc,p7GC_JJ) = p7_FLogsum( XMR(dpp,p7GC_J) + gm->xsc[p7P_J][p7P_LOOP], XMR(dpc,p7GC_B) + gm->xsc[p7P_J][p7P_MOVE]); |
| 203 |
|
| 204 |
XMR(dpc,p7GC_N) = p7_FLogsum( XMR(dpp,p7GC_N) + gm->xsc[p7P_N][p7P_LOOP], XMR(dpc,p7GC_B) + gm->xsc[p7P_N][p7P_MOVE]); |
| 205 |
XMR(dpc,p7GC_E) = p7_FLogsum( XMR(dpc,p7GC_J) + gm->xsc[p7P_E][p7P_LOOP], XMR(dpc,p7GC_C) + gm->xsc[p7P_E][p7P_MOVE]); |
| 206 |
|
| 207 |
DMR(dpc,M) = XMR(dpc,p7GC_E); |
| 208 |
IMR(dpc,M) = -eslINFINITY; |
| 209 |
MMR(dpc,M) = XMR(dpc,p7GC_E); |
| 210 |
|
| 211 |
for (k = M-1; k >= 1; k--) |
| 212 |
{ |
| 213 |
DMR(dpc,k) = p7_FLogsum( p7_FLogsum( DMR(dpc, k+1) + TSC(p7P_DD,k), |
| 214 |
XMR(dpc, p7GC_E) + esc), |
| 215 |
MMR(dpp,k+1) + TSC(p7P_DM,k) + MSC(k+1)); |
| 216 |
|
| 217 |
IMR(dpc,k) = p7_FLogsum( MMR(dpp,k+1) + TSC(p7P_IM,k) + MSC(k+1), |
| 218 |
IMR(dpp,k) + TSC(p7P_II,k) + ISC(k)); |
| 219 |
|
| 220 |
MMR(dpc,k) = p7_FLogsum( p7_FLogsum(MMR(dpp,k+1) + TSC(p7P_MM,k) + MSC(k+1), |
| 221 |
IMR(dpp,k) + TSC(p7P_MI,k) + ISC(k)), |
| 222 |
p7_FLogsum(XMR(dpc,p7GC_E) + esc, |
| 223 |
DMR(dpc,k+1) + TSC(p7P_MD,k))); |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
int |
| 229 |
p7_GBackwardCheckpointed(const ESL_DSQ *dsq, int L, const P7_PROFILE *gm, P7_GMXCHK *gxc, P7_GBANDS *bnd, float *opt_sc) |
| 230 |
{ |
| 231 |
float const *tsc = gm->tsc; |
| 232 |
float const *rsc = NULL; |
| 233 |
int M = gm->M; |
| 234 |
float esc = p7_profile_IsLocal(gm) ? 0 : -eslINFINITY; |
| 235 |
float *fwd; |
| 236 |
float *bck; |
| 237 |
float *dpp; |
| 238 |
int i,i2,k,b,w,s; |
| 239 |
float overall_sc = gxc->dp[gxc->R0+gxc->R-1][(M+1)*p7G_NSCELLS + p7GC_C] + gm->xsc[p7P_C][p7P_MOVE]; |
| 240 |
|
| 241 |
#if eslDEBUGLEVEL > 0 |
| 242 |
if (gxc->do_debugging) p7_gmxchk_DumpHeader(gxc->dfp, gxc, 0, gxc->M, gxc->dbg_flags); |
| 243 |
#endif |
| 244 |
|
| 245 |
|
| 246 |
for (s = 0; s < p7G_NSCELLS; s++) gxc->dp[0][s] = gxc->dp[1][s] = -eslINFINITY; |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
i = L; |
| 254 |
gxc->R--; |
| 255 |
fwd = gxc->dp[gxc->R0+gxc->R]; |
| 256 |
bck = gxc->dp[L%2]; |
| 257 |
XMR(bck, p7GC_C) = gm->xsc[p7P_C][p7P_MOVE]; |
| 258 |
XMR(bck, p7GC_CC) = gm->xsc[p7P_C][p7P_MOVE]; |
| 259 |
XMR(bck, p7GC_B) = -eslINFINITY; |
| 260 |
XMR(bck, p7GC_J) = -eslINFINITY; |
| 261 |
XMR(bck, p7GC_JJ) = -eslINFINITY; |
| 262 |
XMR(bck, p7GC_N) = -eslINFINITY; |
| 263 |
XMR(bck, p7GC_E) = XMR(bck, p7GC_C) + gm->xsc[p7P_E][p7P_MOVE]; |
| 264 |
|
| 265 |
DMR(bck, M) = XMR(bck, p7GC_E); |
| 266 |
IMR(bck, M) = -eslINFINITY; |
| 267 |
MMR(bck, M) = XMR(bck, p7GC_E); |
| 268 |
|
| 269 |
for (k = M-1; k >= 1; k--) |
| 270 |
{ |
| 271 |
DMR(bck, k) = p7_FLogsum( XMR(bck, p7GC_E) + esc, |
| 272 |
DMR(bck, k+1) + TSC(p7P_DD, k)); |
| 273 |
IMR(bck, k) = -eslINFINITY; |
| 274 |
MMR(bck, k) = p7_FLogsum( XMR(bck, p7GC_E) + esc, |
| 275 |
DMR(bck, k+1) + TSC(p7P_MD, k)); |
| 276 |
} |
| 277 |
#if eslDEBUGLEVEL > 0 |
| 278 |
if (gxc->do_debugging) p7_gmxchk_DumpRow(gxc->dfp, gxc, bck, i, 0, gxc->M, gxc->dbg_flags); |
| 279 |
#endif |
| 280 |
posterior_decode_row(i, fwd, bck, M, overall_sc, bnd); |
| 281 |
i--; |
| 282 |
dpp = bck; |
| 283 |
|
| 284 |
|
| 285 |
if (gxc->Rb+gxc->Rc > 0) |
| 286 |
{ |
| 287 |
|
| 288 |
dpp = gxc->dp[gxc->R0+gxc->R-1]; |
| 289 |
fwd = gxc->dp[gxc->R0+gxc->R]; |
| 290 |
forward_row(dsq, gm, gxc, dpp, fwd, i); |
| 291 |
|
| 292 |
|
| 293 |
dpp = bck; |
| 294 |
bck = gxc->dp[(L-1)%2]; |
| 295 |
backward_row(dsq, gm, gxc, dpp, bck, i); |
| 296 |
#if eslDEBUGLEVEL > 0 |
| 297 |
if (gxc->do_debugging) p7_gmxchk_DumpRow(gxc->dfp, gxc, bck, i, 0, gxc->M, gxc->dbg_flags); |
| 298 |
#endif |
| 299 |
|
| 300 |
posterior_decode_row(i, fwd, bck, M, overall_sc, bnd); |
| 301 |
dpp = bck; |
| 302 |
i--; |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
for (b = 2; b <= gxc->Rb+gxc->Rc; b++) |
| 307 |
{ |
| 308 |
w = (b <= gxc->Rc ? b+1 : gxc->Lb); |
| 309 |
|
| 310 |
|
| 311 |
gxc->R--; |
| 312 |
fwd = gxc->dp[gxc->R0+gxc->R]; |
| 313 |
bck = gxc->dp[i%2]; |
| 314 |
backward_row(dsq, gm, gxc, dpp, bck, i); |
| 315 |
#if eslDEBUGLEVEL > 0 |
| 316 |
if (gxc->do_debugging) p7_gmxchk_DumpRow(gxc->dfp, gxc, bck, i, 0, gxc->M, gxc->dbg_flags); |
| 317 |
#endif |
| 318 |
posterior_decode_row(i, fwd, bck, M, overall_sc, bnd); |
| 319 |
|
| 320 |
|
| 321 |
dpp = gxc->dp[gxc->R0+gxc->R-1]; |
| 322 |
for (i2 = i-w+1; i2 <= i-1; i2++) |
| 323 |
{ |
| 324 |
fwd = gxc->dp[gxc->R0+gxc->R]; gxc->R++; |
| 325 |
forward_row(dsq, gm, gxc, dpp, fwd, i2); |
| 326 |
dpp = fwd; |
| 327 |
} |
| 328 |
|
| 329 |
|
| 330 |
dpp = bck; |
| 331 |
for (i2 = i-1; i2 >= i-w+1; i2--) |
| 332 |
{ |
| 333 |
gxc->R--; |
| 334 |
fwd = gxc->dp[gxc->R0+gxc->R]; |
| 335 |
bck = gxc->dp[i2%2]; |
| 336 |
|
| 337 |
backward_row(dsq, gm, gxc, dpp, bck, i2); |
| 338 |
#if eslDEBUGLEVEL > 0 |
| 339 |
if (gxc->do_debugging) p7_gmxchk_DumpRow(gxc->dfp, gxc, bck, i2, 0, gxc->M, gxc->dbg_flags); |
| 340 |
#endif |
| 341 |
|
| 342 |
posterior_decode_row(i2, fwd, bck, M, overall_sc, bnd); |
| 343 |
dpp = bck; |
| 344 |
} |
| 345 |
|
| 346 |
i -= w; |
| 347 |
} |
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
for (; i >= 1; i--) |
| 353 |
{ |
| 354 |
gxc->R--; |
| 355 |
fwd = gxc->dp[gxc->R0+gxc->R]; |
| 356 |
bck = gxc->dp[i%2]; |
| 357 |
|
| 358 |
backward_row(dsq, gm, gxc, dpp, bck, i); |
| 359 |
#if eslDEBUGLEVEL > 0 |
| 360 |
if (gxc->do_debugging) p7_gmxchk_DumpRow(gxc->dfp, gxc, bck, i, 0, gxc->M, gxc->dbg_flags); |
| 361 |
#endif |
| 362 |
posterior_decode_row(i, fwd, bck, M, overall_sc, bnd); |
| 363 |
|
| 364 |
dpp = bck; |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
bck = gxc->dp[0]; |
| 369 |
rsc = gm->rsc[dsq[1]]; |
| 370 |
XMR(bck,p7GC_B) = MMR(dpp,1) + TSC(p7P_BM,0) + MSC(1); |
| 371 |
for (k = 2; k <= M; k++) |
| 372 |
XMR(bck,p7GC_B) = p7_FLogsum(XMR(bck,p7GC_B), MMR(dpp,k) + TSC(p7P_BM,k-1) + MSC(k)); |
| 373 |
XMR(bck,p7GC_J) = -eslINFINITY; |
| 374 |
XMR(bck,p7GC_C) = -eslINFINITY; |
| 375 |
XMR(bck,p7GC_N) = p7_FLogsum( XMR(dpp, p7GC_N) + gm->xsc[p7P_N][p7P_LOOP], |
| 376 |
XMR(bck, p7GC_B) + gm->xsc[p7P_N][p7P_MOVE]); |
| 377 |
XMR(bck,p7GC_E) = -eslINFINITY; |
| 378 |
|
| 379 |
for (k = M; k >= 1; k--) |
| 380 |
MMR(bck,k) = IMR(bck,k) = DMR(bck,k) = -eslINFINITY; |
| 381 |
#if eslDEBUGLEVEL > 0 |
| 382 |
if (gxc->do_debugging) p7_gmxchk_DumpRow(gxc->dfp, gxc, bck, i, 0, gxc->M, gxc->dbg_flags); |
| 383 |
#endif |
| 384 |
|
| 385 |
bnd->L = L; |
| 386 |
bnd->M = M; |
| 387 |
p7_gbands_Reverse(bnd); |
| 388 |
if (opt_sc != NULL) *opt_sc = XMR(bck,p7GC_N); |
| 389 |
return eslOK; |
| 390 |
} |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
static inline void |
| 405 |
posterior_decode_row(int rowi, float *fwd, float *bck, int M, float overall_sc, P7_GBANDS *bnd) |
| 406 |
{ |
| 407 |
int k; |
| 408 |
int ka, kb; |
| 409 |
|
| 410 |
XMR(fwd, p7GC_N) = expf(XMR(fwd, p7GC_N) + XMR(bck, p7GC_N) - overall_sc); |
| 411 |
XMR(fwd, p7GC_JJ) = expf(XMR(fwd, p7GC_JJ) + XMR(bck, p7GC_JJ) - overall_sc); |
| 412 |
XMR(fwd, p7GC_CC) = expf(XMR(fwd, p7GC_CC) + XMR(bck, p7GC_CC) - overall_sc); |
| 413 |
|
| 414 |
if (XMR(fwd, p7GC_N) + XMR(fwd, p7GC_JJ) + XMR(fwd, p7GC_CC) >= 0.9) return; |
| 415 |
|
| 416 |
for (k = 1; k < M; k++) |
| 417 |
{ |
| 418 |
MMR(fwd, k) = expf(MMR(fwd,k) + MMR(bck,k) - overall_sc); |
| 419 |
IMR(fwd, k) = expf(IMR(fwd,k) + IMR(bck,k) - overall_sc); |
| 420 |
} |
| 421 |
MMR(fwd, M) = expf(MMR(fwd, M) + MMR(bck,M) - overall_sc); |
| 422 |
IMR(fwd, M) = 0.0f; |
| 423 |
|
| 424 |
for (ka = 1; ka <= M; ka++) if (MMR(fwd, ka) + IMR(fwd, ka) >= 0.02) break; |
| 425 |
if (ka == M+1) return; |
| 426 |
for (kb = M; kb >= 1; kb--) if (MMR(fwd, kb) + IMR(fwd, kb) >= 0.02) break; |
| 427 |
|
| 428 |
p7_gbands_Prepend(bnd, rowi, ka, kb); |
| 429 |
|
| 430 |
} |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
#ifdef p7GENERIC_FWDBACK_CHK_BENCHMARK |
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
#include <p7_config.h> |
| 443 |
|
| 444 |
#include "easel.h" |
| 445 |
#include "esl_alphabet.h" |
| 446 |
#include "esl_getopts.h" |
| 447 |
#include "esl_random.h" |
| 448 |
#include "esl_randomseq.h" |
| 449 |
#include "esl_stopwatch.h" |
| 450 |
|
| 451 |
#include "hmmer.h" |
| 452 |
#include "p7_gmxchk.h" |
| 453 |
|
| 454 |
static ESL_OPTIONS options[] = { |
| 455 |
|
| 456 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 457 |
{ "-s", eslARG_INT, "42", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 }, |
| 458 |
{ "-L", eslARG_INT, "400", NULL, "n>0", NULL, NULL, NULL, "length of random target seqs", 0 }, |
| 459 |
{ "-N", eslARG_INT, "2000", NULL, "n>0", NULL, NULL, NULL, "number of random target seqs", 0 }, |
| 460 |
{ "-F", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "only benchmark GForwardCheckpointed()", 0 }, |
| 461 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 462 |
}; |
| 463 |
static char usage[] = "[-options] <hmmfile>"; |
| 464 |
static char banner[] = "benchmark driver for checkpointed generic Forward/Backward"; |
| 465 |
|
| 466 |
int |
| 467 |
main(int argc, char **argv) |
| 468 |
{ |
| 469 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 1, argc, argv, banner, usage); |
| 470 |
char *hmmfile = esl_opt_GetArg(go, 1); |
| 471 |
ESL_STOPWATCH *w = esl_stopwatch_Create(); |
| 472 |
ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s")); |
| 473 |
ESL_ALPHABET *abc = NULL; |
| 474 |
P7_HMMFILE *hfp = NULL; |
| 475 |
P7_HMM *hmm = NULL; |
| 476 |
P7_BG *bg = NULL; |
| 477 |
P7_PROFILE *gm = NULL; |
| 478 |
P7_GMXCHK *gxc = NULL; |
| 479 |
P7_GBANDS *bnd = NULL; |
| 480 |
int L = esl_opt_GetInteger(go, "-L"); |
| 481 |
int N = esl_opt_GetInteger(go, "-N"); |
| 482 |
ESL_DSQ *dsq = malloc(sizeof(ESL_DSQ) * (L+2)); |
| 483 |
int i; |
| 484 |
float sc; |
| 485 |
double base_time, bench_time, Mcs; |
| 486 |
|
| 487 |
if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile); |
| 488 |
if (p7_hmmfile_Read(hfp, &abc, &hmm) != eslOK) p7_Fail("Failed to read HMM"); |
| 489 |
|
| 490 |
bg = p7_bg_Create(abc); |
| 491 |
p7_bg_SetLength(bg, L); |
| 492 |
gm = p7_profile_Create(hmm->M, abc); |
| 493 |
p7_ProfileConfig(hmm, bg, gm, L, p7_UNILOCAL); |
| 494 |
|
| 495 |
gxc = p7_gmxchk_Create(gm->M, L, ESL_MBYTES(32)); |
| 496 |
bnd = p7_gbands_Create(); |
| 497 |
|
| 498 |
|
| 499 |
esl_stopwatch_Start(w); |
| 500 |
for (i = 0; i < N; i++) esl_rsq_xfIID(r, bg->f, abc->K, L, dsq); |
| 501 |
esl_stopwatch_Stop(w); |
| 502 |
base_time = w->user; |
| 503 |
|
| 504 |
|
| 505 |
esl_stopwatch_Start(w); |
| 506 |
for (i = 0; i < N; i++) |
| 507 |
{ |
| 508 |
esl_rsq_xfIID(r, bg->f, abc->K, L, dsq); |
| 509 |
p7_GForwardCheckpointed (dsq, L, gm, gxc, &sc); |
| 510 |
if (! esl_opt_GetBoolean(go, "-F")) |
| 511 |
p7_GBackwardCheckpointed(dsq, L, gm, gxc, bnd, &sc); |
| 512 |
|
| 513 |
p7_gmxchk_Reuse(gxc); |
| 514 |
p7_gbands_Reuse(bnd); |
| 515 |
} |
| 516 |
esl_stopwatch_Stop(w); |
| 517 |
bench_time = w->user - base_time; |
| 518 |
Mcs = (double) N * (double) L * (double) gm->M * 1e-6 / (double) bench_time; |
| 519 |
esl_stopwatch_Display(stdout, w, "# CPU time: "); |
| 520 |
printf("# M = %d\n", gm->M); |
| 521 |
printf("# %.1f Mc/s\n", Mcs); |
| 522 |
|
| 523 |
free(dsq); |
| 524 |
p7_gmxchk_Destroy(gxc); |
| 525 |
p7_gbands_Destroy(bnd); |
| 526 |
p7_profile_Destroy(gm); |
| 527 |
p7_bg_Destroy(bg); |
| 528 |
p7_hmm_Destroy(hmm); |
| 529 |
p7_hmmfile_Close(hfp); |
| 530 |
esl_alphabet_Destroy(abc); |
| 531 |
esl_stopwatch_Destroy(w); |
| 532 |
esl_randomness_Destroy(r); |
| 533 |
esl_getopts_Destroy(go); |
| 534 |
return 0; |
| 535 |
} |
| 536 |
#endif |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
#ifdef p7GENERIC_FWDBACK_CHK_TESTDRIVE |
| 545 |
#include "esl_sq.h" |
| 546 |
#include "esl_randomseq.h" |
| 547 |
|
| 548 |
static void |
| 549 |
scoring_comparison(ESL_DSQ *dsq, int L, P7_PROFILE *gm, P7_GMX *gx, P7_GMXCHK *gxc, P7_GBANDS *bnd) |
| 550 |
{ |
| 551 |
char msg[] = "generic_fwdback_chk: score comparison test failure"; |
| 552 |
float tolerance = 0.01; |
| 553 |
float fsc1, fsc2; |
| 554 |
float bsc1, bsc2; |
| 555 |
|
| 556 |
if ( p7_gmx_GrowTo(gx, gm->M, L) != eslOK) esl_fatal(msg); |
| 557 |
if ( p7_gmxchk_GrowTo(gxc, gm->M, L) != eslOK) esl_fatal(msg); |
| 558 |
|
| 559 |
if ( p7_GForward(dsq, L, gm, gx, &fsc1) != eslOK) esl_fatal(msg); |
| 560 |
if ( p7_gmx_Reuse(gx) != eslOK) esl_fatal(msg); |
| 561 |
if ( p7_GBackward(dsq, L, gm, gx, &bsc1) != eslOK) esl_fatal(msg); |
| 562 |
if ( p7_GForwardCheckpointed (dsq, L, gm, gxc, &fsc2) != eslOK) esl_fatal(msg); |
| 563 |
if ( p7_GBackwardCheckpointed(dsq, L, gm, gxc, bnd, &bsc2) != eslOK) esl_fatal(msg); |
| 564 |
|
| 565 |
if ( fabs(fsc1-bsc1) > tolerance) esl_fatal(msg); |
| 566 |
if ( fabs(fsc1-fsc2) > tolerance) esl_fatal(msg); |
| 567 |
if ( fabs(bsc1-bsc2) > tolerance) esl_fatal(msg); |
| 568 |
|
| 569 |
if ( p7_gmx_Reuse(gx) != eslOK) esl_fatal(msg); |
| 570 |
if ( p7_gmxchk_Reuse(gxc) != eslOK) esl_fatal(msg); |
| 571 |
if ( p7_gbands_Reuse(bnd) != eslOK) esl_fatal(msg); |
| 572 |
} |
| 573 |
|
| 574 |
static void |
| 575 |
utest_randomseq(ESL_RANDOMNESS *rng, ESL_ALPHABET *abc, |
| 576 |
P7_PROFILE *gm, P7_BG *bg, int nseq, int L) |
| 577 |
{ |
| 578 |
char msg[] = "generic_fwdback_chk: random seq test failure"; |
| 579 |
ESL_DSQ *dsq = malloc(sizeof(ESL_DSQ) * (L+2)); |
| 580 |
P7_GMX *gx = p7_gmx_Create(gm->M, 100); |
| 581 |
P7_GMXCHK *gxc = p7_gmxchk_Create(gm->M, 100, ESL_MBYTES(32)); |
| 582 |
P7_GBANDS *bnd = p7_gbands_Create(); |
| 583 |
int idx; |
| 584 |
|
| 585 |
for (idx = 0; idx < nseq; idx++) |
| 586 |
{ |
| 587 |
if (esl_rsq_xfIID(rng, bg->f, abc->K, L, dsq) != eslOK) esl_fatal(msg); |
| 588 |
scoring_comparison(dsq, L, gm, gx, gxc, bnd); |
| 589 |
} |
| 590 |
|
| 591 |
p7_gmxchk_Destroy(gxc); |
| 592 |
p7_gmx_Destroy(gx); |
| 593 |
p7_gbands_Destroy(bnd); |
| 594 |
free(dsq); |
| 595 |
} |
| 596 |
|
| 597 |
static void |
| 598 |
utest_emitseq(ESL_RANDOMNESS *rng, ESL_ALPHABET *abc, |
| 599 |
P7_HMM *hmm, P7_PROFILE *gm, P7_BG *bg, int nseq) |
| 600 |
{ |
| 601 |
char msg[] = "generic_fwdback_chk: emitted seq test failure"; |
| 602 |
ESL_SQ *sq = esl_sq_CreateDigital(abc); |
| 603 |
P7_GMX *gx = p7_gmx_Create(gm->M, 100); |
| 604 |
P7_GMXCHK *gxc = p7_gmxchk_Create(gm->M, 100, ESL_MBYTES(32)); |
| 605 |
P7_GBANDS *bnd = p7_gbands_Create(); |
| 606 |
int idx; |
| 607 |
|
| 608 |
for (idx = 0; idx < nseq; idx++) |
| 609 |
{ |
| 610 |
if ( p7_ProfileEmit(rng, hmm, gm, bg, sq, NULL) != eslOK) esl_fatal(msg); |
| 611 |
|
| 612 |
scoring_comparison(sq->dsq, sq->n, gm, gx, gxc, bnd); |
| 613 |
} |
| 614 |
|
| 615 |
p7_gmxchk_Destroy(gxc); |
| 616 |
p7_gmx_Destroy(gx); |
| 617 |
p7_gbands_Destroy(bnd); |
| 618 |
esl_sq_Destroy(sq); |
| 619 |
} |
| 620 |
|
| 621 |
|
| 622 |
#endif |
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
#ifdef p7GENERIC_FWDBACK_CHK_TESTDRIVE |
| 631 |
|
| 632 |
#include <p7_config.h> |
| 633 |
#include "easel.h" |
| 634 |
#include "esl_getopts.h" |
| 635 |
|
| 636 |
#include "hmmer.h" |
| 637 |
#include "p7_gmxchk.h" |
| 638 |
|
| 639 |
static ESL_OPTIONS options[] = { |
| 640 |
|
| 641 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 642 |
{ "-s", eslARG_INT, "0", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 }, |
| 643 |
{ "-v", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "be verbose", 0 }, |
| 644 |
{ "--vv", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "be very verbose", 0 }, |
| 645 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 646 |
}; |
| 647 |
static char usage[] = "[-options]"; |
| 648 |
static char banner[] = "tests for generic checkpointed Forward/Backward implementation"; |
| 649 |
|
| 650 |
int |
| 651 |
main(int argc, char **argv) |
| 652 |
{ |
| 653 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 0, argc, argv, banner, usage); |
| 654 |
ESL_RANDOMNESS *rng = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s")); |
| 655 |
ESL_ALPHABET *abc = NULL; |
| 656 |
P7_HMM *hmm = NULL; |
| 657 |
P7_PROFILE *gm = NULL; |
| 658 |
P7_BG *bg = NULL; |
| 659 |
int M = 100; |
| 660 |
int L = 200; |
| 661 |
int nseq = 20; |
| 662 |
char errbuf[eslERRBUFSIZE]; |
| 663 |
|
| 664 |
p7_FLogsumInit(); |
| 665 |
|
| 666 |
if ((abc = esl_alphabet_Create(eslAMINO)) == NULL) esl_fatal("failed to create alphabet"); |
| 667 |
if (p7_hmm_Sample(rng, M, abc, &hmm) != eslOK) esl_fatal("failed to sample an HMM"); |
| 668 |
if ((bg = p7_bg_Create(abc)) == NULL) esl_fatal("failed to create null model"); |
| 669 |
if ((gm = p7_profile_Create(hmm->M, abc)) == NULL) esl_fatal("failed to create profile"); |
| 670 |
if (p7_ProfileConfig(hmm, bg, gm, L, p7_LOCAL) != eslOK) esl_fatal("failed to config profile"); |
| 671 |
if (p7_hmm_Validate (hmm, errbuf, 0.0001) != eslOK) esl_fatal("whoops, HMM is bad!: %s", errbuf); |
| 672 |
if (p7_profile_Validate(gm, errbuf, 0.0001) != eslOK) esl_fatal("whoops, profile is bad!: %s", errbuf); |
| 673 |
|
| 674 |
utest_randomseq(rng, abc, gm, bg, nseq, L); |
| 675 |
utest_emitseq (rng, abc, hmm, gm, bg, nseq); |
| 676 |
|
| 677 |
p7_profile_Destroy(gm); |
| 678 |
p7_bg_Destroy(bg); |
| 679 |
p7_hmm_Destroy(hmm); |
| 680 |
esl_alphabet_Destroy(abc); |
| 681 |
esl_randomness_Destroy(rng); |
| 682 |
esl_getopts_Destroy(go); |
| 683 |
return 0; |
| 684 |
} |
| 685 |
|
| 686 |
#endif |
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
#ifdef p7GENERIC_FWDBACK_CHK_EXAMPLE |
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
#include <p7_config.h> |
| 699 |
|
| 700 |
#include "easel.h" |
| 701 |
#include "esl_alphabet.h" |
| 702 |
#include "esl_getopts.h" |
| 703 |
#include "esl_sq.h" |
| 704 |
#include "esl_sqio.h" |
| 705 |
|
| 706 |
#include "hmmer.h" |
| 707 |
#include "p7_gmxchk.h" |
| 708 |
|
| 709 |
static ESL_OPTIONS options[] = { |
| 710 |
|
| 711 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 712 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 713 |
}; |
| 714 |
static char usage[] = "[-options] <hmmfile> <seqfile>"; |
| 715 |
static char banner[] = "example of checkpointed Forward/Backward, generic implementation"; |
| 716 |
|
| 717 |
int |
| 718 |
main(int argc, char **argv) |
| 719 |
{ |
| 720 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 2, argc, argv, banner, usage); |
| 721 |
char *hmmfile = esl_opt_GetArg(go, 1); |
| 722 |
char *seqfile = esl_opt_GetArg(go, 2); |
| 723 |
ESL_ALPHABET *abc = NULL; |
| 724 |
P7_HMMFILE *hfp = NULL; |
| 725 |
P7_HMM *hmm = NULL; |
| 726 |
P7_BG *bg = NULL; |
| 727 |
P7_PROFILE *gm = NULL; |
| 728 |
P7_GMX *fwd = NULL; |
| 729 |
P7_GMX *bck = NULL; |
| 730 |
P7_GMXCHK *gxc = NULL; |
| 731 |
P7_GBANDS *bnd = NULL; |
| 732 |
ESL_SQ *sq = NULL; |
| 733 |
ESL_SQFILE *sqfp = NULL; |
| 734 |
int format = eslSQFILE_UNKNOWN; |
| 735 |
float fsc, fsc2; |
| 736 |
float bsc, bsc2; |
| 737 |
float nullsc; |
| 738 |
int status; |
| 739 |
|
| 740 |
|
| 741 |
p7_FLogsumInit(); |
| 742 |
|
| 743 |
|
| 744 |
if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile); |
| 745 |
if (p7_hmmfile_Read(hfp, &abc, &hmm) != eslOK) p7_Fail("Failed to read HMM"); |
| 746 |
p7_hmmfile_Close(hfp); |
| 747 |
|
| 748 |
|
| 749 |
sq = esl_sq_CreateDigital(abc); |
| 750 |
status = esl_sqfile_Open(seqfile, format, NULL, &sqfp); |
| 751 |
if (status == eslENOTFOUND) p7_Fail("No such file, or file open failed"); |
| 752 |
else if (status == eslEFORMAT) p7_Fail("Format unrecognized."); |
| 753 |
else if (status != eslOK) p7_Fail("Open failed, code %d.", status); |
| 754 |
|
| 755 |
|
| 756 |
bg = p7_bg_Create(abc); |
| 757 |
gm = p7_profile_Create(hmm->M, abc); |
| 758 |
p7_ProfileConfig(hmm, bg, gm, 400, p7_LOCAL); |
| 759 |
|
| 760 |
|
| 761 |
fwd = p7_gmx_Create(gm->M, 400); |
| 762 |
bck = p7_gmx_Create(gm->M, 400); |
| 763 |
gxc = p7_gmxchk_Create(gm->M, 400, ESL_MBYTES(32)); |
| 764 |
bnd = p7_gbands_Create(); |
| 765 |
|
| 766 |
while ( (status = esl_sqio_Read(sqfp, sq)) != eslEOF) |
| 767 |
{ |
| 768 |
if (status == eslEFORMAT) p7_Fail("Parse failed (sequence file %s)\n%s\n", sqfp->filename, sqfp->get_error(sqfp)); |
| 769 |
else if (status != eslOK) p7_Fail("Unexpected error %d reading sequence file %s", status, sqfp->filename); |
| 770 |
|
| 771 |
|
| 772 |
p7_gmx_GrowTo (fwd, gm->M, sq->n); |
| 773 |
p7_gmx_GrowTo (bck, gm->M, sq->n); |
| 774 |
p7_gmxchk_GrowTo(gxc, gm->M, sq->n); |
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
p7_bg_SetLength(bg, sq->n); |
| 780 |
p7_ReconfigLength(gm, sq->n); |
| 781 |
|
| 782 |
|
| 783 |
p7_GForward (sq->dsq, sq->n, gm, fwd, &fsc); |
| 784 |
p7_GForwardCheckpointed(sq->dsq, sq->n, gm, gxc, &fsc2); |
| 785 |
|
| 786 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
p7_GBackward (sq->dsq, sq->n, gm, bck, &bsc); |
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
p7_GBackwardCheckpointed(sq->dsq, sq->n, gm, gxc, bnd, &bsc2); |
| 796 |
|
| 797 |
|
| 798 |
p7_gbands_Dump(stdout, bnd); |
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
p7_bg_NullOne(bg, sq->dsq, sq->n, &nullsc); |
| 804 |
|
| 805 |
printf("%-30s %10.4f %10.4f %10.4f %10.4f %10.4f %10.4f %10.4f %10.4f\n", |
| 806 |
sq->name, |
| 807 |
fsc, fsc2, |
| 808 |
(fsc - nullsc) / eslCONST_LOG2, (fsc2 - nullsc) / eslCONST_LOG2, |
| 809 |
bsc, bsc2, |
| 810 |
(bsc - nullsc) / eslCONST_LOG2, (bsc2 - nullsc) / eslCONST_LOG2); |
| 811 |
|
| 812 |
p7_gmx_Reuse(fwd); |
| 813 |
p7_gmx_Reuse(bck); |
| 814 |
p7_gmxchk_Reuse(gxc); |
| 815 |
p7_gbands_Reuse(bnd); |
| 816 |
esl_sq_Reuse(sq); |
| 817 |
} |
| 818 |
|
| 819 |
|
| 820 |
esl_sqfile_Close(sqfp); |
| 821 |
esl_sq_Destroy(sq); |
| 822 |
p7_gmx_Destroy(fwd); |
| 823 |
p7_gmx_Destroy(bck); |
| 824 |
p7_gmxchk_Destroy(gxc); |
| 825 |
p7_gbands_Destroy(bnd); |
| 826 |
p7_profile_Destroy(gm); |
| 827 |
p7_bg_Destroy(bg); |
| 828 |
p7_hmm_Destroy(hmm); |
| 829 |
esl_alphabet_Destroy(abc); |
| 830 |
esl_getopts_Destroy(go); |
| 831 |
return 0; |
| 832 |
} |
| 833 |
#endif |
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
|