| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
#include <esl_config.h> |
| 8 |
#include <p7_config.h> |
| 9 |
#include "config.h" |
| 10 |
|
| 11 |
#include <limits.h> |
| 12 |
#include <math.h> |
| 13 |
#include <stdio.h> |
| 14 |
#include <stdlib.h> |
| 15 |
#include <string.h> |
| 16 |
#include <time.h> |
| 17 |
|
| 18 |
#include "easel.h" |
| 19 |
#include "esl_vectorops.h" |
| 20 |
#include "esl_alphabet.h" |
| 21 |
#include "esl_stack.h" |
| 22 |
|
| 23 |
#include "hmmer.h" |
| 24 |
|
| 25 |
#include "infernal.h" |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
CM_t * |
| 48 |
CreateCM(int nnodes, int nstates, int clen, const ESL_ALPHABET *abc) |
| 49 |
{ |
| 50 |
CM_t *cm; |
| 51 |
|
| 52 |
cm = CreateCMShell(); |
| 53 |
if (cm != NULL) CreateCMBody(cm, nnodes, nstates, clen, abc); |
| 54 |
return cm; |
| 55 |
} |
| 56 |
CM_t * |
| 57 |
CreateCMShell(void) |
| 58 |
{ |
| 59 |
int status, z; |
| 60 |
CM_t *cm; |
| 61 |
|
| 62 |
ESL_ALLOC(cm, sizeof(CM_t)); |
| 63 |
|
| 64 |
cm->abc = NULL; |
| 65 |
|
| 66 |
cm->name = NULL; |
| 67 |
cm->acc = NULL; |
| 68 |
cm->desc = NULL; |
| 69 |
cm->rf = NULL; |
| 70 |
cm->consensus = NULL; |
| 71 |
cm->map = NULL; |
| 72 |
cm->checksum = 0; |
| 73 |
|
| 74 |
cm->null = NULL; |
| 75 |
|
| 76 |
|
| 77 |
cm->M = 0; |
| 78 |
cm->clen = 0; |
| 79 |
cm->W = 0; |
| 80 |
cm->W_setby = CM_W_SETBY_INIT; |
| 81 |
cm->sttype = NULL; |
| 82 |
cm->ndidx = NULL; |
| 83 |
cm->stid = NULL; |
| 84 |
cm->cfirst = NULL; |
| 85 |
cm->cnum = NULL; |
| 86 |
cm->plast = NULL; |
| 87 |
cm->pnum = NULL; |
| 88 |
|
| 89 |
cm->nodes = 0; |
| 90 |
cm->nodemap = NULL; |
| 91 |
cm->ndtype = NULL; |
| 92 |
|
| 93 |
cm->t = NULL; |
| 94 |
cm->e = NULL; |
| 95 |
cm->begin = NULL; |
| 96 |
cm->end = NULL; |
| 97 |
cm->tsc = NULL; |
| 98 |
cm->esc = NULL; |
| 99 |
cm->oesc = NULL; |
| 100 |
cm->beginsc = NULL; |
| 101 |
cm->endsc = NULL; |
| 102 |
cm->itsc = NULL; |
| 103 |
cm->iesc = NULL; |
| 104 |
cm->ioesc = NULL; |
| 105 |
cm->ibeginsc = NULL; |
| 106 |
cm->iendsc = NULL; |
| 107 |
|
| 108 |
cm->lmesc = NULL; |
| 109 |
cm->rmesc = NULL; |
| 110 |
cm->ilmesc = NULL; |
| 111 |
cm->irmesc = NULL; |
| 112 |
|
| 113 |
cm->flags = 0; |
| 114 |
cm->offset = 0; |
| 115 |
|
| 116 |
cm->el_selfsc = sreLOG2(DEFAULT_EL_SELFPROB); |
| 117 |
|
| 118 |
cm->qdbinfo = NULL; |
| 119 |
cm->beta_W = DEFAULT_BETA_W; |
| 120 |
cm->tau = DEFAULT_TAU; |
| 121 |
cm->maxtau = DEFAULT_MAXTAU; |
| 122 |
cm->null2_omega = V1P0_NULL2_OMEGA; |
| 123 |
cm->null3_omega = V1P0_NULL3_OMEGA; |
| 124 |
cm->cp9 = NULL; |
| 125 |
cm->Lcp9 = NULL; |
| 126 |
cm->Rcp9 = NULL; |
| 127 |
cm->Tcp9 = NULL; |
| 128 |
cm->cp9b = NULL; |
| 129 |
cm->cp9map = NULL; |
| 130 |
cm->root_trans = NULL; |
| 131 |
cm->expA = NULL; |
| 132 |
cm->smx = NULL; |
| 133 |
cm->trsmx = NULL; |
| 134 |
cm->hb_mx = NULL; |
| 135 |
cm->hb_omx = NULL; |
| 136 |
cm->hb_emx = NULL; |
| 137 |
cm->hb_shmx = NULL; |
| 138 |
cm->trhb_mx = NULL; |
| 139 |
cm->trhb_omx = NULL; |
| 140 |
cm->trhb_emx = NULL; |
| 141 |
cm->trhb_shmx = NULL; |
| 142 |
cm->nb_mx = NULL; |
| 143 |
cm->nb_omx = NULL; |
| 144 |
cm->nb_emx = NULL; |
| 145 |
cm->nb_shmx = NULL; |
| 146 |
cm->trnb_mx = NULL; |
| 147 |
cm->trnb_omx = NULL; |
| 148 |
cm->trnb_emx = NULL; |
| 149 |
cm->trnb_shmx = NULL; |
| 150 |
cm->cp9_mx = NULL; |
| 151 |
cm->cp9_bmx = NULL; |
| 152 |
cm->pbegin = DEFAULT_PBEGIN; |
| 153 |
cm->pend = DEFAULT_PEND; |
| 154 |
cm->mlp7 = NULL; |
| 155 |
cm->fp7 = NULL; |
| 156 |
|
| 157 |
for (z = 0; z < CM_p7_NEVPARAM; z++) cm->fp7_evparam[z] = CM_p7_EVPARAM_UNSET; |
| 158 |
|
| 159 |
cm->ga = 0.; |
| 160 |
cm->tc = 0.; |
| 161 |
cm->nc = 0.; |
| 162 |
cm->eff_nseq = 0.; |
| 163 |
cm->nseq = 0; |
| 164 |
cm->clen = 0; |
| 165 |
cm->ctime = NULL; |
| 166 |
cm->comlog = NULL; |
| 167 |
cm->emap = NULL; |
| 168 |
cm->cmcons = NULL; |
| 169 |
cm->trp = NULL; |
| 170 |
|
| 171 |
return cm; |
| 172 |
|
| 173 |
ERROR: |
| 174 |
cm_Fail("CreateCMShell() Memory allocation error.\n"); |
| 175 |
return NULL; |
| 176 |
} |
| 177 |
|
| 178 |
void |
| 179 |
CreateCMBody(CM_t *cm, int nnodes, int nstates, int clen, const ESL_ALPHABET *abc) |
| 180 |
{ |
| 181 |
int status; |
| 182 |
int v; |
| 183 |
|
| 184 |
cm->abc = abc; |
| 185 |
|
| 186 |
cm->M = nstates; |
| 187 |
cm->nodes = nnodes; |
| 188 |
cm->clen = clen; |
| 189 |
|
| 190 |
CMAllocNullModel(cm); |
| 191 |
|
| 192 |
ESL_ALLOC(cm->sttype, (nstates+1) * sizeof(char)); |
| 193 |
ESL_ALLOC(cm->ndidx, nstates * sizeof(int)); |
| 194 |
ESL_ALLOC(cm->stid, (nstates+1) * sizeof(char)); |
| 195 |
ESL_ALLOC(cm->cfirst, nstates * sizeof(int)); |
| 196 |
ESL_ALLOC(cm->cnum, nstates * sizeof(int)); |
| 197 |
ESL_ALLOC(cm->plast, nstates * sizeof(int)); |
| 198 |
ESL_ALLOC(cm->pnum, nstates * sizeof(int)); |
| 199 |
|
| 200 |
ESL_ALLOC(cm->nodemap, nnodes * sizeof(int)); |
| 201 |
ESL_ALLOC(cm->ndtype, nnodes * sizeof(char)); |
| 202 |
|
| 203 |
if((cm->qdbinfo = CreateCMQDBInfo(nstates, clen)) == NULL) goto ERROR; |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
ESL_ALLOC(cm->t, (nstates) * sizeof(float *)); |
| 208 |
ESL_ALLOC(cm->e, (nstates) * sizeof(float *)); |
| 209 |
ESL_ALLOC(cm->tsc, (nstates) * sizeof(float *)); |
| 210 |
ESL_ALLOC(cm->esc, (nstates) * sizeof(float *)); |
| 211 |
ESL_ALLOC(cm->lmesc, (nstates) * sizeof(float *)); |
| 212 |
ESL_ALLOC(cm->rmesc, (nstates) * sizeof(float *)); |
| 213 |
ESL_ALLOC(cm->itsc, (nstates) * sizeof(int *)); |
| 214 |
ESL_ALLOC(cm->iesc, (nstates) * sizeof(int *)); |
| 215 |
ESL_ALLOC(cm->ilmesc, (nstates) * sizeof(int *)); |
| 216 |
ESL_ALLOC(cm->irmesc, (nstates) * sizeof(int *)); |
| 217 |
cm->t[0] = NULL; |
| 218 |
cm->e[0] = NULL; |
| 219 |
cm->tsc[0] = NULL; |
| 220 |
cm->esc[0] = NULL; |
| 221 |
cm->lmesc[0] = NULL; |
| 222 |
cm->rmesc[0] = NULL; |
| 223 |
cm->itsc[0] = NULL; |
| 224 |
cm->iesc[0] = NULL; |
| 225 |
cm->ilmesc[0] = NULL; |
| 226 |
cm->irmesc[0] = NULL; |
| 227 |
ESL_ALLOC(cm->begin, (nstates) * sizeof(float)); |
| 228 |
ESL_ALLOC(cm->end, (nstates) * sizeof(float)); |
| 229 |
ESL_ALLOC(cm->beginsc, (nstates) * sizeof(float)); |
| 230 |
ESL_ALLOC(cm->endsc, (nstates) * sizeof(float)); |
| 231 |
ESL_ALLOC(cm->ibeginsc, (nstates) * sizeof(int)); |
| 232 |
ESL_ALLOC(cm->iendsc, (nstates) * sizeof(int)); |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
ESL_ALLOC(cm->t[0], MAXCONNECT * nstates * sizeof(float)); |
| 240 |
ESL_ALLOC(cm->e[0], cm->abc->K * cm->abc->K * nstates * sizeof(float)); |
| 241 |
ESL_ALLOC(cm->tsc[0], MAXCONNECT * nstates * sizeof(float)); |
| 242 |
ESL_ALLOC(cm->esc[0], cm->abc->K * cm->abc->K * nstates * sizeof(float)); |
| 243 |
ESL_ALLOC(cm->lmesc[0], cm->abc->Kp * nstates * sizeof(float)); |
| 244 |
ESL_ALLOC(cm->rmesc[0], cm->abc->Kp * nstates * sizeof(float)); |
| 245 |
ESL_ALLOC(cm->itsc[0], MAXCONNECT * nstates * sizeof(int)); |
| 246 |
ESL_ALLOC(cm->iesc[0], cm->abc->K * cm->abc->K * nstates * sizeof(int)); |
| 247 |
ESL_ALLOC(cm->ilmesc[0], cm->abc->Kp * nstates * sizeof(int)); |
| 248 |
ESL_ALLOC(cm->irmesc[0], cm->abc->Kp * nstates * sizeof(int)); |
| 249 |
for (v = 0; v < nstates; v++) |
| 250 |
{ |
| 251 |
cm->e[v] = cm->e[0] + v * (cm->abc->K * cm->abc->K); |
| 252 |
cm->t[v] = cm->t[0] + v * MAXCONNECT; |
| 253 |
cm->tsc[v] = cm->tsc[0] + v * MAXCONNECT; |
| 254 |
cm->esc[v] = cm->esc[0] + v * (cm->abc->K * cm->abc->K); |
| 255 |
cm->lmesc[v] = cm->lmesc[0] + v * cm->abc->Kp; |
| 256 |
cm->rmesc[v] = cm->rmesc[0] + v * cm->abc->Kp; |
| 257 |
cm->iesc[v] = cm->iesc[0] + v * (cm->abc->K * cm->abc->K); |
| 258 |
cm->itsc[v] = cm->itsc[0] + v * MAXCONNECT; |
| 259 |
cm->ilmesc[v] = cm->ilmesc[0] + v * cm->abc->Kp; |
| 260 |
cm->irmesc[v] = cm->irmesc[0] + v * cm->abc->Kp; |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
CMZero(cm); |
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
cm->sttype[cm->M] = EL_st; |
| 272 |
cm->stid[cm->M] = END_EL; |
| 273 |
|
| 274 |
|
| 275 |
|
| 276 |
cm->config_opts = 0; |
| 277 |
cm->align_opts = 0; |
| 278 |
cm->search_opts = 0; |
| 279 |
cm->cp9 = NULL; |
| 280 |
cm->Lcp9 = NULL; |
| 281 |
cm->Rcp9 = NULL; |
| 282 |
cm->Tcp9 = NULL; |
| 283 |
cm->cp9b = NULL; |
| 284 |
cm->cp9map = NULL; |
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
if (cm->flags & CMH_RF) ESL_ALLOC(cm->rf, (cm->clen+2) * sizeof(char)); |
| 293 |
if (cm->flags & CMH_CONS) ESL_ALLOC(cm->consensus, (cm->clen+2) * sizeof(char)); |
| 294 |
if (cm->flags & CMH_MAP) ESL_ALLOC(cm->map, (cm->clen+1) * sizeof(int)); |
| 295 |
|
| 296 |
return; |
| 297 |
|
| 298 |
ERROR: |
| 299 |
cm_Fail("CreateCMBody(), memory allocation error."); |
| 300 |
return; |
| 301 |
} |
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
void |
| 311 |
CMZero(CM_t *cm) |
| 312 |
{ |
| 313 |
int v; |
| 314 |
|
| 315 |
for (v = 0; v < cm->M; v++) { |
| 316 |
esl_vec_FSet(cm->e[v], (cm->abc->K * cm->abc->K), 0.); |
| 317 |
esl_vec_FSet(cm->t[v], MAXCONNECT, 0.); |
| 318 |
esl_vec_FSet(cm->tsc[v], MAXCONNECT, 0.); |
| 319 |
esl_vec_FSet(cm->esc[v], (cm->abc->K * cm->abc->K), 0.); |
| 320 |
esl_vec_FSet(cm->lmesc[v], cm->abc->Kp, 0.); |
| 321 |
esl_vec_FSet(cm->rmesc[v], cm->abc->Kp, 0.); |
| 322 |
esl_vec_ISet(cm->itsc[v], MAXCONNECT, 0); |
| 323 |
esl_vec_ISet(cm->iesc[v], (cm->abc->K * cm->abc->K), 0); |
| 324 |
esl_vec_ISet(cm->ilmesc[v], cm->abc->Kp, 0); |
| 325 |
esl_vec_ISet(cm->irmesc[v], cm->abc->Kp, 0); |
| 326 |
} |
| 327 |
esl_vec_FSet(cm->begin, cm->M, 0.); |
| 328 |
esl_vec_FSet(cm->end, cm->M, 0.); |
| 329 |
esl_vec_FSet(cm->beginsc, cm->M, 0.); |
| 330 |
esl_vec_FSet(cm->endsc, cm->M, 0.); |
| 331 |
esl_vec_ISet(cm->ibeginsc, cm->M, 0); |
| 332 |
esl_vec_ISet(cm->iendsc, cm->M, 0); |
| 333 |
} |
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
void |
| 344 |
CMRenormalize(CM_t *cm) |
| 345 |
{ |
| 346 |
int v; |
| 347 |
|
| 348 |
esl_vec_FNorm(cm->null, cm->abc->K); |
| 349 |
for (v = 0; v < cm->M; v++) |
| 350 |
{ |
| 351 |
if (cm->cnum[v] > 0 && cm->sttype[v] != B_st) |
| 352 |
esl_vec_FNorm(cm->t[v], cm->cnum[v]); |
| 353 |
|
| 354 |
if (cm->sttype[v] == ML_st || cm->sttype[v] == MR_st || cm->sttype[v] == IL_st || cm->sttype[v] == IR_st) |
| 355 |
esl_vec_FNorm(cm->e[v], cm->abc->K); |
| 356 |
if (cm->sttype[v] == MP_st) |
| 357 |
esl_vec_FNorm(cm->e[v], cm->abc->K * cm->abc->K); |
| 358 |
} |
| 359 |
if (cm->flags & CMH_LOCAL_BEGIN) esl_vec_FNorm(cm->begin, cm->M); |
| 360 |
if (cm->flags & CMH_LOCAL_END) cm_Fail("Renormalization of models in local end mode not supported yet"); |
| 361 |
} |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
void |
| 377 |
FreeCM(CM_t *cm) |
| 378 |
{ |
| 379 |
int i; |
| 380 |
|
| 381 |
if (! cm) return; |
| 382 |
|
| 383 |
if (cm->smx != NULL) cm_scan_mx_Destroy (cm, cm->smx); |
| 384 |
if (cm->trsmx != NULL) cm_tr_scan_mx_Destroy(cm, cm->trsmx); |
| 385 |
|
| 386 |
if (cm->name != NULL) free(cm->name); |
| 387 |
if (cm->acc != NULL) free(cm->acc); |
| 388 |
if (cm->desc != NULL) free(cm->desc); |
| 389 |
if (cm->rf != NULL) free(cm->rf); |
| 390 |
if (cm->consensus != NULL) free(cm->consensus); |
| 391 |
if (cm->map != NULL) free(cm->map); |
| 392 |
if (cm->null != NULL) free(cm->null); |
| 393 |
|
| 394 |
free(cm->sttype); |
| 395 |
free(cm->ndidx); |
| 396 |
free(cm->stid); |
| 397 |
free(cm->cfirst); |
| 398 |
free(cm->cnum); |
| 399 |
free(cm->plast); |
| 400 |
free(cm->pnum); |
| 401 |
free(cm->nodemap); |
| 402 |
free(cm->ndtype); |
| 403 |
|
| 404 |
if (cm->lmesc != NULL) { free(cm->lmesc[0]); free(cm->lmesc); } |
| 405 |
if (cm->rmesc != NULL) { free(cm->rmesc[0]); free(cm->rmesc); } |
| 406 |
if (cm->ilmesc != NULL) { free(cm->ilmesc[0]); free(cm->ilmesc); } |
| 407 |
if (cm->irmesc != NULL) { free(cm->irmesc[0]); free(cm->irmesc); } |
| 408 |
|
| 409 |
if(cm->t != NULL) { |
| 410 |
if(cm->t[0] != NULL) free(cm->t[0]); |
| 411 |
free(cm->t); |
| 412 |
} |
| 413 |
if(cm->e != NULL) { |
| 414 |
if(cm->e[0] != NULL) free(cm->e[0]); |
| 415 |
free(cm->e); |
| 416 |
} |
| 417 |
if(cm->tsc != NULL) { |
| 418 |
if(cm->tsc[0] != NULL) free(cm->tsc[0]); |
| 419 |
free(cm->tsc); |
| 420 |
} |
| 421 |
if(cm->esc != NULL) { |
| 422 |
if(cm->esc[0] != NULL) free(cm->esc[0]); |
| 423 |
free(cm->esc); |
| 424 |
} |
| 425 |
if(cm->itsc != NULL) { |
| 426 |
if(cm->itsc[0] != NULL) free(cm->itsc[0]); |
| 427 |
free(cm->itsc); |
| 428 |
} |
| 429 |
if(cm->iesc != NULL) { |
| 430 |
if(cm->iesc[0] != NULL) free(cm->iesc[0]); |
| 431 |
free(cm->iesc); |
| 432 |
} |
| 433 |
if(cm->begin != NULL) free(cm->begin); |
| 434 |
if(cm->end != NULL) free(cm->end); |
| 435 |
if(cm->beginsc != NULL) free(cm->beginsc); |
| 436 |
if(cm->endsc != NULL) free(cm->endsc); |
| 437 |
if(cm->ibeginsc != NULL) free(cm->ibeginsc); |
| 438 |
if(cm->iendsc != NULL) free(cm->iendsc); |
| 439 |
|
| 440 |
if(cm->ctime != NULL) free(cm->ctime); |
| 441 |
if(cm->comlog != NULL) free(cm->comlog); |
| 442 |
if(cm->qdbinfo != NULL) FreeCMQDBInfo(cm->qdbinfo); |
| 443 |
if(cm->cp9map != NULL) FreeCP9Map(cm->cp9map); |
| 444 |
if(cm->cp9b != NULL) FreeCP9Bands(cm->cp9b); |
| 445 |
if(cm->cp9 != NULL) FreeCPlan9(cm->cp9); |
| 446 |
if(cm->Lcp9 != NULL) FreeCPlan9(cm->Lcp9); |
| 447 |
if(cm->Rcp9 != NULL) FreeCPlan9(cm->Rcp9); |
| 448 |
if(cm->Tcp9 != NULL) FreeCPlan9(cm->Tcp9); |
| 449 |
if(cm->root_trans != NULL) free(cm->root_trans); |
| 450 |
if(cm->hb_mx != NULL) cm_hb_mx_Destroy(cm->hb_mx); |
| 451 |
if(cm->hb_omx != NULL) cm_hb_mx_Destroy(cm->hb_omx); |
| 452 |
if(cm->hb_emx != NULL) cm_hb_emit_mx_Destroy(cm->hb_emx); |
| 453 |
if(cm->hb_shmx != NULL) cm_hb_shadow_mx_Destroy(cm->hb_shmx); |
| 454 |
if(cm->trhb_mx != NULL) cm_tr_hb_mx_Destroy(cm->trhb_mx); |
| 455 |
if(cm->trhb_omx != NULL) cm_tr_hb_mx_Destroy(cm->trhb_omx); |
| 456 |
if(cm->trhb_emx != NULL) cm_tr_hb_emit_mx_Destroy(cm->trhb_emx); |
| 457 |
if(cm->trhb_shmx != NULL) cm_tr_hb_shadow_mx_Destroy(cm->trhb_shmx); |
| 458 |
if(cm->nb_mx != NULL) cm_mx_Destroy(cm->nb_mx); |
| 459 |
if(cm->nb_omx != NULL) cm_mx_Destroy(cm->nb_omx); |
| 460 |
if(cm->nb_emx != NULL) cm_emit_mx_Destroy(cm->nb_emx); |
| 461 |
if(cm->nb_shmx != NULL) cm_shadow_mx_Destroy(cm->nb_shmx); |
| 462 |
if(cm->trnb_mx != NULL) cm_tr_mx_Destroy(cm->trnb_mx); |
| 463 |
if(cm->trnb_omx != NULL) cm_tr_mx_Destroy(cm->trnb_omx); |
| 464 |
if(cm->trnb_emx != NULL) cm_tr_emit_mx_Destroy(cm->trnb_emx); |
| 465 |
if(cm->trnb_shmx != NULL) cm_tr_shadow_mx_Destroy(cm->trnb_shmx); |
| 466 |
if(cm->cp9_mx != NULL) FreeCP9Matrix(cm->cp9_mx); |
| 467 |
if(cm->cp9_bmx != NULL) FreeCP9Matrix(cm->cp9_bmx); |
| 468 |
if(cm->oesc != NULL || cm->ioesc != NULL) FreeOptimizedEmitScores(cm->oesc, cm->ioesc, cm->M); |
| 469 |
|
| 470 |
if(cm->expA != NULL) { |
| 471 |
for(i = 0; i < EXP_NMODES; i++) { |
| 472 |
free(cm->expA[i]); |
| 473 |
} |
| 474 |
free(cm->expA); |
| 475 |
} |
| 476 |
|
| 477 |
if(cm->mlp7 != NULL) { |
| 478 |
p7_hmm_Destroy(cm->mlp7); |
| 479 |
if(cm->fp7 == cm->mlp7) cm->fp7 = NULL; |
| 480 |
cm->mlp7 = NULL; |
| 481 |
} |
| 482 |
if(cm->fp7 != NULL) { |
| 483 |
p7_hmm_Destroy(cm->fp7); |
| 484 |
cm->fp7 = NULL; |
| 485 |
} |
| 486 |
if(cm->emap != NULL) FreeEmitMap(cm->emap); |
| 487 |
if(cm->cmcons != NULL) FreeCMConsensus(cm->cmcons); |
| 488 |
if(cm->trp != NULL) cm_tr_penalties_Destroy(cm->trp); |
| 489 |
|
| 490 |
free(cm); |
| 491 |
} |
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
int |
| 501 |
DefaultNullModel(const ESL_ALPHABET *abc, float **ret_null) |
| 502 |
{ |
| 503 |
|
| 504 |
if(abc == NULL) cm_Fail("ERROR in CMCreateNullModel, cm->abc is NULL.\n"); |
| 505 |
|
| 506 |
int status; |
| 507 |
float *null = NULL; |
| 508 |
ESL_ALLOC(null, sizeof(float) * abc->K); |
| 509 |
int x; |
| 510 |
for (x = 0; x < abc->K; x++) |
| 511 |
null[x] = 1./(float) abc->K; |
| 512 |
esl_vec_FNorm(null, abc->K); |
| 513 |
*ret_null = null; |
| 514 |
return eslOK; |
| 515 |
|
| 516 |
ERROR: |
| 517 |
if(null != NULL) free(null); |
| 518 |
return status; |
| 519 |
} |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
int |
| 528 |
CMAllocNullModel(CM_t *cm) |
| 529 |
{ |
| 530 |
int status; |
| 531 |
|
| 532 |
|
| 533 |
if(cm->abc == NULL) cm_Fail("ERROR in CMAllocNullModel, cm->abc is NULL.\n"); |
| 534 |
if(cm->null != NULL) cm_Fail("ERROR in CMAllocNullModel, cm->null is not NULL.\n"); |
| 535 |
|
| 536 |
status = DefaultNullModel(cm->abc, &(cm->null)); |
| 537 |
return status; |
| 538 |
} |
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
void |
| 545 |
CMSetNullModel(CM_t *cm, float *null) |
| 546 |
{ |
| 547 |
|
| 548 |
if(cm->abc == NULL) cm_Fail("ERROR in CMCreateNullModel, cm->abc is NULL.\n"); |
| 549 |
if(cm->null == NULL) cm_Fail("ERROR in CMSetNullModel, cm->null is NULL.\n"); |
| 550 |
|
| 551 |
int x; |
| 552 |
for (x = 0; x < cm->abc->K; x++) |
| 553 |
cm->null[x] = null[x]; |
| 554 |
esl_vec_FNorm(cm->null, cm->abc->K); |
| 555 |
return; |
| 556 |
} |
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
|
| 567 |
|
| 568 |
|
| 569 |
int |
| 570 |
CMReadNullModel(const ESL_ALPHABET *abc, char *nullfile, float **ret_null) |
| 571 |
{ |
| 572 |
FILE *fp = NULL; |
| 573 |
float *null = NULL; |
| 574 |
char *buf = NULL; |
| 575 |
char *s; |
| 576 |
int n; |
| 577 |
int x; |
| 578 |
char *tok; |
| 579 |
float sum; |
| 580 |
int status; |
| 581 |
|
| 582 |
|
| 583 |
if (!abc) cm_Fail("ERROR in CMReadNullModel, abc is NULL.\n"); |
| 584 |
|
| 585 |
ESL_ALLOC(null, sizeof(float) * abc->K); |
| 586 |
n = 0; |
| 587 |
sum = 0.; |
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
if ((fp = fopen(nullfile, "r")) == NULL) |
| 595 |
cm_Fail("Failed to open null model file %s\n", nullfile); |
| 596 |
|
| 597 |
|
| 598 |
x = 0; |
| 599 |
while(x < abc->K) { |
| 600 |
if((status = esl_fgets(&buf, &n, fp)) != eslOK) goto ERROR; |
| 601 |
s = buf; |
| 602 |
if((status = esl_strtok(&s, " \t\n", &tok)) != eslOK) goto ERROR; |
| 603 |
if(strcmp(tok, "#") != 0) |
| 604 |
{ |
| 605 |
null[x] = atof(tok); |
| 606 |
sum += null[x]; |
| 607 |
x++; |
| 608 |
} |
| 609 |
} |
| 610 |
|
| 611 |
if(sum > 1.00001 || sum < 0.99999) |
| 612 |
cm_Fail("%s is not in CM null model file format.\nThere are not %d background probabilities that sum to exactly 1.0", nullfile, abc->K); |
| 613 |
esl_vec_FNorm(null, abc->K); |
| 614 |
|
| 615 |
*ret_null = null; |
| 616 |
free(buf); |
| 617 |
fclose(fp); |
| 618 |
return eslOK; |
| 619 |
|
| 620 |
ERROR: |
| 621 |
*ret_null = NULL; |
| 622 |
fclose(fp); |
| 623 |
free(buf); |
| 624 |
free(null); |
| 625 |
return status; |
| 626 |
} |
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
void |
| 635 |
CMSimpleProbify(CM_t *cm) |
| 636 |
{ |
| 637 |
int v,x; |
| 638 |
|
| 639 |
for (v = 0; v < cm->M; v++) |
| 640 |
{ |
| 641 |
|
| 642 |
|
| 643 |
if (cm->sttype[v] != B_st && cm->sttype[v] != E_st) |
| 644 |
{ |
| 645 |
for (x = 0; x < cm->cnum[v]; x++) cm->t[v][x] += 1.0; |
| 646 |
esl_vec_FNorm(cm->t[v], cm->cnum[v]); |
| 647 |
} |
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
if (cm->sttype[v] == MP_st) |
| 652 |
{ |
| 653 |
for (x = 0; x < cm->abc->K*cm->abc->K; x++) cm->e[v][x] += 1.0; |
| 654 |
esl_vec_FNorm(cm->e[v], cm->abc->K*cm->abc->K); |
| 655 |
} |
| 656 |
else if (cm->sttype[v] == ML_st || cm->sttype[v] == MR_st || |
| 657 |
cm->sttype[v] == IL_st || cm->sttype[v] == IR_st) |
| 658 |
{ |
| 659 |
for (x = 0; x < cm->abc->K; x++) cm->e[v][x] += 1.0; |
| 660 |
esl_vec_FNorm(cm->e[v], cm->abc->K); |
| 661 |
} |
| 662 |
} |
| 663 |
} |
| 664 |
|
| 665 |
|
| 666 |
|
| 667 |
|
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
int |
| 683 |
rsearch_CMProbifyEmissions(CM_t *cm, fullmat_t *fullmat) |
| 684 |
{ |
| 685 |
int v,x,y; |
| 686 |
int cur_emission; |
| 687 |
float thresh; |
| 688 |
int found_ct_flag; |
| 689 |
thresh = 0.000001; |
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
if(fullmat->scores_flag) ESL_EXCEPTION(eslEINVAL, "in rsearch_CMProbifyEmissions(), matrix is in log odds mode, it should be in probs mode"); |
| 695 |
if(!(cm->flags & CM_RSEARCHEMIT)) ESL_EXCEPTION(eslEINVAL, "in rsearch_CMProbifyEmissions(), CM_RSEARCHEMIT flag is down"); |
| 696 |
|
| 697 |
for (v = 0; v < cm->M; v++) |
| 698 |
{ |
| 699 |
found_ct_flag = FALSE; |
| 700 |
if (cm->stid[v] == MATP_MP) |
| 701 |
{ |
| 702 |
|
| 703 |
|
| 704 |
for (x=0; x<cm->abc->K; x++) |
| 705 |
for (y=0; y<cm->abc->K; y++) |
| 706 |
if (fabs(cm->e[v][x*cm->abc->K+y] - 0.) > thresh) |
| 707 |
{ |
| 708 |
if(found_ct_flag) |
| 709 |
{ |
| 710 |
for (x=0; x<cm->abc->K; x++) |
| 711 |
for (y=0; y<cm->abc->K; y++) |
| 712 |
printf("cm->e[v:%d][%d]: %f\n", v, (x*cm->abc->K+y), cm->e[v][(x*cm->abc->K+y)]); |
| 713 |
ESL_EXCEPTION(eslEINVAL, "cm->e[v:%d] a MATP_MP has > 1 non-zero count", v); |
| 714 |
} |
| 715 |
cur_emission = numbered_basepair(cm->abc->sym[x], cm->abc->sym[y]); |
| 716 |
found_ct_flag = TRUE; |
| 717 |
} |
| 718 |
|
| 719 |
for (x=0; x<cm->abc->K*cm->abc->K; x++) |
| 720 |
cm->e[v][x] = fullmat->paired->matrix[matrix_index(cur_emission, x)]; |
| 721 |
esl_vec_FNorm(cm->e[v], cm->abc->K*cm->abc->K); |
| 722 |
} |
| 723 |
else if (cm->stid[v] == MATL_ML || cm->stid[v] == MATR_MR) |
| 724 |
{ |
| 725 |
for (x=0; x<cm->abc->K; x++) |
| 726 |
if (fabs(cm->e[v][x] - 0.) > thresh) |
| 727 |
{ |
| 728 |
if(found_ct_flag) { |
| 729 |
for (y=0; y<cm->abc->K; y++) printf("cm->e[v:%d][%d]: %f\n", v, x, cm->e[v][x]); |
| 730 |
ESL_EXCEPTION(eslEINVAL, "cm->e[v:%d] a MAT{L,R}_M{L,R} has > 1 non-zero count", v); |
| 731 |
} |
| 732 |
cur_emission = numbered_nucleotide(cm->abc->sym[x]); |
| 733 |
found_ct_flag = TRUE; |
| 734 |
} |
| 735 |
|
| 736 |
for (x=0; x<cm->abc->K; x++) |
| 737 |
cm->e[v][x] = fullmat->unpaired->matrix[matrix_index(cur_emission, x)]; |
| 738 |
esl_vec_FNorm(cm->e[v], cm->abc->K); |
| 739 |
} |
| 740 |
else if (cm->stid[v] == MATP_ML || cm->stid[v] == MATP_MR) |
| 741 |
{ |
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
for (x=0; x<cm->abc->K; x++) |
| 748 |
for (y=0; y<cm->abc->K; y++) |
| 749 |
{ |
| 750 |
if (cm->stid[v] == MATP_ML && (fabs(cm->e[(v-1)][x*cm->abc->K + y] - 0.) > thresh)) |
| 751 |
cur_emission = numbered_nucleotide(cm->abc->sym[x]); |
| 752 |
else if (cm->stid[v] == MATP_MR && (fabs(cm->e[(v-2)][x*cm->abc->K + y] - 0.) > thresh)) |
| 753 |
cur_emission = numbered_nucleotide(cm->abc->sym[y]); |
| 754 |
|
| 755 |
|
| 756 |
} |
| 757 |
|
| 758 |
for (x=0; x<cm->abc->K; x++) |
| 759 |
cm->e[v][x] = fullmat->unpaired->matrix[matrix_index(cur_emission, x)]; |
| 760 |
esl_vec_FNorm(cm->e[v], cm->abc->K); |
| 761 |
} |
| 762 |
else if (cm->sttype[v] == IL_st || cm->sttype[v] == IR_st) |
| 763 |
{ |
| 764 |
|
| 765 |
|
| 766 |
for (x = 0; x < cm->abc->K; x++) |
| 767 |
if(fabs(cm->e[v][x] - 0.) > thresh) ESL_EXCEPTION(eslEINVAL, "cm->e[v:%d] an I{L,R} has > 0 non-zero count", v); |
| 768 |
esl_vec_FNorm(cm->e[v], cm->abc->K); |
| 769 |
} |
| 770 |
} |
| 771 |
return eslOK; |
| 772 |
} |
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
int |
| 784 |
CMLogoddsify(CM_t *cm) |
| 785 |
{ |
| 786 |
|
| 787 |
int v, x, y; |
| 788 |
|
| 789 |
|
| 790 |
esl_vec_FSet(cm->lmesc[0], cm->M * cm->abc->Kp, 0.); |
| 791 |
esl_vec_FSet(cm->rmesc[0], cm->M * cm->abc->Kp, 0.); |
| 792 |
|
| 793 |
for (v = 0; v < cm->M; v++) { |
| 794 |
|
| 795 |
cm->lmesc[v][cm->abc->K] = cm->rmesc[v][cm->abc->K] = IMPOSSIBLE; |
| 796 |
cm->lmesc[v][cm->abc->Kp-2] = cm->rmesc[v][cm->abc->Kp-2] = IMPOSSIBLE; |
| 797 |
cm->lmesc[v][cm->abc->Kp-1] = cm->rmesc[v][cm->abc->Kp-1] = IMPOSSIBLE; |
| 798 |
cm->ilmesc[v][cm->abc->K] = cm->irmesc[v][cm->abc->K] = -INFTY; ; |
| 799 |
cm->ilmesc[v][cm->abc->Kp-2] = cm->irmesc[v][cm->abc->Kp-2] = -INFTY; ; |
| 800 |
cm->ilmesc[v][cm->abc->Kp-1] = cm->irmesc[v][cm->abc->Kp-1] = -INFTY; ; |
| 801 |
|
| 802 |
if (cm->sttype[v] != B_st && cm->sttype[v] != E_st) { |
| 803 |
for (x = 0; x < cm->cnum[v]; x++) { |
| 804 |
cm->tsc[v][x] = sreLOG2(cm->t[v][x]); |
| 805 |
cm->itsc[v][x] = Prob2Score(cm->t[v][x], 1.0); |
| 806 |
|
| 807 |
} |
| 808 |
} |
| 809 |
if (cm->sttype[v] == MP_st) { |
| 810 |
for (x = 0; x < cm->abc->K; x++) { |
| 811 |
for (y = 0; y < cm->abc->K; y++) { |
| 812 |
cm->esc[v][x*cm->abc->K+y] = sreLOG2 (cm->e[v][x*cm->abc->K+y] / (cm->null[x]*cm->null[y])); |
| 813 |
cm->iesc[v][x*cm->abc->K+y] = Prob2Score(cm->e[v][x*cm->abc->K+y], (cm->null[x]*cm->null[y])); |
| 814 |
|
| 815 |
cm->lmesc[v][x] += cm->e[v][x*cm->abc->K+y]; |
| 816 |
cm->rmesc[v][y] += cm->e[v][x*cm->abc->K+y]; |
| 817 |
} |
| 818 |
} |
| 819 |
for (x = 0; x < cm->abc->K; x++) { |
| 820 |
cm->ilmesc[v][x] = Prob2Score(cm->lmesc[v][x], cm->null[x]); |
| 821 |
cm->irmesc[v][x] = Prob2Score(cm->rmesc[v][x], cm->null[x]); |
| 822 |
cm->lmesc[v][x] = sreLOG2 (cm->lmesc[v][x] / cm->null[x]); |
| 823 |
cm->rmesc[v][x] = sreLOG2 (cm->rmesc[v][x] / cm->null[x]); |
| 824 |
} |
| 825 |
|
| 826 |
esl_abc_FExpectScVec(cm->abc, cm->lmesc[v], cm->null); |
| 827 |
esl_abc_FExpectScVec(cm->abc, cm->rmesc[v], cm->null); |
| 828 |
esl_abc_IExpectScVec(cm->abc, cm->ilmesc[v], cm->null); |
| 829 |
esl_abc_IExpectScVec(cm->abc, cm->irmesc[v], cm->null); |
| 830 |
} |
| 831 |
else if (cm->sttype[v] == ML_st || cm->sttype[v] == MR_st || cm->sttype[v] == IL_st || cm->sttype[v] == IR_st) { |
| 832 |
for (x = 0; x < cm->abc->K; x++) { |
| 833 |
cm->esc[v][x] = sreLOG2(cm->e[v][x] / cm->null[x]); |
| 834 |
cm->iesc[v][x] = Prob2Score(cm->e[v][x], cm->null[x]); |
| 835 |
|
| 836 |
|
| 837 |
} |
| 838 |
|
| 839 |
if(cm->sttype[v] == ML_st || cm->sttype[v] == IL_st) { |
| 840 |
for (x = 0; x < cm->abc->K; x++) { |
| 841 |
cm->lmesc[v][x] = cm->esc[v][x]; |
| 842 |
cm->ilmesc[v][x] = cm->iesc[v][x]; |
| 843 |
cm->rmesc[v][x] = 0.; |
| 844 |
cm->irmesc[v][x] = 0; |
| 845 |
} |
| 846 |
esl_abc_FExpectScVec(cm->abc, cm->lmesc[v], cm->null); |
| 847 |
esl_abc_IExpectScVec(cm->abc, cm->ilmesc[v], cm->null); |
| 848 |
esl_vec_FSet(cm->rmesc[v] + cm->abc->K+1, ((cm->abc->Kp-3) - cm->abc->K), 0.); |
| 849 |
esl_vec_ISet(cm->irmesc[v] + cm->abc->K+1, ((cm->abc->Kp-3) - cm->abc->K), 0); |
| 850 |
} |
| 851 |
else if(cm->sttype[v] == MR_st || cm->sttype[v] == IR_st) { |
| 852 |
for (x = 0; x < cm->abc->K; x++) { |
| 853 |
cm->lmesc[v][x] = 0.; |
| 854 |
cm->ilmesc[v][x] = 0; |
| 855 |
cm->rmesc[v][x] = cm->esc[v][x]; |
| 856 |
cm->irmesc[v][x] = cm->iesc[v][x]; |
| 857 |
} |
| 858 |
esl_vec_FSet(cm->lmesc[v] + cm->abc->K+1, ((cm->abc->Kp-3) - cm->abc->K), 0.); |
| 859 |
esl_vec_ISet(cm->ilmesc[v] + cm->abc->K+1, ((cm->abc->Kp-3) - cm->abc->K), 0); |
| 860 |
esl_abc_FExpectScVec(cm->abc, cm->rmesc[v], cm->null); |
| 861 |
esl_abc_IExpectScVec(cm->abc, cm->irmesc[v], cm->null); |
| 862 |
} |
| 863 |
} |
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
cm->beginsc[v] = sreLOG2(cm->begin[v]); |
| 869 |
cm->ibeginsc[v] = Prob2Score(cm->begin[v], 1.0); |
| 870 |
|
| 871 |
|
| 872 |
cm->endsc[v] = sreLOG2(cm->end[v]); |
| 873 |
cm->iendsc[v] = Prob2Score(cm->end[v], 1.0); |
| 874 |
|
| 875 |
} |
| 876 |
|
| 877 |
cm->iel_selfsc = Prob2Score(sreEXP2(cm->el_selfsc), 1.0); |
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
if(cm->oesc != NULL || cm->ioesc != NULL) FreeOptimizedEmitScores(cm->oesc, cm->ioesc, cm->M); |
| 886 |
cm->oesc = FCalcOptimizedEmitScores(cm); |
| 887 |
|
| 888 |
|
| 889 |
|
| 890 |
|
| 891 |
cm->ioesc = ICopyOptimizedEmitScoresFromFloats(cm, cm->oesc); |
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
if(cm->flags & CM_RSEARCHTRANS) |
| 898 |
{ |
| 899 |
float alpha = DEFAULT_RALPHA; |
| 900 |
float beta = DEFAULT_RBETA; |
| 901 |
float alphap = DEFAULT_RALPHAP; |
| 902 |
float betap = DEFAULT_RBETAP; |
| 903 |
float beginsc = DEFAULT_RBEGINSC; |
| 904 |
float endsc = DEFAULT_RENDSC; |
| 905 |
int nd; |
| 906 |
|
| 907 |
for (v=0; v<cm->M; v++) |
| 908 |
{ |
| 909 |
if (cm->sttype[v] != B_st && cm->sttype[v] != E_st) |
| 910 |
{ |
| 911 |
for (x=0; x<cm->cnum[v]; x++) |
| 912 |
{ |
| 913 |
cm->tsc[v][x] = -1. * rsearch_calculate_gap_penalty |
| 914 |
(cm->stid[v], cm->stid[cm->cfirst[v]+x], |
| 915 |
cm->ndtype[cm->ndidx[v]], cm->ndtype[cm->ndidx[cm->cfirst[v]+x]], |
| 916 |
alpha, beta, alphap, betap); |
| 917 |
|
| 918 |
|
| 919 |
cm->itsc[v][x] = INTSCALE * cm->tsc[v][x]; |
| 920 |
} |
| 921 |
} |
| 922 |
} |
| 923 |
|
| 924 |
for (v=cm->M - 1; v>=0; v--) { |
| 925 |
cm->beginsc[v] = IMPOSSIBLE; |
| 926 |
cm->endsc[v] = IMPOSSIBLE; |
| 927 |
} |
| 928 |
|
| 929 |
|
| 930 |
for (nd = 2; nd < cm->nodes; nd++) { |
| 931 |
if (cm->ndtype[nd] == MATP_nd || cm->ndtype[nd] == MATL_nd || |
| 932 |
cm->ndtype[nd] == MATR_nd || cm->ndtype[nd] == BIF_nd) |
| 933 |
{ |
| 934 |
cm->beginsc[cm->nodemap[nd]] = beginsc; |
| 935 |
cm->ibeginsc[cm->nodemap[nd]] = INTSCALE * beginsc; |
| 936 |
} |
| 937 |
} |
| 938 |
|
| 939 |
|
| 940 |
for (nd = 1; nd < cm->nodes; nd++) { |
| 941 |
if ((cm->ndtype[nd] == MATP_nd || cm->ndtype[nd] == MATL_nd || |
| 942 |
cm->ndtype[nd] == MATR_nd || cm->ndtype[nd] == BEGL_nd || |
| 943 |
cm->ndtype[nd] == BEGR_nd) && |
| 944 |
cm->ndtype[nd+1] != END_nd) |
| 945 |
{ |
| 946 |
cm->endsc[cm->nodemap[nd]] = endsc; |
| 947 |
cm->iendsc[cm->nodemap[nd]] = INTSCALE * endsc; |
| 948 |
} |
| 949 |
} |
| 950 |
|
| 951 |
cm->flags |= CMH_LOCAL_BEGIN; |
| 952 |
cm->flags |= CMH_LOCAL_END; |
| 953 |
} |
| 954 |
|
| 955 |
|
| 956 |
cm->flags |= CMH_BITS; |
| 957 |
|
| 958 |
|
| 959 |
if(cm->cmcons != NULL) FreeCMConsensus(cm->cmcons); |
| 960 |
if((cm->cmcons = CreateCMConsensus(cm, cm->abc)) == NULL) return eslFAIL; |
| 961 |
|
| 962 |
return eslOK; |
| 963 |
} |
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
int |
| 985 |
CMSegmentCountStatetype(CM_t *cm, int r, int z, char type) |
| 986 |
{ |
| 987 |
int count = 0; |
| 988 |
int v; |
| 989 |
for (v = r; v <= z; v++) |
| 990 |
if (cm->sttype[v] == type) count++; |
| 991 |
return count; |
| 992 |
} |
| 993 |
int |
| 994 |
CMSubtreeCountStatetype(CM_t *cm, int v, char type) |
| 995 |
{ |
| 996 |
int unsatisfied_starts = 1; |
| 997 |
int count = 0; |
| 998 |
|
| 999 |
while (unsatisfied_starts) { |
| 1000 |
if (cm->sttype[v] == B_st) unsatisfied_starts++; |
| 1001 |
if (cm->sttype[v] == E_st) unsatisfied_starts--; |
| 1002 |
if (cm->sttype[v] == type) count++; |
| 1003 |
v++; |
| 1004 |
} |
| 1005 |
return count; |
| 1006 |
} |
| 1007 |
int |
| 1008 |
CMCountStatetype(CM_t *cm, char type) |
| 1009 |
{ |
| 1010 |
return CMSubtreeCountStatetype(cm, 0, type); |
| 1011 |
} |
| 1012 |
int |
| 1013 |
CMSubtreeFindEnd(CM_t *cm, int r) |
| 1014 |
{ |
| 1015 |
int unsatisfied_starts = 1; |
| 1016 |
|
| 1017 |
while (unsatisfied_starts) { |
| 1018 |
if (cm->sttype[r] == B_st) unsatisfied_starts++; |
| 1019 |
if (cm->sttype[r] == E_st) unsatisfied_starts--; |
| 1020 |
r++; |
| 1021 |
} |
| 1022 |
return (r-1); |
| 1023 |
} |
| 1024 |
int |
| 1025 |
CMCountNodetype(CM_t *cm, char type) |
| 1026 |
{ |
| 1027 |
int nd; |
| 1028 |
int count = 0; |
| 1029 |
for(nd = 0; nd < cm->nodes; nd++) { |
| 1030 |
if(cm->ndtype[nd] == type) count++; |
| 1031 |
} |
| 1032 |
return count; |
| 1033 |
} |
| 1034 |
int |
| 1035 |
CMSubtreeCountNodetype(CM_t *cm, int v, char type) |
| 1036 |
{ |
| 1037 |
int unsatisfied_starts = 1; |
| 1038 |
int count = 0; |
| 1039 |
|
| 1040 |
while (unsatisfied_starts) { |
| 1041 |
if (cm->sttype[v] == B_st) unsatisfied_starts++; |
| 1042 |
if (cm->sttype[v] == E_st) unsatisfied_starts--; |
| 1043 |
if (cm->stid[v] == type) count++; |
| 1044 |
v++; |
| 1045 |
} |
| 1046 |
return count; |
| 1047 |
} |
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
int |
| 1068 |
CalculateStateIndex(CM_t *cm, int node, char utype) |
| 1069 |
{ |
| 1070 |
int base; |
| 1071 |
|
| 1072 |
base = cm->nodemap[node]; |
| 1073 |
switch (utype) { |
| 1074 |
case ROOT_S: return base; |
| 1075 |
case ROOT_IL: return base+1; |
| 1076 |
case ROOT_IR: return base+2; |
| 1077 |
case BEGL_S: return base; |
| 1078 |
case BEGR_S: return base; |
| 1079 |
case BEGR_IL: return base+1; |
| 1080 |
case MATP_MP: return base; |
| 1081 |
case MATP_ML: return base+1; |
| 1082 |
case MATP_MR: return base+2; |
| 1083 |
case MATP_D: return base+3; |
| 1084 |
case MATP_IL: return base+4; |
| 1085 |
case MATP_IR: return base+5; |
| 1086 |
case MATL_ML: return base; |
| 1087 |
case MATL_D: return base+1; |
| 1088 |
case MATL_IL: return base+2; |
| 1089 |
case MATR_MR: return base; |
| 1090 |
case MATR_D: return base+1; |
| 1091 |
case MATR_IR: return base+2; |
| 1092 |
case END_E: return base; |
| 1093 |
case BIF_B: return base; |
| 1094 |
default: cm_Fail("bogus utype %d in CalculateStateIndex()", utype); |
| 1095 |
} |
| 1096 |
return base; |
| 1097 |
} |
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
int |
| 1107 |
TotalStatesInNode(int ndtype) |
| 1108 |
{ |
| 1109 |
switch (ndtype) { |
| 1110 |
case BIF_nd: return 1; |
| 1111 |
case MATP_nd: return 6; |
| 1112 |
case MATL_nd: return 3; |
| 1113 |
case MATR_nd: return 3; |
| 1114 |
case BEGL_nd: return 1; |
| 1115 |
case BEGR_nd: return 2; |
| 1116 |
case ROOT_nd: return 3; |
| 1117 |
case END_nd: return 1; |
| 1118 |
default: cm_Fail("Bogus node type %d", ndtype); |
| 1119 |
} |
| 1120 |
return 0; |
| 1121 |
} |
| 1122 |
int |
| 1123 |
SplitStatesInNode(int ndtype) |
| 1124 |
{ |
| 1125 |
switch (ndtype) { |
| 1126 |
case BIF_nd: return 1; |
| 1127 |
case MATP_nd: return 4; |
| 1128 |
case MATL_nd: return 2; |
| 1129 |
case MATR_nd: return 2; |
| 1130 |
case BEGL_nd: return 1; |
| 1131 |
case BEGR_nd: return 1; |
| 1132 |
case ROOT_nd: return 1; |
| 1133 |
case END_nd: return 1; |
| 1134 |
default: cm_Fail("Bogus node type %d", ndtype); |
| 1135 |
} |
| 1136 |
return 0; |
| 1137 |
} |
| 1138 |
int |
| 1139 |
InsertStatesInNode(int ndtype) |
| 1140 |
{ |
| 1141 |
switch (ndtype) { |
| 1142 |
case BIF_nd: return 0; |
| 1143 |
case MATP_nd: return 2; |
| 1144 |
case MATL_nd: return 1; |
| 1145 |
case MATR_nd: return 1; |
| 1146 |
case BEGL_nd: return 0; |
| 1147 |
case BEGR_nd: return 1; |
| 1148 |
case ROOT_nd: return 2; |
| 1149 |
case END_nd: return 0; |
| 1150 |
default: cm_Fail("Bogus node type %d", ndtype); |
| 1151 |
} |
| 1152 |
return 0; |
| 1153 |
} |
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
|
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
int |
| 1177 |
StateDelta(int sttype) |
| 1178 |
{ |
| 1179 |
switch (sttype) { |
| 1180 |
case D_st: return 0; |
| 1181 |
case MP_st: return 2; |
| 1182 |
case ML_st: return 1; |
| 1183 |
case MR_st: return 1; |
| 1184 |
case IL_st: return 1; |
| 1185 |
case IR_st: return 1; |
| 1186 |
case S_st: return 0; |
| 1187 |
case E_st: return 0; |
| 1188 |
case B_st: return 0; |
| 1189 |
case EL_st: return 0; |
| 1190 |
default: cm_Fail("bogus state type %d\n", sttype); |
| 1191 |
} |
| 1192 |
|
| 1193 |
return 0; |
| 1194 |
} |
| 1195 |
int |
| 1196 |
StateLeftDelta(int sttype) |
| 1197 |
{ |
| 1198 |
switch (sttype) { |
| 1199 |
case D_st: return 0; |
| 1200 |
case MP_st: return 1; |
| 1201 |
case ML_st: return 1; |
| 1202 |
case MR_st: return 0; |
| 1203 |
case IL_st: return 1; |
| 1204 |
case IR_st: return 0; |
| 1205 |
case S_st: return 0; |
| 1206 |
case E_st: return 0; |
| 1207 |
case B_st: return 0; |
| 1208 |
case EL_st: return 0; |
| 1209 |
default: cm_Fail("bogus state type %d\n", sttype); |
| 1210 |
} |
| 1211 |
|
| 1212 |
return 0; |
| 1213 |
} |
| 1214 |
int |
| 1215 |
StateRightDelta(int sttype) |
| 1216 |
{ |
| 1217 |
switch (sttype) { |
| 1218 |
case D_st: return 0; |
| 1219 |
case MP_st: return 1; |
| 1220 |
case ML_st: return 0; |
| 1221 |
case MR_st: return 1; |
| 1222 |
case IL_st: return 0; |
| 1223 |
case IR_st: return 1; |
| 1224 |
case S_st: return 0; |
| 1225 |
case E_st: return 0; |
| 1226 |
case B_st: return 0; |
| 1227 |
case EL_st: return 0; |
| 1228 |
default: cm_Fail("bogus state type %d\n", sttype); |
| 1229 |
} |
| 1230 |
|
| 1231 |
return 0; |
| 1232 |
} |
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
int |
| 1244 |
Emitmode(int sttype) |
| 1245 |
{ |
| 1246 |
switch (sttype) { |
| 1247 |
case IL_st: return EMITLEFT; |
| 1248 |
case IR_st: return EMITRIGHT; |
| 1249 |
case D_st: return EMITNONE; |
| 1250 |
case ML_st: return EMITLEFT; |
| 1251 |
case MR_st: return EMITRIGHT; |
| 1252 |
case MP_st: return EMITPAIR; |
| 1253 |
case S_st: return EMITNONE; |
| 1254 |
case E_st: return EMITNONE; |
| 1255 |
case B_st: return EMITNONE; |
| 1256 |
case EL_st: return EMITNONE; |
| 1257 |
default: cm_Fail("bogus state type %d\n", sttype); |
| 1258 |
} |
| 1259 |
|
| 1260 |
return 0; |
| 1261 |
} |
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
int |
| 1274 |
NumReachableInserts(int stid) |
| 1275 |
{ |
| 1276 |
switch (stid) { |
| 1277 |
case MATL_ML: return 1; |
| 1278 |
case MATL_D: return 1; |
| 1279 |
case MATL_IL: return 1; |
| 1280 |
case MATP_MP: return 2; |
| 1281 |
case MATP_ML: return 2; |
| 1282 |
case MATP_MR: return 2; |
| 1283 |
case MATP_D: return 2; |
| 1284 |
case MATP_IL: return 2; |
| 1285 |
case MATP_IR: return 1; |
| 1286 |
case MATR_MR: return 1; |
| 1287 |
case MATR_D: return 1; |
| 1288 |
case MATR_IR: return 1; |
| 1289 |
case BIF_B: return 0; |
| 1290 |
case BEGL_S: return 0; |
| 1291 |
case BEGR_S: return 1; |
| 1292 |
case BEGR_IL: return 1; |
| 1293 |
case END_E: return 0; |
| 1294 |
case ROOT_S: return 2; |
| 1295 |
case ROOT_IL: return 2; |
| 1296 |
case ROOT_IR: return 1; |
| 1297 |
case END_EL: return 0; |
| 1298 |
default: cm_Fail("bogus state id %d\n", stid); |
| 1299 |
} |
| 1300 |
|
| 1301 |
return 0; |
| 1302 |
} |
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
void |
| 1315 |
PrintCM(FILE *fp, CM_t *cm) |
| 1316 |
{ |
| 1317 |
int x; |
| 1318 |
|
| 1319 |
fprintf(fp, "%5s %6s %5s %6s %7s %6s %5s %5s %5s\n", |
| 1320 |
" idx ","sttype", "ndidx", "ndtype", " stid ", "cfirst", " cnum", "plast", " pnum"); |
| 1321 |
fprintf(fp, "%5s %6s %5s %6s %7s %5s %5s %5s %5s\n", |
| 1322 |
"-----", "------", "-----", "------","-------","------","-----", "-----", "-----"); |
| 1323 |
|
| 1324 |
for (x = 0; x < cm->M; x++) |
| 1325 |
{ |
| 1326 |
fprintf(fp, "%5d %-6s %5d %6s %-7s %6d %5d %5d %5d\n", |
| 1327 |
x, Statetype(cm->sttype[x]), cm->ndidx[x], |
| 1328 |
Nodetype(cm->ndtype[cm->ndidx[x]]), UniqueStatetype(cm->stid[x]), |
| 1329 |
cm->cfirst[x], cm->cnum[x], |
| 1330 |
cm->plast[x], cm->pnum[x]); |
| 1331 |
} |
| 1332 |
} |
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
void |
| 1346 |
SummarizeCM(FILE *fp, CM_t *cm) |
| 1347 |
{ |
| 1348 |
int x; |
| 1349 |
int count[UNIQUESTATES]; |
| 1350 |
|
| 1351 |
for (x = 0; x < UNIQUESTATES; x++) count[x] = 0; |
| 1352 |
|
| 1353 |
for (x = 0; x < cm->M; x++) |
| 1354 |
count[(int) cm->stid[x]]++; |
| 1355 |
|
| 1356 |
fprintf(fp, "Summary report for CM structure:\n"); |
| 1357 |
fprintf(fp, "--------------------------------------\n"); |
| 1358 |
fprintf(fp, "Total states: %4d\n", cm->M); |
| 1359 |
fprintf(fp, "Total nodes: %4d\n", cm->nodes); |
| 1360 |
fprintf(fp, "Bifurcations: %4d\n", count[BIF_B]); |
| 1361 |
fprintf(fp, "MATP nodes: %4d\n", count[MATP_MP]); |
| 1362 |
fprintf(fp, "MATL nodes: %4d\n", count[MATL_ML]); |
| 1363 |
fprintf(fp, "MATR nodes: %4d\n", count[MATR_MR]); |
| 1364 |
fprintf(fp, "Consensus columns: %4d (2*MATP+MATL+MATR)\n", |
| 1365 |
count[MATP_MP]*2+count[MATL_ML]+count[MATR_MR]); |
| 1366 |
fprintf(fp, "Base pairs: %4d (MATP)\n", count[MATP_MP]); |
| 1367 |
fprintf(fp, "Single stranded: %4d (MATL+MATR)\n", count[MATL_ML]+count[MATR_MR]); |
| 1368 |
|
| 1369 |
|
| 1370 |
} |
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
char * |
| 1386 |
Statetype(int type) |
| 1387 |
{ |
| 1388 |
switch (type) { |
| 1389 |
case D_st: return "D"; |
| 1390 |
case MP_st: return "MP"; |
| 1391 |
case ML_st: return "ML"; |
| 1392 |
case MR_st: return "MR"; |
| 1393 |
case IL_st: return "IL"; |
| 1394 |
case IR_st: return "IR"; |
| 1395 |
case S_st: return "S"; |
| 1396 |
case E_st: return "E"; |
| 1397 |
case B_st: return "B"; |
| 1398 |
case EL_st: return "EL"; |
| 1399 |
default: cm_Fail("bogus state type %d\n", type); |
| 1400 |
} |
| 1401 |
return ""; |
| 1402 |
} |
| 1403 |
int |
| 1404 |
StateCode(char *s) |
| 1405 |
{ |
| 1406 |
if (strcmp(s, "D") == 0) return D_st; |
| 1407 |
else if (strcmp(s, "MP") == 0) return MP_st; |
| 1408 |
else if (strcmp(s, "ML") == 0) return ML_st; |
| 1409 |
else if (strcmp(s, "MR") == 0) return MR_st; |
| 1410 |
else if (strcmp(s, "IL") == 0) return IL_st; |
| 1411 |
else if (strcmp(s, "IR") == 0) return IR_st; |
| 1412 |
else if (strcmp(s, "S") == 0) return S_st; |
| 1413 |
else if (strcmp(s, "E") == 0) return E_st; |
| 1414 |
else if (strcmp(s, "B") == 0) return B_st; |
| 1415 |
else if (strcmp(s, "EL") == 0) return EL_st; |
| 1416 |
return -1; |
| 1417 |
} |
| 1418 |
char * |
| 1419 |
Nodetype(int type) |
| 1420 |
{ |
| 1421 |
switch (type) { |
| 1422 |
case DUMMY_nd: return "-"; |
| 1423 |
case BIF_nd: return "BIF"; |
| 1424 |
case MATP_nd: return "MATP"; |
| 1425 |
case MATL_nd: return "MATL"; |
| 1426 |
case MATR_nd: return "MATR"; |
| 1427 |
case BEGL_nd: return "BEGL"; |
| 1428 |
case BEGR_nd: return "BEGR"; |
| 1429 |
case ROOT_nd: return "ROOT"; |
| 1430 |
case END_nd: return "END"; |
| 1431 |
default: cm_Fail("bogus node type %d\n", type); |
| 1432 |
} |
| 1433 |
return ""; |
| 1434 |
} |
| 1435 |
int |
| 1436 |
NodeCode(char *s) |
| 1437 |
{ |
| 1438 |
if (strcmp(s, "BIF") == 0) return BIF_nd; |
| 1439 |
else if (strcmp(s, "MATP") == 0) return MATP_nd; |
| 1440 |
else if (strcmp(s, "MATL") == 0) return MATL_nd; |
| 1441 |
else if (strcmp(s, "MATR") == 0) return MATR_nd; |
| 1442 |
else if (strcmp(s, "BEGL") == 0) return BEGL_nd; |
| 1443 |
else if (strcmp(s, "BEGR") == 0) return BEGR_nd; |
| 1444 |
else if (strcmp(s, "ROOT") == 0) return ROOT_nd; |
| 1445 |
else if (strcmp(s, "END") == 0) return END_nd; |
| 1446 |
return -1; |
| 1447 |
} |
| 1448 |
char * |
| 1449 |
UniqueStatetype(int type) |
| 1450 |
{ |
| 1451 |
switch (type) { |
| 1452 |
case DUMMY: return "DUMMY"; |
| 1453 |
case ROOT_S: return "ROOT_S"; |
| 1454 |
case ROOT_IL: return "ROOT_IL"; |
| 1455 |
case ROOT_IR: return "ROOT_IR"; |
| 1456 |
case BEGL_S : return "BEGL_S"; |
| 1457 |
case BEGR_S : return "BEGR_S"; |
| 1458 |
case BEGR_IL: return "BEGR_IL"; |
| 1459 |
case MATP_MP: return "MATP_MP"; |
| 1460 |
case MATP_ML: return "MATP_ML"; |
| 1461 |
case MATP_MR: return "MATP_MR"; |
| 1462 |
case MATP_D : return "MATP_D"; |
| 1463 |
case MATP_IL: return "MATP_IL"; |
| 1464 |
case MATP_IR: return "MATP_IR"; |
| 1465 |
case MATL_ML: return "MATL_ML"; |
| 1466 |
case MATL_D : return "MATL_D"; |
| 1467 |
case MATL_IL: return "MATL_IL"; |
| 1468 |
case MATR_MR: return "MATR_MR"; |
| 1469 |
case MATR_D : return "MATR_D"; |
| 1470 |
case MATR_IR: return "MATR_IR"; |
| 1471 |
case END_E : return "END_E"; |
| 1472 |
case BIF_B : return "BIF_B"; |
| 1473 |
case END_EL : return "END_EL"; |
| 1474 |
default: cm_Fail("bogus unique state type %d\n", type); |
| 1475 |
} |
| 1476 |
return ""; |
| 1477 |
} |
| 1478 |
int |
| 1479 |
UniqueStateCode(char *s) |
| 1480 |
{ |
| 1481 |
if (strcmp(s, "ROOT_S") == 0) return ROOT_S; |
| 1482 |
else if (strcmp(s, "ROOT_IL") == 0) return ROOT_IL; |
| 1483 |
else if (strcmp(s, "ROOT_IR") == 0) return ROOT_IR; |
| 1484 |
else if (strcmp(s, "BEGL_S") == 0) return BEGL_S; |
| 1485 |
else if (strcmp(s, "BEGR_S") == 0) return BEGR_S; |
| 1486 |
else if (strcmp(s, "BEGR_IL") == 0) return BEGR_IL; |
| 1487 |
else if (strcmp(s, "MATP_MP") == 0) return MATP_MP; |
| 1488 |
else if (strcmp(s, "MATP_ML") == 0) return MATP_ML; |
| 1489 |
else if (strcmp(s, "MATP_MR") == 0) return MATP_MR; |
| 1490 |
else if (strcmp(s, "MATP_D") == 0) return MATP_D; |
| 1491 |
else if (strcmp(s, "MATP_IL") == 0) return MATP_IL; |
| 1492 |
else if (strcmp(s, "MATP_IR") == 0) return MATP_IR; |
| 1493 |
else if (strcmp(s, "MATL_ML") == 0) return MATL_ML; |
| 1494 |
else if (strcmp(s, "MATL_D") == 0) return MATL_D; |
| 1495 |
else if (strcmp(s, "MATL_IL") == 0) return MATL_IL; |
| 1496 |
else if (strcmp(s, "MATR_MR") == 0) return MATR_MR; |
| 1497 |
else if (strcmp(s, "MATR_D") == 0) return MATR_D; |
| 1498 |
else if (strcmp(s, "MATR_IR") == 0) return MATR_IR; |
| 1499 |
else if (strcmp(s, "BIF_B") == 0) return BIF_B; |
| 1500 |
else if (strcmp(s, "END_E") == 0) return END_E; |
| 1501 |
else if (strcmp(s, "END_EL") == 0) return END_EL; |
| 1502 |
else cm_Fail("bogus unique statetype %s\n", s); |
| 1503 |
return 0; |
| 1504 |
} |
| 1505 |
int |
| 1506 |
DeriveUniqueStateCode(int ndtype, int sttype) |
| 1507 |
{ |
| 1508 |
switch (ndtype) { |
| 1509 |
case BIF_nd: |
| 1510 |
switch (sttype) { |
| 1511 |
case B_st: return BIF_B; |
| 1512 |
default: return -1; |
| 1513 |
} |
| 1514 |
case MATP_nd: |
| 1515 |
switch (sttype) { |
| 1516 |
case D_st: return MATP_D; |
| 1517 |
case MP_st: return MATP_MP; |
| 1518 |
case ML_st: return MATP_ML; |
| 1519 |
case MR_st: return MATP_MR; |
| 1520 |
case IL_st: return MATP_IL; |
| 1521 |
case IR_st: return MATP_IR; |
| 1522 |
default: return -1; |
| 1523 |
} |
| 1524 |
case MATL_nd: |
| 1525 |
switch (sttype) { |
| 1526 |
case D_st: return MATL_D; |
| 1527 |
case ML_st: return MATL_ML; |
| 1528 |
case IL_st: return MATL_IL; |
| 1529 |
default: return -1; |
| 1530 |
} |
| 1531 |
case MATR_nd: |
| 1532 |
switch (sttype) { |
| 1533 |
case D_st: return MATR_D; |
| 1534 |
case MR_st: return MATR_MR; |
| 1535 |
case IR_st: return MATR_IR; |
| 1536 |
default: return -1; |
| 1537 |
} |
| 1538 |
case BEGL_nd: |
| 1539 |
switch (sttype) { |
| 1540 |
case S_st: return BEGL_S; |
| 1541 |
default: return -1; |
| 1542 |
} |
| 1543 |
case BEGR_nd: |
| 1544 |
switch (sttype) { |
| 1545 |
case S_st: return BEGR_S; |
| 1546 |
case IL_st: return BEGR_IL; |
| 1547 |
default: return -1; |
| 1548 |
} |
| 1549 |
case ROOT_nd: |
| 1550 |
switch (sttype) { |
| 1551 |
case S_st: return ROOT_S; |
| 1552 |
case IL_st: return ROOT_IL; |
| 1553 |
case IR_st: return ROOT_IR; |
| 1554 |
default: return -1; |
| 1555 |
} |
| 1556 |
case END_nd: |
| 1557 |
switch (sttype) { |
| 1558 |
case E_st: return END_E; |
| 1559 |
default: return -1; |
| 1560 |
} |
| 1561 |
default: |
| 1562 |
return -1; |
| 1563 |
} |
| 1564 |
} |
| 1565 |
|
| 1566 |
|
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
char * |
| 1578 |
MarginalMode(char mode) |
| 1579 |
{ |
| 1580 |
switch (mode) { |
| 1581 |
case TRMODE_J: return "Joint"; |
| 1582 |
case TRMODE_L: return "Left"; |
| 1583 |
case TRMODE_R: return "Right"; |
| 1584 |
case TRMODE_T: return "Term"; |
| 1585 |
case TRMODE_UNKNOWN: return "Unkwn"; |
| 1586 |
default: cm_Fail("bogus marginal mode type %d\n", mode); |
| 1587 |
} |
| 1588 |
return ""; |
| 1589 |
} |
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
|
| 1597 |
|
| 1598 |
int |
| 1599 |
ModeEmitsLeft(char mode) |
| 1600 |
{ |
| 1601 |
if(mode == TRMODE_J || mode == TRMODE_L) return TRUE; |
| 1602 |
return FALSE; |
| 1603 |
} |
| 1604 |
|
| 1605 |
|
| 1606 |
|
| 1607 |
|
| 1608 |
|
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
int |
| 1613 |
ModeEmitsRight(char mode) |
| 1614 |
{ |
| 1615 |
if(mode == TRMODE_J || mode == TRMODE_R) return TRUE; |
| 1616 |
return FALSE; |
| 1617 |
} |
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
int |
| 1625 |
StateMapsLeft(char stid) |
| 1626 |
{ |
| 1627 |
switch (stid) { |
| 1628 |
case MATP_MP: |
| 1629 |
case MATP_ML: |
| 1630 |
case MATP_MR: |
| 1631 |
case MATP_D: |
| 1632 |
case MATP_IL: |
| 1633 |
case BEGR_IL: |
| 1634 |
case MATL_ML: |
| 1635 |
case MATL_D: |
| 1636 |
case MATL_IL: |
| 1637 |
case ROOT_IL: |
| 1638 |
return TRUE; |
| 1639 |
default: |
| 1640 |
return FALSE; |
| 1641 |
} |
| 1642 |
} |
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
int |
| 1650 |
StateMapsRight(char stid) |
| 1651 |
{ |
| 1652 |
switch (stid) { |
| 1653 |
case MATP_MP: |
| 1654 |
case MATP_ML: |
| 1655 |
case MATP_MR: |
| 1656 |
case MATP_D: |
| 1657 |
case MATP_IR: |
| 1658 |
case MATR_MR: |
| 1659 |
case MATR_D: |
| 1660 |
case MATR_IR: |
| 1661 |
case ROOT_IR: |
| 1662 |
return TRUE; |
| 1663 |
default: |
| 1664 |
return FALSE; |
| 1665 |
} |
| 1666 |
} |
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
int |
| 1674 |
StateMapsMatch(char stid) |
| 1675 |
{ |
| 1676 |
switch (stid) { |
| 1677 |
case MATP_MP: |
| 1678 |
case MATL_ML: |
| 1679 |
case MATR_MR: |
| 1680 |
return TRUE; |
| 1681 |
default: |
| 1682 |
return FALSE; |
| 1683 |
} |
| 1684 |
} |
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
int |
| 1692 |
StateMapsInsert(char stid) |
| 1693 |
{ |
| 1694 |
switch (stid) { |
| 1695 |
case MATP_IL: |
| 1696 |
case MATP_IR: |
| 1697 |
case MATL_IL: |
| 1698 |
case MATR_IR: |
| 1699 |
case BEGR_IL: |
| 1700 |
case ROOT_IL: |
| 1701 |
case ROOT_IR: |
| 1702 |
return TRUE; |
| 1703 |
default: |
| 1704 |
return FALSE; |
| 1705 |
} |
| 1706 |
} |
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
int |
| 1714 |
StateMapsDelete(char stid) |
| 1715 |
{ |
| 1716 |
switch (stid) { |
| 1717 |
case MATP_ML: |
| 1718 |
case MATP_MR: |
| 1719 |
case MATP_D: |
| 1720 |
case MATL_D: |
| 1721 |
case MATR_D: |
| 1722 |
return TRUE; |
| 1723 |
default: |
| 1724 |
return FALSE; |
| 1725 |
} |
| 1726 |
} |
| 1727 |
|
| 1728 |
|
| 1729 |
|
| 1730 |
|
| 1731 |
|
| 1732 |
|
| 1733 |
|
| 1734 |
int |
| 1735 |
NodeMapsLeft(char ndtype) |
| 1736 |
{ |
| 1737 |
switch (ndtype) { |
| 1738 |
case MATP_nd: |
| 1739 |
case MATL_nd: |
| 1740 |
case ROOT_nd: |
| 1741 |
case BEGR_nd: |
| 1742 |
return TRUE; |
| 1743 |
default: |
| 1744 |
return FALSE; |
| 1745 |
} |
| 1746 |
} |
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
int |
| 1755 |
NodeMapsRight(char ndtype) |
| 1756 |
{ |
| 1757 |
switch (ndtype) { |
| 1758 |
case MATP_nd: |
| 1759 |
case MATR_nd: |
| 1760 |
case ROOT_nd: |
| 1761 |
return TRUE; |
| 1762 |
default: |
| 1763 |
return FALSE; |
| 1764 |
} |
| 1765 |
} |
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
int |
| 1775 |
StateIsDetached(CM_t *cm, int v) |
| 1776 |
{ |
| 1777 |
if(cm->stid[(v+1)] == END_E) { |
| 1778 |
#if eslDEBUGLEVEL >= 1 |
| 1779 |
|
| 1780 |
int y, x, x_offset; |
| 1781 |
|
| 1782 |
if(cm->sttype[v] == IL_st) x_offset = 0; |
| 1783 |
else { |
| 1784 |
ESL_DASSERT1((cm->stid[v] == MATP_IR)); |
| 1785 |
x_offset = 1; |
| 1786 |
|
| 1787 |
} |
| 1788 |
for (y = cm->pnum[v]-1; y >= 1; y--) { |
| 1789 |
x = cm->plast[v] - y; |
| 1790 |
ESL_DASSERT1((fabs(cm->t[x][x_offset] - 0.0) < eslSMALLX1)); |
| 1791 |
} |
| 1792 |
#endif |
| 1793 |
return TRUE; |
| 1794 |
} |
| 1795 |
return FALSE; |
| 1796 |
} |
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
int |
| 1821 |
CMRebalance(CM_t *cm, char *errbuf, CM_t **ret_new_cm) |
| 1822 |
{ |
| 1823 |
int status; |
| 1824 |
ESL_STACK *pda = NULL; |
| 1825 |
CM_t *new = NULL; |
| 1826 |
int *wgt = NULL; |
| 1827 |
int *newidx = NULL; |
| 1828 |
int v, w, y,z; |
| 1829 |
int nv; |
| 1830 |
int x; |
| 1831 |
|
| 1832 |
if((status = cm_nonconfigured_Verify(cm, errbuf)) != eslOK) goto ERROR; |
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
|
| 1837 |
new = CreateCM(cm->nodes, cm->M, cm->clen, cm->abc); |
| 1838 |
if((status = esl_strdup(cm->name, -1, &(new->name))) != eslOK) goto ERROR; |
| 1839 |
if((status = esl_strdup(cm->acc, -1, &(new->acc))) != eslOK) goto ERROR; |
| 1840 |
if((status = esl_strdup(cm->desc, -1, &(new->desc))) != eslOK) goto ERROR; |
| 1841 |
if((status = esl_strdup(cm->rf, -1, &(new->rf))) != eslOK) goto ERROR; |
| 1842 |
if((status = esl_strdup(cm->consensus, -1, &(new->consensus))) != eslOK) goto ERROR; |
| 1843 |
if(cm->map != NULL) { |
| 1844 |
ESL_ALLOC(new->map, sizeof(int) * (cm->clen+1)); |
| 1845 |
esl_vec_ICopy(cm->map, cm->clen+1, new->map); |
| 1846 |
} |
| 1847 |
|
| 1848 |
new->flags = cm->flags; |
| 1849 |
new->offset = cm->offset; |
| 1850 |
new->clen = cm->clen; |
| 1851 |
new->nseq = cm->nseq; |
| 1852 |
new->eff_nseq = cm->eff_nseq; |
| 1853 |
if(cm->flags & CMH_GA) new->ga = cm->ga; |
| 1854 |
if(cm->flags & CMH_TC) new->tc = cm->tc; |
| 1855 |
if(cm->flags & CMH_NC) new->nc = cm->nc; |
| 1856 |
|
| 1857 |
for (x = 0; x < cm->abc->K; x++) new->null[x] = cm->null[x]; |
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
ESL_ALLOC(wgt, sizeof(int) * cm->M); |
| 1863 |
for (v = cm->M-1; v >= 0; v--) |
| 1864 |
{ |
| 1865 |
if (cm->sttype[v] == E_st) |
| 1866 |
wgt[v] = 1; |
| 1867 |
else if (cm->sttype[v] == B_st) |
| 1868 |
wgt[v] = 1 + ESL_MIN(wgt[cm->cfirst[v]], wgt[cm->cnum[v]]); |
| 1869 |
else |
| 1870 |
wgt[v] = wgt[v+1]; |
| 1871 |
} |
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
v = 0; |
| 1881 |
z = cm->M-1; |
| 1882 |
if((pda = esl_stack_ICreate()) == NULL) goto ERROR; |
| 1883 |
ESL_ALLOC(newidx, sizeof(int) * cm->M); |
| 1884 |
for (nv = 0; nv < cm->M; nv++) |
| 1885 |
{ |
| 1886 |
|
| 1887 |
|
| 1888 |
|
| 1889 |
|
| 1890 |
newidx[v] = nv; |
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
new->sttype[nv] = cm->sttype[v]; |
| 1896 |
new->ndidx[nv] = cm->ndidx[v]; |
| 1897 |
new->stid[nv] = cm->stid[v]; |
| 1898 |
new->pnum[nv] = cm->pnum[v]; |
| 1899 |
for (x = 0; x < MAXCONNECT; x++) { |
| 1900 |
new->t[nv][x] = cm->t[v][x]; |
| 1901 |
new->tsc[nv][x] = cm->t[v][x]; |
| 1902 |
} |
| 1903 |
for (x = 0; x < cm->abc->K*cm->abc->K; x++) { |
| 1904 |
new->e[nv][x] = cm->e[v][x]; |
| 1905 |
new->esc[nv][x] = cm->esc[v][x]; |
| 1906 |
} |
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
if (nv != 0) new->plast[nv] = newidx[cm->plast[v]]; |
| 1912 |
else new->plast[nv] = -1; |
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
|
| 1928 |
|
| 1929 |
|
| 1930 |
|
| 1931 |
if (cm->sttype[v] == B_st) |
| 1932 |
{ |
| 1933 |
w = cm->cfirst[v]; |
| 1934 |
y = cm->cnum[v]; |
| 1935 |
|
| 1936 |
if (wgt[w] <= wgt[y]) |
| 1937 |
{ |
| 1938 |
if((status = esl_stack_IPush(pda, y)) != eslOK) goto ERROR; |
| 1939 |
if((status = esl_stack_IPush(pda, z)) != eslOK) goto ERROR; |
| 1940 |
v = w; |
| 1941 |
z = y-1; |
| 1942 |
new->cfirst[nv] = nv+1; |
| 1943 |
new->cnum[nv] = nv+y-w+1; |
| 1944 |
} |
| 1945 |
else |
| 1946 |
{ |
| 1947 |
if((status = esl_stack_IPush(pda, w)) != eslOK) goto ERROR; |
| 1948 |
if((status = esl_stack_IPush(pda, y-1)) != eslOK) goto ERROR; |
| 1949 |
v = y; |
| 1950 |
new->cfirst[nv] = nv+z-y+2; |
| 1951 |
new->cnum[nv] = nv+1; |
| 1952 |
} |
| 1953 |
} |
| 1954 |
else if (cm->sttype[v] == E_st) |
| 1955 |
{ |
| 1956 |
new->cfirst[nv] = -1; |
| 1957 |
new->cnum[nv] = 0; |
| 1958 |
esl_stack_IPop(pda, &z); |
| 1959 |
esl_stack_IPop(pda, &v); |
| 1960 |
} |
| 1961 |
else |
| 1962 |
{ |
| 1963 |
new->cfirst[nv] = nv + (cm->cfirst[v]-v); |
| 1964 |
new->cnum[nv] = cm->cnum[v]; |
| 1965 |
v++; |
| 1966 |
} |
| 1967 |
} |
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
for (v = 0; v < cm->M; v++) |
| 1973 |
{ |
| 1974 |
new->begin[newidx[v]] = cm->begin[v]; |
| 1975 |
new->beginsc[newidx[v]] = cm->beginsc[v]; |
| 1976 |
new->ibeginsc[newidx[v]] = cm->ibeginsc[v]; |
| 1977 |
new->end[newidx[v]] = cm->end[v]; |
| 1978 |
new->endsc[newidx[v]] = cm->endsc[v]; |
| 1979 |
new->iendsc[newidx[v]] = cm->iendsc[v]; |
| 1980 |
} |
| 1981 |
if(cm->qdbinfo != NULL) { |
| 1982 |
if((status = CopyCMQDBInfo(cm->qdbinfo, new->qdbinfo, errbuf)) != eslOK) goto ERROR; |
| 1983 |
for (v = 0; v < cm->M; v++) new->qdbinfo->dmin1[newidx[v]] = cm->qdbinfo->dmin1[v]; |
| 1984 |
for (v = 0; v < cm->M; v++) new->qdbinfo->dmax1[newidx[v]] = cm->qdbinfo->dmax1[v]; |
| 1985 |
for (v = 0; v < cm->M; v++) new->qdbinfo->dmin2[newidx[v]] = cm->qdbinfo->dmin2[v]; |
| 1986 |
for (v = 0; v < cm->M; v++) new->qdbinfo->dmax2[newidx[v]] = cm->qdbinfo->dmax2[v]; |
| 1987 |
} |
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
|
| 1992 |
for (x = 0; x < new->nodes; x++) |
| 1993 |
{ |
| 1994 |
new->nodemap[x] = newidx[cm->nodemap[x]]; |
| 1995 |
new->ndtype[x] = cm->ndtype[x]; |
| 1996 |
} |
| 1997 |
|
| 1998 |
if(wgt != NULL) free(wgt); |
| 1999 |
if(newidx != NULL) free(newidx); |
| 2000 |
if(pda != NULL) esl_stack_Destroy(pda); |
| 2001 |
*ret_new_cm = new; |
| 2002 |
return eslOK; |
| 2003 |
|
| 2004 |
ERROR: |
| 2005 |
if(wgt != NULL) free(wgt); |
| 2006 |
if(newidx != NULL) free(newidx); |
| 2007 |
if(pda != NULL) esl_stack_Destroy(pda); |
| 2008 |
if(new != NULL) FreeCM(new); |
| 2009 |
*ret_new_cm = NULL; |
| 2010 |
if(status == eslEMEM) ESL_FAIL(status, errbuf, "out of memory"); |
| 2011 |
else return status; |
| 2012 |
} |
| 2013 |
|
| 2014 |
|
| 2015 |
|
| 2016 |
|
| 2017 |
|
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
float rsearch_calculate_gap_penalty (char from_state, char to_state, |
| 2023 |
int from_node, int to_node, |
| 2024 |
float input_alpha, float input_beta, |
| 2025 |
float input_alphap, float input_betap) { |
| 2026 |
int from_class, to_class; |
| 2027 |
double alpha, beta; |
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
|
| 2034 |
|
| 2035 |
|
| 2036 |
|
| 2037 |
|
| 2038 |
|
| 2039 |
switch (from_state) { |
| 2040 |
case MATP_D: |
| 2041 |
from_class = DB_cl; |
| 2042 |
break; |
| 2043 |
case MATP_ML: |
| 2044 |
case MATR_D: |
| 2045 |
from_class = DR_cl; |
| 2046 |
break; |
| 2047 |
case ROOT_IR: |
| 2048 |
case MATP_IR: |
| 2049 |
case MATR_IR: |
| 2050 |
from_class = IR_cl; |
| 2051 |
break; |
| 2052 |
case MATP_MR: |
| 2053 |
case MATL_D: |
| 2054 |
from_class = DL_cl; |
| 2055 |
break; |
| 2056 |
case ROOT_IL: |
| 2057 |
case BEGR_IL: |
| 2058 |
case MATP_IL: |
| 2059 |
case MATL_IL: |
| 2060 |
from_class = IL_cl; |
| 2061 |
break; |
| 2062 |
default: |
| 2063 |
from_class = M_cl; |
| 2064 |
} |
| 2065 |
|
| 2066 |
switch (to_state) { |
| 2067 |
case MATP_D: |
| 2068 |
to_class = DB_cl; |
| 2069 |
break; |
| 2070 |
case MATP_ML: |
| 2071 |
case MATR_D: |
| 2072 |
to_class = DR_cl; |
| 2073 |
break; |
| 2074 |
case ROOT_IR: |
| 2075 |
case MATP_IR: |
| 2076 |
case MATR_IR: |
| 2077 |
to_class = IR_cl; |
| 2078 |
break; |
| 2079 |
case MATP_MR: |
| 2080 |
case MATL_D: |
| 2081 |
to_class = DL_cl; |
| 2082 |
break; |
| 2083 |
case ROOT_IL: |
| 2084 |
case BEGR_IL: |
| 2085 |
case MATP_IL: |
| 2086 |
case MATL_IL: |
| 2087 |
to_class = IL_cl; |
| 2088 |
break; |
| 2089 |
default: |
| 2090 |
to_class = M_cl; |
| 2091 |
} |
| 2092 |
|
| 2093 |
|
| 2094 |
|
| 2095 |
if (from_node == MATP_nd && to_node == MATP_nd) |
| 2096 |
alpha = input_alphap; |
| 2097 |
else |
| 2098 |
alpha = input_alpha; |
| 2099 |
|
| 2100 |
if (from_class == DB_cl && from_node == MATP_nd && to_node == MATP_nd) |
| 2101 |
beta = input_betap; |
| 2102 |
else |
| 2103 |
beta = input_beta; |
| 2104 |
|
| 2105 |
|
| 2106 |
if (from_class == M_cl) { |
| 2107 |
if (to_class == M_cl) { |
| 2108 |
return (0.); |
| 2109 |
} else if (to_class == DB_cl) { |
| 2110 |
return (alpha); |
| 2111 |
} else { |
| 2112 |
return (0.5*alpha); |
| 2113 |
} |
| 2114 |
} else if (from_class == IL_cl) { |
| 2115 |
if (to_class == M_cl) { |
| 2116 |
return (beta + 0.5*alpha); |
| 2117 |
} else if (to_class == IL_cl) { |
| 2118 |
return (beta); |
| 2119 |
} else if (to_class == DB_cl) { |
| 2120 |
return (beta+1.5*alpha); |
| 2121 |
} else { |
| 2122 |
return (beta + alpha); |
| 2123 |
} |
| 2124 |
} else if (from_class == DL_cl) { |
| 2125 |
if (to_class == M_cl) { |
| 2126 |
return (beta + 0.5*alpha); |
| 2127 |
} else if (to_class == DL_cl) { |
| 2128 |
return (beta); |
| 2129 |
} else if (to_class == DB_cl) { |
| 2130 |
return (beta + 0.5*alpha); |
| 2131 |
} else { |
| 2132 |
return (beta + alpha); |
| 2133 |
} |
| 2134 |
} else if (from_class == IR_cl) { |
| 2135 |
if (to_class == M_cl) { |
| 2136 |
return (beta + 0.5*alpha); |
| 2137 |
} else if (to_class == IR_cl) { |
| 2138 |
return (beta); |
| 2139 |
} else if (to_class == DB_cl) { |
| 2140 |
return (beta+1.5*alpha); |
| 2141 |
} else { |
| 2142 |
return (beta + alpha); |
| 2143 |
} |
| 2144 |
} else if (from_class == DR_cl) { |
| 2145 |
if (to_class == M_cl) { |
| 2146 |
return (beta + 0.5*alpha); |
| 2147 |
} else if (to_class == DR_cl) { |
| 2148 |
return (beta); |
| 2149 |
} else if (to_class == DB_cl) { |
| 2150 |
return (beta + 0.5*alpha); |
| 2151 |
} else { |
| 2152 |
return (beta + alpha); |
| 2153 |
} |
| 2154 |
} else { |
| 2155 |
if (to_class == IL_cl || to_class == IR_cl) { |
| 2156 |
return (2*beta + 1.5*alpha); |
| 2157 |
} else if (to_class == M_cl) { |
| 2158 |
return (2*beta + alpha); |
| 2159 |
} else if (to_class == DB_cl) { |
| 2160 |
return (2*beta); |
| 2161 |
} else { |
| 2162 |
return (2*beta + 0.5*alpha); |
| 2163 |
} |
| 2164 |
} |
| 2165 |
return (0); |
| 2166 |
} |
| 2167 |
|
| 2168 |
|
| 2169 |
|
| 2170 |
|
| 2171 |
|
| 2172 |
|
| 2173 |
|
| 2174 |
|
| 2175 |
|
| 2176 |
|
| 2177 |
|
| 2178 |
|
| 2179 |
|
| 2180 |
int |
| 2181 |
cm_Exponentiate(CM_t *cm, double z) |
| 2182 |
{ |
| 2183 |
int v; |
| 2184 |
int x,y; |
| 2185 |
|
| 2186 |
|
| 2187 |
if(cm->flags & CMH_LOCAL_BEGIN || cm->flags & CMH_LOCAL_END) { |
| 2188 |
cm_Fail("cm_Exponentiate() model is not in global configuration"); |
| 2189 |
} |
| 2190 |
|
| 2191 |
for(v = 0; v < cm->M; v++) |
| 2192 |
{ |
| 2193 |
if (cm->sttype[v] != B_st && cm->sttype[v] != E_st) |
| 2194 |
for (x = 0; x < cm->cnum[v]; x++) |
| 2195 |
cm->t[v][x] = pow(cm->t[v][x], z); |
| 2196 |
if (cm->sttype[v] == MP_st) |
| 2197 |
{ |
| 2198 |
for (x = 0; x < cm->abc->K; x++) |
| 2199 |
for (y = 0; y < cm->abc->K; y++) |
| 2200 |
cm->e[v][x*cm->abc->K+y] = pow(cm->e[v][x*cm->abc->K+y], z); |
| 2201 |
} |
| 2202 |
if (cm->sttype[v] == ML_st || cm->sttype[v] == MR_st || |
| 2203 |
cm->sttype[v] == IL_st || cm->sttype[v] == IR_st) |
| 2204 |
{ |
| 2205 |
for (x = 0; x < cm->abc->K; x++) |
| 2206 |
cm->e[v][x] = pow(cm->e[v][x], z); |
| 2207 |
} |
| 2208 |
} |
| 2209 |
CMRenormalize(cm); |
| 2210 |
|
| 2211 |
|
| 2212 |
cm->flags &= ~CMH_BITS; |
| 2213 |
return eslOK; |
| 2214 |
} |
| 2215 |
|
| 2216 |
|
| 2217 |
|
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
|
| 2223 |
|
| 2224 |
|
| 2225 |
|
| 2226 |
int |
| 2227 |
cm_p7_Exponentiate(P7_HMM *hmm, double z) |
| 2228 |
{ |
| 2229 |
int k, i; |
| 2230 |
|
| 2231 |
for(k = 0; k <= hmm->M; k++) { |
| 2232 |
for(i = 0; i < p7H_NTRANSITIONS; i++) { |
| 2233 |
hmm->t[k][i] = pow(hmm->t[k][i], z); |
| 2234 |
} |
| 2235 |
} |
| 2236 |
for(k = 1; k <= hmm->M; k++) { |
| 2237 |
for(i = 0; i < hmm->abc->K; i++) { |
| 2238 |
hmm->mat[k][i] = pow(hmm->mat[k][i], z); |
| 2239 |
hmm->ins[k][i] = pow(hmm->ins[k][i], z); |
| 2240 |
} |
| 2241 |
} |
| 2242 |
p7_hmm_Renormalize(hmm); |
| 2243 |
|
| 2244 |
return eslOK; |
| 2245 |
} |
| 2246 |
|
| 2247 |
|
| 2248 |
|
| 2249 |
|
| 2250 |
|
| 2251 |
|
| 2252 |
|
| 2253 |
|
| 2254 |
|
| 2255 |
|
| 2256 |
|
| 2257 |
|
| 2258 |
|
| 2259 |
|
| 2260 |
|
| 2261 |
|
| 2262 |
|
| 2263 |
|
| 2264 |
|
| 2265 |
|
| 2266 |
|
| 2267 |
|
| 2268 |
|
| 2269 |
void |
| 2270 |
cm_banner(FILE *fp, char *progname, char *banner) |
| 2271 |
{ |
| 2272 |
char *appname = NULL; |
| 2273 |
|
| 2274 |
if (esl_FileTail(progname, FALSE, &appname) != eslOK) appname = progname; |
| 2275 |
|
| 2276 |
fprintf(fp, "# %s :: %s\n", appname, banner); |
| 2277 |
fprintf(fp, "# INFERNAL %s (%s)\n", INFERNAL_VERSION, INFERNAL_DATE); |
| 2278 |
fprintf(fp, "# %s\n", INFERNAL_COPYRIGHT); |
| 2279 |
fprintf(fp, "# %s\n", INFERNAL_LICENSE); |
| 2280 |
fprintf(fp, "# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n"); |
| 2281 |
|
| 2282 |
if (appname != NULL) free(appname); |
| 2283 |
return; |
| 2284 |
} |
| 2285 |
|
| 2286 |
|
| 2287 |
|
| 2288 |
|
| 2289 |
|
| 2290 |
|
| 2291 |
|
| 2292 |
|
| 2293 |
|
| 2294 |
|
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
void |
| 2303 |
cm_CalcExpSc(CM_t *cm, float **ret_expsc, float **ret_expsc_noss) |
| 2304 |
{ |
| 2305 |
int status; |
| 2306 |
float *expsc; |
| 2307 |
float *expsc_noss; |
| 2308 |
int v,x,y,yoffset; |
| 2309 |
float *left_e, *left_esc; |
| 2310 |
float *right_e, *right_esc; |
| 2311 |
int i,j; |
| 2312 |
|
| 2313 |
|
| 2314 |
if(cm->flags & CMH_LOCAL_BEGIN) cm_Fail("cm_CalcExpSc() CMH_LOCAL_BEGIN flag up.\n"); |
| 2315 |
if(cm->flags & CMH_LOCAL_END) cm_Fail("cm_CalcExpSc() CMH_LOCAL_END flag up.\n"); |
| 2316 |
if(ret_expsc == NULL) cm_Fail("cm_CalcExpSc() ret_expsc is NULL.\n"); |
| 2317 |
|
| 2318 |
ESL_ALLOC(left_e, sizeof(float) * cm->abc->K); |
| 2319 |
ESL_ALLOC(right_e, sizeof(float) * cm->abc->K); |
| 2320 |
ESL_ALLOC(left_esc, sizeof(float) * cm->abc->K); |
| 2321 |
ESL_ALLOC(right_esc, sizeof(float) * cm->abc->K); |
| 2322 |
|
| 2323 |
ESL_ALLOC(expsc, sizeof(float) * cm->M); |
| 2324 |
ESL_ALLOC(expsc_noss, sizeof(float) * cm->M); |
| 2325 |
esl_vec_FSet(expsc, cm->M, 0.); |
| 2326 |
esl_vec_FSet(expsc_noss, cm->M, 0.); |
| 2327 |
|
| 2328 |
for(v = cm->M-1; v >= 0; v--) |
| 2329 |
{ |
| 2330 |
switch (cm->sttype[v]) { |
| 2331 |
case E_st: |
| 2332 |
break; |
| 2333 |
|
| 2334 |
case B_st: |
| 2335 |
expsc[v] = expsc[cm->cfirst[v]] + expsc[cm->cnum[v]]; |
| 2336 |
expsc_noss[v] = expsc_noss[cm->cfirst[v]] + expsc_noss[cm->cnum[v]]; |
| 2337 |
break; |
| 2338 |
|
| 2339 |
case MP_st: |
| 2340 |
|
| 2341 |
|
| 2342 |
esl_vec_FSet(left_e, cm->abc->K, 0.); |
| 2343 |
for(i = 0; i < cm->abc->K; i++) |
| 2344 |
for(j = (i*cm->abc->K); j < ((i+1)*cm->abc->K); j++) |
| 2345 |
left_e[i] += cm->e[v][j]; |
| 2346 |
|
| 2347 |
esl_vec_FNorm(left_e, cm->abc->K); |
| 2348 |
for(i = 0; i < cm->abc->K; i++) left_esc[i] = sreLOG2(left_e[i] / cm->null[i]); |
| 2349 |
|
| 2350 |
|
| 2351 |
esl_vec_FSet(right_e, cm->abc->K, 0.); |
| 2352 |
for(i = 0; i < cm->abc->K; i++) |
| 2353 |
for(j = i; j < cm->abc->K * cm->abc->K; j += cm->abc->K) |
| 2354 |
right_e[i] += cm->e[v][j]; |
| 2355 |
|
| 2356 |
esl_vec_FNorm(right_e, cm->abc->K); |
| 2357 |
for(i = 0; i < cm->abc->K; i++) right_esc[i] = sreLOG2(right_e[i] / cm->null[i]); |
| 2358 |
|
| 2359 |
|
| 2360 |
for(x = 0; x < cm->abc->K * cm->abc->K; x++) |
| 2361 |
expsc[v] += cm->e[v][x] * cm->esc[v][x]; |
| 2362 |
|
| 2363 |
|
| 2364 |
for(x = 0; x < cm->abc->K; x++) |
| 2365 |
expsc_noss[v] += left_e[x] * left_esc[x]; |
| 2366 |
for(x = 0; x < cm->abc->K; x++) |
| 2367 |
expsc_noss[v] += right_e[x] * right_esc[x]; |
| 2368 |
|
| 2369 |
for (yoffset = 0; yoffset < cm->cnum[v]; yoffset++) { |
| 2370 |
y = cm->cfirst[v] + yoffset; |
| 2371 |
expsc[v] += cm->t[v][yoffset] * (expsc[y] + cm->tsc[v][yoffset]); |
| 2372 |
expsc_noss[v] += cm->t[v][yoffset] * (expsc_noss[y] + cm->tsc[v][yoffset]); |
| 2373 |
} |
| 2374 |
break; |
| 2375 |
|
| 2376 |
case ML_st: |
| 2377 |
case MR_st: |
| 2378 |
case IL_st: |
| 2379 |
case IR_st: |
| 2380 |
for(x = 0; x < cm->abc->K; x++) { |
| 2381 |
expsc[v] += cm->e[v][x] * cm->esc[v][x]; |
| 2382 |
expsc_noss[v] += cm->e[v][x] * cm->esc[v][x]; |
| 2383 |
} |
| 2384 |
for (yoffset = 0; yoffset < cm->cnum[v]; yoffset++) { |
| 2385 |
y = cm->cfirst[v] + yoffset; |
| 2386 |
expsc[v] += cm->t[v][yoffset] * (expsc[y] + cm->tsc[v][yoffset]); |
| 2387 |
expsc_noss[v] += cm->t[v][yoffset] * (expsc_noss[y] + cm->tsc[v][yoffset]); |
| 2388 |
} |
| 2389 |
break; |
| 2390 |
|
| 2391 |
case S_st: |
| 2392 |
case D_st: |
| 2393 |
for (yoffset = 0; yoffset < cm->cnum[v]; yoffset++) { |
| 2394 |
y = cm->cfirst[v] + yoffset; |
| 2395 |
expsc[v] += cm->t[v][yoffset] * (expsc[y] + cm->tsc[v][yoffset]); |
| 2396 |
expsc_noss[v] += cm->t[v][yoffset] * (expsc_noss[y] + cm->tsc[v][yoffset]); |
| 2397 |
} |
| 2398 |
break; |
| 2399 |
} |
| 2400 |
} |
| 2401 |
|
| 2402 |
*ret_expsc = expsc; |
| 2403 |
|
| 2404 |
if(ret_expsc_noss != NULL) *ret_expsc_noss = expsc_noss; |
| 2405 |
else free(expsc_noss); |
| 2406 |
|
| 2407 |
for(v = 0; v < cm->M; v++) |
| 2408 |
printf("EXPSC[%4d]: %10.6f NOSS: %10.6f (%10.6f)\n", v, expsc[v], expsc_noss[v], (expsc[v] - expsc_noss[v])); |
| 2409 |
|
| 2410 |
return; |
| 2411 |
ERROR: |
| 2412 |
cm_Fail("ERROR in cm_CalcExpSc().\n"); |
| 2413 |
} |
| 2414 |
|
| 2415 |
|
| 2416 |
|
| 2417 |
|
| 2418 |
|
| 2419 |
|
| 2420 |
|
| 2421 |
|
| 2422 |
|
| 2423 |
|
| 2424 |
|
| 2425 |
|
| 2426 |
|
| 2427 |
|
| 2428 |
|
| 2429 |
int |
| 2430 |
cm_Validate(CM_t *cm, float tol, char *errbuf) |
| 2431 |
{ |
| 2432 |
int status; |
| 2433 |
int v; |
| 2434 |
int clen = 0; |
| 2435 |
float pvec[MAXCONNECT+1]; |
| 2436 |
int y; |
| 2437 |
|
| 2438 |
if (cm == NULL) ESL_XFAIL(eslFAIL, errbuf, "CM is a null pointer"); |
| 2439 |
if (cm->M < 1) ESL_XFAIL(eslFAIL, errbuf, "CM has M < 1"); |
| 2440 |
if (cm->abc == NULL) ESL_XFAIL(eslFAIL, errbuf, "CM has no alphabet reference"); |
| 2441 |
if (cm->abc->type == eslUNKNOWN) ESL_XFAIL(eslFAIL, errbuf, "CM's alphabet is set to unknown"); |
| 2442 |
if (cm->qdbinfo == NULL) ESL_XFAIL(eslFAIL, errbuf, "CM's qdbinfo is NULL"); |
| 2443 |
|
| 2444 |
esl_vec_FSet(pvec, MAXCONNECT+1, 0.); |
| 2445 |
for (v = 0; v < cm->M; v++) |
| 2446 |
{ |
| 2447 |
if(StateDelta(cm->sttype[v]) == 2) |
| 2448 |
{ |
| 2449 |
if (esl_vec_FValidate(cm->e[v], (cm->abc->K * cm->abc->K), tol, NULL) != eslOK) |
| 2450 |
ESL_XFAIL(eslFAIL, errbuf, "e[%d] fails pvector validation", v); |
| 2451 |
} |
| 2452 |
else if(StateDelta(cm->sttype[v]) > 0) |
| 2453 |
{ |
| 2454 |
if (esl_vec_FValidate(cm->e[v], cm->abc->K, tol, NULL) != eslOK) |
| 2455 |
ESL_XFAIL(eslFAIL, errbuf, "e[%d] fails pvector validation", v); |
| 2456 |
} |
| 2457 |
if (cm->sttype[v] != B_st && cm->sttype[v] != E_st) |
| 2458 |
{ |
| 2459 |
if ((! (cm->flags & CMH_LOCAL_BEGIN)) && (! (cm->flags & CMH_LOCAL_END))) |
| 2460 |
{ |
| 2461 |
if(esl_vec_FValidate(cm->t[v], cm->cnum[v], tol, NULL) != eslOK) |
| 2462 |
ESL_XFAIL(eslFAIL, errbuf, "t[%d] fails pvector validation", v); |
| 2463 |
} |
| 2464 |
else if (v > 0 && (cm->flags & CMH_LOCAL_END)) |
| 2465 |
{ |
| 2466 |
esl_vec_FSet(pvec, MAXCONNECT+1, 0.); |
| 2467 |
for(y = 0; y < cm->cnum[v]; y++) pvec[y] = cm->t[v][y]; |
| 2468 |
pvec[cm->cnum[v]] = cm->end[v]; |
| 2469 |
if(esl_vec_FValidate(pvec, (cm->cnum[v]+1), tol, NULL) != eslOK) |
| 2470 |
ESL_XFAIL(eslFAIL, errbuf, "t[%d] (with local end) fails pvector validation", v); |
| 2471 |
} |
| 2472 |
} |
| 2473 |
if(cm->stid[v] == MATL_ML) clen++; |
| 2474 |
if(cm->stid[v] == MATR_MR) clen++; |
| 2475 |
if(cm->stid[v] == MATP_MP) clen+=2; |
| 2476 |
} |
| 2477 |
if(cm->flags & CMH_LOCAL_BEGIN) |
| 2478 |
if(esl_vec_FValidate(cm->begin, cm->M, tol, NULL) != eslOK) |
| 2479 |
if(cm->clen != clen) ESL_XFAIL(eslFAIL, errbuf, "consensus length %d not correctly stored in CM, should be %d", cm->clen, clen); |
| 2480 |
|
| 2481 |
return eslOK; |
| 2482 |
|
| 2483 |
ERROR: |
| 2484 |
return status; |
| 2485 |
} |
| 2486 |
|
| 2487 |
|
| 2488 |
|
| 2489 |
|
| 2490 |
|
| 2491 |
|
| 2492 |
char * |
| 2493 |
CMStatetype(char st) |
| 2494 |
{ |
| 2495 |
switch (st) { |
| 2496 |
case D_st: return "D"; |
| 2497 |
case MP_st: return "MP"; |
| 2498 |
case ML_st: return "ML"; |
| 2499 |
case MR_st: return "MR"; |
| 2500 |
case IL_st: return "IL"; |
| 2501 |
case IR_st: return "IR"; |
| 2502 |
case S_st: return "S"; |
| 2503 |
case E_st: return "E"; |
| 2504 |
case B_st: return "B"; |
| 2505 |
case EL_st: return "EL"; |
| 2506 |
default: return "BOGUS"; |
| 2507 |
} |
| 2508 |
} |
| 2509 |
|
| 2510 |
|
| 2511 |
|
| 2512 |
|
| 2513 |
|
| 2514 |
|
| 2515 |
char * |
| 2516 |
CMNodetype(char nd) |
| 2517 |
{ |
| 2518 |
switch (nd) { |
| 2519 |
|
| 2520 |
case BIF_nd: return "BIF"; |
| 2521 |
case MATP_nd: return "MATP"; |
| 2522 |
case MATL_nd: return "MATL"; |
| 2523 |
case MATR_nd: return "MATR"; |
| 2524 |
case BEGL_nd: return "BEGL"; |
| 2525 |
case BEGR_nd: return "BEGR"; |
| 2526 |
case ROOT_nd: return "ROOT"; |
| 2527 |
case END_nd: return "END"; |
| 2528 |
default: return "BOGUS"; |
| 2529 |
} |
| 2530 |
} |
| 2531 |
|
| 2532 |
|
| 2533 |
|
| 2534 |
|
| 2535 |
|
| 2536 |
|
| 2537 |
char * |
| 2538 |
CMStateid(char st) |
| 2539 |
{ |
| 2540 |
switch (st) { |
| 2541 |
|
| 2542 |
case ROOT_S: return "ROOT_S"; |
| 2543 |
case ROOT_IL: return "ROOT_IL"; |
| 2544 |
case ROOT_IR: return "ROOT_IR"; |
| 2545 |
case BEGL_S: return "BEGL_S"; |
| 2546 |
case BEGR_S: return "BEGR_S"; |
| 2547 |
case BEGR_IL: return "BEGR_IL"; |
| 2548 |
case MATP_MP: return "MATP_MP"; |
| 2549 |
case MATP_ML: return "MATP_ML"; |
| 2550 |
case MATP_MR: return "MATP_MR"; |
| 2551 |
case MATP_D: return "MATP_D"; |
| 2552 |
case MATP_IL: return "MATP_IL"; |
| 2553 |
case MATP_IR: return "MATP_IR"; |
| 2554 |
case MATL_ML: return "MATL_ML"; |
| 2555 |
case MATL_D: return "MATL_D"; |
| 2556 |
case MATL_IL: return "MATL_IL"; |
| 2557 |
case MATR_MR: return "MATR_MR"; |
| 2558 |
case MATR_D: return "MATR_D"; |
| 2559 |
case MATR_IR: return "MATR_IR"; |
| 2560 |
case END_E: return "END_E"; |
| 2561 |
case BIF_B: return "BIF_B"; |
| 2562 |
case END_EL: return "END_EL"; |
| 2563 |
default: return "BOGUS"; |
| 2564 |
} |
| 2565 |
} |
| 2566 |
|
| 2567 |
|
| 2568 |
|
| 2569 |
|
| 2570 |
|
| 2571 |
|
| 2572 |
|
| 2573 |
|
| 2574 |
|
| 2575 |
|
| 2576 |
|
| 2577 |
|
| 2578 |
|
| 2579 |
|
| 2580 |
|
| 2581 |
|
| 2582 |
int |
| 2583 |
cm_SetName(CM_t *cm, char *name) |
| 2584 |
{ |
| 2585 |
int status; |
| 2586 |
void *tmp; |
| 2587 |
int n; |
| 2588 |
|
| 2589 |
if (name == NULL) { |
| 2590 |
if (cm->name != NULL) free(cm->name); |
| 2591 |
cm->name = NULL; |
| 2592 |
} else { |
| 2593 |
n = strlen(name); |
| 2594 |
ESL_RALLOC(cm->name, tmp, sizeof(char)*(n+1)); |
| 2595 |
strcpy(cm->name, name); |
| 2596 |
if ((status = esl_strchop(cm->name, n)) != eslOK) goto ERROR; |
| 2597 |
} |
| 2598 |
return eslOK; |
| 2599 |
|
| 2600 |
ERROR: |
| 2601 |
return status; |
| 2602 |
} |
| 2603 |
|
| 2604 |
|
| 2605 |
|
| 2606 |
|
| 2607 |
|
| 2608 |
|
| 2609 |
|
| 2610 |
|
| 2611 |
|
| 2612 |
|
| 2613 |
|
| 2614 |
|
| 2615 |
|
| 2616 |
|
| 2617 |
|
| 2618 |
|
| 2619 |
int |
| 2620 |
cm_SetAccession(CM_t *cm, char *acc) |
| 2621 |
{ |
| 2622 |
int status; |
| 2623 |
void *tmp; |
| 2624 |
int n; |
| 2625 |
|
| 2626 |
if (acc == NULL) { |
| 2627 |
if (cm->acc != NULL) free(cm->acc); |
| 2628 |
cm->acc = NULL; |
| 2629 |
cm->flags &= ~CMH_ACC; |
| 2630 |
} else { |
| 2631 |
n = strlen(acc); |
| 2632 |
ESL_RALLOC(cm->acc, tmp, sizeof(char)*(n+1)); |
| 2633 |
strcpy(cm->acc, acc); |
| 2634 |
if ((status = esl_strchop(cm->acc, n)) != eslOK) goto ERROR; |
| 2635 |
cm->flags |= CMH_ACC; |
| 2636 |
} |
| 2637 |
return eslOK; |
| 2638 |
|
| 2639 |
ERROR: |
| 2640 |
return status; |
| 2641 |
} |
| 2642 |
|
| 2643 |
|
| 2644 |
|
| 2645 |
|
| 2646 |
|
| 2647 |
|
| 2648 |
|
| 2649 |
int |
| 2650 |
cm_SetDescription(CM_t *cm, char *desc) |
| 2651 |
{ |
| 2652 |
int status; |
| 2653 |
void *tmp; |
| 2654 |
int n; |
| 2655 |
|
| 2656 |
if (desc == NULL) |
| 2657 |
{ |
| 2658 |
if (cm->desc != NULL) free(cm->desc); |
| 2659 |
cm->desc = NULL; |
| 2660 |
cm->flags &= ~CMH_DESC; |
| 2661 |
} |
| 2662 |
else |
| 2663 |
{ |
| 2664 |
n = strlen(desc); |
| 2665 |
ESL_RALLOC(cm->desc, tmp, sizeof(char)*(n+1)); |
| 2666 |
strcpy(cm->desc, desc); |
| 2667 |
if ((status = esl_strchop(cm->desc, n)) != eslOK) goto ERROR; |
| 2668 |
cm->flags |= CMH_DESC; |
| 2669 |
} |
| 2670 |
return eslOK; |
| 2671 |
|
| 2672 |
ERROR: |
| 2673 |
return status; |
| 2674 |
} |
| 2675 |
|
| 2676 |
|
| 2677 |
|
| 2678 |
|
| 2679 |
|
| 2680 |
|
| 2681 |
|
| 2682 |
|
| 2683 |
|
| 2684 |
|
| 2685 |
|
| 2686 |
|
| 2687 |
|
| 2688 |
|
| 2689 |
|
| 2690 |
|
| 2691 |
|
| 2692 |
|
| 2693 |
|
| 2694 |
|
| 2695 |
|
| 2696 |
|
| 2697 |
|
| 2698 |
|
| 2699 |
|
| 2700 |
|
| 2701 |
|
| 2702 |
|
| 2703 |
|
| 2704 |
|
| 2705 |
|
| 2706 |
|
| 2707 |
|
| 2708 |
|
| 2709 |
|
| 2710 |
|
| 2711 |
|
| 2712 |
|
| 2713 |
int |
| 2714 |
cm_SetConsensus(CM_t *cm, CMConsensus_t *cons, ESL_SQ *sq) |
| 2715 |
{ |
| 2716 |
int status; |
| 2717 |
int cpos; |
| 2718 |
|
| 2719 |
if(cons == NULL || sq != NULL) { status = eslEINVAL; goto ERROR; } |
| 2720 |
|
| 2721 |
|
| 2722 |
if (! cm->consensus) ESL_ALLOC(cm->consensus, sizeof(char) * (cm->clen+2)); |
| 2723 |
|
| 2724 |
|
| 2725 |
cm->consensus[0] = ' '; |
| 2726 |
for (cpos = 1; cpos <= cm->clen; cpos++) cm->consensus[cpos] = cons->cseq[cpos-1]; |
| 2727 |
cm->consensus[cm->clen+1] = '\0'; |
| 2728 |
cm->flags |= CMH_CONS; |
| 2729 |
return eslOK; |
| 2730 |
|
| 2731 |
ERROR: |
| 2732 |
if (cm->consensus) free(cm->consensus); |
| 2733 |
cm->consensus = NULL; |
| 2734 |
cm->flags &= (~CMH_CONS); |
| 2735 |
return status; |
| 2736 |
} |
| 2737 |
|
| 2738 |
|
| 2739 |
|
| 2740 |
|
| 2741 |
|
| 2742 |
|
| 2743 |
|
| 2744 |
|
| 2745 |
|
| 2746 |
|
| 2747 |
|
| 2748 |
|
| 2749 |
|
| 2750 |
|
| 2751 |
|
| 2752 |
|
| 2753 |
|
| 2754 |
|
| 2755 |
|
| 2756 |
|
| 2757 |
int |
| 2758 |
cm_AppendComlog(CM_t *cm, int argc, char **argv, int add_seed, uint32_t seed) |
| 2759 |
{ |
| 2760 |
int status; |
| 2761 |
void *tmp; |
| 2762 |
int n; |
| 2763 |
int i; |
| 2764 |
int seedlen; |
| 2765 |
uint32_t temp; |
| 2766 |
char *seedstr; |
| 2767 |
|
| 2768 |
|
| 2769 |
n = argc-1; |
| 2770 |
for (i = 0; i < argc; i++) { |
| 2771 |
n += strlen(argv[i]); |
| 2772 |
} |
| 2773 |
|
| 2774 |
if(add_seed) { |
| 2775 |
temp = seed; |
| 2776 |
seedlen = 1; |
| 2777 |
while(temp > 0) { temp/=10; seedlen++; } |
| 2778 |
seedlen += 8; |
| 2779 |
n += seedlen; |
| 2780 |
} |
| 2781 |
|
| 2782 |
if (cm->comlog != NULL) { |
| 2783 |
n += strlen(cm->comlog) + 1; |
| 2784 |
ESL_RALLOC(cm->comlog, tmp, sizeof(char)* (n+1)); |
| 2785 |
strcat(cm->comlog, "\n"); |
| 2786 |
} else { |
| 2787 |
ESL_ALLOC(cm->comlog, sizeof(char)* (n+1)); |
| 2788 |
*(cm->comlog) = '\0'; |
| 2789 |
} |
| 2790 |
|
| 2791 |
for (i = 0; i < argc-1; i++) |
| 2792 |
{ |
| 2793 |
strcat(cm->comlog, argv[i]); |
| 2794 |
strcat(cm->comlog, " "); |
| 2795 |
} |
| 2796 |
strcat(cm->comlog, argv[argc-1]); |
| 2797 |
|
| 2798 |
if(add_seed) { |
| 2799 |
ESL_ALLOC(seedstr, sizeof(char) * (seedlen+1)); |
| 2800 |
snprintf(seedstr, seedlen+10, " --seed %" PRIu32 " ", seed); |
| 2801 |
strcat(cm->comlog, seedstr); |
| 2802 |
free(seedstr); |
| 2803 |
} |
| 2804 |
|
| 2805 |
return eslOK; |
| 2806 |
|
| 2807 |
ERROR: |
| 2808 |
return status; |
| 2809 |
} |
| 2810 |
|
| 2811 |
|
| 2812 |
|
| 2813 |
|
| 2814 |
|
| 2815 |
|
| 2816 |
|
| 2817 |
|
| 2818 |
|
| 2819 |
|
| 2820 |
|
| 2821 |
|
| 2822 |
|
| 2823 |
|
| 2824 |
|
| 2825 |
|
| 2826 |
|
| 2827 |
|
| 2828 |
|
| 2829 |
|
| 2830 |
|
| 2831 |
|
| 2832 |
|
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
|
| 2837 |
|
| 2838 |
|
| 2839 |
|
| 2840 |
|
| 2841 |
|
| 2842 |
|
| 2843 |
|
| 2844 |
|
| 2845 |
|
| 2846 |
int |
| 2847 |
cm_SetCtime(CM_t *cm) |
| 2848 |
{ |
| 2849 |
char *s = NULL; |
| 2850 |
time_t date; |
| 2851 |
int status; |
| 2852 |
const char *sde = getenv("SOURCE_DATE_EPOCH"); |
| 2853 |
|
| 2854 |
ESL_ALLOC(s, 32); |
| 2855 |
if (sde) { |
| 2856 |
date = strtoul(sde, NULL, 0); |
| 2857 |
} else { |
| 2858 |
if ((date = time(NULL)) == -1) { status = eslESYS; goto ERROR; } |
| 2859 |
} |
| 2860 |
if (ctime_r(&date, s) == NULL) { status = eslESYS; goto ERROR; } |
| 2861 |
if ((status = esl_strchop(s, -1)) != eslOK) { goto ERROR; } |
| 2862 |
|
| 2863 |
if (cm->ctime != NULL) free(cm->ctime); |
| 2864 |
cm->ctime = s; |
| 2865 |
return eslOK; |
| 2866 |
|
| 2867 |
ERROR: |
| 2868 |
if (s) free(s); |
| 2869 |
return status; |
| 2870 |
} |
| 2871 |
|
| 2872 |
|
| 2873 |
|
| 2874 |
|
| 2875 |
|
| 2876 |
|
| 2877 |
|
| 2878 |
|
| 2879 |
|
| 2880 |
|
| 2881 |
|
| 2882 |
int |
| 2883 |
IntMaxDigits() |
| 2884 |
{ |
| 2885 |
int big = INT_MAX; |
| 2886 |
return IntDigits(big); |
| 2887 |
} |
| 2888 |
|
| 2889 |
|
| 2890 |
|
| 2891 |
|
| 2892 |
|
| 2893 |
|
| 2894 |
|
| 2895 |
int |
| 2896 |
IntDigits(int i) |
| 2897 |
{ |
| 2898 |
int n = 0; |
| 2899 |
while(i > 0) { i/=10; n++; } |
| 2900 |
return n; |
| 2901 |
} |
| 2902 |
|
| 2903 |
|
| 2904 |
|
| 2905 |
|
| 2906 |
|
| 2907 |
|
| 2908 |
|
| 2909 |
|
| 2910 |
int |
| 2911 |
cm_GetAvgHitLen(CM_t *cm, char *errbuf, float *ret_avgL_loc, float *ret_avgL_glb) |
| 2912 |
{ |
| 2913 |
int status; |
| 2914 |
int Z; |
| 2915 |
float avgL_loc; |
| 2916 |
float avgL_glb; |
| 2917 |
double *gamma0_loc; |
| 2918 |
double *gamma0_glb; |
| 2919 |
int n; |
| 2920 |
|
| 2921 |
if((status = CalculateQueryDependentBands(cm, errbuf, NULL, DEFAULT_BETA_W, NULL, &gamma0_loc, &gamma0_glb, &Z)) != eslOK) return status; |
| 2922 |
avgL_loc = avgL_glb = 0.; |
| 2923 |
for(n = 0; n <= Z; n++) avgL_loc += gamma0_loc[n] * (float) n; |
| 2924 |
for(n = 0; n <= Z; n++) avgL_glb += gamma0_glb[n] * (float) n; |
| 2925 |
free(gamma0_loc); |
| 2926 |
free(gamma0_glb); |
| 2927 |
|
| 2928 |
if(ret_avgL_loc != NULL) *ret_avgL_loc = avgL_loc; |
| 2929 |
if(ret_avgL_glb != NULL) *ret_avgL_glb = avgL_glb; |
| 2930 |
|
| 2931 |
return eslOK; |
| 2932 |
} |
| 2933 |
|
| 2934 |
|
| 2935 |
|
| 2936 |
|
| 2937 |
|
| 2938 |
|
| 2939 |
|
| 2940 |
|
| 2941 |
|
| 2942 |
|
| 2943 |
|
| 2944 |
|
| 2945 |
int |
| 2946 |
CompareCMGuideTrees(CM_t *cm1, CM_t *cm2) |
| 2947 |
{ |
| 2948 |
int nd; |
| 2949 |
if(cm1->nodes != cm2->nodes) return FALSE; |
| 2950 |
for(nd = 0; nd < cm1->nodes; nd++) { |
| 2951 |
if(cm1->ndtype[nd] != cm2->ndtype[nd]) return FALSE; |
| 2952 |
} |
| 2953 |
return TRUE; |
| 2954 |
} |
| 2955 |
|
| 2956 |
|
| 2957 |
|
| 2958 |
|
| 2959 |
|
| 2960 |
|
| 2961 |
|
| 2962 |
|
| 2963 |
|
| 2964 |
|
| 2965 |
|
| 2966 |
|
| 2967 |
|
| 2968 |
|
| 2969 |
|
| 2970 |
|
| 2971 |
|
| 2972 |
|
| 2973 |
|
| 2974 |
|
| 2975 |
|
| 2976 |
int |
| 2977 |
cm_nonconfigured_Verify(CM_t *cm, char *errbuf) |
| 2978 |
{ |
| 2979 |
|
| 2980 |
|
| 2981 |
|
| 2982 |
|
| 2983 |
if(cm->flags & CM_IS_CONFIGURED) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): CM_IS_CONFIGURED flag is up (should be down in a non-configured CM)"); |
| 2984 |
if(cm->flags & CMH_BITS) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): CMH_BITS flag is up (should be down in a non-configured CM)"); |
| 2985 |
if(cm->flags & CMH_LOCAL_BEGIN) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): CMH_LOCAL_BEGIN flag is up (should be down in a non-configured CM)"); |
| 2986 |
if(cm->flags & CMH_LOCAL_END) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): CMH_LOCAL_END flag is up (should be down in a non-configured CM)"); |
| 2987 |
if(cm->flags & CMH_CP9) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): CMH_CP9 flag is up (should be down in a non-configured CM)"); |
| 2988 |
if(cm->flags & CMH_CP9_TRUNC) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): CMH_CP9_TRUNC flag is up (should be down in a non-configured CM)"); |
| 2989 |
if(cm->flags & CM_EMIT_NO_LOCAL_BEGINS) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): CM_EMIT_NO_LOCAL_BEGINS flag is up (should be down in a non-configured CM)"); |
| 2990 |
if(cm->flags & CM_EMIT_NO_LOCAL_ENDS) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): CM_EMIT_NO_LOCAL_ENDS flag is up (should be down in a non-configured CM)"); |
| 2991 |
if(cm->flags & CMH_MLP7) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): CMH_MLP7 flag is up (should be down in a non-configured CM)"); |
| 2992 |
|
| 2993 |
|
| 2994 |
|
| 2995 |
if(cm->cp9 != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): cp9 is non-NULL (it should be NULL in a non-configured CM)"); |
| 2996 |
if(cm->Lcp9 != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): Lcp9 is non-NULL (it should be NULL in a non-configured CM)"); |
| 2997 |
if(cm->Rcp9 != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): Rcp9 is non-NULL (it should be NULL in a non-configured CM)"); |
| 2998 |
if(cm->Tcp9 != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): Tcp9 is non-NULL (it should be NULL in a non-configured CM)"); |
| 2999 |
if(cm->cp9map != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): cp9map is non-NULL (it should be NULL in a non-configured CM)"); |
| 3000 |
if(cm->cp9b != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): cp9b is non-NULL (it should be NULL in a non-configured CM)"); |
| 3001 |
|
| 3002 |
if(cm->hb_mx != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): hb_mx is non-NULL (it should be NULL in a non-configured CM)"); |
| 3003 |
if(cm->hb_omx != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): hb_omx is non-NULL (it should be NULL in a non-configured CM)"); |
| 3004 |
if(cm->hb_emx != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): hb_emx is non-NULL (it should be NULL in a non-configured CM)"); |
| 3005 |
if(cm->hb_shmx != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): hb_shmx is non-NULL (it should be NULL in a non-configured CM)"); |
| 3006 |
if(cm->trhb_mx != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): trhb_mx is non-NULL (it should be NULL in a non-configured CM)"); |
| 3007 |
if(cm->trhb_omx != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): trhb_omx is non-NULL (it should be NULL in a non-configured CM)"); |
| 3008 |
if(cm->trhb_emx != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): trhb_emx is non-NULL (it should be NULL in a non-configured CM)"); |
| 3009 |
if(cm->trhb_shmx != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): trhb_shmx is non-NULL (it should be NULL in a non-configured CM)"); |
| 3010 |
if(cm->nb_mx != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): nb_mx is non-NULL (it should be NULL in a non-configured CM)"); |
| 3011 |
if(cm->nb_omx != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): nb_omx is non-NULL (it should be NULL in a non-configured CM)"); |
| 3012 |
if(cm->nb_emx != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): nb_emx is non-NULL (it should be NULL in a non-configured CM)"); |
| 3013 |
if(cm->nb_shmx != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): nb_shmx is non-NULL (it should be NULL in a non-configured CM)"); |
| 3014 |
if(cm->trnb_mx != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): trnb_mx is non-NULL (it should be NULL in a non-configured CM)"); |
| 3015 |
if(cm->trnb_omx != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): trnb_omx is non-NULL (it should be NULL in a non-configured CM)"); |
| 3016 |
if(cm->trnb_emx != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): trnb_emx is non-NULL (it should be NULL in a non-configured CM)"); |
| 3017 |
if(cm->trnb_shmx != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): trnb_shmx is non-NULL (it should be NULL in a non-configured CM)"); |
| 3018 |
if(cm->smx != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): smx is non-NULL (it should be NULL in a non-configured CM)"); |
| 3019 |
if(cm->trsmx != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): trsmx is non-NULL (it should be NULL in a non-configured CM)"); |
| 3020 |
if(cm->cp9_mx != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): cp9_mx is non-NULL (it should be NULL in a non-configured CM)"); |
| 3021 |
if(cm->cp9_bmx != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): cp9_bmx is non-NULL (it should be NULL in a non-configured CM)"); |
| 3022 |
|
| 3023 |
if(cm->mlp7 != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): mlp7 is non-NULL (it should be NULL in a non-configured CM)"); |
| 3024 |
if(cm->root_trans != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): root_trans is non-NULL (it should be NULL in a non-configured CM)"); |
| 3025 |
if(cm->trp != NULL) ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): trp is non-NULL (it should be NULL in a non-configured CM)"); |
| 3026 |
if(cm->qdbinfo != NULL && cm->qdbinfo->setby == CM_QDBINFO_SETBY_BANDCALC) { |
| 3027 |
ESL_FAIL(eslFAIL, errbuf, "cm_nonconfigured_Verify(): qdbinfo is not in its initial state"); |
| 3028 |
} |
| 3029 |
return eslOK; |
| 3030 |
} |
| 3031 |
|
| 3032 |
|
| 3033 |
|
| 3034 |
|
| 3035 |
|
| 3036 |
|
| 3037 |
|
| 3038 |
|
| 3039 |
|
| 3040 |
|
| 3041 |
|
| 3042 |
|
| 3043 |
|
| 3044 |
|
| 3045 |
|
| 3046 |
|
| 3047 |
|
| 3048 |
|
| 3049 |
int |
| 3050 |
cm_Clone(CM_t *cm, char *errbuf, CM_t **ret_cm) |
| 3051 |
{ |
| 3052 |
int status; |
| 3053 |
CM_t *new = NULL; |
| 3054 |
int i, v; |
| 3055 |
|
| 3056 |
if ((new = CreateCM(cm->nodes, cm->M, cm->clen, cm->abc)) == NULL) { status = eslEMEM; goto ERROR;} |
| 3057 |
|
| 3058 |
|
| 3059 |
if (esl_strdup(cm->name, -1, &(new->name)) != eslOK) { status = eslEMEM; goto ERROR;} |
| 3060 |
if (cm->acc != NULL) { if (esl_strdup(cm->acc, -1, &(new->acc)) != eslOK) { status = eslEMEM; goto ERROR;} } |
| 3061 |
if (cm->desc != NULL) { if (esl_strdup(cm->desc, -1, &(new->desc)) != eslOK) { status = eslEMEM; goto ERROR;} } |
| 3062 |
if (cm->rf != NULL) { if (esl_strdup(cm->rf, -1, &(new->rf)) != eslOK) { status = eslEMEM; goto ERROR;} } |
| 3063 |
if (cm->consensus != NULL) { if (esl_strdup(cm->consensus, -1, &(new->consensus)) != eslOK) { status = eslEMEM; goto ERROR;} } |
| 3064 |
if(cm->map != NULL) { |
| 3065 |
ESL_ALLOC(new->map, sizeof(int) * (new->clen+1)); |
| 3066 |
esl_vec_ICopy(cm->map, (new->clen+1), new->map); |
| 3067 |
} |
| 3068 |
|
| 3069 |
if ((cm->comlog != NULL) && (status = esl_strdup(cm->comlog, -1, &(new->comlog))) != eslOK) goto ERROR; |
| 3070 |
if ((cm->ctime != NULL) && (status = esl_strdup(cm->ctime, -1, &(new->ctime))) != eslOK) goto ERROR; |
| 3071 |
|
| 3072 |
new->flags = cm->flags; |
| 3073 |
new->checksum = cm->checksum; |
| 3074 |
new->nseq = cm->nseq; |
| 3075 |
new->eff_nseq = cm->eff_nseq; |
| 3076 |
new->ga = cm->ga; |
| 3077 |
new->tc = cm->tc; |
| 3078 |
new->nc = cm->nc; |
| 3079 |
new->offset = cm->offset; |
| 3080 |
new->clen = cm->clen; |
| 3081 |
new->W = cm->W; |
| 3082 |
new->W_setby = cm->W_setby; |
| 3083 |
new->beta_W = cm->beta_W; |
| 3084 |
new->pbegin = cm->pbegin; |
| 3085 |
new->pend = cm->pend; |
| 3086 |
new->null2_omega = cm->null2_omega; |
| 3087 |
new->null3_omega = cm->null3_omega; |
| 3088 |
new->el_selfsc = cm->el_selfsc; |
| 3089 |
new->iel_selfsc = cm->iel_selfsc; |
| 3090 |
new->tau = cm->tau; |
| 3091 |
new->maxtau = cm->maxtau; |
| 3092 |
new->config_opts = cm->config_opts; |
| 3093 |
new->align_opts = cm->align_opts; |
| 3094 |
new->search_opts = cm->search_opts; |
| 3095 |
|
| 3096 |
esl_vec_FCopy(cm->null, cm->abc->K, new->null); |
| 3097 |
esl_vec_ICopy(cm->ndidx, cm->M, new->ndidx); |
| 3098 |
esl_vec_ICopy(cm->cfirst, cm->M, new->cfirst); |
| 3099 |
esl_vec_ICopy(cm->cnum, cm->M, new->cnum); |
| 3100 |
esl_vec_ICopy(cm->plast, cm->M, new->plast); |
| 3101 |
esl_vec_ICopy(cm->pnum, cm->M, new->pnum); |
| 3102 |
for(i = 0; i < cm->M+1; i++) new->sttype[i] = cm->sttype[i]; |
| 3103 |
for(i = 0; i < cm->M+1; i++) new->stid[i] = cm->stid[i]; |
| 3104 |
|
| 3105 |
esl_vec_ICopy(cm->nodemap, cm->nodes, new->nodemap); |
| 3106 |
for(i = 0; i < cm->nodes; i++) new->ndtype[i] = cm->ndtype[i]; |
| 3107 |
|
| 3108 |
if(cm->root_trans != NULL) { |
| 3109 |
ESL_ALLOC(new->root_trans, sizeof(float) * cm->cnum[0]); |
| 3110 |
esl_vec_FCopy(cm->root_trans, cm->cnum[0], new->root_trans); |
| 3111 |
} |
| 3112 |
|
| 3113 |
|
| 3114 |
for (v = 0; v < cm->M; v++) { |
| 3115 |
esl_vec_FCopy(cm->e[v], (cm->abc->K * cm->abc->K), new->e[v]); |
| 3116 |
esl_vec_FCopy(cm->t[v], MAXCONNECT, new->t[v]); |
| 3117 |
esl_vec_FCopy(cm->tsc[v], MAXCONNECT, new->tsc[v]); |
| 3118 |
esl_vec_FCopy(cm->esc[v], (cm->abc->K * cm->abc->K), new->esc[v]); |
| 3119 |
esl_vec_FCopy(cm->lmesc[v], cm->abc->Kp, new->lmesc[v]); |
| 3120 |
esl_vec_FCopy(cm->rmesc[v], cm->abc->Kp, new->rmesc[v]); |
| 3121 |
esl_vec_ICopy(cm->itsc[v], MAXCONNECT, new->itsc[v]); |
| 3122 |
esl_vec_ICopy(cm->iesc[v], (cm->abc->K * cm->abc->K), new->iesc[v]); |
| 3123 |
esl_vec_ICopy(cm->ilmesc[v], cm->abc->Kp, new->ilmesc[v]); |
| 3124 |
esl_vec_ICopy(cm->irmesc[v], cm->abc->Kp, new->irmesc[v]); |
| 3125 |
} |
| 3126 |
esl_vec_FCopy(cm->begin, cm->M, new->begin); |
| 3127 |
esl_vec_FCopy(cm->end, cm->M, new->end); |
| 3128 |
esl_vec_FCopy(cm->beginsc, cm->M, new->beginsc); |
| 3129 |
esl_vec_FCopy(cm->endsc, cm->M, new->endsc); |
| 3130 |
esl_vec_ICopy(cm->ibeginsc, cm->M, new->ibeginsc); |
| 3131 |
esl_vec_ICopy(cm->iendsc, cm->M, new->iendsc); |
| 3132 |
|
| 3133 |
|
| 3134 |
if(cm->oesc != NULL && cm->ioesc == NULL) ESL_XFAIL(eslEINCOMPAT, errbuf, "cloning cm, cm->oesc != NULL and cm->ioesc == NULL"); |
| 3135 |
if(cm->oesc == NULL && cm->ioesc != NULL) ESL_XFAIL(eslEINCOMPAT, errbuf, "cloning cm, cm->oesc == NULL and cm->ioesc != NULL"); |
| 3136 |
if(cm->oesc != NULL && cm->ioesc != NULL) { |
| 3137 |
if((status = CloneOptimizedEmitScores(cm, new, errbuf)) != eslOK) goto ERROR; |
| 3138 |
} |
| 3139 |
|
| 3140 |
|
| 3141 |
if(cm->emap != NULL) if((new->emap = CreateEmitMap(new)) == NULL) ESL_XFAIL(eslFAIL, errbuf, "Cloning CM, unable to create new emit map"); |
| 3142 |
|
| 3143 |
|
| 3144 |
if(cm->cmcons != NULL && (new->flags & CMH_BITS)) if((new->cmcons = CreateCMConsensus(cm, cm->abc)) == NULL) ESL_XFAIL(eslFAIL, errbuf, "Cloning CM, unable to create a new CMConsensus_t"); |
| 3145 |
|
| 3146 |
|
| 3147 |
if(cm->trp != NULL) if((new->trp = cm_tr_penalties_Create(new, cm->trp->ignored_inserts, errbuf)) == NULL) ESL_XFAIL(eslFAIL, errbuf, "Cloning CM, unable to create new truncation penalties"); |
| 3148 |
|
| 3149 |
|
| 3150 |
if(cm->qdbinfo != NULL) { |
| 3151 |
if((status = CopyCMQDBInfo(cm->qdbinfo, new->qdbinfo, errbuf)) != eslOK) return status; |
| 3152 |
} |
| 3153 |
|
| 3154 |
|
| 3155 |
if(cm->cp9 != NULL) { if((new->cp9 = cp9_Clone(cm->cp9)) == NULL) ESL_XFAIL(eslFAIL, errbuf, "Cloning CM, couldn't clone cp9"); } |
| 3156 |
if(cm->Lcp9 != NULL) { if((new->Lcp9 = cp9_Clone(cm->Lcp9)) == NULL) ESL_XFAIL(eslFAIL, errbuf, "Cloning CM, couldn't clone Lcp9"); } |
| 3157 |
if(cm->Rcp9 != NULL) { if((new->Rcp9 = cp9_Clone(cm->Rcp9)) == NULL) ESL_XFAIL(eslFAIL, errbuf, "Cloning CM, couldn't clone Rcp9"); } |
| 3158 |
if(cm->Tcp9 != NULL) { if((new->Tcp9 = cp9_Clone(cm->Tcp9)) == NULL) ESL_XFAIL(eslFAIL, errbuf, "Cloning CM, couldn't clone Tcp9"); } |
| 3159 |
|
| 3160 |
if(cm->cp9map != NULL) { |
| 3161 |
new->cp9map = AllocCP9Map(new); |
| 3162 |
CP9_map_cm2hmm(new, new->cp9map, 0); |
| 3163 |
|
| 3164 |
} |
| 3165 |
if(cm->cp9b != NULL) new->cp9b = AllocCP9Bands(new->M, new->cp9->M); |
| 3166 |
if(cm->cp9_mx != NULL) new->cp9_mx = CreateCP9Matrix(1, new->cp9->M); |
| 3167 |
if(cm->cp9_bmx != NULL) new->cp9_bmx = CreateCP9Matrix(1, new->cp9->M); |
| 3168 |
|
| 3169 |
|
| 3170 |
if(cm->mlp7 != NULL) { |
| 3171 |
if((new->mlp7 = p7_hmm_Clone(cm->mlp7)) == NULL) { status = eslEMEM; goto ERROR; } |
| 3172 |
} |
| 3173 |
if(cm->fp7 != NULL) { |
| 3174 |
if((new->fp7 = p7_hmm_Clone(cm->fp7)) == NULL) { status = eslEMEM; goto ERROR; } |
| 3175 |
esl_vec_FCopy(cm->fp7_evparam, CM_p7_NEVPARAM, new->fp7_evparam); |
| 3176 |
} |
| 3177 |
|
| 3178 |
|
| 3179 |
if(cm->hb_mx != NULL) new->hb_mx = cm_hb_mx_Create(new->M); |
| 3180 |
if(cm->hb_omx != NULL) new->hb_omx = cm_hb_mx_Create(new->M); |
| 3181 |
if(cm->hb_emx != NULL) new->hb_emx = cm_hb_emit_mx_Create(new); |
| 3182 |
if(cm->hb_shmx != NULL) new->hb_shmx = cm_hb_shadow_mx_Create(new); |
| 3183 |
if(cm->trhb_mx != NULL) new->trhb_mx = cm_tr_hb_mx_Create(new); |
| 3184 |
if(cm->trhb_omx != NULL) new->trhb_omx = cm_tr_hb_mx_Create(new); |
| 3185 |
if(cm->trhb_emx != NULL) new->trhb_emx = cm_tr_hb_emit_mx_Create(new); |
| 3186 |
if(cm->trhb_shmx != NULL) new->trhb_shmx = cm_tr_hb_shadow_mx_Create(new); |
| 3187 |
|
| 3188 |
|
| 3189 |
if(cm->nb_mx != NULL) new->nb_mx = cm_mx_Create(new->M); |
| 3190 |
if(cm->nb_omx != NULL) new->nb_omx = cm_mx_Create(new->M); |
| 3191 |
if(cm->nb_emx != NULL) new->nb_emx = cm_emit_mx_Create(new); |
| 3192 |
if(cm->nb_shmx != NULL) new->nb_shmx = cm_shadow_mx_Create(new); |
| 3193 |
if(cm->trnb_mx != NULL) new->trnb_mx = cm_tr_mx_Create(new); |
| 3194 |
if(cm->trnb_omx != NULL) new->trnb_omx = cm_tr_mx_Create(new); |
| 3195 |
if(cm->trnb_emx != NULL) new->trnb_emx = cm_tr_emit_mx_Create(new); |
| 3196 |
if(cm->trnb_shmx != NULL) new->trnb_shmx = cm_tr_shadow_mx_Create(new); |
| 3197 |
|
| 3198 |
|
| 3199 |
|
| 3200 |
|
| 3201 |
if(cm->smx != NULL) { if((status = cm_scan_mx_Create (new, errbuf, cm->smx->floats_valid, cm->smx->ints_valid, &(new->smx))) != eslOK) goto ERROR; } |
| 3202 |
if(cm->trsmx != NULL) { if((status = cm_tr_scan_mx_Create(new, errbuf, cm->trsmx->floats_valid, cm->trsmx->ints_valid, &(new->trsmx))) != eslOK) goto ERROR; } |
| 3203 |
|
| 3204 |
|
| 3205 |
if(cm->expA != NULL) { |
| 3206 |
ESL_ALLOC(new->expA, sizeof(ExpInfo_t *) * EXP_NMODES); |
| 3207 |
for(i = 0; i < EXP_NMODES; i++) { |
| 3208 |
new->expA[i] = CreateExpInfo(); |
| 3209 |
CopyExpInfo(cm->expA[i], new->expA[i]); |
| 3210 |
} |
| 3211 |
} |
| 3212 |
|
| 3213 |
*ret_cm = new; |
| 3214 |
|
| 3215 |
return eslOK; |
| 3216 |
|
| 3217 |
ERROR: |
| 3218 |
if(new != NULL) { |
| 3219 |
FreeCM(new); |
| 3220 |
*ret_cm = NULL; |
| 3221 |
} |
| 3222 |
if(status == eslEMEM) ESL_FAIL(status, errbuf, "Cloning CM, out of memory"); |
| 3223 |
return status; |
| 3224 |
} |
| 3225 |
|
| 3226 |
|
| 3227 |
|
| 3228 |
|
| 3229 |
|
| 3230 |
|
| 3231 |
|
| 3232 |
|
| 3233 |
|
| 3234 |
|
| 3235 |
|
| 3236 |
|
| 3237 |
|
| 3238 |
float |
| 3239 |
cm_Sizeof(CM_t *cm) |
| 3240 |
{ |
| 3241 |
float bytes = 0.; |
| 3242 |
|
| 3243 |
bytes = sizeof(CM_t); |
| 3244 |
|
| 3245 |
if(cm->M > 0 && cm->abc != NULL) { |
| 3246 |
bytes += sizeof(char) * (cm->M+1); |
| 3247 |
bytes += sizeof(int) * cm->M; |
| 3248 |
bytes += sizeof(char) * (cm->M+1); |
| 3249 |
bytes += sizeof(int) * cm->M; |
| 3250 |
bytes += sizeof(int) * cm->M; |
| 3251 |
bytes += sizeof(int) * cm->M; |
| 3252 |
bytes += sizeof(int) * cm->M; |
| 3253 |
bytes += sizeof(int) * cm->nodes; |
| 3254 |
bytes += sizeof(int) * cm->nodes; |
| 3255 |
|
| 3256 |
if(cm->comlog != NULL) bytes += sizeof(char) * strlen(cm->comlog); |
| 3257 |
if(cm->ctime != NULL) bytes += sizeof(char) * strlen(cm->ctime); |
| 3258 |
if(cm->qdbinfo != NULL) bytes += (1000000. * SizeofCMQDBInfo(cm->qdbinfo)); |
| 3259 |
if(cm->null != NULL) bytes += sizeof(float) * (cm->abc->K); |
| 3260 |
|
| 3261 |
bytes += sizeof(float *) * cm->M; |
| 3262 |
bytes += sizeof(float *) * cm->M; |
| 3263 |
bytes += sizeof(float *) * cm->M; |
| 3264 |
bytes += sizeof(float *) * cm->M; |
| 3265 |
bytes += sizeof(float *) * cm->M; |
| 3266 |
bytes += sizeof(float *) * cm->M; |
| 3267 |
bytes += sizeof(int *) * cm->M; |
| 3268 |
bytes += sizeof(int *) * cm->M; |
| 3269 |
bytes += sizeof(int *) * cm->M; |
| 3270 |
bytes += sizeof(int *) * cm->M; |
| 3271 |
|
| 3272 |
bytes += sizeof(float) * cm->M; |
| 3273 |
bytes += sizeof(float) * cm->M; |
| 3274 |
bytes += sizeof(float) * cm->M; |
| 3275 |
bytes += sizeof(float) * cm->M; |
| 3276 |
bytes += sizeof(int) * cm->M; |
| 3277 |
bytes += sizeof(int) * cm->M; |
| 3278 |
|
| 3279 |
bytes += sizeof(float) * MAXCONNECT * cm->M; |
| 3280 |
bytes += sizeof(float) * cm->abc->K * cm->abc->K * cm->M; |
| 3281 |
bytes += sizeof(float) * MAXCONNECT * cm->M; |
| 3282 |
bytes += sizeof(float) * cm->abc->K * cm->abc->K * cm->M; |
| 3283 |
bytes += sizeof(float) * cm->abc->Kp * cm->M; |
| 3284 |
bytes += sizeof(float) * cm->abc->Kp * cm->M; |
| 3285 |
bytes += sizeof(int) * MAXCONNECT * cm->M; |
| 3286 |
bytes += sizeof(int) * cm->abc->K * cm->abc->K * cm->M; |
| 3287 |
bytes += sizeof(int) * cm->abc->Kp * cm->M; |
| 3288 |
bytes += sizeof(int) * cm->abc->Kp * cm->M; |
| 3289 |
} |
| 3290 |
|
| 3291 |
if(cm->name != NULL) bytes += sizeof(char) * (strlen(cm->name) + 2); |
| 3292 |
if(cm->acc != NULL) bytes += sizeof(char) * (strlen(cm->acc) + 2); |
| 3293 |
if(cm->desc != NULL) bytes += sizeof(char) * (strlen(cm->desc) + 2); |
| 3294 |
if(cm->rf != NULL) bytes += sizeof(char) * (strlen(cm->rf) + 2); |
| 3295 |
if(cm->consensus != NULL) bytes += sizeof(char) * (strlen(cm->consensus) + 2); |
| 3296 |
if(cm->map != NULL) bytes += sizeof(int) * (cm->clen+1); |
| 3297 |
if(cm->root_trans != NULL) bytes += sizeof(float) * (cm->cnum[0]); |
| 3298 |
|
| 3299 |
if(cm->oesc != NULL || cm->ioesc != NULL) { |
| 3300 |
int nsinglets = 0; |
| 3301 |
int npairs = 0; |
| 3302 |
int v; |
| 3303 |
for(v = 0; v < cm->M; v++) { |
| 3304 |
if(cm->sttype[v] == IL_st || cm->sttype[v] == ML_st || cm->sttype[v] == IR_st || cm->sttype[v] == MR_st) nsinglets++; |
| 3305 |
if(cm->sttype[v] == MP_st) npairs++; |
| 3306 |
} |
| 3307 |
if(cm->oesc != NULL) { |
| 3308 |
bytes += sizeof(float *) * cm->M; |
| 3309 |
bytes += sizeof(float) * ((cm->abc->Kp * nsinglets) + (cm->abc->Kp * cm->abc->Kp * npairs)); |
| 3310 |
} |
| 3311 |
if(cm->ioesc != NULL) { |
| 3312 |
bytes += sizeof(int *) * cm->M; |
| 3313 |
bytes += sizeof(int) * ((cm->abc->Kp * nsinglets) + (cm->abc->Kp * cm->abc->Kp * npairs)); |
| 3314 |
} |
| 3315 |
} |
| 3316 |
|
| 3317 |
|
| 3318 |
if(cm->cp9 != NULL) bytes += (1000000. * cp9_Sizeof(cm->cp9)); |
| 3319 |
if(cm->Lcp9 != NULL) bytes += (1000000. * cp9_Sizeof(cm->Lcp9)); |
| 3320 |
if(cm->Rcp9 != NULL) bytes += (1000000. * cp9_Sizeof(cm->Rcp9)); |
| 3321 |
if(cm->Tcp9 != NULL) bytes += (1000000. * cp9_Sizeof(cm->Tcp9)); |
| 3322 |
|
| 3323 |
if(cm->cp9map != NULL) bytes += (1000000. * SizeofCP9Map(cm->cp9map)); |
| 3324 |
if(cm->cp9b != NULL) bytes += (1000000. * SizeofCP9Bands(cm->cp9b)); |
| 3325 |
if(cm->cp9_mx != NULL) bytes += cm->cp9_mx->size_Mb; |
| 3326 |
if(cm->cp9_bmx != NULL) bytes += cm->cp9_bmx->size_Mb; |
| 3327 |
|
| 3328 |
|
| 3329 |
if(cm->mlp7 != NULL) bytes += (1000000. * cm_p7_hmm_Sizeof(cm->mlp7)); |
| 3330 |
if(cm->fp7 != NULL) bytes += (1000000. * cm_p7_hmm_Sizeof(cm->fp7)); |
| 3331 |
|
| 3332 |
|
| 3333 |
if(cm->hb_mx != NULL) bytes += (1000000. * cm->hb_mx->size_Mb); |
| 3334 |
if(cm->hb_omx != NULL) bytes += (1000000. * cm->hb_omx->size_Mb); |
| 3335 |
if(cm->hb_emx != NULL) bytes += (1000000. * cm->hb_emx->size_Mb); |
| 3336 |
if(cm->hb_shmx != NULL) bytes += (1000000. * cm->hb_shmx->size_Mb); |
| 3337 |
if(cm->trhb_mx != NULL) bytes += (1000000. * cm->trhb_mx->size_Mb); |
| 3338 |
if(cm->trhb_omx != NULL) bytes += (1000000. * cm->trhb_omx->size_Mb); |
| 3339 |
if(cm->trhb_emx != NULL) bytes += (1000000. * cm->trhb_emx->size_Mb); |
| 3340 |
if(cm->trhb_shmx != NULL) bytes += (1000000. * cm->trhb_shmx->size_Mb); |
| 3341 |
|
| 3342 |
|
| 3343 |
if(cm->nb_mx != NULL) bytes += (1000000. * cm->nb_mx->size_Mb); |
| 3344 |
if(cm->nb_omx != NULL) bytes += (1000000. * cm->nb_omx->size_Mb); |
| 3345 |
if(cm->nb_emx != NULL) bytes += (1000000. * cm->nb_emx->size_Mb); |
| 3346 |
if(cm->nb_shmx != NULL) bytes += (1000000. * cm->nb_shmx->size_Mb); |
| 3347 |
if(cm->trnb_mx != NULL) bytes += (1000000. * cm->trnb_mx->size_Mb); |
| 3348 |
if(cm->trnb_omx != NULL) bytes += (1000000. * cm->trnb_omx->size_Mb); |
| 3349 |
if(cm->trnb_emx != NULL) bytes += (1000000. * cm->trnb_emx->size_Mb); |
| 3350 |
if(cm->trnb_shmx != NULL) bytes += (1000000. * cm->trnb_shmx->size_Mb); |
| 3351 |
|
| 3352 |
|
| 3353 |
if(cm->smx != NULL) bytes += (1000000. * cm->smx->size_Mb); |
| 3354 |
if(cm->trsmx != NULL) bytes += (1000000. * cm->trsmx->size_Mb); |
| 3355 |
|
| 3356 |
|
| 3357 |
if(cm->expA != NULL) { |
| 3358 |
bytes += sizeof(ExpInfo_t *) * EXP_NMODES; |
| 3359 |
bytes += sizeof(ExpInfo_t) * EXP_NMODES; |
| 3360 |
} |
| 3361 |
|
| 3362 |
|
| 3363 |
if(cm->emap != NULL) bytes += (1000000. * SizeofEmitMap(cm, cm->emap)); |
| 3364 |
|
| 3365 |
|
| 3366 |
if(cm->trp != NULL) bytes += (1000000. * cm_tr_penalties_Sizeof(cm->trp)); |
| 3367 |
|
| 3368 |
return (bytes / 1000000.); |
| 3369 |
} |
| 3370 |
|
| 3371 |
|
| 3372 |
|
| 3373 |
|
| 3374 |
|
| 3375 |
|
| 3376 |
|
| 3377 |
|
| 3378 |
void |
| 3379 |
DumpCMFlags(FILE *fp, CM_t *cm) |
| 3380 |
{ |
| 3381 |
fprintf(fp, "Dumping CM flags:\n"); |
| 3382 |
if(cm->flags & CMH_BITS) fprintf(fp, "\tCMH_BITS\n"); |
| 3383 |
if(cm->flags & CMH_ACC) fprintf(fp, "\tCMH_ACC\n"); |
| 3384 |
if(cm->flags & CMH_DESC) fprintf(fp, "\tCMH_DESC\n"); |
| 3385 |
if(cm->flags & CMH_RF) fprintf(fp, "\tCMH_RF\n"); |
| 3386 |
if(cm->flags & CMH_GA) fprintf(fp, "\tCMH_GA\n"); |
| 3387 |
if(cm->flags & CMH_TC) fprintf(fp, "\tCMH_TC\n"); |
| 3388 |
if(cm->flags & CMH_NC) fprintf(fp, "\tCMH_NC\n"); |
| 3389 |
if(cm->flags & CMH_CHKSUM) fprintf(fp, "\tCMH_CHKSUM\n"); |
| 3390 |
if(cm->flags & CMH_MAP) fprintf(fp, "\tCMH_MAP\n"); |
| 3391 |
if(cm->flags & CMH_CONS) fprintf(fp, "\tCMH_CONS\n"); |
| 3392 |
if(cm->flags & CMH_LOCAL_BEGIN) fprintf(fp, "\tCMH_LOCAL_BEGIN\n"); |
| 3393 |
if(cm->flags & CMH_LOCAL_END) fprintf(fp, "\tCMH_LOCAL_END\n"); |
| 3394 |
if(cm->flags & CMH_EXPTAIL_STATS) fprintf(fp, "\tCMH_EXPTAIL_STATS\n"); |
| 3395 |
if(cm->flags & CMH_CP9) fprintf(fp, "\tCMH_CP9\n"); |
| 3396 |
if(cm->flags & CMH_CP9_TRUNC) fprintf(fp, "\tCMH_CP9_TRUNC\n"); |
| 3397 |
if(cm->flags & CMH_MLP7) fprintf(fp, "\tCMH_MLP7\n"); |
| 3398 |
if(cm->flags & CMH_FP7) fprintf(fp, "\tCMH_FP7\n"); |
| 3399 |
|
| 3400 |
if(cm->flags & CM_IS_SUB) fprintf(fp, "\tCM_IS_SUB\n"); |
| 3401 |
if(cm->flags & CM_IS_RSEARCH) fprintf(fp, "\tCM_IS_RSEARCH\n"); |
| 3402 |
if(cm->flags & CM_RSEARCHTRANS) fprintf(fp, "\tCM_RSEARCHTRANS\n"); |
| 3403 |
if(cm->flags & CM_RSEARCHEMIT) fprintf(fp, "\tCM_RSEARCHEMIT\n"); |
| 3404 |
if(cm->flags & CM_EMIT_NO_LOCAL_BEGINS) fprintf(fp, "\tCM_EMIT_NO_LOCAL_BEGINS\n"); |
| 3405 |
if(cm->flags & CM_EMIT_NO_LOCAL_ENDS) fprintf(fp, "\tCM_EMIT_NO_LOCAL_ENDS\n"); |
| 3406 |
|
| 3407 |
fprintf(fp, "Finished dumping CM flags.\n"); |
| 3408 |
return; |
| 3409 |
} |
| 3410 |
|
| 3411 |
|
| 3412 |
|
| 3413 |
|
| 3414 |
|
| 3415 |
|
| 3416 |
|
| 3417 |
|
| 3418 |
|
| 3419 |
|
| 3420 |
|
| 3421 |
|
| 3422 |
|
| 3423 |
|
| 3424 |
|
| 3425 |
|
| 3426 |
|
| 3427 |
|
| 3428 |
|
| 3429 |
|
| 3430 |
|
| 3431 |
|
| 3432 |
|
| 3433 |
|
| 3434 |
|
| 3435 |
|
| 3436 |
|
| 3437 |
|
| 3438 |
|
| 3439 |
|
| 3440 |
|
| 3441 |
|
| 3442 |
|
| 3443 |
|
| 3444 |
|
| 3445 |
|
| 3446 |
ESL_GETOPTS * |
| 3447 |
cm_CreateDefaultApp(ESL_OPTIONS *options, int nargs, int argc, char **argv, char *banner, char *usage) |
| 3448 |
{ |
| 3449 |
ESL_GETOPTS *go = NULL; |
| 3450 |
|
| 3451 |
go = esl_getopts_Create(options); |
| 3452 |
if (esl_opt_ProcessCmdline(go, argc, argv) != eslOK || |
| 3453 |
esl_opt_VerifyConfig(go) != eslOK) |
| 3454 |
{ |
| 3455 |
printf("Failed to parse command line: %s\n", go->errbuf); |
| 3456 |
if (usage != NULL) esl_usage(stdout, argv[0], usage); |
| 3457 |
printf("\nTo see more help on available options, do %s -h\n\n", argv[0]); |
| 3458 |
exit(1); |
| 3459 |
} |
| 3460 |
if (esl_opt_GetBoolean(go, "-h") == TRUE) |
| 3461 |
{ |
| 3462 |
if (banner != NULL) cm_banner(stdout, argv[0], banner); |
| 3463 |
if (usage != NULL) esl_usage (stdout, argv[0], usage); |
| 3464 |
puts("\nOptions:"); |
| 3465 |
esl_opt_DisplayHelp(stdout, go, 0, 2, 80); |
| 3466 |
exit(0); |
| 3467 |
} |
| 3468 |
if (esl_opt_ArgNumber(go) != nargs) |
| 3469 |
{ |
| 3470 |
puts("Incorrect number of command line arguments."); |
| 3471 |
esl_usage(stdout, argv[0], usage); |
| 3472 |
printf("\nTo see more help on available options, do %s -h\n\n", argv[0]); |
| 3473 |
exit(1); |
| 3474 |
} |
| 3475 |
return go; |
| 3476 |
} |
| 3477 |
|
| 3478 |
|
| 3479 |
|
| 3480 |
|
| 3481 |
|
| 3482 |
|
| 3483 |
|
| 3484 |
|
| 3485 |
|
| 3486 |
|
| 3487 |
|
| 3488 |
|
| 3489 |
CM_P7_OM_BLOCK * |
| 3490 |
cm_p7_oprofile_CreateBlock(int count) |
| 3491 |
{ |
| 3492 |
int i = 0; |
| 3493 |
|
| 3494 |
CM_P7_OM_BLOCK *block = NULL; |
| 3495 |
int status = eslOK; |
| 3496 |
|
| 3497 |
ESL_ALLOC(block, sizeof(*block)); |
| 3498 |
|
| 3499 |
block->count = 0; |
| 3500 |
block->idx0 = 0; |
| 3501 |
block->listSize = 0; |
| 3502 |
block->list = NULL; |
| 3503 |
block->msvdataA = NULL; |
| 3504 |
block->cm_offsetA = NULL; |
| 3505 |
block->cm_clenA = NULL; |
| 3506 |
block->cm_WA = NULL; |
| 3507 |
block->cm_nbpA = NULL; |
| 3508 |
block->gfmuA = NULL; |
| 3509 |
block->gflambdaA = NULL; |
| 3510 |
block->clan_idxA = NULL; |
| 3511 |
|
| 3512 |
ESL_ALLOC(block->list, sizeof(P7_OPROFILE *) * count); |
| 3513 |
ESL_ALLOC(block->msvdataA, sizeof(P7_SCOREDATA *)* count); |
| 3514 |
ESL_ALLOC(block->cm_offsetA, sizeof(off_t) * count); |
| 3515 |
ESL_ALLOC(block->cm_clenA, sizeof(int) * count); |
| 3516 |
ESL_ALLOC(block->cm_WA, sizeof(int) * count); |
| 3517 |
ESL_ALLOC(block->cm_nbpA, sizeof(int) * count); |
| 3518 |
ESL_ALLOC(block->gfmuA, sizeof(float) * count); |
| 3519 |
ESL_ALLOC(block->gflambdaA, sizeof(float) * count); |
| 3520 |
ESL_ALLOC(block->clan_idxA, sizeof(int) * count); |
| 3521 |
block->listSize = count; |
| 3522 |
|
| 3523 |
for (i = 0; i < count; ++i) |
| 3524 |
{ |
| 3525 |
block->list[i] = NULL; |
| 3526 |
block->msvdataA[i] = NULL; |
| 3527 |
block->cm_offsetA[i] = 0; |
| 3528 |
block->cm_clenA[i] = 0; |
| 3529 |
block->cm_WA[i] = 0; |
| 3530 |
block->cm_nbpA[i] = 0; |
| 3531 |
block->gfmuA[i] = 0.; |
| 3532 |
block->gflambdaA[i] = 0.; |
| 3533 |
block->clan_idxA[i] = -1; |
| 3534 |
} |
| 3535 |
|
| 3536 |
return block; |
| 3537 |
|
| 3538 |
ERROR: |
| 3539 |
if (block != NULL) |
| 3540 |
{ |
| 3541 |
if (block->list != NULL) free(block->list); |
| 3542 |
if (block->msvdataA != NULL) free(block->msvdataA); |
| 3543 |
if (block->cm_offsetA != NULL) free(block->cm_offsetA); |
| 3544 |
if (block->cm_clenA != NULL) free(block->cm_clenA); |
| 3545 |
if (block->cm_WA != NULL) free(block->cm_WA); |
| 3546 |
if (block->cm_nbpA != NULL) free(block->cm_clenA); |
| 3547 |
if (block->gfmuA != NULL) free(block->gfmuA); |
| 3548 |
if (block->gflambdaA != NULL) free(block->gflambdaA); |
| 3549 |
if (block->clan_idxA != NULL) free(block->clan_idxA); |
| 3550 |
free(block); |
| 3551 |
} |
| 3552 |
|
| 3553 |
return NULL; |
| 3554 |
} |
| 3555 |
|
| 3556 |
|
| 3557 |
|
| 3558 |
|
| 3559 |
|
| 3560 |
|
| 3561 |
|
| 3562 |
void |
| 3563 |
cm_p7_oprofile_DestroyBlock(CM_P7_OM_BLOCK *block) |
| 3564 |
{ |
| 3565 |
int i; |
| 3566 |
|
| 3567 |
if (block == NULL) return; |
| 3568 |
|
| 3569 |
if (block->list != NULL) { |
| 3570 |
for (i = 0; i < block->listSize; ++i) { |
| 3571 |
if (block->list[i] != NULL) p7_oprofile_Destroy(block->list[i]); |
| 3572 |
} |
| 3573 |
free(block->list); |
| 3574 |
} |
| 3575 |
if (block->msvdataA != NULL) { |
| 3576 |
for (i = 0; i < block->listSize; ++i) { |
| 3577 |
if (block->msvdataA[i] != NULL) p7_hmm_ScoreDataDestroy(block->msvdataA[i]); |
| 3578 |
} |
| 3579 |
free(block->msvdataA); |
| 3580 |
} |
| 3581 |
if (block->cm_offsetA != NULL) free(block->cm_offsetA); |
| 3582 |
if (block->cm_clenA != NULL) free(block->cm_clenA); |
| 3583 |
if (block->cm_WA != NULL) free(block->cm_WA); |
| 3584 |
if (block->cm_nbpA != NULL) free(block->cm_nbpA); |
| 3585 |
if (block->gfmuA != NULL) free(block->gfmuA); |
| 3586 |
if (block->gflambdaA != NULL) free(block->gflambdaA); |
| 3587 |
if (block->clan_idxA != NULL) free(block->clan_idxA); |
| 3588 |
|
| 3589 |
free(block); |
| 3590 |
return; |
| 3591 |
} |
| 3592 |
|
| 3593 |
|
| 3594 |
|
| 3595 |
|
| 3596 |
|
| 3597 |
|
| 3598 |
|
| 3599 |
|
| 3600 |
|
| 3601 |
|
| 3602 |
|
| 3603 |
float ** |
| 3604 |
FCalcOptimizedEmitScores(CM_t *cm) |
| 3605 |
{ |
| 3606 |
int status; |
| 3607 |
float **esc_vAA; |
| 3608 |
ESL_DSQ a,b; |
| 3609 |
int v; |
| 3610 |
int cur_cell; |
| 3611 |
int npairs = 0; |
| 3612 |
int nsinglets = 0; |
| 3613 |
float *ptr_to_start; |
| 3614 |
float **leftAA; |
| 3615 |
float **rightAA; |
| 3616 |
|
| 3617 |
|
| 3618 |
for(v = 0; v < cm->M; v++) { |
| 3619 |
switch(cm->sttype[v]) { |
| 3620 |
case IL_st: |
| 3621 |
case ML_st: |
| 3622 |
case IR_st: |
| 3623 |
case MR_st: |
| 3624 |
nsinglets++; |
| 3625 |
break; |
| 3626 |
case MP_st: |
| 3627 |
npairs++; |
| 3628 |
break; |
| 3629 |
} |
| 3630 |
} |
| 3631 |
|
| 3632 |
|
| 3633 |
|
| 3634 |
|
| 3635 |
|
| 3636 |
ESL_ALLOC(leftAA, sizeof(float *) * cm->abc->Kp); |
| 3637 |
ESL_ALLOC(rightAA, sizeof(float *) * cm->abc->Kp); |
| 3638 |
for(a = 0; a <= cm->abc->K; a++) leftAA[a] = rightAA[a] = NULL; |
| 3639 |
for(a = cm->abc->K+1; a < cm->abc->Kp-1; a++) { |
| 3640 |
ESL_ALLOC(leftAA[a], sizeof(float) * cm->abc->K); |
| 3641 |
ESL_ALLOC(rightAA[a], sizeof(float) * cm->abc->K); |
| 3642 |
esl_vec_FSet(leftAA[a], cm->abc->K, 0.); |
| 3643 |
esl_vec_FSet(rightAA[a], cm->abc->K, 0.); |
| 3644 |
esl_abc_FCount(cm->abc, leftAA[a], a, 1.); |
| 3645 |
esl_abc_FCount(cm->abc, rightAA[a], a, 1.); |
| 3646 |
} |
| 3647 |
leftAA[cm->abc->Kp-1] = rightAA[cm->abc->Kp-1] = NULL; |
| 3648 |
|
| 3649 |
|
| 3650 |
ESL_ALLOC(esc_vAA, sizeof(float *) * (cm->M)); |
| 3651 |
ESL_ALLOC(esc_vAA[0], sizeof(float) * ((cm->abc->Kp * nsinglets) + (cm->abc->Kp * cm->abc->Kp * npairs))); |
| 3652 |
ptr_to_start = esc_vAA[0]; |
| 3653 |
cur_cell = 0; |
| 3654 |
for(v = 0; v < cm->M; v++) { |
| 3655 |
switch(cm->sttype[v]) { |
| 3656 |
case IL_st: |
| 3657 |
case ML_st: |
| 3658 |
case IR_st: |
| 3659 |
case MR_st: |
| 3660 |
esc_vAA[v] = ptr_to_start + cur_cell; |
| 3661 |
cur_cell += cm->abc->Kp; |
| 3662 |
for(a = 0; a < cm->abc->K; a++) |
| 3663 |
esc_vAA[v][a] = cm->esc[v][a]; |
| 3664 |
esc_vAA[v][cm->abc->K] = IMPOSSIBLE; |
| 3665 |
for(a = cm->abc->K+1; a < cm->abc->Kp-1; a++) |
| 3666 |
esc_vAA[v][a] = esl_abc_FAvgScore(cm->abc, a, cm->esc[v]); |
| 3667 |
esc_vAA[v][cm->abc->Kp-1] = IMPOSSIBLE; |
| 3668 |
break; |
| 3669 |
case MP_st: |
| 3670 |
esc_vAA[v] = ptr_to_start + cur_cell; |
| 3671 |
esl_vec_FSet(esc_vAA[v], cm->abc->Kp * cm->abc->Kp, IMPOSSIBLE); |
| 3672 |
cur_cell += cm->abc->Kp * cm->abc->Kp; |
| 3673 |
|
| 3674 |
for(a = 0; a < cm->abc->K; a++) { |
| 3675 |
for(b = 0; b < cm->abc->K; b++) { |
| 3676 |
esc_vAA[v][(a * cm->abc->Kp) + b] = cm->esc[v][(a * cm->abc->K) + b]; |
| 3677 |
} |
| 3678 |
} |
| 3679 |
|
| 3680 |
for(a = cm->abc->K+1; a < cm->abc->Kp-1; a++) { |
| 3681 |
for(b = 0; b < cm->abc->K; b++) { |
| 3682 |
esc_vAA[v][(a * cm->abc->Kp) + b] = FastPairScoreLeftOnlyDegenerate(cm->abc->K, cm->esc[v], leftAA[a], b); |
| 3683 |
} |
| 3684 |
} |
| 3685 |
|
| 3686 |
for(a = 0; a < cm->abc->K; a++) { |
| 3687 |
for(b = cm->abc->K+1; b < cm->abc->Kp-1; b++) { |
| 3688 |
esc_vAA[v][(a * cm->abc->Kp) + b] = FastPairScoreRightOnlyDegenerate(cm->abc->K, cm->esc[v], rightAA[b], a); |
| 3689 |
} |
| 3690 |
} |
| 3691 |
|
| 3692 |
for(a = cm->abc->K+1; a < cm->abc->Kp-1; a++) { |
| 3693 |
for(b = cm->abc->K+1; b < cm->abc->Kp-1; b++) { |
| 3694 |
esc_vAA[v][(a * cm->abc->Kp) + b] = FastPairScoreBothDegenerate(cm->abc->K, cm->esc[v], leftAA[a], rightAA[b]); |
| 3695 |
} |
| 3696 |
} |
| 3697 |
|
| 3698 |
break; |
| 3699 |
default: |
| 3700 |
esc_vAA[v] = NULL; |
| 3701 |
break; |
| 3702 |
} |
| 3703 |
} |
| 3704 |
for(a = 0; a < cm->abc->Kp; a++) { |
| 3705 |
if(leftAA[a] != NULL) free(leftAA[a]); |
| 3706 |
if(rightAA[a] != NULL) free(rightAA[a]); |
| 3707 |
} |
| 3708 |
free(leftAA); |
| 3709 |
free(rightAA); |
| 3710 |
return esc_vAA; |
| 3711 |
|
| 3712 |
ERROR: |
| 3713 |
cm_Fail("memory allocation error."); |
| 3714 |
return NULL; |
| 3715 |
} |
| 3716 |
|
| 3717 |
|
| 3718 |
|
| 3719 |
|
| 3720 |
|
| 3721 |
|
| 3722 |
|
| 3723 |
|
| 3724 |
|
| 3725 |
|
| 3726 |
int ** |
| 3727 |
ICalcOptimizedEmitScores(CM_t *cm) |
| 3728 |
{ |
| 3729 |
int status; |
| 3730 |
int **iesc_vAA; |
| 3731 |
ESL_DSQ a,b; |
| 3732 |
int v; |
| 3733 |
int cur_cell; |
| 3734 |
int npairs = 0; |
| 3735 |
int nsinglets = 0; |
| 3736 |
int *ptr_to_start; |
| 3737 |
float **leftAA; |
| 3738 |
float **rightAA; |
| 3739 |
|
| 3740 |
|
| 3741 |
for(v = 0; v < cm->M; v++) { |
| 3742 |
switch(cm->sttype[v]) { |
| 3743 |
case IL_st: |
| 3744 |
case ML_st: |
| 3745 |
case IR_st: |
| 3746 |
case MR_st: |
| 3747 |
nsinglets++; |
| 3748 |
break; |
| 3749 |
case MP_st: |
| 3750 |
npairs++; |
| 3751 |
break; |
| 3752 |
} |
| 3753 |
} |
| 3754 |
|
| 3755 |
|
| 3756 |
|
| 3757 |
|
| 3758 |
|
| 3759 |
ESL_ALLOC(leftAA, sizeof(float *) * cm->abc->Kp); |
| 3760 |
ESL_ALLOC(rightAA, sizeof(float *) * cm->abc->Kp); |
| 3761 |
for(a = 0; a <= cm->abc->K; a++) leftAA[a] = rightAA[a] = NULL; |
| 3762 |
for(a = cm->abc->K+1; a < cm->abc->Kp-1; a++) { |
| 3763 |
ESL_ALLOC(leftAA[a], sizeof(float) * cm->abc->K); |
| 3764 |
ESL_ALLOC(rightAA[a], sizeof(float) * cm->abc->K); |
| 3765 |
esl_vec_FSet(leftAA[a], cm->abc->K, 0.); |
| 3766 |
esl_vec_FSet(rightAA[a], cm->abc->K, 0.); |
| 3767 |
esl_abc_FCount(cm->abc, leftAA[a], a, 1.); |
| 3768 |
esl_abc_FCount(cm->abc, rightAA[a], a, 1.); |
| 3769 |
} |
| 3770 |
leftAA[cm->abc->Kp-1] = rightAA[cm->abc->Kp-1] = NULL; |
| 3771 |
|
| 3772 |
|
| 3773 |
ESL_ALLOC(iesc_vAA, sizeof(int *) * (cm->M)); |
| 3774 |
ESL_ALLOC(iesc_vAA[0], sizeof(int) * ((cm->abc->Kp * nsinglets) + (cm->abc->Kp * cm->abc->Kp * npairs))); |
| 3775 |
ptr_to_start = iesc_vAA[0]; |
| 3776 |
cur_cell = 0; |
| 3777 |
for(v = 0; v < cm->M; v++) { |
| 3778 |
switch(cm->sttype[v]) { |
| 3779 |
case IL_st: |
| 3780 |
case ML_st: |
| 3781 |
case IR_st: |
| 3782 |
case MR_st: |
| 3783 |
iesc_vAA[v] = ptr_to_start + cur_cell; |
| 3784 |
cur_cell += cm->abc->Kp; |
| 3785 |
for(a = 0; a < cm->abc->K; a++) |
| 3786 |
iesc_vAA[v][a] = cm->iesc[v][a]; |
| 3787 |
iesc_vAA[v][cm->abc->K] = -INFTY; |
| 3788 |
for(a = cm->abc->K+1; a < cm->abc->Kp-1; a++) |
| 3789 |
iesc_vAA[v][a] = esl_abc_IAvgScore(cm->abc, a, cm->iesc[v]); |
| 3790 |
iesc_vAA[v][cm->abc->Kp-1] = -INFTY; |
| 3791 |
break; |
| 3792 |
case MP_st: |
| 3793 |
iesc_vAA[v] = ptr_to_start + cur_cell; |
| 3794 |
esl_vec_ISet(iesc_vAA[v], cm->abc->Kp * cm->abc->Kp, -INFTY); |
| 3795 |
cur_cell += cm->abc->Kp * cm->abc->Kp; |
| 3796 |
|
| 3797 |
for(a = 0; a < cm->abc->K; a++) { |
| 3798 |
for(b = 0; b < cm->abc->K; b++) { |
| 3799 |
iesc_vAA[v][(a * cm->abc->Kp) + b] = cm->iesc[v][(a * cm->abc->K) + b]; |
| 3800 |
} |
| 3801 |
} |
| 3802 |
|
| 3803 |
for(a = cm->abc->K+1; a < cm->abc->Kp-1; a++) { |
| 3804 |
for(b = 0; b < cm->abc->K; b++) { |
| 3805 |
iesc_vAA[v][(a * cm->abc->Kp) + b] = iFastPairScoreLeftOnlyDegenerate(cm->abc->K, cm->iesc[v], leftAA[a], b); |
| 3806 |
} |
| 3807 |
} |
| 3808 |
|
| 3809 |
for(a = 0; a < cm->abc->K; a++) { |
| 3810 |
for(b = cm->abc->K+1; b < cm->abc->Kp-1; b++) { |
| 3811 |
iesc_vAA[v][(a * cm->abc->Kp) + b] = iFastPairScoreRightOnlyDegenerate(cm->abc->K, cm->iesc[v], rightAA[b], a); |
| 3812 |
} |
| 3813 |
} |
| 3814 |
|
| 3815 |
for(a = cm->abc->K+1; a < cm->abc->Kp-1; a++) { |
| 3816 |
for(b = cm->abc->K+1; b < cm->abc->Kp-1; b++) { |
| 3817 |
iesc_vAA[v][(a * cm->abc->Kp) + b] = iFastPairScoreBothDegenerate(cm->abc->K, cm->iesc[v], leftAA[a], rightAA[b]); |
| 3818 |
} |
| 3819 |
} |
| 3820 |
|
| 3821 |
break; |
| 3822 |
default: |
| 3823 |
iesc_vAA[v] = NULL; |
| 3824 |
break; |
| 3825 |
} |
| 3826 |
} |
| 3827 |
for(a = 0; a < cm->abc->Kp; a++) { |
| 3828 |
if(leftAA[a] != NULL) free(leftAA[a]); |
| 3829 |
if(rightAA[a] != NULL) free(rightAA[a]); |
| 3830 |
} |
| 3831 |
free(leftAA); |
| 3832 |
free(rightAA); |
| 3833 |
return iesc_vAA; |
| 3834 |
|
| 3835 |
ERROR: |
| 3836 |
cm_Fail("memory allocation error."); |
| 3837 |
return NULL; |
| 3838 |
} |
| 3839 |
|
| 3840 |
|
| 3841 |
|
| 3842 |
|
| 3843 |
|
| 3844 |
|
| 3845 |
|
| 3846 |
|
| 3847 |
|
| 3848 |
|
| 3849 |
|
| 3850 |
|
| 3851 |
|
| 3852 |
|
| 3853 |
|
| 3854 |
int ** |
| 3855 |
ICopyOptimizedEmitScoresFromFloats(CM_t *cm, float **oesc) |
| 3856 |
{ |
| 3857 |
int status; |
| 3858 |
int **iesc_vAA; |
| 3859 |
ESL_DSQ a,b; |
| 3860 |
int v; |
| 3861 |
int cur_cell; |
| 3862 |
int npairs = 0; |
| 3863 |
int nsinglets = 0; |
| 3864 |
int *ptr_to_start; |
| 3865 |
|
| 3866 |
|
| 3867 |
for(v = 0; v < cm->M; v++) { |
| 3868 |
switch(cm->sttype[v]) { |
| 3869 |
case IL_st: |
| 3870 |
case ML_st: |
| 3871 |
case IR_st: |
| 3872 |
case MR_st: |
| 3873 |
nsinglets++; |
| 3874 |
break; |
| 3875 |
case MP_st: |
| 3876 |
npairs++; |
| 3877 |
break; |
| 3878 |
} |
| 3879 |
} |
| 3880 |
|
| 3881 |
|
| 3882 |
ESL_ALLOC(iesc_vAA, sizeof(int *) * (cm->M)); |
| 3883 |
ESL_ALLOC(iesc_vAA[0], sizeof(int) * ((cm->abc->Kp * nsinglets) + (cm->abc->Kp * cm->abc->Kp * npairs))); |
| 3884 |
ptr_to_start = iesc_vAA[0]; |
| 3885 |
cur_cell = 0; |
| 3886 |
for(v = 0; v < cm->M; v++) { |
| 3887 |
switch(cm->sttype[v]) { |
| 3888 |
case IL_st: |
| 3889 |
case ML_st: |
| 3890 |
case IR_st: |
| 3891 |
case MR_st: |
| 3892 |
iesc_vAA[v] = ptr_to_start + cur_cell; |
| 3893 |
cur_cell += cm->abc->Kp; |
| 3894 |
for(a = 0; a < cm->abc->K; a++) |
| 3895 |
iesc_vAA[v][a] = cm->iesc[v][a]; |
| 3896 |
iesc_vAA[v][cm->abc->K] = -INFTY; |
| 3897 |
for(a = cm->abc->K+1; a < cm->abc->Kp-1; a++) |
| 3898 |
iesc_vAA[v][a] = (int) floor(0.5 + INTSCALE * oesc[v][a]); |
| 3899 |
iesc_vAA[v][cm->abc->Kp-1] = -INFTY; |
| 3900 |
break; |
| 3901 |
case MP_st: |
| 3902 |
iesc_vAA[v] = ptr_to_start + cur_cell; |
| 3903 |
esl_vec_ISet(iesc_vAA[v], cm->abc->Kp * cm->abc->Kp, -INFTY); |
| 3904 |
cur_cell += cm->abc->Kp * cm->abc->Kp; |
| 3905 |
|
| 3906 |
for(a = 0; a < cm->abc->K; a++) { |
| 3907 |
for(b = 0; b < cm->abc->K; b++) { |
| 3908 |
iesc_vAA[v][(a * cm->abc->Kp) + b] = cm->iesc[v][(a * cm->abc->K) + b]; |
| 3909 |
} |
| 3910 |
} |
| 3911 |
|
| 3912 |
for(a = cm->abc->K+1; a < cm->abc->Kp-1; a++) { |
| 3913 |
for(b = 0; b < cm->abc->K; b++) { |
| 3914 |
iesc_vAA[v][(a * cm->abc->Kp) + b] = (int) floor(0.5 + INTSCALE * oesc[v][(a * cm->abc->Kp)+b]); |
| 3915 |
} |
| 3916 |
} |
| 3917 |
|
| 3918 |
for(a = 0; a < cm->abc->K; a++) { |
| 3919 |
for(b = cm->abc->K+1; b < cm->abc->Kp-1; b++) { |
| 3920 |
iesc_vAA[v][(a * cm->abc->Kp) + b] = (int) floor(0.5 + INTSCALE * oesc[v][(a * cm->abc->Kp)+b]); |
| 3921 |
} |
| 3922 |
} |
| 3923 |
|
| 3924 |
for(a = cm->abc->K+1; a < cm->abc->Kp-1; a++) { |
| 3925 |
for(b = cm->abc->K+1; b < cm->abc->Kp-1; b++) { |
| 3926 |
iesc_vAA[v][(a * cm->abc->Kp) + b] = (int) floor(0.5 + INTSCALE * oesc[v][(a * cm->abc->Kp)+b]); |
| 3927 |
} |
| 3928 |
} |
| 3929 |
|
| 3930 |
break; |
| 3931 |
default: |
| 3932 |
iesc_vAA[v] = NULL; |
| 3933 |
break; |
| 3934 |
} |
| 3935 |
} |
| 3936 |
return iesc_vAA; |
| 3937 |
|
| 3938 |
ERROR: |
| 3939 |
cm_Fail("memory allocation error."); |
| 3940 |
return NULL; |
| 3941 |
} |
| 3942 |
|
| 3943 |
|
| 3944 |
|
| 3945 |
|
| 3946 |
|
| 3947 |
|
| 3948 |
|
| 3949 |
|
| 3950 |
|
| 3951 |
|
| 3952 |
|
| 3953 |
int |
| 3954 |
CloneOptimizedEmitScores(const CM_t *src, CM_t *dest, char *errbuf) |
| 3955 |
{ |
| 3956 |
int status; |
| 3957 |
int v; |
| 3958 |
int nsinglets = 0; |
| 3959 |
int npairs = 0; |
| 3960 |
float *fptr_to_start; |
| 3961 |
int *iptr_to_start; |
| 3962 |
int cur_cell; |
| 3963 |
|
| 3964 |
if(src->M != dest->M) ESL_FAIL(eslEINCOMPAT, errbuf, "cloning optimized emit scores, src->M != dest->M"); |
| 3965 |
if(src->nodes != dest->nodes) ESL_FAIL(eslEINCOMPAT, errbuf, "cloning optimized emit scores, src->nodes != dest->nodes"); |
| 3966 |
if(src->clen != dest->clen) ESL_FAIL(eslEINCOMPAT, errbuf, "cloning optimized emit scores, src->clen != dest->clen"); |
| 3967 |
if(src->abc->type != dest->abc->type) ESL_FAIL(eslEINCOMPAT, errbuf, "cloning optimized emit scores, src->abc->type != dest->abc->type"); |
| 3968 |
if(dest->oesc != NULL) ESL_FAIL(eslEINCOMPAT, errbuf, "cloning optimized emit scores, dest->oesc != NULL"); |
| 3969 |
if(dest->ioesc != NULL) ESL_FAIL(eslEINCOMPAT, errbuf, "cloning optimized emit scores, dest->ioesc != NULL"); |
| 3970 |
if(src->oesc == NULL) ESL_FAIL(eslEINCOMPAT, errbuf, "cloning optimized emit scores, src->oesc == NULL"); |
| 3971 |
if(src->ioesc == NULL) ESL_FAIL(eslEINCOMPAT, errbuf, "cloning optimized emit scores, src->ioesc == NULL"); |
| 3972 |
|
| 3973 |
|
| 3974 |
for(v = 0; v < src->M; v++) { |
| 3975 |
if(src->sttype[v] == IL_st || src->sttype[v] == ML_st || src->sttype[v] == IR_st || src->sttype[v] == MR_st) nsinglets++; |
| 3976 |
if(src->sttype[v] == MP_st) npairs++; |
| 3977 |
} |
| 3978 |
|
| 3979 |
ESL_ALLOC(dest->oesc, sizeof(float *) * (src->M)); |
| 3980 |
ESL_ALLOC(dest->oesc[0], sizeof(float) * ((src->abc->Kp * nsinglets) + (src->abc->Kp * src->abc->Kp * npairs))); |
| 3981 |
ESL_ALLOC(dest->ioesc, sizeof(int *) * (src->M)); |
| 3982 |
ESL_ALLOC(dest->ioesc[0], sizeof(int) * ((src->abc->Kp * nsinglets) + (src->abc->Kp * src->abc->Kp * npairs))); |
| 3983 |
fptr_to_start = dest->oesc[0]; |
| 3984 |
iptr_to_start = dest->ioesc[0]; |
| 3985 |
cur_cell = 0; |
| 3986 |
for(v = 0; v < src->M; v++) { |
| 3987 |
if(src->sttype[v] == IL_st || src->sttype[v] == ML_st || src->sttype[v] == IR_st || src->sttype[v] == MR_st) { |
| 3988 |
dest->oesc[v] = fptr_to_start + cur_cell; |
| 3989 |
dest->ioesc[v] = iptr_to_start + cur_cell; |
| 3990 |
esl_vec_FCopy(src->oesc[v], src->abc->Kp, dest->oesc[v]); |
| 3991 |
esl_vec_ICopy(src->ioesc[v], src->abc->Kp, dest->ioesc[v]); |
| 3992 |
cur_cell += src->abc->Kp; |
| 3993 |
} |
| 3994 |
else if(src->sttype[v] == MP_st) { |
| 3995 |
dest->oesc[v] = fptr_to_start + cur_cell; |
| 3996 |
dest->ioesc[v] = iptr_to_start + cur_cell; |
| 3997 |
esl_vec_FCopy(src->oesc[v], src->abc->Kp * src->abc->Kp, dest->oesc[v]); |
| 3998 |
esl_vec_ICopy(src->ioesc[v], src->abc->Kp * src->abc->Kp, dest->ioesc[v]); |
| 3999 |
cur_cell += src->abc->Kp * src->abc->Kp; |
| 4000 |
} |
| 4001 |
else { |
| 4002 |
dest->oesc[v] = NULL; |
| 4003 |
dest->ioesc[v] = NULL; |
| 4004 |
} |
| 4005 |
} |
| 4006 |
return eslOK; |
| 4007 |
|
| 4008 |
ERROR: |
| 4009 |
ESL_FAIL(status, errbuf, "out of memory"); |
| 4010 |
return status; |
| 4011 |
} |
| 4012 |
|
| 4013 |
|
| 4014 |
|
| 4015 |
void |
| 4016 |
DumpOptimizedEmitScores(CM_t *cm, FILE *fp) |
| 4017 |
{ |
| 4018 |
int v; |
| 4019 |
|
| 4020 |
for(v = 0; v < cm->M; v++) { |
| 4021 |
switch(cm->sttype[v]) { |
| 4022 |
case IL_st: |
| 4023 |
case ML_st: |
| 4024 |
case IR_st: |
| 4025 |
case MR_st: |
| 4026 |
if(cm->oesc != NULL) { |
| 4027 |
fprintf(fp, "SF v: %5d\t", v); |
| 4028 |
esl_vec_FDump(fp, cm->oesc[v], cm->abc->Kp, NULL); |
| 4029 |
} |
| 4030 |
if(cm->ioesc != NULL) { |
| 4031 |
fprintf(fp, "SI v: %5d\t", v); |
| 4032 |
esl_vec_IDump(fp, cm->ioesc[v], cm->abc->Kp, NULL); |
| 4033 |
} |
| 4034 |
break; |
| 4035 |
case MP_st: |
| 4036 |
if(cm->oesc != NULL) { |
| 4037 |
fprintf(fp, "PF v: %5d\t", v); |
| 4038 |
esl_vec_FDump(fp, cm->oesc[v], cm->abc->Kp * cm->abc->Kp, NULL); |
| 4039 |
} |
| 4040 |
if(cm->ioesc != NULL) { |
| 4041 |
esl_vec_IDump(fp, cm->ioesc[v], cm->abc->Kp * cm->abc->Kp, NULL); |
| 4042 |
fprintf(fp, "PI v: %5d\t", v); |
| 4043 |
} |
| 4044 |
break; |
| 4045 |
} |
| 4046 |
} |
| 4047 |
} |
| 4048 |
|
| 4049 |
|
| 4050 |
|
| 4051 |
|
| 4052 |
|
| 4053 |
|
| 4054 |
|
| 4055 |
|
| 4056 |
|
| 4057 |
|
| 4058 |
void |
| 4059 |
FreeOptimizedEmitScores(float **fesc_vAA, int **iesc_vAA, int M) |
| 4060 |
{ |
| 4061 |
if(fesc_vAA == NULL && iesc_vAA == NULL) cm_Fail("FreeOptimizedEmitScores() but fesc and iesc are NULL.\n"); |
| 4062 |
|
| 4063 |
if(fesc_vAA != NULL) { |
| 4064 |
if(fesc_vAA[1] != NULL) { |
| 4065 |
free(fesc_vAA[1]); |
| 4066 |
|
| 4067 |
|
| 4068 |
|
| 4069 |
} |
| 4070 |
free(fesc_vAA); |
| 4071 |
fesc_vAA = NULL; |
| 4072 |
} |
| 4073 |
|
| 4074 |
if(iesc_vAA != NULL) { |
| 4075 |
if(iesc_vAA[1] != NULL) { |
| 4076 |
free(iesc_vAA[1]); |
| 4077 |
|
| 4078 |
|
| 4079 |
|
| 4080 |
} |
| 4081 |
free(iesc_vAA); |
| 4082 |
iesc_vAA = NULL; |
| 4083 |
} |
| 4084 |
return; |
| 4085 |
} |
| 4086 |
|
| 4087 |
|
| 4088 |
|
| 4089 |
|
| 4090 |
|
| 4091 |
|
| 4092 |
|
| 4093 |
|
| 4094 |
|
| 4095 |
|
| 4096 |
|
| 4097 |
|
| 4098 |
|
| 4099 |
float ** |
| 4100 |
FCalcInitDPScores(CM_t *cm) |
| 4101 |
{ |
| 4102 |
int status; |
| 4103 |
float *el_scA; |
| 4104 |
float **init_scAA; |
| 4105 |
int v, d; |
| 4106 |
|
| 4107 |
|
| 4108 |
ESL_ALLOC(el_scA, sizeof(float) * (cm->W+1)); |
| 4109 |
for(d = 0; d <= cm->W; d++) el_scA[d] = cm->el_selfsc * d; |
| 4110 |
|
| 4111 |
|
| 4112 |
|
| 4113 |
ESL_ALLOC(init_scAA, sizeof(float *) * (cm->M)); |
| 4114 |
ESL_ALLOC(init_scAA[0], sizeof(float) * (cm->M) * (cm->W+1)); |
| 4115 |
for (v = 0; v < cm->M; v++) { |
| 4116 |
init_scAA[v] = init_scAA[0] + (v * (cm->W+1)); |
| 4117 |
if(NOT_IMPOSSIBLE(cm->endsc[v])) { |
| 4118 |
for(d = 0; d <= cm->W; d++) init_scAA[v][d] = el_scA[d] + cm->endsc[v]; |
| 4119 |
} |
| 4120 |
else { |
| 4121 |
for(d = 0; d <= cm->W; d++) init_scAA[v][d] = IMPOSSIBLE; |
| 4122 |
} |
| 4123 |
} |
| 4124 |
free(el_scA); |
| 4125 |
return init_scAA; |
| 4126 |
|
| 4127 |
ERROR: |
| 4128 |
cm_Fail("memory allocation error."); |
| 4129 |
return NULL; |
| 4130 |
} |
| 4131 |
|
| 4132 |
|
| 4133 |
|
| 4134 |
|
| 4135 |
|
| 4136 |
|
| 4137 |
|
| 4138 |
|
| 4139 |
|
| 4140 |
|
| 4141 |
|
| 4142 |
|
| 4143 |
|
| 4144 |
|
| 4145 |
int ** |
| 4146 |
ICalcInitDPScores(CM_t *cm) |
| 4147 |
{ |
| 4148 |
int status; |
| 4149 |
int *el_scA; |
| 4150 |
int **init_scAA; |
| 4151 |
int v, d; |
| 4152 |
|
| 4153 |
|
| 4154 |
ESL_ALLOC(el_scA, sizeof(int) * (cm->W+1)); |
| 4155 |
for(d = 0; d <= cm->W; d++) el_scA[d] = cm->iel_selfsc * d; |
| 4156 |
|
| 4157 |
|
| 4158 |
|
| 4159 |
ESL_ALLOC(init_scAA, sizeof(int *) * (cm->M)); |
| 4160 |
ESL_ALLOC(init_scAA[0], sizeof(int) * (cm->M) * (cm->W+1)); |
| 4161 |
for (v = 0; v < cm->M; v++) { |
| 4162 |
init_scAA[v] = init_scAA[0] + (v * (cm->W+1)); |
| 4163 |
if(cm->iendsc[v] != -INFTY) { |
| 4164 |
for(d = 0; d <= cm->W; d++) init_scAA[v][d] = el_scA[d] + cm->iendsc[v]; |
| 4165 |
} |
| 4166 |
else { |
| 4167 |
for(d = 0; d <= cm->W; d++) init_scAA[v][d] = -INFTY; |
| 4168 |
} |
| 4169 |
} |
| 4170 |
|
| 4171 |
|
| 4172 |
free(el_scA); |
| 4173 |
return init_scAA; |
| 4174 |
|
| 4175 |
ERROR: |
| 4176 |
cm_Fail("memory allocation error."); |
| 4177 |
return NULL; |
| 4178 |
} |
| 4179 |
|
| 4180 |
|
| 4181 |
|
| 4182 |
|
| 4183 |
|
| 4184 |
|
| 4185 |
|
| 4186 |
|
| 4187 |
|
| 4188 |
|
| 4189 |
|
| 4190 |
|
| 4191 |
|
| 4192 |
|
| 4193 |
|
| 4194 |
|
| 4195 |
|
| 4196 |
|
| 4197 |
|
| 4198 |
|
| 4199 |
|
| 4200 |
int |
| 4201 |
Prob2Score(float p, float null) |
| 4202 |
{ |
| 4203 |
if(p == 0.0) return -INFTY; |
| 4204 |
else return (int) floor(0.5 + INTSCALE * sreLOG2(p/null)); |
| 4205 |
} |
| 4206 |
|
| 4207 |
|
| 4208 |
|
| 4209 |
|
| 4210 |
|
| 4211 |
|
| 4212 |
float |
| 4213 |
Score2Prob(int sc, float null) |
| 4214 |
{ |
| 4215 |
if (sc == -INFTY) return 0.; |
| 4216 |
else return (null * sreEXP2((float) sc / INTSCALE)); |
| 4217 |
} |
| 4218 |
|
| 4219 |
|
| 4220 |
|
| 4221 |
|
| 4222 |
|
| 4223 |
|
| 4224 |
float |
| 4225 |
Scorify(int sc) |
| 4226 |
{ |
| 4227 |
if (sc == -INFTY) return IMPOSSIBLE; |
| 4228 |
else return ((float) sc / INTSCALE); |
| 4229 |
} |
| 4230 |
|
| 4231 |
|
| 4232 |
|
| 4233 |
|
| 4234 |
|
| 4235 |
|
| 4236 |
|
| 4237 |
|
| 4238 |
|
| 4239 |
|
| 4240 |
|
| 4241 |
|
| 4242 |
|
| 4243 |
|
| 4244 |
|
| 4245 |
|
| 4246 |
|
| 4247 |
|
| 4248 |
|
| 4249 |
double * |
| 4250 |
cm_ExpectedStateOccupancy(CM_t *cm) |
| 4251 |
{ |
| 4252 |
int status; |
| 4253 |
int v; |
| 4254 |
int y; |
| 4255 |
int x; |
| 4256 |
char tmap_val; |
| 4257 |
int nd; |
| 4258 |
double summed_psi; |
| 4259 |
int nstates; |
| 4260 |
int is_insert; |
| 4261 |
int final_y; |
| 4262 |
char ***tmap = NULL; |
| 4263 |
float **t_copy = NULL; |
| 4264 |
double *psi = NULL; |
| 4265 |
double tol = 0.001; |
| 4266 |
|
| 4267 |
|
| 4268 |
|
| 4269 |
|
| 4270 |
|
| 4271 |
|
| 4272 |
if(cm->clen > 25000) { |
| 4273 |
tol = ((float) cm->clen / 25000.) * 0.001; |
| 4274 |
} |
| 4275 |
|
| 4276 |
|
| 4277 |
ESL_ALLOC(t_copy, cm->M * sizeof(float *)); |
| 4278 |
ESL_ALLOC(t_copy[0], cm->M * MAXCONNECT * sizeof(float)); |
| 4279 |
for (v = 0; v < cm->M; v++) { |
| 4280 |
t_copy[v] = t_copy[0] + v * MAXCONNECT; |
| 4281 |
} |
| 4282 |
esl_vec_FCopy(cm->t[0], cm->M * MAXCONNECT, t_copy[0]); |
| 4283 |
|
| 4284 |
if(cm->root_trans != NULL) { |
| 4285 |
esl_vec_FCopy(cm->root_trans, cm->cnum[0], t_copy[0]); |
| 4286 |
} |
| 4287 |
|
| 4288 |
|
| 4289 |
|
| 4290 |
if(cm->flags & CMH_LOCAL_END) { |
| 4291 |
for (nd = 1; nd < cm->nodes; nd++) { |
| 4292 |
if ((cm->ndtype[nd] == MATP_nd || cm->ndtype[nd] == MATL_nd || |
| 4293 |
cm->ndtype[nd] == MATR_nd || cm->ndtype[nd] == BEGL_nd || |
| 4294 |
cm->ndtype[nd] == BEGR_nd) && |
| 4295 |
cm->ndtype[nd+1] != END_nd) |
| 4296 |
{ |
| 4297 |
v = cm->nodemap[nd]; |
| 4298 |
esl_vec_FNorm(t_copy[v], cm->cnum[v]); |
| 4299 |
} |
| 4300 |
} |
| 4301 |
} |
| 4302 |
|
| 4303 |
|
| 4304 |
ESL_ALLOC(psi, sizeof(double) * cm->M); |
| 4305 |
esl_vec_DSet(psi, cm->M, 0.); |
| 4306 |
|
| 4307 |
|
| 4308 |
tmap = cm_CreateTransitionMap(); |
| 4309 |
|
| 4310 |
|
| 4311 |
for (v = 0; v <= cm->M-1; v++) { |
| 4312 |
is_insert = (cm->sttype[v] == IL_st || cm->sttype[v] == IR_st) ? TRUE : FALSE; |
| 4313 |
|
| 4314 |
if(cm->sttype[v] == S_st) { |
| 4315 |
psi[v] = 1.0; |
| 4316 |
} |
| 4317 |
else { |
| 4318 |
final_y = (is_insert) ? 1 : 0; |
| 4319 |
for (y = cm->pnum[v]-1; y >= final_y; y--) { |
| 4320 |
x = cm->plast[v] - y; |
| 4321 |
tmap_val = tmap[(int) cm->stid[x]][(int) cm->ndtype[cm->ndidx[v]+is_insert]][(int) cm->stid[v]]; |
| 4322 |
psi[v] += psi[x] * t_copy[x][(int) tmap_val]; |
| 4323 |
} |
| 4324 |
if(is_insert) { |
| 4325 |
psi[v] += psi[v] * (t_copy[v][0] / (1.-t_copy[v][0])); |
| 4326 |
} |
| 4327 |
} |
| 4328 |
} |
| 4329 |
|
| 4330 |
|
| 4331 |
|
| 4332 |
for(nd = 0; nd < cm->nodes; nd++) { |
| 4333 |
summed_psi = 0.; |
| 4334 |
nstates = TotalStatesInNode(cm->ndtype[nd]); |
| 4335 |
for(v = cm->nodemap[nd]; v < cm->nodemap[nd] + nstates; v++) { |
| 4336 |
if(cm->sttype[v] != IL_st && cm->sttype[v] != IR_st) summed_psi += psi[v]; |
| 4337 |
} |
| 4338 |
if((summed_psi < (1. - tol)) || (summed_psi > (1.0 + tol))) { |
| 4339 |
cm_Fail("summed psi of split states in node %d not 1.0 but : %f\n", nd, summed_psi); |
| 4340 |
} |
| 4341 |
|
| 4342 |
} |
| 4343 |
|
| 4344 |
|
| 4345 |
for(v = 0; v < cm->M; v++) { |
| 4346 |
if(psi[v] == 0. && (! StateIsDetached(cm, v))) { |
| 4347 |
cm_Fail("psi of state v:%d is 0.0 and this state is not a detached insert! HMM banding would have failed...\n", v); |
| 4348 |
} |
| 4349 |
} |
| 4350 |
|
| 4351 |
cm_FreeTransitionMap(tmap); |
| 4352 |
if(t_copy != NULL) { |
| 4353 |
if(t_copy[0] != NULL) free(t_copy[0]); |
| 4354 |
free(t_copy); |
| 4355 |
} |
| 4356 |
return psi; |
| 4357 |
|
| 4358 |
ERROR: |
| 4359 |
cm_FreeTransitionMap(tmap); |
| 4360 |
if(t_copy != NULL) { |
| 4361 |
if(t_copy[0] != NULL) free(t_copy[0]); |
| 4362 |
free(t_copy); |
| 4363 |
} |
| 4364 |
if(psi != NULL) free(psi); |
| 4365 |
return NULL; |
| 4366 |
} |
| 4367 |
|
| 4368 |
|
| 4369 |
|
| 4370 |
|
| 4371 |
|
| 4372 |
|
| 4373 |
|
| 4374 |
|
| 4375 |
|
| 4376 |
|
| 4377 |
|
| 4378 |
|
| 4379 |
|
| 4380 |
|
| 4381 |
|
| 4382 |
|
| 4383 |
|
| 4384 |
|
| 4385 |
|
| 4386 |
|
| 4387 |
|
| 4388 |
|
| 4389 |
|
| 4390 |
|
| 4391 |
|
| 4392 |
|
| 4393 |
|
| 4394 |
|
| 4395 |
|
| 4396 |
|
| 4397 |
|
| 4398 |
|
| 4399 |
|
| 4400 |
|
| 4401 |
|
| 4402 |
|
| 4403 |
|
| 4404 |
int |
| 4405 |
cm_ExpectedPositionOccupancy(CM_t *cm, float **ret_mexpocc, float **ret_iexpocc, double **opt_psi, int **opt_m2v_1, int **opt_m2v_2, int **opt_i2v) |
| 4406 |
{ |
| 4407 |
int status; |
| 4408 |
double *psi = NULL; |
| 4409 |
float *mexpocc = NULL; |
| 4410 |
float *iexpocc = NULL; |
| 4411 |
int *m2v_1 = NULL; |
| 4412 |
int *m2v_2 = NULL; |
| 4413 |
int *i2v = NULL; |
| 4414 |
int lpos, rpos; |
| 4415 |
int v, nd; |
| 4416 |
|
| 4417 |
if((psi = cm_ExpectedStateOccupancy(cm)) == NULL) goto ERROR; |
| 4418 |
|
| 4419 |
ESL_ALLOC(mexpocc, sizeof(float) * (cm->clen+1)); |
| 4420 |
ESL_ALLOC(iexpocc, sizeof(float) * (cm->clen+1)); |
| 4421 |
ESL_ALLOC(m2v_1, sizeof(int) * (cm->clen+1)); |
| 4422 |
ESL_ALLOC(m2v_2, sizeof(int) * (cm->clen+1)); |
| 4423 |
ESL_ALLOC(i2v, sizeof(int) * (cm->clen+1)); |
| 4424 |
esl_vec_FSet(mexpocc, (cm->clen+1), 0.); |
| 4425 |
esl_vec_FSet(iexpocc, (cm->clen+1), 0.); |
| 4426 |
esl_vec_ISet(m2v_1, (cm->clen+1), -1); |
| 4427 |
esl_vec_ISet(m2v_2, (cm->clen+1), -1); |
| 4428 |
esl_vec_ISet(i2v, (cm->clen+1), -1); |
| 4429 |
|
| 4430 |
mexpocc[0] = 0.; |
| 4431 |
|
| 4432 |
for(v = 0; v < cm->M; v++) { |
| 4433 |
if(! StateIsDetached(cm, v)) { |
| 4434 |
nd = cm->ndidx[v]; |
| 4435 |
lpos = cm->emap->lpos[nd]; |
| 4436 |
rpos = cm->emap->rpos[nd]; |
| 4437 |
|
| 4438 |
if(cm->sttype[v] == MP_st || cm->sttype[v] == ML_st) mexpocc[lpos] += psi[v]; |
| 4439 |
if(cm->sttype[v] == MP_st || cm->sttype[v] == MR_st) mexpocc[rpos] += psi[v]; |
| 4440 |
if(cm->sttype[v] == IL_st) { iexpocc[lpos] = psi[v]; i2v[lpos] = v; } |
| 4441 |
if(cm->sttype[v] == IR_st) { iexpocc[rpos-1] = psi[v]; i2v[rpos-1] = v; } |
| 4442 |
|
| 4443 |
if(cm->stid[v] == MATP_MP) { m2v_1[lpos] = v; m2v_1[rpos] = v; } |
| 4444 |
if(cm->stid[v] == MATL_ML) { m2v_1[lpos] = v; } |
| 4445 |
if(cm->stid[v] == MATR_MR) { m2v_1[rpos] = v; } |
| 4446 |
if(cm->stid[v] == MATP_ML) { m2v_2[lpos] = v; } |
| 4447 |
if(cm->stid[v] == MATP_MR) { m2v_2[rpos] = v; } |
| 4448 |
} |
| 4449 |
} |
| 4450 |
|
| 4451 |
|
| 4452 |
|
| 4453 |
*ret_mexpocc = mexpocc; |
| 4454 |
*ret_iexpocc = iexpocc; |
| 4455 |
if(opt_psi != NULL) *opt_psi = psi; else free(psi); |
| 4456 |
if(opt_m2v_1 != NULL) *opt_m2v_1 = m2v_1; else free(m2v_1); |
| 4457 |
if(opt_m2v_2 != NULL) *opt_m2v_2 = m2v_2; else free(m2v_2); |
| 4458 |
if(opt_i2v != NULL) *opt_i2v = i2v; else free(i2v); |
| 4459 |
return eslOK; |
| 4460 |
|
| 4461 |
ERROR: |
| 4462 |
if(psi != NULL) free(psi); |
| 4463 |
if(mexpocc != NULL) free(mexpocc); |
| 4464 |
if(iexpocc != NULL) free(iexpocc); |
| 4465 |
*ret_mexpocc = NULL; |
| 4466 |
*ret_iexpocc = NULL; |
| 4467 |
if(opt_psi != NULL) *opt_psi = NULL; |
| 4468 |
if(opt_m2v_1 != NULL) *opt_m2v_1 = NULL; |
| 4469 |
if(opt_m2v_2 != NULL) *opt_m2v_2 = NULL; |
| 4470 |
if(opt_i2v != NULL) *opt_i2v = NULL; |
| 4471 |
return eslEMEM; |
| 4472 |
} |
| 4473 |
|
| 4474 |
|
| 4475 |
|
| 4476 |
|
| 4477 |
|
| 4478 |
|
| 4479 |
|
| 4480 |
|
| 4481 |
|
| 4482 |
|
| 4483 |
|
| 4484 |
|
| 4485 |
|
| 4486 |
|
| 4487 |
|
| 4488 |
|
| 4489 |
|
| 4490 |
|
| 4491 |
|
| 4492 |
|
| 4493 |
|
| 4494 |
char *** |
| 4495 |
cm_CreateTransitionMap() |
| 4496 |
{ |
| 4497 |
int status; |
| 4498 |
int i,j,k; |
| 4499 |
char ***tmap; |
| 4500 |
|
| 4501 |
ESL_ALLOC(tmap, sizeof(char **) * UNIQUESTATES); |
| 4502 |
for(i = 0; i < UNIQUESTATES; i++) { |
| 4503 |
ESL_ALLOC(tmap[i], sizeof(char *) * NODETYPES); |
| 4504 |
for(j = 0; j < NODETYPES; j++) { |
| 4505 |
ESL_ALLOC(tmap[i][j], sizeof(char) * UNIQUESTATES); |
| 4506 |
for(k = 0; k < UNIQUESTATES; k++) { |
| 4507 |
tmap[i][j][k] = -1; |
| 4508 |
} |
| 4509 |
} |
| 4510 |
} |
| 4511 |
|
| 4512 |
|
| 4513 |
|
| 4514 |
|
| 4515 |
tmap[ROOT_S][BIF_nd][ROOT_IL] = 0; |
| 4516 |
tmap[ROOT_S][BIF_nd][ROOT_IR] = 1; |
| 4517 |
tmap[ROOT_S][BIF_nd][BIF_B] = 2; |
| 4518 |
|
| 4519 |
tmap[ROOT_S][MATP_nd][ROOT_IL] = 0; |
| 4520 |
tmap[ROOT_S][MATP_nd][ROOT_IR] = 1; |
| 4521 |
tmap[ROOT_S][MATP_nd][MATP_MP] = 2; |
| 4522 |
tmap[ROOT_S][MATP_nd][MATP_ML] = 3; |
| 4523 |
tmap[ROOT_S][MATP_nd][MATP_MR] = 4; |
| 4524 |
tmap[ROOT_S][MATP_nd][MATP_D] = 5; |
| 4525 |
|
| 4526 |
tmap[ROOT_S][MATL_nd][ROOT_IL] = 0; |
| 4527 |
tmap[ROOT_S][MATL_nd][ROOT_IR] = 1; |
| 4528 |
tmap[ROOT_S][MATL_nd][MATL_ML] = 2; |
| 4529 |
tmap[ROOT_S][MATL_nd][MATL_D] = 3; |
| 4530 |
|
| 4531 |
tmap[ROOT_S][MATR_nd][ROOT_IL] = 0; |
| 4532 |
tmap[ROOT_S][MATR_nd][ROOT_IR] = 1; |
| 4533 |
tmap[ROOT_S][MATR_nd][MATR_MR] = 2; |
| 4534 |
tmap[ROOT_S][MATR_nd][MATR_D] = 3; |
| 4535 |
|
| 4536 |
tmap[ROOT_IL][BIF_nd][ROOT_IL] = 0; |
| 4537 |
tmap[ROOT_IL][BIF_nd][ROOT_IR] = 1; |
| 4538 |
tmap[ROOT_IL][BIF_nd][BIF_B] = 2; |
| 4539 |
|
| 4540 |
tmap[ROOT_IL][MATP_nd][ROOT_IL] = 0; |
| 4541 |
tmap[ROOT_IL][MATP_nd][ROOT_IR] = 1; |
| 4542 |
tmap[ROOT_IL][MATP_nd][MATP_MP] = 2; |
| 4543 |
tmap[ROOT_IL][MATP_nd][MATP_ML] = 3; |
| 4544 |
tmap[ROOT_IL][MATP_nd][MATP_MR] = 4; |
| 4545 |
tmap[ROOT_IL][MATP_nd][MATP_D] = 5; |
| 4546 |
|
| 4547 |
tmap[ROOT_IL][MATL_nd][ROOT_IL] = 0; |
| 4548 |
tmap[ROOT_IL][MATL_nd][ROOT_IR] = 1; |
| 4549 |
tmap[ROOT_IL][MATL_nd][MATL_ML] = 2; |
| 4550 |
tmap[ROOT_IL][MATL_nd][MATL_D] = 3; |
| 4551 |
|
| 4552 |
tmap[ROOT_IL][MATR_nd][ROOT_IL] = 0; |
| 4553 |
tmap[ROOT_IL][MATR_nd][ROOT_IR] = 1; |
| 4554 |
tmap[ROOT_IL][MATR_nd][MATR_MR] = 2; |
| 4555 |
tmap[ROOT_IL][MATR_nd][MATR_D] = 3; |
| 4556 |
|
| 4557 |
tmap[ROOT_IR][BIF_nd][ROOT_IR] = 0; |
| 4558 |
tmap[ROOT_IR][BIF_nd][BIF_B] = 1; |
| 4559 |
|
| 4560 |
tmap[ROOT_IR][MATP_nd][ROOT_IR] = 0; |
| 4561 |
tmap[ROOT_IR][MATP_nd][MATP_MP] = 1; |
| 4562 |
tmap[ROOT_IR][MATP_nd][MATP_ML] = 2; |
| 4563 |
tmap[ROOT_IR][MATP_nd][MATP_MR] = 3; |
| 4564 |
tmap[ROOT_IR][MATP_nd][MATP_D] = 4; |
| 4565 |
|
| 4566 |
tmap[ROOT_IR][MATL_nd][ROOT_IR] = 0; |
| 4567 |
tmap[ROOT_IR][MATL_nd][MATL_ML] = 1; |
| 4568 |
tmap[ROOT_IR][MATL_nd][MATL_D] = 2; |
| 4569 |
|
| 4570 |
tmap[ROOT_IR][MATR_nd][ROOT_IR] = 0; |
| 4571 |
tmap[ROOT_IR][MATR_nd][MATR_MR] = 1; |
| 4572 |
tmap[ROOT_IR][MATR_nd][MATR_D] = 2; |
| 4573 |
|
| 4574 |
tmap[BEGL_S][BIF_nd][BIF_B] = 0; |
| 4575 |
|
| 4576 |
tmap[BEGL_S][MATP_nd][MATP_MP] = 0; |
| 4577 |
tmap[BEGL_S][MATP_nd][MATP_ML] = 1; |
| 4578 |
tmap[BEGL_S][MATP_nd][MATP_MR] = 2; |
| 4579 |
tmap[BEGL_S][MATP_nd][MATP_D] = 3; |
| 4580 |
|
| 4581 |
tmap[BEGR_S][BIF_nd][BEGR_IL] = 0; |
| 4582 |
tmap[BEGR_S][BIF_nd][BIF_B] = 1; |
| 4583 |
|
| 4584 |
tmap[BEGR_S][MATP_nd][BEGR_IL] = 0; |
| 4585 |
tmap[BEGR_S][MATP_nd][MATP_MP] = 1; |
| 4586 |
tmap[BEGR_S][MATP_nd][MATP_ML] = 2; |
| 4587 |
tmap[BEGR_S][MATP_nd][MATP_MR] = 3; |
| 4588 |
tmap[BEGR_S][MATP_nd][MATP_D] = 4; |
| 4589 |
|
| 4590 |
tmap[BEGR_S][MATL_nd][BEGR_IL] = 0; |
| 4591 |
tmap[BEGR_S][MATL_nd][MATL_ML] = 1; |
| 4592 |
tmap[BEGR_S][MATL_nd][MATL_D] = 2; |
| 4593 |
|
| 4594 |
tmap[BEGR_IL][BIF_nd][BEGR_IL] = 0; |
| 4595 |
tmap[BEGR_IL][BIF_nd][BIF_B] = 1; |
| 4596 |
|
| 4597 |
tmap[BEGR_IL][MATP_nd][BEGR_IL] = 0; |
| 4598 |
tmap[BEGR_IL][MATP_nd][MATP_MP] = 1; |
| 4599 |
tmap[BEGR_IL][MATP_nd][MATP_ML] = 2; |
| 4600 |
tmap[BEGR_IL][MATP_nd][MATP_MR] = 3; |
| 4601 |
tmap[BEGR_IL][MATP_nd][MATP_D] = 4; |
| 4602 |
|
| 4603 |
tmap[BEGR_IL][MATL_nd][BEGR_IL] = 0; |
| 4604 |
tmap[BEGR_IL][MATL_nd][MATL_ML] = 1; |
| 4605 |
tmap[BEGR_IL][MATL_nd][MATL_D] = 2; |
| 4606 |
|
| 4607 |
tmap[MATP_MP][BIF_nd][MATP_IL] = 0; |
| 4608 |
tmap[MATP_MP][BIF_nd][MATP_IR] = 1; |
| 4609 |
tmap[MATP_MP][BIF_nd][BIF_B] = 2; |
| 4610 |
|
| 4611 |
tmap[MATP_MP][MATP_nd][MATP_IL] = 0; |
| 4612 |
tmap[MATP_MP][MATP_nd][MATP_IR] = 1; |
| 4613 |
tmap[MATP_MP][MATP_nd][MATP_MP] = 2; |
| 4614 |
tmap[MATP_MP][MATP_nd][MATP_ML] = 3; |
| 4615 |
tmap[MATP_MP][MATP_nd][MATP_MR] = 4; |
| 4616 |
tmap[MATP_MP][MATP_nd][MATP_D] = 5; |
| 4617 |
|
| 4618 |
tmap[MATP_MP][MATL_nd][MATP_IL] = 0; |
| 4619 |
tmap[MATP_MP][MATL_nd][MATP_IR] = 1; |
| 4620 |
tmap[MATP_MP][MATL_nd][MATL_ML] = 2; |
| 4621 |
tmap[MATP_MP][MATL_nd][MATL_D] = 3; |
| 4622 |
|
| 4623 |
tmap[MATP_MP][MATR_nd][MATP_IL] = 0; |
| 4624 |
tmap[MATP_MP][MATR_nd][MATP_IR] = 1; |
| 4625 |
tmap[MATP_MP][MATR_nd][MATR_MR] = 2; |
| 4626 |
tmap[MATP_MP][MATR_nd][MATR_D] = 3; |
| 4627 |
|
| 4628 |
tmap[MATP_MP][END_nd][MATP_IL] = 0; |
| 4629 |
tmap[MATP_MP][END_nd][MATP_IR] = 1; |
| 4630 |
tmap[MATP_MP][END_nd][END_E] = 2; |
| 4631 |
|
| 4632 |
tmap[MATP_ML][BIF_nd][MATP_IL] = 0; |
| 4633 |
tmap[MATP_ML][BIF_nd][MATP_IR] = 1; |
| 4634 |
tmap[MATP_ML][BIF_nd][BIF_B] = 2; |
| 4635 |
|
| 4636 |
tmap[MATP_ML][MATP_nd][MATP_IL] = 0; |
| 4637 |
tmap[MATP_ML][MATP_nd][MATP_IR] = 1; |
| 4638 |
tmap[MATP_ML][MATP_nd][MATP_MP] = 2; |
| 4639 |
tmap[MATP_ML][MATP_nd][MATP_ML] = 3; |
| 4640 |
tmap[MATP_ML][MATP_nd][MATP_MR] = 4; |
| 4641 |
tmap[MATP_ML][MATP_nd][MATP_D] = 5; |
| 4642 |
|
| 4643 |
tmap[MATP_ML][MATL_nd][MATP_IL] = 0; |
| 4644 |
tmap[MATP_ML][MATL_nd][MATP_IR] = 1; |
| 4645 |
tmap[MATP_ML][MATL_nd][MATL_ML] = 2; |
| 4646 |
tmap[MATP_ML][MATL_nd][MATL_D] = 3; |
| 4647 |
|
| 4648 |
tmap[MATP_ML][MATR_nd][MATP_IL] = 0; |
| 4649 |
tmap[MATP_ML][MATR_nd][MATP_IR] = 1; |
| 4650 |
tmap[MATP_ML][MATR_nd][MATR_MR] = 2; |
| 4651 |
tmap[MATP_ML][MATR_nd][MATR_D] = 3; |
| 4652 |
|
| 4653 |
tmap[MATP_ML][END_nd][MATP_IL] = 0; |
| 4654 |
tmap[MATP_ML][END_nd][MATP_IR] = 1; |
| 4655 |
tmap[MATP_ML][END_nd][END_E] = 2; |
| 4656 |
|
| 4657 |
tmap[MATP_MR][BIF_nd][MATP_IL] = 0; |
| 4658 |
tmap[MATP_MR][BIF_nd][MATP_IR] = 1; |
| 4659 |
tmap[MATP_MR][BIF_nd][BIF_B] = 2; |
| 4660 |
|
| 4661 |
tmap[MATP_MR][MATP_nd][MATP_IL] = 0; |
| 4662 |
tmap[MATP_MR][MATP_nd][MATP_IR] = 1; |
| 4663 |
tmap[MATP_MR][MATP_nd][MATP_MP] = 2; |
| 4664 |
tmap[MATP_MR][MATP_nd][MATP_ML] = 3; |
| 4665 |
tmap[MATP_MR][MATP_nd][MATP_MR] = 4; |
| 4666 |
tmap[MATP_MR][MATP_nd][MATP_D] = 5; |
| 4667 |
|
| 4668 |
tmap[MATP_MR][MATL_nd][MATP_IL] = 0; |
| 4669 |
tmap[MATP_MR][MATL_nd][MATP_IR] = 1; |
| 4670 |
tmap[MATP_MR][MATL_nd][MATL_ML] = 2; |
| 4671 |
tmap[MATP_MR][MATL_nd][MATL_D] = 3; |
| 4672 |
|
| 4673 |
tmap[MATP_MR][MATR_nd][MATP_IL] = 0; |
| 4674 |
tmap[MATP_MR][MATR_nd][MATP_IR] = 1; |
| 4675 |
tmap[MATP_MR][MATR_nd][MATR_MR] = 2; |
| 4676 |
tmap[MATP_MR][MATR_nd][MATR_D] = 3; |
| 4677 |
|
| 4678 |
tmap[MATP_MR][END_nd][MATP_IL] = 0; |
| 4679 |
tmap[MATP_MR][END_nd][MATP_IR] = 1; |
| 4680 |
tmap[MATP_MR][END_nd][END_E] = 2; |
| 4681 |
|
| 4682 |
tmap[MATP_D][BIF_nd][MATP_IL] = 0; |
| 4683 |
tmap[MATP_D][BIF_nd][MATP_IR] = 1; |
| 4684 |
tmap[MATP_D][BIF_nd][BIF_B] = 2; |
| 4685 |
|
| 4686 |
tmap[MATP_D][MATP_nd][MATP_IL] = 0; |
| 4687 |
tmap[MATP_D][MATP_nd][MATP_IR] = 1; |
| 4688 |
tmap[MATP_D][MATP_nd][MATP_MP] = 2; |
| 4689 |
tmap[MATP_D][MATP_nd][MATP_ML] = 3; |
| 4690 |
tmap[MATP_D][MATP_nd][MATP_MR] = 4; |
| 4691 |
tmap[MATP_D][MATP_nd][MATP_D] = 5; |
| 4692 |
|
| 4693 |
tmap[MATP_D][MATL_nd][MATP_IL] = 0; |
| 4694 |
tmap[MATP_D][MATL_nd][MATP_IR] = 1; |
| 4695 |
tmap[MATP_D][MATL_nd][MATL_ML] = 2; |
| 4696 |
tmap[MATP_D][MATL_nd][MATL_D] = 3; |
| 4697 |
|
| 4698 |
tmap[MATP_D][MATR_nd][MATP_IL] = 0; |
| 4699 |
tmap[MATP_D][MATR_nd][MATP_IR] = 1; |
| 4700 |
tmap[MATP_D][MATR_nd][MATR_MR] = 2; |
| 4701 |
tmap[MATP_D][MATR_nd][MATR_D] = 3; |
| 4702 |
|
| 4703 |
tmap[MATP_D][END_nd][MATP_IL] = 0; |
| 4704 |
tmap[MATP_D][END_nd][MATP_IR] = 1; |
| 4705 |
tmap[MATP_D][END_nd][END_E] = 2; |
| 4706 |
|
| 4707 |
tmap[MATP_IL][BIF_nd][MATP_IL] = 0; |
| 4708 |
tmap[MATP_IL][BIF_nd][MATP_IR] = 1; |
| 4709 |
tmap[MATP_IL][BIF_nd][BIF_B] = 2; |
| 4710 |
|
| 4711 |
tmap[MATP_IL][MATP_nd][MATP_IL] = 0; |
| 4712 |
tmap[MATP_IL][MATP_nd][MATP_IR] = 1; |
| 4713 |
tmap[MATP_IL][MATP_nd][MATP_MP] = 2; |
| 4714 |
tmap[MATP_IL][MATP_nd][MATP_ML] = 3; |
| 4715 |
tmap[MATP_IL][MATP_nd][MATP_MR] = 4; |
| 4716 |
tmap[MATP_IL][MATP_nd][MATP_D] = 5; |
| 4717 |
|
| 4718 |
tmap[MATP_IL][MATL_nd][MATP_IL] = 0; |
| 4719 |
tmap[MATP_IL][MATL_nd][MATP_IR] = 1; |
| 4720 |
tmap[MATP_IL][MATL_nd][MATL_ML] = 2; |
| 4721 |
tmap[MATP_IL][MATL_nd][MATL_D] = 3; |
| 4722 |
|
| 4723 |
tmap[MATP_IL][MATR_nd][MATP_IL] = 0; |
| 4724 |
tmap[MATP_IL][MATR_nd][MATP_IR] = 1; |
| 4725 |
tmap[MATP_IL][MATR_nd][MATR_MR] = 2; |
| 4726 |
tmap[MATP_IL][MATR_nd][MATR_D] = 3; |
| 4727 |
|
| 4728 |
tmap[MATP_IL][END_nd][MATP_IL] = 0; |
| 4729 |
tmap[MATP_IL][END_nd][MATP_IR] = 1; |
| 4730 |
tmap[MATP_IL][END_nd][END_E] = 2; |
| 4731 |
|
| 4732 |
tmap[MATP_IR][BIF_nd][MATP_IR] = 0; |
| 4733 |
tmap[MATP_IR][BIF_nd][BIF_B] = 1; |
| 4734 |
|
| 4735 |
tmap[MATP_IR][MATP_nd][MATP_IR] = 0; |
| 4736 |
tmap[MATP_IR][MATP_nd][MATP_MP] = 1; |
| 4737 |
tmap[MATP_IR][MATP_nd][MATP_ML] = 2; |
| 4738 |
tmap[MATP_IR][MATP_nd][MATP_MR] = 3; |
| 4739 |
tmap[MATP_IR][MATP_nd][MATP_D] = 4; |
| 4740 |
|
| 4741 |
tmap[MATP_IR][MATL_nd][MATP_IR] = 0; |
| 4742 |
tmap[MATP_IR][MATL_nd][MATL_ML] = 1; |
| 4743 |
tmap[MATP_IR][MATL_nd][MATL_D] = 2; |
| 4744 |
|
| 4745 |
tmap[MATP_IR][MATR_nd][MATP_IR] = 0; |
| 4746 |
tmap[MATP_IR][MATR_nd][MATR_MR] = 1; |
| 4747 |
tmap[MATP_IR][MATR_nd][MATR_D] = 2; |
| 4748 |
|
| 4749 |
tmap[MATP_IR][END_nd][MATP_IR] = 0; |
| 4750 |
tmap[MATP_IR][END_nd][END_E] = 1; |
| 4751 |
|
| 4752 |
tmap[MATL_ML][BIF_nd][MATL_IL] = 0; |
| 4753 |
tmap[MATL_ML][BIF_nd][BIF_B] = 1; |
| 4754 |
|
| 4755 |
tmap[MATL_ML][MATP_nd][MATL_IL] = 0; |
| 4756 |
tmap[MATL_ML][MATP_nd][MATP_MP] = 1; |
| 4757 |
tmap[MATL_ML][MATP_nd][MATP_ML] = 2; |
| 4758 |
tmap[MATL_ML][MATP_nd][MATP_MR] = 3; |
| 4759 |
tmap[MATL_ML][MATP_nd][MATP_D] = 4; |
| 4760 |
|
| 4761 |
tmap[MATL_ML][MATL_nd][MATL_IL] = 0; |
| 4762 |
tmap[MATL_ML][MATL_nd][MATL_ML] = 1; |
| 4763 |
tmap[MATL_ML][MATL_nd][MATL_D] = 2; |
| 4764 |
|
| 4765 |
tmap[MATL_ML][MATR_nd][MATL_IL] = 0; |
| 4766 |
tmap[MATL_ML][MATR_nd][MATR_MR] = 1; |
| 4767 |
tmap[MATL_ML][MATR_nd][MATR_D] = 2; |
| 4768 |
|
| 4769 |
tmap[MATL_ML][END_nd][MATL_IL] = 0; |
| 4770 |
tmap[MATL_ML][END_nd][END_E] = 1; |
| 4771 |
|
| 4772 |
tmap[MATL_D][BIF_nd][MATL_IL] = 0; |
| 4773 |
tmap[MATL_D][BIF_nd][BIF_B] = 1; |
| 4774 |
|
| 4775 |
tmap[MATL_D][MATP_nd][MATL_IL] = 0; |
| 4776 |
tmap[MATL_D][MATP_nd][MATP_MP] = 1; |
| 4777 |
tmap[MATL_D][MATP_nd][MATP_ML] = 2; |
| 4778 |
tmap[MATL_D][MATP_nd][MATP_MR] = 3; |
| 4779 |
tmap[MATL_D][MATP_nd][MATP_D] = 4; |
| 4780 |
|
| 4781 |
tmap[MATL_D][MATL_nd][MATL_IL] = 0; |
| 4782 |
tmap[MATL_D][MATL_nd][MATL_ML] = 1; |
| 4783 |
tmap[MATL_D][MATL_nd][MATL_D] = 2; |
| 4784 |
|
| 4785 |
tmap[MATL_D][MATR_nd][MATL_IL] = 0; |
| 4786 |
tmap[MATL_D][MATR_nd][MATR_MR] = 1; |
| 4787 |
tmap[MATL_D][MATR_nd][MATR_D] = 2; |
| 4788 |
|
| 4789 |
tmap[MATL_D][END_nd][MATL_IL] = 0; |
| 4790 |
tmap[MATL_D][END_nd][END_E] = 1; |
| 4791 |
|
| 4792 |
tmap[MATL_IL][BIF_nd][MATL_IL] = 0; |
| 4793 |
tmap[MATL_IL][BIF_nd][BIF_B] = 1; |
| 4794 |
|
| 4795 |
tmap[MATL_IL][MATP_nd][MATL_IL] = 0; |
| 4796 |
tmap[MATL_IL][MATP_nd][MATP_MP] = 1; |
| 4797 |
tmap[MATL_IL][MATP_nd][MATP_ML] = 2; |
| 4798 |
tmap[MATL_IL][MATP_nd][MATP_MR] = 3; |
| 4799 |
tmap[MATL_IL][MATP_nd][MATP_D] = 4; |
| 4800 |
|
| 4801 |
tmap[MATL_IL][MATL_nd][MATL_IL] = 0; |
| 4802 |
tmap[MATL_IL][MATL_nd][MATL_ML] = 1; |
| 4803 |
tmap[MATL_IL][MATL_nd][MATL_D] = 2; |
| 4804 |
|
| 4805 |
tmap[MATL_IL][MATR_nd][MATL_IL] = 0; |
| 4806 |
tmap[MATL_IL][MATR_nd][MATR_MR] = 1; |
| 4807 |
tmap[MATL_IL][MATR_nd][MATR_D] = 2; |
| 4808 |
|
| 4809 |
tmap[MATL_IL][END_nd][MATL_IL] = 0; |
| 4810 |
tmap[MATL_IL][END_nd][END_E] = 1; |
| 4811 |
|
| 4812 |
tmap[MATR_MR][BIF_nd][MATR_IR] = 0; |
| 4813 |
tmap[MATR_MR][BIF_nd][BIF_B] = 1; |
| 4814 |
|
| 4815 |
tmap[MATR_MR][MATP_nd][MATR_IR] = 0; |
| 4816 |
tmap[MATR_MR][MATP_nd][MATP_MP] = 1; |
| 4817 |
tmap[MATR_MR][MATP_nd][MATP_ML] = 2; |
| 4818 |
tmap[MATR_MR][MATP_nd][MATP_MR] = 3; |
| 4819 |
tmap[MATR_MR][MATP_nd][MATP_D] = 4; |
| 4820 |
|
| 4821 |
tmap[MATR_MR][MATR_nd][MATR_IR] = 0; |
| 4822 |
tmap[MATR_MR][MATR_nd][MATR_MR] = 1; |
| 4823 |
tmap[MATR_MR][MATR_nd][MATR_D] = 2; |
| 4824 |
|
| 4825 |
tmap[MATR_D][BIF_nd][MATR_IR] = 0; |
| 4826 |
tmap[MATR_D][BIF_nd][BIF_B] = 1; |
| 4827 |
|
| 4828 |
tmap[MATR_D][MATP_nd][MATR_IR] = 0; |
| 4829 |
tmap[MATR_D][MATP_nd][MATP_MP] = 1; |
| 4830 |
tmap[MATR_D][MATP_nd][MATP_ML] = 2; |
| 4831 |
tmap[MATR_D][MATP_nd][MATP_MR] = 3; |
| 4832 |
tmap[MATR_D][MATP_nd][MATP_D] = 4; |
| 4833 |
|
| 4834 |
tmap[MATR_D][MATR_nd][MATR_IR] = 0; |
| 4835 |
tmap[MATR_D][MATR_nd][MATR_MR] = 1; |
| 4836 |
tmap[MATR_D][MATR_nd][MATR_D] = 2; |
| 4837 |
|
| 4838 |
tmap[MATR_IR][BIF_nd][MATR_IR] = 0; |
| 4839 |
tmap[MATR_IR][BIF_nd][BIF_B] = 1; |
| 4840 |
|
| 4841 |
tmap[MATR_IR][MATP_nd][MATR_IR] = 0; |
| 4842 |
tmap[MATR_IR][MATP_nd][MATP_MP] = 1; |
| 4843 |
tmap[MATR_IR][MATP_nd][MATP_ML] = 2; |
| 4844 |
tmap[MATR_IR][MATP_nd][MATP_MR] = 3; |
| 4845 |
tmap[MATR_IR][MATP_nd][MATP_D] = 4; |
| 4846 |
|
| 4847 |
tmap[MATR_IR][MATR_nd][MATR_IR] = 0; |
| 4848 |
tmap[MATR_IR][MATR_nd][MATR_MR] = 1; |
| 4849 |
tmap[MATR_IR][MATR_nd][MATR_D] = 2; |
| 4850 |
|
| 4851 |
tmap[BIF_B][BEGL_nd][BEGL_S] = 0; |
| 4852 |
|
| 4853 |
tmap[BIF_B][BEGR_nd][BEGR_S] = 0; |
| 4854 |
|
| 4855 |
return tmap; |
| 4856 |
|
| 4857 |
ERROR: |
| 4858 |
cm_Fail("Memory allocation error."); |
| 4859 |
return NULL; |
| 4860 |
} |
| 4861 |
|
| 4862 |
|
| 4863 |
|
| 4864 |
|
| 4865 |
|
| 4866 |
|
| 4867 |
|
| 4868 |
void |
| 4869 |
cm_FreeTransitionMap(char ***tmap) |
| 4870 |
{ |
| 4871 |
int i, j; |
| 4872 |
|
| 4873 |
if(tmap != NULL) { |
| 4874 |
for(i = 0; i < UNIQUESTATES; i++) { |
| 4875 |
for(j = 0; j < NODETYPES; j++) { |
| 4876 |
free(tmap[i][j]); |
| 4877 |
} |
| 4878 |
free(tmap[i]); |
| 4879 |
} |
| 4880 |
free(tmap); |
| 4881 |
} |
| 4882 |
return; |
| 4883 |
} |
| 4884 |
|
| 4885 |
|
| 4886 |
|
| 4887 |
|
| 4888 |
|
| 4889 |
|
| 4890 |
|
| 4891 |
|
| 4892 |
|
| 4893 |
|
| 4894 |
|
| 4895 |
|
| 4896 |
void |
| 4897 |
InsertsGivenNodeIndex(CM_t *cm, int nd, int *ret_i1, int *ret_i2) |
| 4898 |
{ |
| 4899 |
int i1 = -1; |
| 4900 |
int i2 = -1; |
| 4901 |
int v = cm->nodemap[nd]; |
| 4902 |
|
| 4903 |
switch (cm->ndtype[nd]) { |
| 4904 |
case MATP_nd: i1 = v+4; i2 = v+5; break; |
| 4905 |
case MATL_nd: i1 = v+2; break; |
| 4906 |
case MATR_nd: i1 = v+2; break; |
| 4907 |
case BEGR_nd: i1 = v+1; break; |
| 4908 |
case ROOT_nd: i1 = v+1; i2 = v+2; break; |
| 4909 |
} |
| 4910 |
|
| 4911 |
|
| 4912 |
*ret_i1 = i1; |
| 4913 |
*ret_i2 = i2; |
| 4914 |
return; |
| 4915 |
} |
| 4916 |
|
| 4917 |
|
| 4918 |
|
| 4919 |
|
| 4920 |
|
| 4921 |
|
| 4922 |
|
| 4923 |
|
| 4924 |
|
| 4925 |
|
| 4926 |
|
| 4927 |
|
| 4928 |
|
| 4929 |
|
| 4930 |
|
| 4931 |
|
| 4932 |
|
| 4933 |
|
| 4934 |
|
| 4935 |
|
| 4936 |
|
| 4937 |
|
| 4938 |
|
| 4939 |
|
| 4940 |
|
| 4941 |
|
| 4942 |
|
| 4943 |
|
| 4944 |
|
| 4945 |
|
| 4946 |
int |
| 4947 |
cm_Guidetree(CM_t *cm, char *errbuf, ESL_MSA *msa, Parsetree_t **ret_gtr) |
| 4948 |
{ |
| 4949 |
Parsetree_t *gtr = NULL; |
| 4950 |
ESL_STACK *pda = NULL; |
| 4951 |
int *matassign = NULL; |
| 4952 |
int *elassign = NULL; |
| 4953 |
int *c2a_map = NULL; |
| 4954 |
int nd, apos, v, cpos; |
| 4955 |
int i, j, k, el_i, el_j; |
| 4956 |
int status; |
| 4957 |
|
| 4958 |
if (msa->rf == NULL) ESL_FAIL(eslEINVAL, errbuf, "msa->rf is NULL in cm_Guidetree()"); |
| 4959 |
|
| 4960 |
|
| 4961 |
|
| 4962 |
|
| 4963 |
ESL_ALLOC(c2a_map, sizeof(int) * (cm->clen+1)); |
| 4964 |
ESL_ALLOC(matassign, sizeof(int) * (msa->alen+1)); |
| 4965 |
ESL_ALLOC(elassign, sizeof(int) * (msa->alen+1)); |
| 4966 |
c2a_map[0] = 0; |
| 4967 |
cpos = 0; |
| 4968 |
|
| 4969 |
for (apos = 1; apos <= msa->alen; apos++) { |
| 4970 |
matassign[apos] = ((esl_abc_CIsGap (msa->abc, msa->rf[apos-1])) || |
| 4971 |
(esl_abc_CIsMissing(msa->abc, msa->rf[apos-1]))) |
| 4972 |
? FALSE : TRUE; |
| 4973 |
elassign[apos] = (esl_abc_CIsMissing(msa->abc, msa->rf[apos-1])) ? TRUE : FALSE; |
| 4974 |
if(! (esl_abc_CIsGap(cm->abc, msa->rf[apos-1]) || esl_abc_CIsMissing(cm->abc, msa->rf[apos-1]))) { |
| 4975 |
cpos++; |
| 4976 |
c2a_map[cpos] = apos; |
| 4977 |
} |
| 4978 |
} |
| 4979 |
if(cpos != cm->clen) ESL_FAIL(eslEINVAL, errbuf, "msa->rf nongap length (%d) != clen (%d)\n", cpos, cm->clen); |
| 4980 |
|
| 4981 |
gtr = CreateParsetree(cm->nodes); |
| 4982 |
|
| 4983 |
|
| 4984 |
|
| 4985 |
|
| 4986 |
|
| 4987 |
|
| 4988 |
|
| 4989 |
|
| 4990 |
|
| 4991 |
|
| 4992 |
|
| 4993 |
if ((pda = esl_stack_ICreate()) == NULL) { status = eslEMEM; goto ERROR; } |
| 4994 |
if((status = esl_stack_IPush(pda, 1)) != eslOK) goto ERROR; |
| 4995 |
if((status = esl_stack_IPush(pda, msa->alen)) != eslOK) goto ERROR; |
| 4996 |
if((status = esl_stack_IPush(pda, 0)) != eslOK) goto ERROR; |
| 4997 |
while (esl_stack_IPop(pda, &nd) != eslEOD) |
| 4998 |
{ |
| 4999 |
esl_stack_IPop(pda, &j); |
| 5000 |
esl_stack_IPop(pda, &i); |
| 5001 |
|
| 5002 |
|
| 5003 |
|
| 5004 |
|
| 5005 |
|
| 5006 |
el_i = i; |
| 5007 |
el_j = j; |
| 5008 |
while(i <= msa->alen && elassign[i]) i++; |
| 5009 |
while(j >= 1 && elassign[j]) j--; |
| 5010 |
if(i > (msa->alen+1)) ESL_XFAIL(eslEINVAL, errbuf, "cm_GuideTree(): problem with local ends (RF='~') during guide tree construction"); |
| 5011 |
if(j < 0) ESL_XFAIL(eslEINVAL, errbuf, "cm_GuideTree(): problem with local ends (RF='~') during guide tree construction"); |
| 5012 |
|
| 5013 |
|
| 5014 |
|
| 5015 |
v = cm->nodemap[nd]; |
| 5016 |
gtr->state[nd] = cm->ndtype[nd]; |
| 5017 |
gtr->mode[nd] = TRMODE_J; |
| 5018 |
gtr->prv[nd] = (cm->ndtype[nd] == ROOT_nd) ? -1 : cm->ndidx[cm->plast[v]]; |
| 5019 |
gtr->n++; |
| 5020 |
|
| 5021 |
if (cm->ndtype[nd] == END_nd) { |
| 5022 |
gtr->nxtl[nd] = -1; |
| 5023 |
gtr->nxtr[nd] = -1; |
| 5024 |
gtr->emitl[nd] = i; |
| 5025 |
gtr->emitr[nd] = j; |
| 5026 |
} |
| 5027 |
|
| 5028 |
else if (cm->ndtype[nd] == ROOT_nd) { |
| 5029 |
gtr->nxtl[nd] = nd+1; |
| 5030 |
gtr->nxtr[nd] = -1; |
| 5031 |
gtr->emitl[nd] = i; |
| 5032 |
gtr->emitr[nd] = j; |
| 5033 |
for (; i <= j; i++) if (matassign[i] || elassign[i]) break; |
| 5034 |
for (; j >= i; j--) if (matassign[j] || elassign[j]) break; |
| 5035 |
if((status = esl_stack_IPush(pda, i)) != eslOK) goto ERROR; |
| 5036 |
if((status = esl_stack_IPush(pda, j)) != eslOK) goto ERROR; |
| 5037 |
if((status = esl_stack_IPush(pda, nd+1)) != eslOK) goto ERROR; |
| 5038 |
} |
| 5039 |
|
| 5040 |
else if (cm->ndtype[nd] == BEGL_nd) { |
| 5041 |
gtr->nxtl[nd] = nd+1; |
| 5042 |
gtr->nxtr[nd] = -1; |
| 5043 |
gtr->emitl[nd] = i; |
| 5044 |
gtr->emitr[nd] = j; |
| 5045 |
if((status = esl_stack_IPush(pda, i)) != eslOK) goto ERROR; |
| 5046 |
if((status = esl_stack_IPush(pda, j)) != eslOK) goto ERROR; |
| 5047 |
if((status = esl_stack_IPush(pda, nd+1)) != eslOK) goto ERROR; |
| 5048 |
} |
| 5049 |
|
| 5050 |
else if (cm->ndtype[nd] == BEGR_nd) { |
| 5051 |
gtr->nxtl[nd] = nd+1; |
| 5052 |
gtr->nxtr[nd] = -1; |
| 5053 |
gtr->emitl[nd] = i; |
| 5054 |
gtr->emitr[nd] = j; |
| 5055 |
for (; i <= j; i++) if (matassign[i] || elassign[i]) break; |
| 5056 |
if((status = esl_stack_IPush(pda, i)) != eslOK) goto ERROR; |
| 5057 |
if((status = esl_stack_IPush(pda, j)) != eslOK) goto ERROR; |
| 5058 |
if((status = esl_stack_IPush(pda, nd+1)) != eslOK) goto ERROR; |
| 5059 |
} |
| 5060 |
|
| 5061 |
else if (cm->ndtype[nd] == MATL_nd) { |
| 5062 |
|
| 5063 |
gtr->nxtl[nd] = nd+1; |
| 5064 |
gtr->nxtr[nd] = -1; |
| 5065 |
gtr->emitl[nd] = i; |
| 5066 |
gtr->emitr[nd] = el_j; |
| 5067 |
for (i = i+1; i <= j; i++) if (matassign[i] || elassign[i]) break; |
| 5068 |
if((status = esl_stack_IPush(pda, i)) != eslOK) goto ERROR; |
| 5069 |
if((status = esl_stack_IPush(pda, el_j)) != eslOK) goto ERROR; |
| 5070 |
if((status = esl_stack_IPush(pda, nd+1)) != eslOK) goto ERROR; |
| 5071 |
} |
| 5072 |
|
| 5073 |
else if (cm->ndtype[nd] == MATR_nd) { |
| 5074 |
gtr->nxtl[nd] = nd+1; |
| 5075 |
gtr->nxtr[nd] = -1; |
| 5076 |
gtr->emitl[nd] = el_i; |
| 5077 |
gtr->emitr[nd] = j; |
| 5078 |
for (j = j-1; j >= i; j--) if (matassign[j] || elassign[j]) break; |
| 5079 |
if((status = esl_stack_IPush(pda, el_i)) != eslOK) goto ERROR; |
| 5080 |
if((status = esl_stack_IPush(pda, j)) != eslOK) goto ERROR; |
| 5081 |
if((status = esl_stack_IPush(pda, nd+1)) != eslOK) goto ERROR; |
| 5082 |
} |
| 5083 |
|
| 5084 |
else if (cm->ndtype[nd] == MATP_nd) { |
| 5085 |
gtr->nxtl[nd] = nd+1; |
| 5086 |
gtr->nxtr[nd] = -1; |
| 5087 |
gtr->emitl[nd] = i; |
| 5088 |
gtr->emitr[nd] = j; |
| 5089 |
for (i = i+1; i <= j; i++) if (matassign[i] || elassign[i]) break; |
| 5090 |
for (j = j-1; j >= i; j--) if (matassign[j] || elassign[j]) break; |
| 5091 |
if((status = esl_stack_IPush(pda, i)) != eslOK) goto ERROR; |
| 5092 |
if((status = esl_stack_IPush(pda, j)) != eslOK) goto ERROR; |
| 5093 |
if((status = esl_stack_IPush(pda, nd+1)) != eslOK) goto ERROR; |
| 5094 |
} |
| 5095 |
|
| 5096 |
else if (cm->ndtype[nd] == BIF_nd) { |
| 5097 |
gtr->nxtl[nd] = cm->ndidx[cm->cfirst[v]]; |
| 5098 |
gtr->nxtr[nd] = cm->ndidx[cm->cnum[v]]; |
| 5099 |
gtr->emitl[nd] = i; |
| 5100 |
gtr->emitr[nd] = j; |
| 5101 |
|
| 5102 |
k = c2a_map[cm->emap->rpos[nd+1]-1]; |
| 5103 |
|
| 5104 |
|
| 5105 |
if((status = esl_stack_IPush(pda, k+1)) != eslOK) goto ERROR; |
| 5106 |
if((status = esl_stack_IPush(pda, j)) != eslOK) goto ERROR; |
| 5107 |
if((status = esl_stack_IPush(pda, cm->ndidx[cm->cnum[cm->nodemap[nd]]])) != eslOK) goto ERROR; |
| 5108 |
|
| 5109 |
if((status = esl_stack_IPush(pda, i)) != eslOK) goto ERROR; |
| 5110 |
if((status = esl_stack_IPush(pda, k)) != eslOK) goto ERROR; |
| 5111 |
if((status = esl_stack_IPush(pda, cm->ndidx[cm->cfirst[cm->nodemap[nd]]])) != eslOK) goto ERROR; |
| 5112 |
} |
| 5113 |
} |
| 5114 |
|
| 5115 |
|
| 5116 |
|
| 5117 |
esl_stack_Destroy(pda); |
| 5118 |
free(elassign); |
| 5119 |
free(matassign); |
| 5120 |
free(c2a_map); |
| 5121 |
|
| 5122 |
*ret_gtr = gtr; |
| 5123 |
return eslOK; |
| 5124 |
|
| 5125 |
ERROR: |
| 5126 |
esl_stack_Destroy(pda); |
| 5127 |
free(elassign); |
| 5128 |
free(matassign); |
| 5129 |
free(c2a_map); |
| 5130 |
|
| 5131 |
*ret_gtr = NULL; |
| 5132 |
FreeParsetree(gtr); |
| 5133 |
return status; |
| 5134 |
} |
| 5135 |
|