| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#include <p7_config.h> |
| 5 |
|
| 6 |
#include "easel.h" |
| 7 |
#include "esl_sq.h" |
| 8 |
|
| 9 |
#include "hmmer.h" |
| 10 |
#include "p7_gbands.h" |
| 11 |
#include "p7_gmxb.h" |
| 12 |
|
| 13 |
int |
| 14 |
p7_GForwardBanded(const ESL_DSQ *dsq, int L, const P7_PROFILE *gm, P7_GMXB *gxb, float *opt_sc) |
| 15 |
{ |
| 16 |
int *bnd_ip = gxb->bnd->imem; |
| 17 |
int *bnd_kp = gxb->bnd->kmem; |
| 18 |
float *dpc = gxb->dp; |
| 19 |
float *xpc = gxb->xmx; |
| 20 |
float const *tsc = gm->tsc; |
| 21 |
float const *rsc; |
| 22 |
float *dpp; |
| 23 |
float *last_dpc; |
| 24 |
int ia, ib; |
| 25 |
int last_ib; |
| 26 |
int kac, kbc; |
| 27 |
int kap, kbp; |
| 28 |
int kbc2; |
| 29 |
float xE, xN, xJ, xB, xC; |
| 30 |
float mvp, ivp, dvp; |
| 31 |
float dc; |
| 32 |
float sc; |
| 33 |
int g, i, k; |
| 34 |
|
| 35 |
|
| 36 |
xN = 0.0f; |
| 37 |
xJ = -eslINFINITY; |
| 38 |
xC = -eslINFINITY; |
| 39 |
last_ib = 0; |
| 40 |
|
| 41 |
for (g = 0; g < gxb->bnd->nseg; g++) |
| 42 |
{ |
| 43 |
ia = *bnd_ip++; |
| 44 |
ib = *bnd_ip++; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
kap = kbp = gm->M+1; |
| 51 |
dpp = dpc; |
| 52 |
|
| 53 |
|
| 54 |
xE = -eslINFINITY; |
| 55 |
xN = xN + (ia - last_ib - 1) * gm->xsc[p7P_N][p7P_LOOP]; |
| 56 |
xJ = xJ + (ia - last_ib - 1) * gm->xsc[p7P_J][p7P_LOOP]; |
| 57 |
xB = p7_FLogsum( xN + gm->xsc[p7P_N][p7P_MOVE], xJ + gm->xsc[p7P_J][p7P_MOVE]); |
| 58 |
xC = xC + (ia - last_ib - 1) * gm->xsc[p7P_C][p7P_LOOP]; |
| 59 |
|
| 60 |
for (i = ia; i <= ib; i++) |
| 61 |
{ |
| 62 |
rsc = gm->rsc[dsq[i]]; |
| 63 |
dc = -eslINFINITY; |
| 64 |
xE = -eslINFINITY; |
| 65 |
last_dpc = dpc; |
| 66 |
|
| 67 |
kac = *bnd_kp++; |
| 68 |
kbc = *bnd_kp++; |
| 69 |
kbc2 = (kbc == gm->M ? kbc-1 : kbc); |
| 70 |
|
| 71 |
|
| 72 |
dpp += (kac-1 > kap ? ESL_MIN(kac-kap-1, kbp-kap+1) : 0); |
| 73 |
|
| 74 |
if (kac > kap && kac-1 <= kbp) { mvp = *dpp++; ivp = *dpp++; dvp = *dpp++; } |
| 75 |
else { mvp = -eslINFINITY; ivp = -eslINFINITY; dvp = -eslINFINITY; } |
| 76 |
|
| 77 |
for (k = kac; k <= kbc2; k++) |
| 78 |
{ |
| 79 |
*dpc++ = sc = MSC(k) + p7_FLogsum( p7_FLogsum(mvp + TSC(p7P_MM, k-1), ivp + TSC(p7P_IM, k-1)), |
| 80 |
dvp + TSC(p7P_DM, k-1)); |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
if (k >= kap && k <= kbp) { mvp = *dpp++; ivp = *dpp++; dvp = *dpp++; } |
| 85 |
else { mvp = -eslINFINITY; ivp = -eslINFINITY; dvp = -eslINFINITY; } |
| 86 |
|
| 87 |
|
| 88 |
*dpc++ = ISC(k) + p7_FLogsum( mvp + TSC(p7P_MI, k), ivp + TSC(p7P_II, k)); |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
*dpc++ = dc; |
| 94 |
dc = p7_FLogsum( sc + TSC(p7P_MD, k), dc + TSC(p7P_DD, k)); |
| 95 |
} |
| 96 |
|
| 97 |
if (kbc2 < kbc) |
| 98 |
{ |
| 99 |
*dpc++ = sc = MSC(k) + p7_FLogsum( p7_FLogsum(mvp + TSC(p7P_MM, k-1), ivp + TSC(p7P_IM, k-1)), |
| 100 |
p7_FLogsum(dvp + TSC(p7P_DM, k-1), xB + TSC(p7P_BM, k-1))); |
| 101 |
*dpc++ = -eslINFINITY; |
| 102 |
*dpc++ = dc; |
| 103 |
xE = p7_FLogsum( p7_FLogsum(sc, dc), xE); |
| 104 |
} |
| 105 |
|
| 106 |
*xpc++ = xE; |
| 107 |
*xpc++ = xN = xN + gm->xsc[p7P_N][p7P_LOOP]; |
| 108 |
*xpc++ = xJ = p7_FLogsum( xJ + gm->xsc[p7P_J][p7P_LOOP], xE + gm->xsc[p7P_E][p7P_MOVE]); |
| 109 |
*xpc++ = xB = p7_FLogsum( xJ + gm->xsc[p7P_J][p7P_MOVE], xN + gm->xsc[p7P_N][p7P_MOVE]); |
| 110 |
*xpc++ = xC = p7_FLogsum( xE + gm->xsc[p7P_E][p7P_MOVE], xC + gm->xsc[p7P_C][p7P_LOOP]); |
| 111 |
|
| 112 |
dpp = last_dpc; |
| 113 |
kap = kac; |
| 114 |
kbp = kbc; |
| 115 |
} |
| 116 |
last_ib = ib; |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
if (opt_sc != NULL) *opt_sc = xC + (L-last_ib) * gm->xsc[p7P_C][p7P_LOOP] + gm->xsc[p7P_C][p7P_MOVE]; |
| 121 |
return eslOK; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
#ifdef p7GENERIC_FWDBACK_BANDED_BENCHMARK |
| 128 |
#include <p7_config.h> |
| 129 |
|
| 130 |
#include "easel.h" |
| 131 |
#include "esl_alphabet.h" |
| 132 |
#include "esl_getopts.h" |
| 133 |
#include "esl_random.h" |
| 134 |
#include "esl_randomseq.h" |
| 135 |
|
| 136 |
#include "hmmer.h" |
| 137 |
#include "p7_gbands.h" |
| 138 |
#include "p7_gmxb.h" |
| 139 |
|
| 140 |
static ESL_OPTIONS options[] = { |
| 141 |
|
| 142 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 143 |
{ "-s", eslARG_INT, "42", NULL, NULL, NULL, NULL, NULL, "set random number seed to <n>", 0 }, |
| 144 |
{ "-L", eslARG_INT, "400", NULL, "n>0", NULL, NULL, NULL, "length of random target seqs", 0 }, |
| 145 |
{ "-N", eslARG_INT, "2000", NULL, "n>0", NULL, NULL, NULL, "number of random target seqs", 0 }, |
| 146 |
{ "-W", eslARG_INT, "3", NULL,"n>=0", NULL, NULL, NULL, "band halfwidth", 0 }, |
| 147 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 148 |
}; |
| 149 |
static char usage[] = "[-options] <hmmfile>"; |
| 150 |
static char banner[] = "benchmark driver for banded Forward/Backward"; |
| 151 |
|
| 152 |
int |
| 153 |
main(int argc, char **argv) |
| 154 |
{ |
| 155 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 1, argc, argv, banner, usage); |
| 156 |
char *hmmfile = esl_opt_GetArg(go, 1); |
| 157 |
ESL_STOPWATCH *w = esl_stopwatch_Create(); |
| 158 |
ESL_RANDOMNESS *r = esl_randomness_CreateFast(esl_opt_GetInteger(go, "-s")); |
| 159 |
ESL_ALPHABET *abc = NULL; |
| 160 |
P7_HMMFILE *hfp = NULL; |
| 161 |
P7_HMM *hmm = NULL; |
| 162 |
P7_BG *bg = NULL; |
| 163 |
P7_PROFILE *gm = NULL; |
| 164 |
P7_GBANDS *bnd = NULL; |
| 165 |
P7_GMXB *fwd = NULL; |
| 166 |
int L = esl_opt_GetInteger(go, "-L"); |
| 167 |
int N = esl_opt_GetInteger(go, "-N"); |
| 168 |
int W = esl_opt_GetInteger(go, "-W"); |
| 169 |
ESL_DSQ *dsq = malloc(sizeof(ESL_DSQ) * (L+2)); |
| 170 |
int idx, k, base; |
| 171 |
float sc; |
| 172 |
double base_time, bench_time, Mcs; |
| 173 |
|
| 174 |
if (p7_hmmfile_Open(hmmfile, NULL, &hfp, NULL) != eslOK) p7_Fail("Failed to open HMM file %s", hmmfile); |
| 175 |
if (p7_hmmfile_Read(hfp, &abc, &hmm) != eslOK) p7_Fail("Failed to read HMM"); |
| 176 |
|
| 177 |
bg = p7_bg_Create(abc); |
| 178 |
p7_bg_SetLength(bg, L); |
| 179 |
gm = p7_profile_Create(hmm->M, abc); |
| 180 |
p7_ProfileConfig(hmm, bg, gm, L, p7_GLOCAL); |
| 181 |
|
| 182 |
|
| 183 |
bnd = p7_gbands_Create(L, gm->M); |
| 184 |
if (L < gm->M) p7_Fail("for now, L must be >=M, because we make a single band"); |
| 185 |
base = (L-gm->M) / 2; |
| 186 |
for (k = 1; k <= gm->M; k++) |
| 187 |
p7_gbands_Append(bnd, k+base, ESL_MAX(1,k-W), ESL_MIN(gm->M,k+W)); |
| 188 |
|
| 189 |
fwd = p7_gmxb_Create(bnd); |
| 190 |
|
| 191 |
|
| 192 |
esl_stopwatch_Start(w); |
| 193 |
for (idx = 0; idx < N; idx++) esl_rsq_xfIID(r, bg->f, abc->K, L, dsq); |
| 194 |
esl_stopwatch_Stop(w); |
| 195 |
base_time = w->user; |
| 196 |
|
| 197 |
|
| 198 |
esl_stopwatch_Start(w); |
| 199 |
for (idx = 0; idx < N; idx++) |
| 200 |
{ |
| 201 |
esl_rsq_xfIID(r, bg->f, abc->K, L, dsq); |
| 202 |
|
| 203 |
p7_gmxb_Reinit(fwd, bnd); |
| 204 |
|
| 205 |
p7_GForwardBanded(dsq, L, gm, fwd, &sc); |
| 206 |
|
| 207 |
p7_gmxb_Reuse(fwd); |
| 208 |
} |
| 209 |
esl_stopwatch_Stop(w); |
| 210 |
bench_time = w->user - base_time; |
| 211 |
Mcs = (double) N * (double) L * (double) gm->M * 1e-6 / (double) bench_time; |
| 212 |
esl_stopwatch_Display(stdout, w, "# CPU time: "); |
| 213 |
printf("# M = %d\n", gm->M); |
| 214 |
printf("# %.1f Mc/s\n", Mcs); |
| 215 |
|
| 216 |
free(dsq); |
| 217 |
p7_gmxb_Destroy(fwd); |
| 218 |
p7_gbands_Destroy(bnd); |
| 219 |
p7_profile_Destroy(gm); |
| 220 |
p7_bg_Destroy(bg); |
| 221 |
p7_hmm_Destroy(hmm); |
| 222 |
p7_hmmfile_Close(hfp); |
| 223 |
esl_alphabet_Destroy(abc); |
| 224 |
esl_stopwatch_Destroy(w); |
| 225 |
esl_randomness_Destroy(r); |
| 226 |
esl_getopts_Destroy(go); |
| 227 |
return 0; |
| 228 |
} |
| 229 |
#endif |
| 230 |
|