| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
#include <p7_config.h> |
| 24 |
|
| 25 |
#include <string.h> |
| 26 |
|
| 27 |
#include "easel.h" |
| 28 |
#include "esl_alphabet.h" |
| 29 |
#include "esl_msa.h" |
| 30 |
#include "esl_msafile.h" |
| 31 |
|
| 32 |
#include "hmmer.h" |
| 33 |
|
| 34 |
static int do_modelmask( ESL_MSA *msa); |
| 35 |
static int matassign2hmm(ESL_MSA *msa, int *matassign, P7_HMM **ret_hmm, P7_TRACE ***opt_tr); |
| 36 |
static int annotate_model(P7_HMM *hmm, int *matassign, ESL_MSA *msa); |
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
int |
| 81 |
p7_Handmodelmaker(ESL_MSA *msa, P7_BUILDER *bld, P7_HMM **ret_hmm, P7_TRACE ***opt_tr) |
| 82 |
{ |
| 83 |
int status; |
| 84 |
int *matassign = NULL; |
| 85 |
int apos; |
| 86 |
|
| 87 |
if (! (msa->flags & eslMSA_DIGITAL)) ESL_XEXCEPTION(eslEINVAL, "need a digital msa"); |
| 88 |
if (msa->rf == NULL) return eslEFORMAT; |
| 89 |
|
| 90 |
ESL_ALLOC(matassign, sizeof(int) * (msa->alen+1)); |
| 91 |
|
| 92 |
|
| 93 |
for (apos = 1; apos <= msa->alen; apos++) |
| 94 |
matassign[apos] = (esl_abc_CIsGap(msa->abc, msa->rf[apos-1])? FALSE : TRUE); |
| 95 |
|
| 96 |
|
| 97 |
if ((status = matassign2hmm(msa, matassign, ret_hmm, opt_tr)) != eslOK) goto ERROR; |
| 98 |
|
| 99 |
free(matassign); |
| 100 |
return eslOK; |
| 101 |
|
| 102 |
ERROR: |
| 103 |
if (matassign != NULL) free(matassign); |
| 104 |
return status; |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
int |
| 155 |
p7_Fastmodelmaker(ESL_MSA *msa, float symfrac, P7_BUILDER *bld, P7_HMM **ret_hmm, P7_TRACE ***opt_tr) |
| 156 |
{ |
| 157 |
int status; |
| 158 |
int *matassign = NULL; |
| 159 |
int idx; |
| 160 |
int apos; |
| 161 |
float r; |
| 162 |
float totwgt; |
| 163 |
|
| 164 |
if (! (msa->flags & eslMSA_DIGITAL)) ESL_XEXCEPTION(eslEINVAL, "need digital MSA"); |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
ESL_ALLOC(matassign, sizeof(int) * (msa->alen+1)); |
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
for (apos = 1; apos <= msa->alen; apos++) |
| 173 |
{ |
| 174 |
r = totwgt = 0.; |
| 175 |
for (idx = 0; idx < msa->nseq; idx++) |
| 176 |
{ |
| 177 |
if (esl_abc_XIsResidue(msa->abc, msa->ax[idx][apos])) { r += msa->wgt[idx]; totwgt += msa->wgt[idx]; } |
| 178 |
else if (esl_abc_XIsGap(msa->abc, msa->ax[idx][apos])) { totwgt += msa->wgt[idx]; } |
| 179 |
else if (esl_abc_XIsMissing(msa->abc, msa->ax[idx][apos])) continue; |
| 180 |
} |
| 181 |
if (r > 0. && r / totwgt >= symfrac) matassign[apos] = TRUE; |
| 182 |
else matassign[apos] = FALSE; |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
if ((status = matassign2hmm(msa, matassign, ret_hmm, opt_tr)) != eslOK) { |
| 191 |
fprintf (stderr, "hmm construction error during trace counting\n"); |
| 192 |
goto ERROR; |
| 193 |
} |
| 194 |
|
| 195 |
free(matassign); |
| 196 |
return eslOK; |
| 197 |
|
| 198 |
ERROR: |
| 199 |
if (matassign != NULL) free(matassign); |
| 200 |
return status; |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
static int |
| 223 |
do_modelmask( ESL_MSA *msa) |
| 224 |
{ |
| 225 |
int i,j; |
| 226 |
|
| 227 |
if (msa->mm == NULL) return eslOK; |
| 228 |
|
| 229 |
for (i = 1; i <= msa->alen; i++) { |
| 230 |
for (j = 0; j < msa->nseq; j++) { |
| 231 |
if (msa->mm[i-1] == 'm') { |
| 232 |
if (msa->ax[j][i] != msa->abc->K && msa->ax[j][i] != msa->abc->Kp-1) |
| 233 |
msa->ax[j][i] = msa->abc->Kp-3; |
| 234 |
} |
| 235 |
} |
| 236 |
} |
| 237 |
return eslOK; |
| 238 |
} |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
static int |
| 258 |
matassign2hmm(ESL_MSA *msa, int *matassign, P7_HMM **ret_hmm, P7_TRACE ***opt_tr) |
| 259 |
{ |
| 260 |
int status; |
| 261 |
P7_HMM *hmm = NULL; |
| 262 |
P7_TRACE **tr = NULL; |
| 263 |
int M; |
| 264 |
int idx; |
| 265 |
int apos; |
| 266 |
char errbuf[eslERRBUFSIZE]; |
| 267 |
|
| 268 |
|
| 269 |
do_modelmask(msa); |
| 270 |
|
| 271 |
|
| 272 |
for (M = 0, apos = 1; apos <= msa->alen; apos++) |
| 273 |
if (matassign[apos]) M++; |
| 274 |
if (M == 0) { status = eslENORESULT; goto ERROR; } |
| 275 |
|
| 276 |
|
| 277 |
ESL_ALLOC(tr, sizeof(P7_TRACE *) * msa->nseq); |
| 278 |
if ((status = p7_trace_FauxFromMSA(msa, matassign, p7_MSA_COORDS, tr)) != eslOK) goto ERROR; |
| 279 |
for (idx = 0; idx < msa->nseq; idx++) |
| 280 |
{ |
| 281 |
if ((status = p7_trace_Doctor(tr[idx], NULL, NULL)) != eslOK) goto ERROR; |
| 282 |
if ((status = p7_trace_Validate(tr[idx], msa->abc, msa->ax[idx], errbuf)) != eslOK) |
| 283 |
ESL_XEXCEPTION(eslFAIL, "validation failed: %s", errbuf); |
| 284 |
} |
| 285 |
|
| 286 |
|
| 287 |
if ((hmm = p7_hmm_Create(M, msa->abc)) == NULL) { status = eslEMEM; goto ERROR; } |
| 288 |
if ((status = p7_hmm_Zero(hmm)) != eslOK) goto ERROR; |
| 289 |
for (idx = 0; idx < msa->nseq; idx++) { |
| 290 |
if (tr[idx] == NULL) continue; |
| 291 |
if ((status = p7_trace_Count(hmm, msa->ax[idx], msa->wgt[idx], tr[idx])) != eslOK) goto ERROR; |
| 292 |
} |
| 293 |
|
| 294 |
hmm->nseq = msa->nseq; |
| 295 |
hmm->eff_nseq = msa->nseq; |
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
if ((status = annotate_model(hmm, matassign, msa)) != eslOK) goto ERROR; |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
if (msa->rf == NULL) ESL_ALLOC(msa->rf, sizeof(char) * (msa->alen + 1)); |
| 306 |
for (apos = 1; apos <= msa->alen; apos++) |
| 307 |
msa->rf[apos-1] = matassign[apos] ? 'x' : '.'; |
| 308 |
msa->rf[msa->alen] = '\0'; |
| 309 |
|
| 310 |
if (opt_tr != NULL) *opt_tr = tr; |
| 311 |
else p7_trace_DestroyArray(tr, msa->nseq); |
| 312 |
*ret_hmm = hmm; |
| 313 |
return eslOK; |
| 314 |
|
| 315 |
ERROR: |
| 316 |
if (tr != NULL) p7_trace_DestroyArray(tr, msa->nseq); |
| 317 |
if (hmm != NULL) p7_hmm_Destroy(hmm); |
| 318 |
if (opt_tr != NULL) *opt_tr = NULL; |
| 319 |
*ret_hmm = NULL; |
| 320 |
return status; |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
static int |
| 339 |
annotate_model(P7_HMM *hmm, int *matassign, ESL_MSA *msa) |
| 340 |
{ |
| 341 |
int apos; |
| 342 |
int k; |
| 343 |
int status; |
| 344 |
|
| 345 |
|
| 346 |
if (msa->rf != NULL) { |
| 347 |
ESL_ALLOC(hmm->rf, sizeof(char) * (hmm->M+2)); |
| 348 |
hmm->rf[0] = ' '; |
| 349 |
for (apos = k = 1; apos <= msa->alen; apos++) |
| 350 |
if (matassign[apos]) hmm->rf[k++] = msa->rf[apos-1]; |
| 351 |
hmm->rf[k] = '\0'; |
| 352 |
hmm->flags |= p7H_RF; |
| 353 |
} |
| 354 |
|
| 355 |
|
| 356 |
if (msa->mm != NULL) { |
| 357 |
ESL_ALLOC(hmm->mm, sizeof(char) * (hmm->M+2)); |
| 358 |
hmm->mm[0] = ' '; |
| 359 |
for (apos = k = 1; apos <= msa->alen; apos++) |
| 360 |
if (matassign[apos]) hmm->mm[k++] = ( msa->mm[apos-1] == '.' ? '-' : msa->mm[apos-1]) ; |
| 361 |
hmm->mm[k] = '\0'; |
| 362 |
hmm->flags |= p7H_MMASK; |
| 363 |
} |
| 364 |
|
| 365 |
|
| 366 |
if (msa->ss_cons != NULL) { |
| 367 |
ESL_ALLOC(hmm->cs, sizeof(char) * (hmm->M+2)); |
| 368 |
hmm->cs[0] = ' '; |
| 369 |
for (apos = k = 1; apos <= msa->alen; apos++) |
| 370 |
if (matassign[apos]) hmm->cs[k++] = msa->ss_cons[apos-1]; |
| 371 |
hmm->cs[k] = '\0'; |
| 372 |
hmm->flags |= p7H_CS; |
| 373 |
} |
| 374 |
|
| 375 |
|
| 376 |
if (msa->sa_cons != NULL) { |
| 377 |
ESL_ALLOC(hmm->ca, sizeof(char) * (hmm->M+2)); |
| 378 |
hmm->ca[0] = ' '; |
| 379 |
for (apos = k = 1; apos <= msa->alen; apos++) |
| 380 |
if (matassign[apos]) hmm->ca[k++] = msa->sa_cons[apos-1]; |
| 381 |
hmm->ca[k] = '\0'; |
| 382 |
hmm->flags |= p7H_CA; |
| 383 |
} |
| 384 |
|
| 385 |
|
| 386 |
ESL_ALLOC(hmm->map, sizeof(int) * (hmm->M+1)); |
| 387 |
hmm->map[0] = 0; |
| 388 |
for (apos = k = 1; apos <= msa->alen; apos++) |
| 389 |
if (matassign[apos]) hmm->map[k++] = apos; |
| 390 |
hmm->flags |= p7H_MAP; |
| 391 |
|
| 392 |
return eslOK; |
| 393 |
|
| 394 |
ERROR: |
| 395 |
return status; |
| 396 |
} |
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
#ifdef p7BUILD_TESTDRIVE |
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
static void |
| 410 |
utest_basic(void) |
| 411 |
{ |
| 412 |
char *failmsg = "failure in build.c::utest_basic() unit test"; |
| 413 |
char msafile[16] = "p7tmpXXXXXX"; |
| 414 |
FILE *ofp = NULL; |
| 415 |
ESL_ALPHABET *abc = esl_alphabet_Create(eslAMINO); |
| 416 |
ESL_MSAFILE *afp = NULL; |
| 417 |
ESL_MSA *msa = NULL; |
| 418 |
P7_HMM *hmm = NULL; |
| 419 |
float symfrac = 0.5; |
| 420 |
|
| 421 |
if (esl_tmpfile_named(msafile, &ofp) != eslOK) esl_fatal(failmsg); |
| 422 |
fprintf(ofp, "# STOCKHOLM 1.0\n"); |
| 423 |
fprintf(ofp, "#=GC RF --xxxxxxxxxxxxxxxx-xxx-x--\n"); |
| 424 |
fprintf(ofp, "seq1 --ACDEFGHIKLMNPZXS-TVW-Yyy\n"); |
| 425 |
fprintf(ofp, "seq2 aaACDEFGHIKLMNPQRS-TVWw---\n"); |
| 426 |
fprintf(ofp, "seq3 aaAC-EFGHIKLMNPQRS-TVW-Y--\n"); |
| 427 |
fprintf(ofp, "seq4 aaAC-EFGHIKLMNPQRS-TVW-Y--\n"); |
| 428 |
fprintf(ofp, "//\n"); |
| 429 |
fclose(ofp); |
| 430 |
|
| 431 |
if (esl_msafile_Open(&abc, msafile, NULL, eslMSAFILE_UNKNOWN, NULL, &afp) != eslOK) esl_fatal(failmsg); |
| 432 |
if (esl_msafile_Read(afp, &msa) != eslOK) esl_fatal(failmsg); |
| 433 |
if (p7_Fastmodelmaker(msa, symfrac, NULL, &hmm, NULL) != eslOK) esl_fatal(failmsg); |
| 434 |
|
| 435 |
p7_hmm_Destroy(hmm); |
| 436 |
esl_msa_Destroy(msa); |
| 437 |
esl_msafile_Close(afp); |
| 438 |
esl_alphabet_Destroy(abc); |
| 439 |
remove(msafile); |
| 440 |
return; |
| 441 |
} |
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
static void |
| 452 |
utest_fragments(void) |
| 453 |
{ |
| 454 |
char *failmsg = "failure in build.c::utest_fragments() unit test"; |
| 455 |
char msafile[16] = "p7tmpXXXXXX"; |
| 456 |
FILE *ofp = NULL; |
| 457 |
ESL_ALPHABET *abc = esl_alphabet_Create(eslAMINO); |
| 458 |
ESL_MSAFILE *afp = NULL; |
| 459 |
ESL_MSA *msa = NULL; |
| 460 |
ESL_MSA *dmsa = NULL; |
| 461 |
ESL_MSA *postmsa = NULL; |
| 462 |
P7_HMM *hmm = NULL; |
| 463 |
P7_TRACE **trarr = NULL; |
| 464 |
int i; |
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
|
| 470 |
|
| 471 |
|
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
if (esl_tmpfile_named(msafile, &ofp) != eslOK) esl_fatal(failmsg); |
| 484 |
fprintf(ofp, "# STOCKHOLM 1.0\n"); |
| 485 |
fprintf(ofp, "#=GC RF xxxxx.xxxxxxxxxxxx.xxx\n"); |
| 486 |
fprintf(ofp, "seq1 ~~~~~~GHIKLMNPQRST~~~~\n"); |
| 487 |
fprintf(ofp, "seq2 ~~~~~aGHIKLMNPQRSTa~~~\n"); |
| 488 |
fprintf(ofp, "seq3 ~~~~~~-HIKLMNPQRS-~~~~\n"); |
| 489 |
fprintf(ofp, "seq4 ACDEF.GHIKLMNPQRST.VWY\n"); |
| 490 |
fprintf(ofp, "seq5 ACDEF.GHIKLMNPQRST.VWY\n"); |
| 491 |
fprintf(ofp, "//\n"); |
| 492 |
fclose(ofp); |
| 493 |
|
| 494 |
|
| 495 |
if (esl_msafile_Open(NULL, msafile, NULL, eslMSAFILE_UNKNOWN, NULL, &afp)!= eslOK) esl_fatal(failmsg); |
| 496 |
if (esl_msafile_Read(afp, &msa) != eslOK) esl_fatal(failmsg); |
| 497 |
if ((dmsa = esl_msa_Clone(msa)) == NULL) esl_fatal(failmsg); |
| 498 |
if (esl_msa_Digitize(abc, dmsa, NULL) != eslOK) esl_fatal(failmsg); |
| 499 |
|
| 500 |
if (p7_Handmodelmaker(dmsa, NULL, &hmm, &trarr) != eslOK) esl_fatal(failmsg); |
| 501 |
for (i = 0; i < dmsa->nseq; i++) |
| 502 |
if (p7_trace_Validate(trarr[i], abc, dmsa->ax[i], NULL) != eslOK) esl_fatal(failmsg); |
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
|
| 507 |
|
| 508 |
|
| 509 |
if (p7_tracealign_MSA(dmsa, trarr, hmm->M, p7_DEFAULT, &postmsa) != eslOK) esl_fatal(failmsg); |
| 510 |
for (i = 0; i < msa->nseq; i++) |
| 511 |
if (strcmp(msa->aseq[i], postmsa->aseq[i]) != 0) esl_fatal(failmsg); |
| 512 |
|
| 513 |
p7_trace_DestroyArray(trarr, msa->nseq); |
| 514 |
p7_hmm_Destroy(hmm); |
| 515 |
esl_msa_Destroy(msa); |
| 516 |
esl_msa_Destroy(dmsa); |
| 517 |
esl_msa_Destroy(postmsa); |
| 518 |
esl_msafile_Close(afp); |
| 519 |
esl_alphabet_Destroy(abc); |
| 520 |
remove(msafile); |
| 521 |
return; |
| 522 |
} |
| 523 |
|
| 524 |
#endif |
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
#ifdef p7BUILD_TESTDRIVE |
| 535 |
|
| 536 |
|
| 537 |
#include "easel.h" |
| 538 |
|
| 539 |
#include <p7_config.h> |
| 540 |
#include "hmmer.h" |
| 541 |
|
| 542 |
int |
| 543 |
main(int argc, char **argv) |
| 544 |
{ |
| 545 |
utest_basic(); |
| 546 |
utest_fragments(); |
| 547 |
|
| 548 |
return eslOK; |
| 549 |
} |
| 550 |
|
| 551 |
|
| 552 |
#endif |
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
#ifdef p7BUILD_EXAMPLE |
| 561 |
|
| 562 |
#include "easel.h" |
| 563 |
#include "esl_alphabet.h" |
| 564 |
#include "esl_getopts.h" |
| 565 |
|
| 566 |
static ESL_OPTIONS options[] = { |
| 567 |
|
| 568 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 569 |
{ "--dna", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "use DNA alphabet", 0 }, |
| 570 |
{ "--rna", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "use RNA alphabet", 0 }, |
| 571 |
{ "--amino", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "use protein alphabet", 0 }, |
| 572 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 573 |
}; |
| 574 |
static char usage[] = "[-options] <msafile>"; |
| 575 |
static char banner[] = "example for the build module"; |
| 576 |
|
| 577 |
|
| 578 |
int |
| 579 |
main(int argc, char **argv) |
| 580 |
{ |
| 581 |
ESL_GETOPTS *go = p7_CreateDefaultApp(options, 1, argc, argv, banner, usage); |
| 582 |
char *msafile = esl_opt_GetArg(go, 1); |
| 583 |
int fmt = eslMSAFILE_UNKNOWN; |
| 584 |
ESL_ALPHABET *abc = NULL; |
| 585 |
ESL_MSAFILE *afp = NULL; |
| 586 |
ESL_MSA *msa = NULL; |
| 587 |
P7_HMM *hmm = NULL; |
| 588 |
P7_PRIOR *prior = NULL; |
| 589 |
P7_TRACE **trarr = NULL; |
| 590 |
P7_BG *bg = NULL; |
| 591 |
P7_PROFILE *gm = NULL; |
| 592 |
ESL_MSA *postmsa = NULL; |
| 593 |
int i; |
| 594 |
int status; |
| 595 |
|
| 596 |
|
| 597 |
if (esl_opt_GetBoolean(go, "--rna")) abc = esl_alphabet_Create(eslRNA); |
| 598 |
else if (esl_opt_GetBoolean(go, "--dna")) abc = esl_alphabet_Create(eslDNA); |
| 599 |
else if (esl_opt_GetBoolean(go, "--amino")) abc = esl_alphabet_Create(eslAMINO); |
| 600 |
|
| 601 |
if ((status = esl_msafile_Open(&abc, msafile, NULL, fmt, NULL, &afp)) != eslOK) |
| 602 |
esl_msafile_OpenFailure(afp, status); |
| 603 |
|
| 604 |
bg = p7_bg_Create(abc); |
| 605 |
|
| 606 |
switch (abc->type) { |
| 607 |
case eslAMINO: prior = p7_prior_CreateAmino(); break; |
| 608 |
case eslDNA: prior = p7_prior_CreateNucleic(); break; |
| 609 |
case eslRNA: prior = p7_prior_CreateNucleic(); break; |
| 610 |
default: prior = p7_prior_CreateLaplace(abc); break; |
| 611 |
} |
| 612 |
if (prior == NULL) esl_fatal("Failed to initialize prior"); |
| 613 |
|
| 614 |
while ((status = esl_msafile_Read(afp, &msa)) != eslEOF) |
| 615 |
{ |
| 616 |
if (status != eslOK) esl_msafile_ReadFailure(afp, status); |
| 617 |
|
| 618 |
|
| 619 |
status = p7_Handmodelmaker(msa, NULL, &hmm, &trarr); |
| 620 |
if (status == eslENORESULT) esl_fatal("no consensus columns in alignment %s\n", msa->name); |
| 621 |
else if (status != eslOK) esl_fatal("failed to build HMM from alignment %s\n", msa->name); |
| 622 |
|
| 623 |
printf("COUNTS:\n"); |
| 624 |
p7_hmm_Dump(stdout, hmm); |
| 625 |
|
| 626 |
|
| 627 |
status = p7_ParameterEstimation(hmm, prior); |
| 628 |
if (status != eslOK) esl_fatal("failed to parameterize HMM for %s", msa->name); |
| 629 |
|
| 630 |
printf("PROBABILITIES:\n"); |
| 631 |
p7_hmm_Dump(stdout, hmm); |
| 632 |
|
| 633 |
|
| 634 |
gm = p7_profile_Create(hmm->M, abc); |
| 635 |
p7_ProfileConfig(hmm, bg, gm, 400, p7_LOCAL); |
| 636 |
|
| 637 |
|
| 638 |
for (i = 0; i < msa->nseq; i++) |
| 639 |
{ |
| 640 |
printf("Trace %d: %s\n", i+1, msa->sqname[i]); |
| 641 |
p7_trace_Dump(stdout, trarr[i], gm, msa->ax[i]); |
| 642 |
} |
| 643 |
|
| 644 |
|
| 645 |
status = p7_tracealign_MSA(msa, trarr, hmm->M, p7_DEFAULT, &postmsa); |
| 646 |
if (status != eslOK) esl_fatal("failed to create new MSA from traces\n"); |
| 647 |
|
| 648 |
esl_msafile_Write(stdout, postmsa, eslMSAFILE_PFAM); |
| 649 |
|
| 650 |
p7_profile_Destroy(gm); |
| 651 |
p7_hmm_Destroy(hmm); |
| 652 |
p7_trace_DestroyArray(trarr, msa->nseq); |
| 653 |
esl_msa_Destroy(postmsa); |
| 654 |
esl_msa_Destroy(msa); |
| 655 |
} |
| 656 |
|
| 657 |
esl_msafile_Close(afp); |
| 658 |
p7_bg_Destroy(bg); |
| 659 |
esl_alphabet_Destroy(abc); |
| 660 |
esl_getopts_Destroy(go); |
| 661 |
return 0; |
| 662 |
} |
| 663 |
|
| 664 |
#endif |
| 665 |
|
| 666 |
|
| 667 |
|