| 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 <arm_neon.h> |
| 18 |
|
| 19 |
#include "easel.h" |
| 20 |
#include "esl_neon.h" |
| 21 |
#include "esl_vectorops.h" |
| 22 |
|
| 23 |
#include "hmmer.h" |
| 24 |
|
| 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 |
int |
| 57 |
p7_OptimalAccuracy(const P7_OPROFILE *om, const P7_OMX *pp, P7_OMX *ox, float *ret_e) |
| 58 |
{ |
| 59 |
register float32x4_t mpv, dpv, ipv; |
| 60 |
register float32x4_t sv; |
| 61 |
register float32x4_t xEv; |
| 62 |
register float32x4_t xBv; |
| 63 |
register float32x4_t dcv; |
| 64 |
float *xmx = ox->xmx; |
| 65 |
float32x4_t *dpc = ox->dpf[0]; |
| 66 |
float32x4_t *dpp; |
| 67 |
float32x4_t *ppp; |
| 68 |
float32x4_t *tp; |
| 69 |
float32x4_t zerov = vmovq_n_f32(0.0); |
| 70 |
float32x4_t infv = vmovq_n_f32(-eslINFINITY); |
| 71 |
int M = om->M; |
| 72 |
int Q = p7O_NQF(M); |
| 73 |
int q; |
| 74 |
int j; |
| 75 |
int i; |
| 76 |
float t1, t2; |
| 77 |
|
| 78 |
ox->M = om->M; |
| 79 |
ox->L = pp->L; |
| 80 |
for (q = 0; q < Q; q++) MMO(dpc, q) = IMO(dpc,q) = DMO(dpc,q) = infv; |
| 81 |
XMXo(0, p7X_E) = -eslINFINITY; |
| 82 |
XMXo(0, p7X_N) = 0.; |
| 83 |
XMXo(0, p7X_J) = -eslINFINITY; |
| 84 |
XMXo(0, p7X_B) = 0.; |
| 85 |
XMXo(0, p7X_C) = -eslINFINITY; |
| 86 |
|
| 87 |
for (i = 1; i <= pp->L; i++) |
| 88 |
{ |
| 89 |
dpp = dpc; |
| 90 |
dpc = ox->dpf[i]; |
| 91 |
ppp = pp->dpf[i]; |
| 92 |
tp = om->tfv; |
| 93 |
dcv = infv; |
| 94 |
xEv = infv; |
| 95 |
xBv = vmovq_n_f32(XMXo(i-1, p7X_B)); |
| 96 |
|
| 97 |
mpv = esl_neon_rightshift_float((esl_neon_128f_t) MMO(dpp,Q-1), (esl_neon_128f_t) infv).f32x4; |
| 98 |
dpv = esl_neon_rightshift_float((esl_neon_128f_t) DMO(dpp,Q-1), (esl_neon_128f_t) infv).f32x4; |
| 99 |
ipv = esl_neon_rightshift_float((esl_neon_128f_t) IMO(dpp,Q-1), (esl_neon_128f_t) infv).f32x4; |
| 100 |
for (q = 0; q < Q; q++) |
| 101 |
{ |
| 102 |
sv = vreinterpretq_f32_u32(vandq_u32(vcgtq_f32(*tp, zerov), vreinterpretq_u32_f32(xBv))); tp++; |
| 103 |
sv = vmaxq_f32(sv, vreinterpretq_f32_u32(vandq_u32(vcgtq_f32(*tp, zerov), vreinterpretq_u32_f32(mpv)))); tp++; |
| 104 |
sv = vmaxq_f32(sv, vreinterpretq_f32_u32(vandq_u32(vcgtq_f32(*tp, zerov), vreinterpretq_u32_f32(ipv)))); tp++; |
| 105 |
sv = vmaxq_f32(sv, vreinterpretq_f32_u32(vandq_u32(vcgtq_f32(*tp, zerov), vreinterpretq_u32_f32(dpv)))); tp++; |
| 106 |
sv = vaddq_f32(sv, *ppp); ppp += 2; |
| 107 |
xEv = vmaxq_f32(xEv, sv); |
| 108 |
|
| 109 |
mpv = MMO(dpp,q); |
| 110 |
dpv = DMO(dpp,q); |
| 111 |
ipv = IMO(dpp,q); |
| 112 |
|
| 113 |
MMO(dpc,q) = sv; |
| 114 |
DMO(dpc,q) = dcv; |
| 115 |
|
| 116 |
dcv = vreinterpretq_f32_u32(vandq_u32(vcgtq_f32(*tp, zerov), vreinterpretq_u32_f32(sv))); tp++; |
| 117 |
|
| 118 |
sv = vreinterpretq_f32_u32(vandq_u32(vcgtq_f32(*tp, zerov), vreinterpretq_u32_f32(mpv))); tp++; |
| 119 |
sv = vmaxq_f32(sv, vreinterpretq_f32_u32(vandq_u32(vcgtq_f32(*tp, zerov), vreinterpretq_u32_f32(ipv)))); tp++; |
| 120 |
IMO(dpc,q) = vaddq_f32(sv, *ppp); ppp++; |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
dcv = esl_neon_rightshift_float((esl_neon_128f_t) dcv, (esl_neon_128f_t) infv).f32x4; |
| 127 |
tp = om->tfv + 7*Q; |
| 128 |
for (q = 0; q < Q; q++) |
| 129 |
{ |
| 130 |
DMO(dpc, q) = vmaxq_f32(dcv, DMO(dpc, q)); |
| 131 |
dcv = vreinterpretq_f32_u32(vandq_u32(vcgtq_f32(*tp, zerov), vreinterpretq_u32_f32(DMO(dpc,q)))); tp++; |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
for (j = 1; j < 4; j++) |
| 136 |
{ |
| 137 |
dcv = esl_neon_rightshift_float((esl_neon_128f_t) dcv, (esl_neon_128f_t) infv).f32x4; |
| 138 |
tp = om->tfv + 7*Q; |
| 139 |
for (q = 0; q < Q; q++) |
| 140 |
{ |
| 141 |
DMO(dpc, q) = vmaxq_f32(dcv, DMO(dpc, q)); |
| 142 |
dcv = vreinterpretq_f32_u32(vandq_u32(vcgtq_f32(*tp, zerov), vreinterpretq_u32_f32(dcv))); tp++; |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
for (q = 0; q < Q; q++) xEv = vmaxq_f32(xEv, DMO(dpc,q)); |
| 148 |
|
| 149 |
|
| 150 |
XMXo(i,p7X_E) = esl_neon_hmax_f32((esl_neon_128f_t) xEv); |
| 151 |
|
| 152 |
t1 = ( (om->xf[p7O_J][p7O_LOOP] == 0.0) ? 0.0 : ox->xmx[(i-1)*p7X_NXCELLS+p7X_J] + pp->xmx[i*p7X_NXCELLS+p7X_J]); |
| 153 |
t2 = ( (om->xf[p7O_E][p7O_LOOP] == 0.0) ? 0.0 : ox->xmx[ i *p7X_NXCELLS+p7X_E]); |
| 154 |
ox->xmx[i*p7X_NXCELLS+p7X_J] = ESL_MAX(t1, t2); |
| 155 |
|
| 156 |
t1 = ( (om->xf[p7O_C][p7O_LOOP] == 0.0) ? 0.0 : ox->xmx[(i-1)*p7X_NXCELLS+p7X_C] + pp->xmx[i*p7X_NXCELLS+p7X_C]); |
| 157 |
t2 = ( (om->xf[p7O_E][p7O_MOVE] == 0.0) ? 0.0 : ox->xmx[ i *p7X_NXCELLS+p7X_E]); |
| 158 |
ox->xmx[i*p7X_NXCELLS+p7X_C] = ESL_MAX(t1, t2); |
| 159 |
|
| 160 |
ox->xmx[i*p7X_NXCELLS+p7X_N] = ((om->xf[p7O_N][p7O_LOOP] == 0.0) ? 0.0 : ox->xmx[(i-1)*p7X_NXCELLS+p7X_N] + pp->xmx[i*p7X_NXCELLS+p7X_N]); |
| 161 |
|
| 162 |
t1 = ( (om->xf[p7O_N][p7O_MOVE] == 0.0) ? 0.0 : ox->xmx[i*p7X_NXCELLS+p7X_N]); |
| 163 |
t2 = ( (om->xf[p7O_J][p7O_MOVE] == 0.0) ? 0.0 : ox->xmx[i*p7X_NXCELLS+p7X_J]); |
| 164 |
ox->xmx[i*p7X_NXCELLS+p7X_B] = ESL_MAX(t1, t2); |
| 165 |
} |
| 166 |
|
| 167 |
*ret_e = ox->xmx[pp->L*p7X_NXCELLS+p7X_C]; |
| 168 |
return eslOK; |
| 169 |
} |
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
static inline float get_postprob(const P7_OMX *pp, int scur, int sprv, int k, int i); |
| 181 |
|
| 182 |
static inline int select_m(const P7_OPROFILE *om, const P7_OMX *ox, int i, int k); |
| 183 |
static inline int select_d(const P7_OPROFILE *om, const P7_OMX *ox, int i, int k); |
| 184 |
static inline int select_i(const P7_OPROFILE *om, const P7_OMX *ox, int i, int k); |
| 185 |
static inline int select_n(int i); |
| 186 |
static inline int select_c(const P7_OPROFILE *om, const P7_OMX *pp, const P7_OMX *ox, int i); |
| 187 |
static inline int select_j(const P7_OPROFILE *om, const P7_OMX *pp, const P7_OMX *ox, int i); |
| 188 |
static inline int select_e(const P7_OPROFILE *om, const P7_OMX *ox, int i, int *ret_k); |
| 189 |
static inline int select_b(const P7_OPROFILE *om, const P7_OMX *ox, int i); |
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
int |
| 224 |
p7_OATrace(const P7_OPROFILE *om, const P7_OMX *pp, const P7_OMX *ox, P7_TRACE *tr) |
| 225 |
{ |
| 226 |
int i = ox->L; |
| 227 |
int k = 0; |
| 228 |
int s0, s1; |
| 229 |
float postprob; |
| 230 |
int status; |
| 231 |
|
| 232 |
if (tr->N != 0) ESL_EXCEPTION(eslEINVAL, "trace not empty; needs to be Reuse()'d?"); |
| 233 |
|
| 234 |
if ((status = p7_trace_AppendWithPP(tr, p7T_T, k, i, 0.0)) != eslOK) return status; |
| 235 |
if ((status = p7_trace_AppendWithPP(tr, p7T_C, k, i, 0.0)) != eslOK) return status; |
| 236 |
|
| 237 |
s0 = tr->st[tr->N-1]; |
| 238 |
while (s0 != p7T_S) |
| 239 |
{ |
| 240 |
switch (s0) { |
| 241 |
case p7T_M: s1 = select_m(om, ox, i, k); k--; i--; break; |
| 242 |
case p7T_D: s1 = select_d(om, ox, i, k); k--; break; |
| 243 |
case p7T_I: s1 = select_i(om, ox, i, k); i--; break; |
| 244 |
case p7T_N: s1 = select_n(i); break; |
| 245 |
case p7T_C: s1 = select_c(om, pp, ox, i); break; |
| 246 |
case p7T_J: s1 = select_j(om, pp, ox, i); break; |
| 247 |
case p7T_E: s1 = select_e(om, ox, i, &k); break; |
| 248 |
case p7T_B: s1 = select_b(om, ox, i); break; |
| 249 |
default: ESL_EXCEPTION(eslEINVAL, "bogus state in traceback"); |
| 250 |
} |
| 251 |
if (s1 == -1) ESL_EXCEPTION(eslEINVAL, "OA traceback choice failed"); |
| 252 |
|
| 253 |
postprob = get_postprob(pp, s1, s0, k, i); |
| 254 |
if ((status = p7_trace_AppendWithPP(tr, s1, k, i, postprob)) != eslOK) return status; |
| 255 |
|
| 256 |
if ( (s1 == p7T_N || s1 == p7T_J || s1 == p7T_C) && s1 == s0) i--; |
| 257 |
s0 = s1; |
| 258 |
} |
| 259 |
tr->M = om->M; |
| 260 |
tr->L = ox->L; |
| 261 |
return p7_trace_Reverse(tr); |
| 262 |
} |
| 263 |
|
| 264 |
static inline float |
| 265 |
get_postprob(const P7_OMX *pp, int scur, int sprv, int k, int i) |
| 266 |
{ |
| 267 |
int Q = p7O_NQF(pp->M); |
| 268 |
int q = (k-1) % Q; |
| 269 |
int r = (k-1) / Q; |
| 270 |
union { float32x4_t v; float p[4]; } u; |
| 271 |
|
| 272 |
switch (scur) { |
| 273 |
case p7T_M: u.v = MMO(pp->dpf[i], q); return u.p[r]; |
| 274 |
case p7T_I: u.v = IMO(pp->dpf[i], q); return u.p[r]; |
| 275 |
case p7T_N: if (sprv == scur) return pp->xmx[i*p7X_NXCELLS+p7X_N]; |
| 276 |
case p7T_C: if (sprv == scur) return pp->xmx[i*p7X_NXCELLS+p7X_C]; |
| 277 |
case p7T_J: if (sprv == scur) return pp->xmx[i*p7X_NXCELLS+p7X_J]; |
| 278 |
default: return 0.0; |
| 279 |
} |
| 280 |
} |
| 281 |
|
| 282 |
|
| 283 |
static inline int |
| 284 |
select_m(const P7_OPROFILE *om, const P7_OMX *ox, int i, int k) |
| 285 |
{ |
| 286 |
int Q = p7O_NQF(ox->M); |
| 287 |
int q = (k-1) % Q; |
| 288 |
int r = (k-1) / Q; |
| 289 |
float32x4_t *tp = om->tfv + 7*q; |
| 290 |
float32x4_t xBv = vmovq_n_f32(ox->xmx[(i-1)*p7X_NXCELLS+p7X_B]); |
| 291 |
float32x4_t zerov = vmovq_n_f32(0.0); |
| 292 |
float32x4_t mpv, dpv, ipv; |
| 293 |
union { float32x4_t v; float p[4]; } u, tv; |
| 294 |
float path[4]; |
| 295 |
int state[4] = { p7T_M, p7T_I, p7T_D, p7T_B }; |
| 296 |
|
| 297 |
if (q > 0) { |
| 298 |
mpv = ox->dpf[i-1][(q-1)*3 + p7X_M]; |
| 299 |
dpv = ox->dpf[i-1][(q-1)*3 + p7X_D]; |
| 300 |
ipv = ox->dpf[i-1][(q-1)*3 + p7X_I]; |
| 301 |
} else { |
| 302 |
mpv = esl_neon_rightshift_float((esl_neon_128f_t) ox->dpf[i-1][(Q-1)*3 + p7X_M], (esl_neon_128f_t) zerov).f32x4; |
| 303 |
dpv = esl_neon_rightshift_float((esl_neon_128f_t) ox->dpf[i-1][(Q-1)*3 + p7X_D], (esl_neon_128f_t) zerov).f32x4; |
| 304 |
ipv = esl_neon_rightshift_float((esl_neon_128f_t) ox->dpf[i-1][(Q-1)*3 + p7X_I], (esl_neon_128f_t) zerov).f32x4; |
| 305 |
} |
| 306 |
|
| 307 |
|
| 308 |
u.v = xBv; tv.v = *tp; path[3] = ((tv.p[r] == 0.0) ? -eslINFINITY : u.p[r]); tp++; |
| 309 |
u.v = mpv; tv.v = *tp; path[0] = ((tv.p[r] == 0.0) ? -eslINFINITY : u.p[r]); tp++; |
| 310 |
u.v = ipv; tv.v = *tp; path[1] = ((tv.p[r] == 0.0) ? -eslINFINITY : u.p[r]); tp++; |
| 311 |
u.v = dpv; tv.v = *tp; path[2] = ((tv.p[r] == 0.0) ? -eslINFINITY : u.p[r]); |
| 312 |
return state[esl_vec_FArgMax(path, 4)]; |
| 313 |
} |
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
static inline int |
| 318 |
select_d(const P7_OPROFILE *om, const P7_OMX *ox, int i, int k) |
| 319 |
{ |
| 320 |
int Q = p7O_NQF(ox->M); |
| 321 |
int q = (k-1) % Q; |
| 322 |
int r = (k-1) / Q; |
| 323 |
float32x4_t zerov = vmovq_n_f32(0.0); |
| 324 |
union { float32x4_t v; float p[4]; } mpv, dpv, tmdv, tddv; |
| 325 |
float path[2]; |
| 326 |
|
| 327 |
if (q > 0) { |
| 328 |
mpv.v = ox->dpf[i][(q-1)*3 + p7X_M]; |
| 329 |
dpv.v = ox->dpf[i][(q-1)*3 + p7X_D]; |
| 330 |
tmdv.v = om->tfv[7*(q-1) + p7O_MD]; |
| 331 |
tddv.v = om->tfv[7*Q + (q-1)]; |
| 332 |
} else { |
| 333 |
mpv.v = esl_neon_rightshift_float((esl_neon_128f_t) ox->dpf[i][(Q-1)*3 + p7X_M], (esl_neon_128f_t) zerov).f32x4; |
| 334 |
dpv.v = esl_neon_rightshift_float((esl_neon_128f_t) ox->dpf[i][(Q-1)*3 + p7X_D], (esl_neon_128f_t) zerov).f32x4; |
| 335 |
tmdv.v = esl_neon_rightshift_float((esl_neon_128f_t) om->tfv[7*(Q-1) + p7O_MD], (esl_neon_128f_t) zerov).f32x4; |
| 336 |
tddv.v = esl_neon_rightshift_float((esl_neon_128f_t) om->tfv[8*Q-1], (esl_neon_128f_t) zerov).f32x4; |
| 337 |
} |
| 338 |
|
| 339 |
path[0] = ((tmdv.p[r] == 0.0) ? -eslINFINITY : mpv.p[r]); |
| 340 |
path[1] = ((tddv.p[r] == 0.0) ? -eslINFINITY : dpv.p[r]); |
| 341 |
return ((path[0] >= path[1]) ? p7T_M : p7T_D); |
| 342 |
} |
| 343 |
|
| 344 |
|
| 345 |
static inline int |
| 346 |
select_i(const P7_OPROFILE *om, const P7_OMX *ox, int i, int k) |
| 347 |
{ |
| 348 |
int Q = p7O_NQF(ox->M); |
| 349 |
int q = (k-1) % Q; |
| 350 |
int r = (k-1) / Q; |
| 351 |
float32x4_t *tp = om->tfv + 7*q + p7O_MI; |
| 352 |
union { float32x4_t v; float p[4]; } tv, mpv, ipv; |
| 353 |
float path[2]; |
| 354 |
|
| 355 |
mpv.v = ox->dpf[i-1][q*3 + p7X_M]; tv.v = *tp; path[0] = ((tv.p[r] == 0.0) ? -eslINFINITY : mpv.p[r]); tp++; |
| 356 |
ipv.v = ox->dpf[i-1][q*3 + p7X_I]; tv.v = *tp; path[1] = ((tv.p[r] == 0.0) ? -eslINFINITY : ipv.p[r]); |
| 357 |
return ((path[0] >= path[1]) ? p7T_M : p7T_I); |
| 358 |
} |
| 359 |
|
| 360 |
|
| 361 |
static inline int |
| 362 |
select_n(int i) |
| 363 |
{ |
| 364 |
return ((i==0) ? p7T_S : p7T_N); |
| 365 |
} |
| 366 |
|
| 367 |
|
| 368 |
static inline int |
| 369 |
select_c(const P7_OPROFILE *om, const P7_OMX *pp, const P7_OMX *ox, int i) |
| 370 |
{ |
| 371 |
float path[2]; |
| 372 |
path[0] = ( (om->xf[p7O_C][p7O_LOOP] == 0.0) ? -eslINFINITY : ox->xmx[(i-1)*p7X_NXCELLS+p7X_C] + pp->xmx[i*p7X_NXCELLS+p7X_C]); |
| 373 |
path[1] = ( (om->xf[p7O_E][p7O_MOVE] == 0.0) ? -eslINFINITY : ox->xmx[ i *p7X_NXCELLS+p7X_E]); |
| 374 |
return ((path[0] > path[1]) ? p7T_C : p7T_E); |
| 375 |
} |
| 376 |
|
| 377 |
|
| 378 |
static inline int |
| 379 |
select_j(const P7_OPROFILE *om, const P7_OMX *pp, const P7_OMX *ox, int i) |
| 380 |
{ |
| 381 |
float path[2]; |
| 382 |
|
| 383 |
path[0] = ( (om->xf[p7O_J][p7O_LOOP] == 0.0) ? -eslINFINITY : ox->xmx[(i-1)*p7X_NXCELLS+p7X_J] + pp->xmx[i*p7X_NXCELLS+p7X_J]); |
| 384 |
path[1] = ( (om->xf[p7O_E][p7O_LOOP] == 0.0) ? -eslINFINITY : ox->xmx[ i *p7X_NXCELLS+p7X_E]); |
| 385 |
return ((path[0] > path[1]) ? p7T_J : p7T_E); |
| 386 |
} |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
static inline int |
| 391 |
select_e(const P7_OPROFILE *om, const P7_OMX *ox, int i, int *ret_k) |
| 392 |
{ |
| 393 |
int Q = p7O_NQF(ox->M); |
| 394 |
float32x4_t *dp = ox->dpf[i]; |
| 395 |
union { float32x4_t v; float p[4]; } u; |
| 396 |
float max = -eslINFINITY; |
| 397 |
int smax, kmax; |
| 398 |
int q,r; |
| 399 |
|
| 400 |
|
| 401 |
for (q = 0; q < Q; q++) |
| 402 |
{ |
| 403 |
u.v = *dp; dp++; for (r = 0; r < 4; r++) if (u.p[r] >= max) { max = u.p[r]; smax = p7T_M; kmax = r*Q + q + 1; } |
| 404 |
u.v = *dp; dp+=2; for (r = 0; r < 4; r++) if (u.p[r] > max) { max = u.p[r]; smax = p7T_D; kmax = r*Q + q + 1; } |
| 405 |
} |
| 406 |
*ret_k = kmax; |
| 407 |
return smax; |
| 408 |
} |
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
static inline int |
| 413 |
select_b(const P7_OPROFILE *om, const P7_OMX *ox, int i) |
| 414 |
{ |
| 415 |
float path[2]; |
| 416 |
|
| 417 |
path[0] = ( (om->xf[p7O_N][p7O_MOVE] == 0.0) ? -eslINFINITY : ox->xmx[i*p7X_NXCELLS+p7X_N]); |
| 418 |
path[1] = ( (om->xf[p7O_J][p7O_MOVE] == 0.0) ? -eslINFINITY : ox->xmx[i*p7X_NXCELLS+p7X_J]); |
| 419 |
return ((path[0] > path[1]) ? p7T_N : p7T_J); |
| 420 |
} |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
#ifdef p7OPTACC_BENCHMARK |
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 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 "impl_neon.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 |
{ "-c", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "-x", "compare scores to generic implementation (debug)", 0 }, |
| 458 |
{ "-s", eslARG_INT, "42", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 }, |
| 459 |
{ "-x", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "-c", "equate scores to trusted implementation (debug)", 0 }, |
| 460 |
{ "-L", eslARG_INT, "400", NULL, "n>0", NULL, NULL, NULL, "length of random target seqs", 0 }, |
| 461 |
{ "-N", eslARG_INT, "50000", NULL, "n>0", NULL, NULL, NULL, "number of random target seqs", 0 }, |
| 462 |
{ "--notrace", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "only benchmark the DP fill stage", 0 }, |
| 463 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 464 |
}; |
| 465 |
static char usage[] = "[-options] <hmmfile>"; |
| 466 |
static char banner[] = "benchmark driver for optimal accuracy alignment, NEON version"; |
| 467 |
|
| 468 |
int |
| 469 |
main(int argc, char **argv) |
| 470 |
{ |
| 471 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 1, argc, argv, banner, usage); |
| 472 |
char *hmmfile = esl_opt_GetArg(go, 1); |
| 473 |
ESL_STOPWATCH *w = esl_stopwatch_Create(); |
| 474 |
ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s")); |
| 475 |
ESL_ALPHABET *abc = NULL; |
| 476 |
P7_HMMFILE *hfp = NULL; |
| 477 |
P7_HMM *hmm = NULL; |
| 478 |
P7_BG *bg = NULL; |
| 479 |
P7_PROFILE *gm = NULL; |
| 480 |
P7_OPROFILE *om = NULL; |
| 481 |
P7_GMX *gx1 = NULL; |
| 482 |
P7_GMX *gx2 = NULL; |
| 483 |
P7_OMX *ox1 = NULL; |
| 484 |
P7_OMX *ox2 = NULL; |
| 485 |
P7_TRACE *tr = NULL; |
| 486 |
int L = esl_opt_GetInteger(go, "-L"); |
| 487 |
int N = esl_opt_GetInteger(go, "-N"); |
| 488 |
ESL_DSQ *dsq = malloc(sizeof(ESL_DSQ) * (L+2)); |
| 489 |
int i; |
| 490 |
float fsc, bsc, accscore; |
| 491 |
float fsc_g, bsc_g, accscore_g; |
| 492 |
double Mcs; |
| 493 |
|
| 494 |
p7_FLogsumInit(); |
| 495 |
|
| 496 |
if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile); |
| 497 |
if (p7_hmmfile_Read(hfp, &abc, &hmm) != eslOK) p7_Fail("Failed to read HMM"); |
| 498 |
|
| 499 |
bg = p7_bg_Create(abc); p7_bg_SetLength(bg, L); |
| 500 |
gm = p7_profile_Create(hmm->M, abc); p7_ProfileConfig(hmm, bg, gm, L, p7_LOCAL); |
| 501 |
om = p7_oprofile_Create(gm->M, abc); p7_oprofile_Convert(gm, om); |
| 502 |
p7_oprofile_ReconfigLength(om, L); |
| 503 |
|
| 504 |
if (esl_opt_GetBoolean(go, "-x") && p7_FLogsumError(-0.4, -0.5) > 0.0001) |
| 505 |
p7_Fail("-x here requires p7_Logsum() recompiled in slow exact mode"); |
| 506 |
|
| 507 |
ox1 = p7_omx_Create(gm->M, L, L); |
| 508 |
ox2 = p7_omx_Create(gm->M, L, L); |
| 509 |
tr = p7_trace_CreateWithPP(); |
| 510 |
|
| 511 |
esl_rsq_xfIID(r, bg->f, abc->K, L, dsq); |
| 512 |
p7_Forward (dsq, L, om, ox1, &fsc); |
| 513 |
p7_Backward(dsq, L, om, ox1, ox2, &bsc); |
| 514 |
p7_Decoding(om, ox1, ox2, ox2); |
| 515 |
|
| 516 |
esl_stopwatch_Start(w); |
| 517 |
for (i = 0; i < N; i++) |
| 518 |
{ |
| 519 |
p7_OptimalAccuracy(om, ox2, ox1, &accscore); |
| 520 |
|
| 521 |
if (! esl_opt_GetBoolean(go, "--notrace")) |
| 522 |
{ |
| 523 |
p7_OATrace(om, ox2, ox1, tr); |
| 524 |
p7_trace_Reuse(tr); |
| 525 |
} |
| 526 |
} |
| 527 |
esl_stopwatch_Stop(w); |
| 528 |
|
| 529 |
Mcs = (double) N * (double) L * (double) gm->M * 1e-6 / (double) w->user; |
| 530 |
esl_stopwatch_Display(stdout, w, "# CPU time: "); |
| 531 |
printf("# M = %d\n", gm->M); |
| 532 |
printf("# %.1f Mc/s\n", Mcs); |
| 533 |
|
| 534 |
if (esl_opt_GetBoolean(go, "-c") || esl_opt_GetBoolean(go, "-x") ) |
| 535 |
{ |
| 536 |
gx1 = p7_gmx_Create(gm->M, L); |
| 537 |
gx2 = p7_gmx_Create(gm->M, L); |
| 538 |
|
| 539 |
p7_GForward (dsq, L, gm, gx1, &fsc_g); |
| 540 |
p7_GBackward(dsq, L, gm, gx2, &bsc_g); |
| 541 |
p7_GDecoding(gm, gx1, gx2, gx2); |
| 542 |
p7_GOptimalAccuracy(gm, gx2, gx1, &accscore_g); |
| 543 |
|
| 544 |
printf("generic: fwd=%8.4f bck=%8.4f acc=%8.4f\n", fsc_g, bsc_g, accscore_g); |
| 545 |
printf("NEON: fwd=%8.4f bck=%8.4f acc=%8.4f\n", fsc, bsc, accscore); |
| 546 |
|
| 547 |
p7_gmx_Destroy(gx1); |
| 548 |
p7_gmx_Destroy(gx2); |
| 549 |
} |
| 550 |
|
| 551 |
free(dsq); |
| 552 |
p7_omx_Destroy(ox1); |
| 553 |
p7_omx_Destroy(ox2); |
| 554 |
p7_trace_Destroy(tr); |
| 555 |
p7_oprofile_Destroy(om); |
| 556 |
p7_profile_Destroy(gm); |
| 557 |
p7_bg_Destroy(bg); |
| 558 |
p7_hmm_Destroy(hmm); |
| 559 |
p7_hmmfile_Close(hfp); |
| 560 |
esl_alphabet_Destroy(abc); |
| 561 |
esl_stopwatch_Destroy(w); |
| 562 |
esl_randomness_Destroy(r); |
| 563 |
esl_getopts_Destroy(go); |
| 564 |
return 0; |
| 565 |
} |
| 566 |
#endif |
| 567 |
|
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
#ifdef p7OPTACC_TESTDRIVE |
| 576 |
#include "esl_alphabet.h" |
| 577 |
#include "esl_getopts.h" |
| 578 |
#include "esl_random.h" |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
static void |
| 594 |
utest_optacc(ESL_GETOPTS *go, ESL_RANDOMNESS *r, ESL_ALPHABET *abc, P7_BG *bg, int M, int L, int N) |
| 595 |
{ |
| 596 |
char *msg = "optimal accuracy unit test failed"; |
| 597 |
P7_HMM *hmm = NULL; |
| 598 |
P7_PROFILE *gm = NULL; |
| 599 |
P7_OPROFILE *om = NULL; |
| 600 |
ESL_SQ *sq = esl_sq_CreateDigital(abc); |
| 601 |
P7_OMX *ox1 = p7_omx_Create(M, L, L); |
| 602 |
P7_OMX *ox2 = p7_omx_Create(M, L, L); |
| 603 |
P7_GMX *gx1 = p7_gmx_Create(M, L); |
| 604 |
P7_GMX *gx2 = p7_gmx_Create(M, L); |
| 605 |
P7_TRACE *tr = p7_trace_CreateWithPP(); |
| 606 |
P7_TRACE *trg = p7_trace_CreateWithPP(); |
| 607 |
P7_TRACE *tro = p7_trace_CreateWithPP(); |
| 608 |
float accscore_o; |
| 609 |
float fsc, bsc, accscore; |
| 610 |
float fsc_g, bsc_g, accscore_g, accscore_g2; |
| 611 |
float pptol = 0.01; |
| 612 |
float sctol = 0.001; |
| 613 |
float gtol; |
| 614 |
|
| 615 |
p7_FLogsumInit(); |
| 616 |
gtol = ( (p7_FLogsumError(-0.4, -0.5) > 0.0001) ? 0.1 : 0.001); |
| 617 |
|
| 618 |
if (p7_oprofile_Sample(r, abc, bg, M, L, &hmm, &gm, &om)!= eslOK) esl_fatal(msg); |
| 619 |
while (N--) |
| 620 |
{ |
| 621 |
if (p7_ProfileEmit(r, hmm, gm, bg, sq, tro) != eslOK) esl_fatal(msg); |
| 622 |
|
| 623 |
if (p7_omx_GrowTo(ox1, M, sq->n, sq->n) != eslOK) esl_fatal(msg); |
| 624 |
if (p7_omx_GrowTo(ox2, M, sq->n, sq->n) != eslOK) esl_fatal(msg); |
| 625 |
if (p7_gmx_GrowTo(gx1, M, sq->n) != eslOK) esl_fatal(msg); |
| 626 |
if (p7_gmx_GrowTo(gx2, M, sq->n) != eslOK) esl_fatal(msg); |
| 627 |
|
| 628 |
if (p7_Forward (sq->dsq, sq->n, om, ox1, &fsc) != eslOK) esl_fatal(msg); |
| 629 |
if (p7_Backward(sq->dsq, sq->n, om, ox1, ox2, &bsc) != eslOK) esl_fatal(msg); |
| 630 |
if (p7_Decoding(om, ox1, ox2, ox2) != eslOK) esl_fatal(msg); |
| 631 |
if (p7_OptimalAccuracy(om, ox2, ox1, &accscore) != eslOK) esl_fatal(msg); |
| 632 |
|
| 633 |
#if 0 |
| 634 |
p7_omx_FDeconvert(ox1, gx1); |
| 635 |
p7_gmx_Dump(stdout, gx1, p7_DEFAULT); |
| 636 |
p7_omx_FDeconvert(ox2, gx1); |
| 637 |
p7_gmx_Dump(stdout, gx1, p7_DEFAULT); |
| 638 |
#endif |
| 639 |
if (p7_OATrace(om, ox2, ox1, tr) != eslOK) esl_fatal(msg); |
| 640 |
|
| 641 |
if (p7_GForward (sq->dsq, sq->n, gm, gx1, &fsc_g) != eslOK) esl_fatal(msg); |
| 642 |
if (p7_GBackward(sq->dsq, sq->n, gm, gx2, &bsc_g) != eslOK) esl_fatal(msg); |
| 643 |
|
| 644 |
#if 0 |
| 645 |
p7_gmx_Dump(stdout, gx1, p7_DEFAULT); |
| 646 |
p7_gmx_Dump(stdout, gx2, p7_DEFAULT); |
| 647 |
#endif |
| 648 |
|
| 649 |
if (p7_GDecoding(gm, gx1, gx2, gx2) != eslOK) esl_fatal(msg); |
| 650 |
if (p7_GOptimalAccuracy(gm, gx2, gx1, &accscore_g) != eslOK) esl_fatal(msg); |
| 651 |
|
| 652 |
#if 0 |
| 653 |
p7_gmx_Dump(stdout, gx1, p7_DEFAULT); |
| 654 |
p7_gmx_Dump(stdout, gx2, p7_DEFAULT); |
| 655 |
#endif |
| 656 |
if (p7_GOATrace(gm, gx2, gx1, trg) != eslOK) esl_fatal(msg); |
| 657 |
|
| 658 |
if (p7_trace_SetPP(tro, gx2) != eslOK) esl_fatal(msg); |
| 659 |
|
| 660 |
if (esl_opt_GetBoolean(go, "--traces")) |
| 661 |
{ |
| 662 |
p7_trace_Dump(stdout, tro, gm, sq->dsq); |
| 663 |
p7_trace_Dump(stdout, tr, gm, sq->dsq); |
| 664 |
p7_trace_Dump(stdout, trg, gm, sq->dsq); |
| 665 |
} |
| 666 |
|
| 667 |
if (p7_trace_Validate(tr, abc, sq->dsq, NULL) != eslOK) esl_fatal(msg); |
| 668 |
if (p7_trace_Validate(trg, abc, sq->dsq, NULL) != eslOK) esl_fatal(msg); |
| 669 |
if (p7_trace_Compare(tr, trg, pptol) != eslOK) esl_fatal(msg); |
| 670 |
|
| 671 |
accscore_o = p7_trace_GetExpectedAccuracy(tro); |
| 672 |
accscore_g2 = p7_trace_GetExpectedAccuracy(trg); |
| 673 |
|
| 674 |
#if 0 |
| 675 |
printf("%f %f %f %f\n", accscore, accscore_g, accscore_g2, accscore_o); |
| 676 |
#endif |
| 677 |
|
| 678 |
if (esl_FCompare_old(fsc, bsc, sctol) != eslOK) esl_fatal(msg); |
| 679 |
if (esl_FCompare_old(fsc_g, bsc_g, gtol) != eslOK) esl_fatal(msg); |
| 680 |
if (esl_FCompare_old(fsc, fsc_g, gtol) != eslOK) esl_fatal(msg); |
| 681 |
if (esl_FCompare_old(accscore, accscore_g, gtol) != eslOK) esl_fatal(msg); |
| 682 |
if (esl_FCompare_old(accscore_g, accscore_g2, gtol) != eslOK) esl_fatal(msg); |
| 683 |
if (accscore_g2 < accscore_o) esl_fatal(msg); |
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
esl_sq_Reuse(sq); |
| 712 |
p7_trace_Reuse(tr); |
| 713 |
p7_trace_Reuse(trg); |
| 714 |
p7_trace_Reuse(tro); |
| 715 |
} |
| 716 |
|
| 717 |
p7_trace_Destroy(tro); |
| 718 |
p7_trace_Destroy(trg); |
| 719 |
p7_trace_Destroy(tr); |
| 720 |
p7_gmx_Destroy(gx2); |
| 721 |
p7_gmx_Destroy(gx1); |
| 722 |
p7_omx_Destroy(ox2); |
| 723 |
p7_omx_Destroy(ox1); |
| 724 |
esl_sq_Destroy(sq); |
| 725 |
p7_oprofile_Destroy(om); |
| 726 |
p7_profile_Destroy(gm); |
| 727 |
p7_hmm_Destroy(hmm); |
| 728 |
} |
| 729 |
|
| 730 |
#endif |
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
#ifdef p7OPTACC_TESTDRIVE |
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
#include <p7_config.h> |
| 761 |
|
| 762 |
#include "easel.h" |
| 763 |
#include "esl_alphabet.h" |
| 764 |
#include "esl_getopts.h" |
| 765 |
|
| 766 |
#include "hmmer.h" |
| 767 |
#include "impl_neon.h" |
| 768 |
|
| 769 |
static ESL_OPTIONS options[] = { |
| 770 |
|
| 771 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 772 |
{ "-s", eslARG_INT, "41", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 }, |
| 773 |
{ "-L", eslARG_INT, "50", NULL, NULL, NULL, NULL, NULL, "size of random sequences to sample", 0 }, |
| 774 |
{ "-M", eslARG_INT, "45", NULL, NULL, NULL, NULL, NULL, "size of random models to sample", 0 }, |
| 775 |
{ "-N", eslARG_INT, "20", NULL, NULL, NULL, NULL, NULL, "number of random sequences to sample", 0 }, |
| 776 |
{ "--traces", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "dump all tracebacks", 0 }, |
| 777 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 778 |
}; |
| 779 |
static char usage[] = "[-options]"; |
| 780 |
static char banner[] = "test driver for NEON Forward, Backward implementations"; |
| 781 |
|
| 782 |
int |
| 783 |
main(int argc, char **argv) |
| 784 |
{ |
| 785 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 0, argc, argv, banner, usage); |
| 786 |
ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s")); |
| 787 |
ESL_ALPHABET *abc = NULL; |
| 788 |
P7_BG *bg = NULL; |
| 789 |
int M = esl_opt_GetInteger(go, "-M"); |
| 790 |
int L = esl_opt_GetInteger(go, "-L"); |
| 791 |
int N = esl_opt_GetInteger(go, "-N"); |
| 792 |
|
| 793 |
|
| 794 |
if ((abc = esl_alphabet_Create(eslDNA)) == NULL) esl_fatal("failed to create alphabet"); |
| 795 |
if ((bg = p7_bg_Create(abc)) == NULL) esl_fatal("failed to create null model"); |
| 796 |
|
| 797 |
utest_optacc(go, r, abc, bg, M, L, N); |
| 798 |
utest_optacc(go, r, abc, bg, 1, L, 10); |
| 799 |
utest_optacc(go, r, abc, bg, M, 1, 10); |
| 800 |
|
| 801 |
esl_alphabet_Destroy(abc); |
| 802 |
p7_bg_Destroy(bg); |
| 803 |
|
| 804 |
|
| 805 |
if ((abc = esl_alphabet_Create(eslAMINO)) == NULL) esl_fatal("failed to create alphabet"); |
| 806 |
if ((bg = p7_bg_Create(abc)) == NULL) esl_fatal("failed to create null model"); |
| 807 |
|
| 808 |
utest_optacc(go, r, abc, bg, M, L, N); |
| 809 |
utest_optacc(go, r, abc, bg, 1, L, 10); |
| 810 |
utest_optacc(go, r, abc, bg, M, 1, 10); |
| 811 |
|
| 812 |
esl_alphabet_Destroy(abc); |
| 813 |
p7_bg_Destroy(bg); |
| 814 |
|
| 815 |
esl_getopts_Destroy(go); |
| 816 |
esl_randomness_Destroy(r); |
| 817 |
return eslOK; |
| 818 |
} |
| 819 |
#endif |
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
|
| 827 |
|
| 828 |
#ifdef p7OPTACC_EXAMPLE |
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
#include <p7_config.h> |
| 834 |
|
| 835 |
#include "easel.h" |
| 836 |
#include "esl_alphabet.h" |
| 837 |
#include "esl_getopts.h" |
| 838 |
#include "esl_sq.h" |
| 839 |
#include "esl_sqio.h" |
| 840 |
|
| 841 |
#include "hmmer.h" |
| 842 |
#include "impl_neon.h" |
| 843 |
|
| 844 |
static ESL_OPTIONS options[] = { |
| 845 |
|
| 846 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 847 |
{ "-d", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "dump posterior residue decoding matrix", 0 }, |
| 848 |
{ "-m", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "dump OA matrix", 0 }, |
| 849 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 850 |
}; |
| 851 |
static char usage[] = "[-options] <hmmfile> <seqfile>"; |
| 852 |
static char banner[] = "example of optimal accuracy alignment, NEON implementation"; |
| 853 |
|
| 854 |
int |
| 855 |
main(int argc, char **argv) |
| 856 |
{ |
| 857 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 2, argc, argv, banner, usage); |
| 858 |
char *hmmfile = esl_opt_GetArg(go, 1); |
| 859 |
char *seqfile = esl_opt_GetArg(go, 2); |
| 860 |
ESL_ALPHABET *abc = NULL; |
| 861 |
P7_HMMFILE *hfp = NULL; |
| 862 |
P7_HMM *hmm = NULL; |
| 863 |
P7_BG *bg = NULL; |
| 864 |
P7_PROFILE *gm = NULL; |
| 865 |
P7_OPROFILE *om = NULL; |
| 866 |
P7_OMX *ox1 = NULL; |
| 867 |
P7_OMX *ox2 = NULL; |
| 868 |
P7_GMX *gx = NULL; |
| 869 |
ESL_SQ *sq = NULL; |
| 870 |
ESL_SQFILE *sqfp = NULL; |
| 871 |
P7_TRACE *tr = NULL; |
| 872 |
int format = eslSQFILE_UNKNOWN; |
| 873 |
char errbuf[eslERRBUFSIZE]; |
| 874 |
float fsc, bsc; |
| 875 |
float accscore; |
| 876 |
int status; |
| 877 |
|
| 878 |
|
| 879 |
if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile); |
| 880 |
if (p7_hmmfile_Read(hfp, &abc, &hmm) != eslOK) p7_Fail("Failed to read HMM"); |
| 881 |
p7_hmmfile_Close(hfp); |
| 882 |
|
| 883 |
|
| 884 |
sq = esl_sq_CreateDigital(abc); |
| 885 |
status = esl_sqfile_OpenDigital(abc, seqfile, format, NULL, &sqfp); |
| 886 |
if (status == eslENOTFOUND) p7_Fail("No such file."); |
| 887 |
else if (status == eslEFORMAT) p7_Fail("Format unrecognized."); |
| 888 |
else if (status == eslEINVAL) p7_Fail("Can't autodetect stdin or .gz."); |
| 889 |
else if (status != eslOK) p7_Fail("Open failed, code %d.", status); |
| 890 |
if (esl_sqio_Read(sqfp, sq) != eslOK) p7_Fail("Failed to read sequence"); |
| 891 |
esl_sqfile_Close(sqfp); |
| 892 |
|
| 893 |
|
| 894 |
bg = p7_bg_Create(abc); p7_bg_SetLength(bg, sq->n); |
| 895 |
gm = p7_profile_Create(hmm->M, abc); p7_ProfileConfig(hmm, bg, gm, sq->n, p7_LOCAL); |
| 896 |
om = p7_oprofile_Create(gm->M, abc); p7_oprofile_Convert(gm, om); |
| 897 |
|
| 898 |
|
| 899 |
ox1 = p7_omx_Create(gm->M, sq->n, sq->n); |
| 900 |
ox2 = p7_omx_Create(gm->M, sq->n, sq->n); |
| 901 |
gx = p7_gmx_Create(gm->M, sq->n); |
| 902 |
tr = p7_trace_CreateWithPP(); |
| 903 |
p7_FLogsumInit(); |
| 904 |
|
| 905 |
|
| 906 |
p7_Forward (sq->dsq, sq->n, om, ox1, &fsc); |
| 907 |
p7_Backward(sq->dsq, sq->n, om, ox1, ox2, &bsc); |
| 908 |
p7_Decoding(om, ox1, ox2, ox2); |
| 909 |
p7_OptimalAccuracy(om, ox2, ox1, &accscore); |
| 910 |
p7_OATrace(om, ox2, ox1, tr); |
| 911 |
|
| 912 |
if (esl_opt_GetBoolean(go, "-d")) { p7_omx_FDeconvert(ox2, gx); p7_gmx_Dump(stdout, gx, p7_DEFAULT); } |
| 913 |
if (esl_opt_GetBoolean(go, "-m")) { p7_omx_FDeconvert(ox1, gx); p7_gmx_Dump(stdout, gx, p7_DEFAULT); } |
| 914 |
|
| 915 |
p7_trace_Dump(stdout, tr, gm, sq->dsq); |
| 916 |
|
| 917 |
if (p7_trace_Validate(tr, abc, sq->dsq, errbuf) != eslOK) p7_Die("trace fails validation:\n%s\n", errbuf); |
| 918 |
|
| 919 |
printf("fwd = %.4f nats\n", fsc); |
| 920 |
printf("bck = %.4f nats\n", bsc); |
| 921 |
printf("acc = %.4f (%.2f%%)\n", accscore, accscore * 100. / (float) sq->n); |
| 922 |
|
| 923 |
|
| 924 |
esl_sq_Destroy(sq); |
| 925 |
p7_trace_Destroy(tr); |
| 926 |
p7_omx_Destroy(ox1); |
| 927 |
p7_omx_Destroy(ox2); |
| 928 |
p7_gmx_Destroy(gx); |
| 929 |
p7_oprofile_Destroy(om); |
| 930 |
p7_profile_Destroy(gm); |
| 931 |
p7_bg_Destroy(bg); |
| 932 |
p7_hmm_Destroy(hmm); |
| 933 |
esl_alphabet_Destroy(abc); |
| 934 |
esl_getopts_Destroy(go); |
| 935 |
return 0; |
| 936 |
} |
| 937 |
#endif |
| 938 |
|