| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <esl_config.h> |
| 20 |
#include <p7_config.h> |
| 21 |
#include "config.h" |
| 22 |
|
| 23 |
#include <stdlib.h> |
| 24 |
#include <stdio.h> |
| 25 |
#include <string.h> |
| 26 |
|
| 27 |
#ifdef HMMER_THREADS |
| 28 |
#include <pthread.h> |
| 29 |
#endif |
| 30 |
|
| 31 |
#include "easel.h" |
| 32 |
#include "esl_alphabet.h" |
| 33 |
#include "esl_ssi.h" |
| 34 |
#include "esl_vectorops.h" |
| 35 |
|
| 36 |
#include "hmmer.h" |
| 37 |
|
| 38 |
#include "infernal.h" |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
#if 0 |
| 44 |
static unsigned int v01magic = 0xe3edb0b1; |
| 45 |
#endif |
| 46 |
|
| 47 |
static uint32_t v1a_magic = 0xe3edb0b2; |
| 48 |
static uint32_t v1a_fmagic = 0xb1e1e6f3; |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
static int read_asc_1p1_cm(CM_FILE *hfp, int read_fp7, ESL_ALPHABET **ret_abc, CM_t **opt_cm); |
| 59 |
static int read_bin_1p1_cm(CM_FILE *hfp, int read_fp7, ESL_ALPHABET **ret_abc, CM_t **opt_cm); |
| 60 |
static int read_asc_1p0_cm(CM_FILE *hfp, int read_fp7, ESL_ALPHABET **ret_abc, CM_t **opt_cm); |
| 61 |
|
| 62 |
static int write_bin_string(FILE *fp, char *s); |
| 63 |
static int read_bin_string (FILE *fp, char **ret_s); |
| 64 |
|
| 65 |
static char *prob2ascii(float p, float null); |
| 66 |
static float ascii2prob(char *s, float null); |
| 67 |
static int is_integer(char *s); |
| 68 |
static int is_real(char *s); |
| 69 |
|
| 70 |
|
| 71 |
static uint32_t v3a_magic = 0xe8ededb6; |
| 72 |
static uint32_t v3b_magic = 0xe8ededb7; |
| 73 |
static uint32_t v3c_magic = 0xe8ededb8; |
| 74 |
static uint32_t v3d_magic = 0xe8ededb9; |
| 75 |
static uint32_t v3e_magic = 0xe8ededb0; |
| 76 |
static uint32_t v3f_magic = 0xe8ededba; |
| 77 |
|
| 78 |
static int read_asc30hmm(P7_HMMFILE *hfp, ESL_ALPHABET **ret_abc, P7_HMM **opt_hmm); |
| 79 |
static int read_bin30hmm(P7_HMMFILE *hfp, ESL_ALPHABET **ret_abc, P7_HMM **opt_hmm); |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
static int open_engine(char *filename, char *env, CM_FILE **ret_cmfp, int do_ascii_only, int allow_1p0, char *errbuf); |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
int |
| 142 |
cm_file_Open(char *filename, char *env, int allow_1p0, CM_FILE **ret_cmfp, char *errbuf) |
| 143 |
{ |
| 144 |
return open_engine(filename, env, ret_cmfp, FALSE, allow_1p0, errbuf); |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
int |
| 159 |
cm_file_OpenNoDB(char *filename, char *env, int allow_1p0, CM_FILE **ret_cmfp, char *errbuf) |
| 160 |
{ |
| 161 |
return open_engine(filename, env, ret_cmfp, TRUE, allow_1p0, errbuf); |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
int |
| 197 |
cm_file_OpenBuffer(char *buffer, int size, int allow_1p0, CM_FILE **ret_cmfp) |
| 198 |
{ |
| 199 |
CM_FILE *cmfp = NULL; |
| 200 |
int status; |
| 201 |
char *tok; |
| 202 |
int toklen; |
| 203 |
|
| 204 |
ESL_ALLOC(cmfp, sizeof(CM_FILE)); |
| 205 |
cmfp->f = NULL; |
| 206 |
cmfp->fname = NULL; |
| 207 |
cmfp->do_gzip = FALSE; |
| 208 |
cmfp->do_stdin = FALSE; |
| 209 |
cmfp->newly_opened = TRUE; |
| 210 |
cmfp->is_pressed = FALSE; |
| 211 |
#ifdef HMMER_THREADS |
| 212 |
cmfp->syncRead = FALSE; |
| 213 |
#endif |
| 214 |
cmfp->parser = NULL; |
| 215 |
cmfp->efp = NULL; |
| 216 |
cmfp->ffp = NULL; |
| 217 |
cmfp->pfp = NULL; |
| 218 |
cmfp->ssi = NULL; |
| 219 |
cmfp->errbuf[0] = '\0'; |
| 220 |
cmfp->msv_errbuf[0] = '\0'; |
| 221 |
|
| 222 |
if ((cmfp->efp = esl_fileparser_CreateMapped(buffer, size)) == NULL) { status = eslEMEM; goto ERROR; } |
| 223 |
if ((status = esl_fileparser_SetCommentChar(cmfp->efp, '#')) != eslOK) goto ERROR; |
| 224 |
if ((status = esl_fileparser_GetToken(cmfp->efp, &tok, &toklen)) != eslOK) goto ERROR; |
| 225 |
|
| 226 |
if ( strcmp("INFERNAL1/a", tok) == 0) { cmfp->format = CM_FILE_1a; cmfp->parser = read_asc_1p1_cm; } |
| 227 |
else if (allow_1p0 && strcmp("INFERNAL-1", tok) == 0) { cmfp->format = CM_FILE_1; cmfp->parser = read_asc_1p0_cm; } |
| 228 |
|
| 229 |
if (cmfp->parser == NULL) { status = eslEFORMAT; goto ERROR; } |
| 230 |
|
| 231 |
*ret_cmfp = cmfp; |
| 232 |
return eslOK; |
| 233 |
|
| 234 |
ERROR: |
| 235 |
if (cmfp != NULL) cm_file_Close(cmfp); |
| 236 |
*ret_cmfp = NULL; |
| 237 |
if (status == eslEMEM) return status; |
| 238 |
else if (status == eslENOTFOUND) return status; |
| 239 |
else return eslEFORMAT; |
| 240 |
} |
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
static int |
| 257 |
open_engine(char *filename, char *env, CM_FILE **ret_cmfp, int do_ascii_only, int allow_1p0, char *errbuf) |
| 258 |
{ |
| 259 |
CM_FILE *cmfp = NULL; |
| 260 |
char *envfile = NULL; |
| 261 |
char *dbfile = NULL; |
| 262 |
char *cmd = NULL; |
| 263 |
int status; |
| 264 |
int n = strlen(filename); |
| 265 |
union { char c[4]; uint32_t n; } magic; |
| 266 |
char *tok; |
| 267 |
int toklen; |
| 268 |
|
| 269 |
ESL_ALLOC(cmfp, sizeof(CM_FILE)); |
| 270 |
cmfp->f = NULL; |
| 271 |
cmfp->fname = NULL; |
| 272 |
cmfp->do_gzip = FALSE; |
| 273 |
cmfp->do_stdin = FALSE; |
| 274 |
cmfp->newly_opened = TRUE; |
| 275 |
cmfp->is_pressed = FALSE; |
| 276 |
cmfp->is_binary = FALSE; |
| 277 |
#ifdef HMMER_THREADS |
| 278 |
cmfp->syncRead = FALSE; |
| 279 |
#endif |
| 280 |
cmfp->parser = NULL; |
| 281 |
cmfp->efp = NULL; |
| 282 |
cmfp->hfp = NULL; |
| 283 |
cmfp->ffp = NULL; |
| 284 |
cmfp->pfp = NULL; |
| 285 |
cmfp->ssi = NULL; |
| 286 |
cmfp->errbuf[0] = '\0'; |
| 287 |
cmfp->msv_errbuf[0] = '\0'; |
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
if (strcmp(filename, "-") == 0) |
| 296 |
{ |
| 297 |
cmfp->f = stdin; |
| 298 |
cmfp->do_stdin = TRUE; |
| 299 |
if ((status = esl_strdup("[STDIN]", -1, &(cmfp->fname))) != eslOK) ESL_XFAIL(status, errbuf, "esl_strdup failed; shouldn't happen"); |
| 300 |
} |
| 301 |
#ifdef HAVE_POPEN |
| 302 |
else if (n > 3 && strcmp(filename+n-3, ".gz") == 0) |
| 303 |
{ |
| 304 |
if (! esl_FileExists(filename)) ESL_XFAIL(eslENOTFOUND, errbuf, ".gz file %s not found or not readable", filename); |
| 305 |
if ((status = esl_sprintf(&cmd, "gzip -dc %s", filename)) != eslOK) ESL_XFAIL(status, errbuf, "when setting up .gz pipe: esl_sprintf() failed"); |
| 306 |
if ((cmfp->f = popen(cmd, "r")) == NULL) ESL_XFAIL(eslENOTFOUND, errbuf, "gzip -dc %s failed; gzip not installed or not in PATH?", filename); |
| 307 |
if ((status = esl_strdup(filename, n, &(cmfp->fname))) != eslOK) ESL_XFAIL(status, errbuf, "esl_strdup() failed, shouldn't happen"); |
| 308 |
cmfp->do_gzip = TRUE; |
| 309 |
free(cmd); cmd = NULL; |
| 310 |
} |
| 311 |
#endif |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
if (cmfp->f == NULL) |
| 322 |
{ |
| 323 |
if ((cmfp->f = fopen(filename, "r")) != NULL) |
| 324 |
{ |
| 325 |
if ((status = esl_strdup(filename, n, &(cmfp->fname))) != eslOK) ESL_XFAIL(status, errbuf, "esl_strdup() failed, shouldn't happen"); |
| 326 |
} |
| 327 |
else if (esl_FileEnvOpen(filename, env, &(cmfp->f), &envfile) == eslOK) |
| 328 |
{ |
| 329 |
n = strlen(envfile); |
| 330 |
if ((status = esl_strdup(envfile, n, &(cmfp->fname))) != eslOK) ESL_XFAIL(status, errbuf, "esl_strdup() failed, shouldn't happen"); |
| 331 |
free(envfile); envfile = NULL; |
| 332 |
} |
| 333 |
else |
| 334 |
{ |
| 335 |
if ((status = esl_strdup(filename, n, &(cmfp->fname))) != eslOK) ESL_XFAIL(status, errbuf, "esl_strdup() failed, shouldn't happen"); |
| 336 |
} |
| 337 |
} |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
if (! do_ascii_only && ! cmfp->do_stdin && ! cmfp->do_gzip) |
| 351 |
{ |
| 352 |
FILE *tmpfp; |
| 353 |
|
| 354 |
if ((status = esl_sprintf(&dbfile, "%s.i1m", cmfp->fname) != eslOK)) ESL_XFAIL(status, errbuf, "esl_sprintf() failed; shouldn't happen"); |
| 355 |
|
| 356 |
if ((tmpfp = fopen(dbfile, "rb")) != NULL) |
| 357 |
{ |
| 358 |
if (cmfp->f != NULL) fclose(cmfp->f); |
| 359 |
cmfp->f = tmpfp; |
| 360 |
cmfp->is_pressed = TRUE; |
| 361 |
free(cmfp->fname); |
| 362 |
if ((status = esl_strdup(dbfile, -1, &(cmfp->fname))) != eslOK) ESL_XFAIL(status, errbuf, "esl_strdup() failed, shouldn't happen"); |
| 363 |
} |
| 364 |
else if (cmfp->f == NULL && esl_FileEnvOpen(dbfile, env, &(cmfp->f), &envfile) == eslOK) |
| 365 |
{ |
| 366 |
free(cmfp->fname); |
| 367 |
if ((status = esl_strdup(envfile, -1, &(cmfp->fname))) != eslOK) ESL_XFAIL(status, errbuf, "esl_strdup() failed; shouldn't happen"); |
| 368 |
cmfp->is_pressed = TRUE; |
| 369 |
} |
| 370 |
free(dbfile); dbfile = NULL; |
| 371 |
} |
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
if (cmfp->f == NULL) |
| 376 |
{ |
| 377 |
if (env) ESL_XFAIL(eslENOTFOUND, errbuf, "CM file %s not found (nor an .i1m binary of it); also looked in %s", filename, env); |
| 378 |
else ESL_XFAIL(eslENOTFOUND, errbuf, "CM file %s not found (nor an .i1m binary of it)", filename); |
| 379 |
} |
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
ESL_ALLOC(cmfp->hfp, sizeof(P7_HMMFILE)); |
| 388 |
|
| 389 |
if (!cmfp->do_stdin && !cmfp->do_gzip) { |
| 390 |
if ((cmfp->hfp->f = fopen(cmfp->fname, "r")) == NULL) goto ERROR; |
| 391 |
} |
| 392 |
else if (cmfp->do_stdin) { |
| 393 |
cmfp->hfp->f = stdin; |
| 394 |
} |
| 395 |
#ifdef HAVE_POPEN |
| 396 |
else if (cmfp->do_gzip) { |
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
cmfp->hfp->f = cmfp->f; |
| 402 |
} |
| 403 |
#endif |
| 404 |
cmfp->hfp->do_gzip = cmfp->do_gzip; |
| 405 |
cmfp->hfp->do_stdin = cmfp->do_stdin; |
| 406 |
cmfp->hfp->newly_opened = TRUE; |
| 407 |
cmfp->hfp->is_pressed = cmfp->is_pressed; |
| 408 |
#ifdef HMMER_THREADS |
| 409 |
cmfp->hfp->syncRead = FALSE; |
| 410 |
#endif |
| 411 |
cmfp->hfp->parser = NULL; |
| 412 |
cmfp->hfp->efp = NULL; |
| 413 |
cmfp->hfp->ffp = NULL; |
| 414 |
cmfp->hfp->pfp = NULL; |
| 415 |
cmfp->hfp->ssi = NULL; |
| 416 |
cmfp->hfp->errbuf[0] = '\0'; |
| 417 |
cmfp->hfp->rr_errbuf[0] = '\0'; |
| 418 |
if ((status = esl_strdup(cmfp->fname, -1, &(cmfp->hfp->fname))) != eslOK) goto ERROR; |
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
if (cmfp->is_pressed) |
| 426 |
{ |
| 427 |
|
| 428 |
n = strlen(cmfp->fname); |
| 429 |
esl_strdup(cmfp->fname, n, &dbfile); |
| 430 |
|
| 431 |
dbfile[n-1] = 'f'; |
| 432 |
if ((cmfp->ffp = fopen(dbfile, "rb")) == NULL) ESL_XFAIL(eslENOTFOUND, errbuf, "Opened %s, a pressed CM file; but no .i1f file found", cmfp->fname); |
| 433 |
if ((cmfp->hfp->ffp = fopen(dbfile, "rb")) == NULL) ESL_XFAIL(eslENOTFOUND, errbuf, "Opened %s, a pressed CM file; but no .i1f file found", cmfp->fname); |
| 434 |
|
| 435 |
dbfile[n-1] = 'p'; |
| 436 |
if ((cmfp->hfp->pfp = fopen(dbfile, "rb")) == NULL) ESL_XFAIL(eslENOTFOUND, errbuf, "Opened %s, a pressed CM file; but no .i1p file found", cmfp->fname); |
| 437 |
|
| 438 |
dbfile[n-1] = 'i'; |
| 439 |
status = esl_ssi_Open(dbfile, &(cmfp->ssi)); |
| 440 |
if (status == eslENOTFOUND) ESL_XFAIL(eslENOTFOUND, errbuf, "Opened %s, a pressed CM file; but no .i1i file found", cmfp->fname); |
| 441 |
else if (status == eslEFORMAT) ESL_XFAIL(eslEFORMAT, errbuf, "Opened %s, a pressed CM file; but format of its .i1i file unrecognized", cmfp->fname); |
| 442 |
else if (status == eslERANGE) ESL_XFAIL(eslEFORMAT, errbuf, "Opened %s, a pressed CM file; but its .i1i file is 64-bit and your system is 32-bit", cmfp->fname); |
| 443 |
else if (status != eslOK) ESL_XFAIL(eslEFORMAT, errbuf, "Opened %s, a pressed CM file; but failed to open its .i1i file", cmfp->fname); |
| 444 |
|
| 445 |
free(dbfile); dbfile = NULL; |
| 446 |
} |
| 447 |
else |
| 448 |
{ |
| 449 |
if ((status = esl_sprintf(&dbfile, "%s.ssi", cmfp->fname)) != eslOK) ESL_XFAIL(status, errbuf, "esl_sprintf() failed"); |
| 450 |
|
| 451 |
status = esl_ssi_Open(dbfile, &(cmfp->ssi)); |
| 452 |
if (status == eslEFORMAT) ESL_XFAIL(status, errbuf, "a %s.ssi file exists (an SSI index), but its SSI format is not recognized", cmfp->fname); |
| 453 |
else if (status == eslERANGE) ESL_XFAIL(status, errbuf, "a %s.ssi file exists (an SSI index), but is 64-bit, and your system is 32-bit", cmfp->fname); |
| 454 |
else if (status != eslOK && status != eslENOTFOUND) ESL_XFAIL(status, errbuf, "esl_ssi_Open() failed"); |
| 455 |
free(dbfile); dbfile = NULL; |
| 456 |
} |
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
if (! fread((char *) &(magic.n), sizeof(uint32_t), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, errbuf, "File exists, but appears to be empty?"); |
| 461 |
if (magic.n == v1a_magic) { cmfp->format = CM_FILE_1a; cmfp->parser = read_bin_1p1_cm; cmfp->is_binary = TRUE; } |
| 462 |
else if (cmfp->is_pressed) ESL_XFAIL(eslEFORMAT, errbuf, "Binary format tag in %s unrecognized\nCurrent Infernal format is INFERNAL1/a. Previous binary formats are not supported.", cmfp->fname); |
| 463 |
|
| 464 |
|
| 465 |
if (cmfp->parser == NULL) |
| 466 |
{ |
| 467 |
|
| 468 |
if (magic.n & 0x80000000) ESL_XFAIL(eslEFORMAT, errbuf, "Format tag appears binary, but unrecognized\nCurrent Infernal format is INFERNAL1/a. Previous binary formats are not supported."); |
| 469 |
|
| 470 |
if ((cmfp->efp = esl_fileparser_Create(cmfp->f)) == NULL) ESL_XFAIL(eslEMEM, errbuf, "internal error in esl_fileparser_Create()"); |
| 471 |
if ((status = esl_fileparser_SetCommentChar(cmfp->efp, '#')) != eslOK) ESL_XFAIL(status, errbuf, "internal error in esl_fileparser_SetCommentChar()"); |
| 472 |
if ((status = esl_fileparser_NextLinePeeked(cmfp->efp, magic.c, 4)) != eslOK) ESL_XFAIL(status, errbuf, "internal error in esl_fileparser_NextLinePeeked()"); |
| 473 |
if ((status = esl_fileparser_GetToken(cmfp->efp, &tok, &toklen)) != eslOK) ESL_XFAIL(status, errbuf, "internal error in esl_fileparser_GetToken()"); |
| 474 |
|
| 475 |
if ( strcmp("INFERNAL1/a", tok) == 0) { cmfp->format = CM_FILE_1a; cmfp->parser = read_asc_1p1_cm; } |
| 476 |
else if (( allow_1p0) && strcmp("INFERNAL-1", tok) == 0) { cmfp->format = CM_FILE_1; cmfp->parser = read_asc_1p0_cm; } |
| 477 |
else if ((! allow_1p0) && strcmp("INFERNAL-1", tok) == 0) { ESL_XFAIL(eslEFORMAT, errbuf, "Format tag is '%s': use cmconvert to reformat Infernal v1.0 to v1.0.2 CM files to current format", tok); } |
| 478 |
else { ESL_XFAIL(eslEFORMAT, errbuf, "Format tag is '%s': unrecognized or not supported.", tok); } |
| 479 |
} |
| 480 |
|
| 481 |
*ret_cmfp = cmfp; |
| 482 |
return eslOK; |
| 483 |
|
| 484 |
ERROR: |
| 485 |
if (cmd != NULL) free(cmd); |
| 486 |
if (dbfile != NULL) free(dbfile); |
| 487 |
if (envfile != NULL) free(envfile); |
| 488 |
if (cmfp != NULL) cm_file_Close(cmfp); |
| 489 |
*ret_cmfp = NULL; |
| 490 |
if (status == eslEMEM) return status; |
| 491 |
else if (status == eslENOTFOUND) return status; |
| 492 |
else return eslEFORMAT; |
| 493 |
} |
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
void |
| 504 |
cm_file_Close(CM_FILE *cmfp) |
| 505 |
{ |
| 506 |
if (cmfp == NULL) return; |
| 507 |
|
| 508 |
#ifdef HAVE_POPEN |
| 509 |
if (cmfp->do_gzip && cmfp->f != NULL) { |
| 510 |
pclose(cmfp->f); |
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
if(cmfp->f == cmfp->hfp->f) { |
| 517 |
cmfp->hfp->f = NULL; |
| 518 |
} |
| 519 |
cmfp->f = NULL; |
| 520 |
} |
| 521 |
#endif |
| 522 |
if (!cmfp->do_gzip && !cmfp->do_stdin && cmfp->f != NULL) fclose(cmfp->f); |
| 523 |
if (cmfp->ffp != NULL) fclose(cmfp->ffp); |
| 524 |
if (cmfp->pfp != NULL) fclose(cmfp->pfp); |
| 525 |
if (cmfp->fname != NULL) free(cmfp->fname); |
| 526 |
if (cmfp->efp != NULL) esl_fileparser_Destroy(cmfp->efp); |
| 527 |
if (cmfp->ssi != NULL) esl_ssi_Close(cmfp->ssi); |
| 528 |
#ifdef HMMER_THREADS |
| 529 |
if (cmfp->syncRead) pthread_mutex_destroy (&cmfp->readMutex); |
| 530 |
#endif |
| 531 |
|
| 532 |
if(cmfp->hfp != NULL) p7_hmmfile_Close(cmfp->hfp); |
| 533 |
|
| 534 |
free(cmfp); |
| 535 |
} |
| 536 |
|
| 537 |
#ifdef HMMER_THREADS |
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
int |
| 547 |
cm_file_CreateLock(CM_FILE *cmfp) |
| 548 |
{ |
| 549 |
int status; |
| 550 |
|
| 551 |
if (cmfp == NULL) return eslEINVAL; |
| 552 |
|
| 553 |
|
| 554 |
if (!cmfp->syncRead) |
| 555 |
{ |
| 556 |
cmfp->syncRead = TRUE; |
| 557 |
status = pthread_mutex_init(&cmfp->readMutex, NULL); |
| 558 |
if (status != 0) goto ERROR; |
| 559 |
} |
| 560 |
|
| 561 |
|
| 562 |
if (cmfp->hfp != NULL) |
| 563 |
if((status = p7_hmmfile_CreateLock(cmfp->hfp)) != eslOK) goto ERROR; |
| 564 |
|
| 565 |
return eslOK; |
| 566 |
|
| 567 |
ERROR: |
| 568 |
cmfp->syncRead = FALSE; |
| 569 |
return eslFAIL; |
| 570 |
} |
| 571 |
#endif |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
static int multiline(FILE *fp, const char *pfx, char *s); |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
int |
| 602 |
cm_file_WriteASCII(FILE *fp, int format, CM_t *cm) |
| 603 |
{ |
| 604 |
int x, v, nd, y; |
| 605 |
|
| 606 |
if((cm->flags & CMH_LOCAL_BEGIN) || (cm->flags & CMH_LOCAL_END)) cm_Fail("cm_file_WriteASCII(): CM is in local mode"); |
| 607 |
|
| 608 |
if (format == -1) format = CM_FILE_1a; |
| 609 |
|
| 610 |
if (format == CM_FILE_1a) fprintf(fp, "INFERNAL1/a [%s | %s]\n", INFERNAL_VERSION, INFERNAL_DATE); |
| 611 |
else ESL_EXCEPTION(eslEINVAL, "invalid CM file format code"); |
| 612 |
|
| 613 |
fprintf(fp, "NAME %s\n", cm->name); |
| 614 |
if (cm->acc) fprintf(fp, "ACC %s\n", cm->acc); |
| 615 |
if (cm->desc) fprintf(fp, "DESC %s\n", cm->desc); |
| 616 |
fprintf(fp, "STATES %d\n", cm->M); |
| 617 |
fprintf(fp, "NODES %d\n", cm->nodes); |
| 618 |
fprintf(fp, "CLEN %d\n", cm->clen); |
| 619 |
fprintf(fp, "W %d\n", cm->W); |
| 620 |
fprintf(fp, "ALPH %s\n", esl_abc_DecodeType(cm->abc->type)); |
| 621 |
fprintf(fp, "RF %s\n", (cm->flags & CMH_RF) ? "yes" : "no"); |
| 622 |
fprintf(fp, "CONS %s\n", (cm->flags & CMH_CONS) ? "yes" : "no"); |
| 623 |
fprintf(fp, "MAP %s\n", (cm->flags & CMH_MAP) ? "yes" : "no"); |
| 624 |
if (cm->ctime != NULL) fprintf (fp, "DATE %s\n", cm->ctime); |
| 625 |
if (cm->comlog != NULL) multiline(fp, "COM ", cm->comlog); |
| 626 |
fprintf(fp, "PBEGIN %g\n", cm->pbegin); |
| 627 |
fprintf(fp, "PEND %g\n", cm->pend); |
| 628 |
fprintf(fp, "WBETA %g\n", cm->beta_W); |
| 629 |
fprintf(fp, "QDBBETA1 %g\n", cm->qdbinfo->beta1); |
| 630 |
fprintf(fp, "QDBBETA2 %g\n", cm->qdbinfo->beta2); |
| 631 |
fprintf(fp, "N2OMEGA %6g\n",cm->null2_omega); |
| 632 |
fprintf(fp, "N3OMEGA %6g\n",cm->null3_omega); |
| 633 |
fprintf(fp, "ELSELF %.8f\n",cm->el_selfsc); |
| 634 |
fprintf(fp, "NSEQ %d\n", cm->nseq); |
| 635 |
fprintf(fp, "EFFN %f\n",cm->eff_nseq); |
| 636 |
if (cm->flags & CMH_CHKSUM) fprintf(fp, "CKSUM %u\n", cm->checksum); |
| 637 |
fputs("NULL ", fp); |
| 638 |
for (x = 0; x < cm->abc->K; x++) { fprintf(fp, "%6s ", prob2ascii(cm->null[x], 1/(float)(cm->abc->K))); } |
| 639 |
fputc('\n', fp); |
| 640 |
if (cm->flags & CMH_GA) fprintf(fp, "GA %.2f\n", cm->ga); |
| 641 |
if (cm->flags & CMH_TC) fprintf(fp, "TC %.2f\n", cm->tc); |
| 642 |
if (cm->flags & CMH_NC) fprintf(fp, "NC %.2f\n", cm->nc); |
| 643 |
|
| 644 |
if (cm->flags & CMH_FP7) { |
| 645 |
fprintf(fp, "EFP7GF %.4f %.5f\n", cm->fp7_evparam[CM_p7_GFMU], cm->fp7_evparam[CM_p7_GFLAMBDA]); |
| 646 |
} |
| 647 |
if (cm->flags & CMH_EXPTAIL_STATS) |
| 648 |
{ |
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
if(cm->expA[EXP_CM_LC]->dbsize > (2000. * 1000000.)) ESL_EXCEPTION(eslEINVAL, "invalid dbsize (too big) EXP_CM_LC"); |
| 655 |
if(cm->expA[EXP_CM_GC]->dbsize > (2000. * 1000000.)) ESL_EXCEPTION(eslEINVAL, "invalid dbsize (too big) EXP_CM_GC"); |
| 656 |
if(cm->expA[EXP_CM_LI]->dbsize > (2000. * 1000000.)) ESL_EXCEPTION(eslEINVAL, "invalid dbsize (too big) EXP_CM_LI"); |
| 657 |
if(cm->expA[EXP_CM_GI]->dbsize > (2000. * 1000000.)) ESL_EXCEPTION(eslEINVAL, "invalid dbsize (too big) EXP_CM_GI"); |
| 658 |
|
| 659 |
fprintf(fp, "ECMLC %.5f %10.5f %10.5f %10ld %10d %.6f\n", |
| 660 |
cm->expA[EXP_CM_LC]->lambda, cm->expA[EXP_CM_LC]->mu_extrap, cm->expA[EXP_CM_LC]->mu_orig, |
| 661 |
(long) (cm->expA[EXP_CM_LC]->dbsize + 0.5), cm->expA[EXP_CM_LC]->nrandhits, cm->expA[EXP_CM_LC]->tailp); |
| 662 |
fprintf(fp, "ECMGC %.5f %10.5f %10.5f %10ld %10d %.6f\n", |
| 663 |
cm->expA[EXP_CM_GC]->lambda, cm->expA[EXP_CM_GC]->mu_extrap, cm->expA[EXP_CM_GC]->mu_orig, |
| 664 |
(long) (cm->expA[EXP_CM_GC]->dbsize + 0.5), cm->expA[EXP_CM_GC]->nrandhits, cm->expA[EXP_CM_GC]->tailp); |
| 665 |
fprintf(fp, "ECMLI %.5f %10.5f %10.5f %10ld %10d %.6f\n", |
| 666 |
cm->expA[EXP_CM_LI]->lambda, cm->expA[EXP_CM_LI]->mu_extrap, cm->expA[EXP_CM_LI]->mu_orig, |
| 667 |
(long) (cm->expA[EXP_CM_LI]->dbsize + 0.5), cm->expA[EXP_CM_LI]->nrandhits, cm->expA[EXP_CM_LI]->tailp); |
| 668 |
fprintf(fp, "ECMGI %.5f %10.5f %10.5f %10ld %10d %.6f\n", |
| 669 |
cm->expA[EXP_CM_GI]->lambda, cm->expA[EXP_CM_GI]->mu_extrap, cm->expA[EXP_CM_GI]->mu_orig, |
| 670 |
(long) (cm->expA[EXP_CM_GI]->dbsize + 0.5), cm->expA[EXP_CM_GI]->nrandhits, cm->expA[EXP_CM_GI]->tailp); |
| 671 |
} |
| 672 |
|
| 673 |
|
| 674 |
fputs("CM\n", fp); |
| 675 |
|
| 676 |
|
| 677 |
if(cm->emap == NULL) { |
| 678 |
cm->emap = CreateEmitMap(cm); |
| 679 |
if(cm->emap == NULL) ESL_EXCEPTION(eslEINVAL, "unable to create an emit map"); |
| 680 |
} |
| 681 |
|
| 682 |
for (v = 0; v < cm->M; v++) { |
| 683 |
nd = cm->ndidx[v]; |
| 684 |
|
| 685 |
|
| 686 |
if (cm->nodemap[nd] == v) { |
| 687 |
fprintf(fp, "%45s[ %-4s %4d ]", "", Nodetype(cm->ndtype[nd]), nd); |
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
if(cm->flags & CMH_MAP) { |
| 692 |
if (cm->ndtype[nd] == MATP_nd) fprintf(fp, " %6d %6d", cm->map[cm->emap->lpos[nd]], cm->map[cm->emap->rpos[nd]]); |
| 693 |
else if(cm->ndtype[nd] == MATL_nd) fprintf(fp, " %6d %6s", cm->map[cm->emap->lpos[nd]], "-"); |
| 694 |
else if(cm->ndtype[nd] == MATR_nd) fprintf(fp, " %6s %6d", "-", cm->map[cm->emap->rpos[nd]]); |
| 695 |
else fprintf(fp, " %6s %6s", "-", "-"); |
| 696 |
} |
| 697 |
else { |
| 698 |
fprintf(fp, " %6s %6s", "-", "-"); |
| 699 |
} |
| 700 |
|
| 701 |
if (cm->ndtype[nd] == MATP_nd) fprintf(fp, " %c %c", cm->consensus[cm->emap->lpos[nd]], cm->consensus[cm->emap->rpos[nd]]); |
| 702 |
else if(cm->ndtype[nd] == MATL_nd) fprintf(fp, " %c %c", cm->consensus[cm->emap->lpos[nd]], '-'); |
| 703 |
else if(cm->ndtype[nd] == MATR_nd) fprintf(fp, " %c %c", '-', cm->consensus[cm->emap->rpos[nd]]); |
| 704 |
else fprintf(fp, " %c %c", '-', '-'); |
| 705 |
|
| 706 |
if(cm->flags & CMH_RF) { |
| 707 |
if (cm->ndtype[nd] == MATP_nd) fprintf(fp, " %c %c", cm->rf[cm->emap->lpos[nd]], cm->rf[cm->emap->rpos[nd]]); |
| 708 |
else if(cm->ndtype[nd] == MATL_nd) fprintf(fp, " %c %c", cm->rf[cm->emap->lpos[nd]], '-'); |
| 709 |
else if(cm->ndtype[nd] == MATR_nd) fprintf(fp, " %c %c", '-', cm->rf[cm->emap->rpos[nd]]); |
| 710 |
else fprintf(fp, " %c %c", '-', '-'); |
| 711 |
} |
| 712 |
else { |
| 713 |
fprintf(fp, " %c %c", '-', '-'); |
| 714 |
} |
| 715 |
fputs("\n", fp); |
| 716 |
} |
| 717 |
|
| 718 |
|
| 719 |
fprintf(fp, " %2s %5d %5d %1d %5d %5d %5d %5d %5d %5d ", |
| 720 |
Statetype(cm->sttype[v]), v, |
| 721 |
cm->plast[v], cm->pnum[v], |
| 722 |
cm->cfirst[v], cm->cnum[v], |
| 723 |
cm->qdbinfo->dmin2[v], cm->qdbinfo->dmin1[v], |
| 724 |
cm->qdbinfo->dmax1[v], cm->qdbinfo->dmax2[v]); |
| 725 |
|
| 726 |
|
| 727 |
if (cm->sttype[v] != B_st) { |
| 728 |
for (x = 0; x < cm->cnum[v]; x++) { |
| 729 |
fprintf(fp, "%7s ", prob2ascii(cm->t[v][x], 1.)); |
| 730 |
} |
| 731 |
} |
| 732 |
else { |
| 733 |
x = 0; |
| 734 |
} |
| 735 |
for (; x < 6; x++) { |
| 736 |
fprintf(fp, "%7s ", ""); |
| 737 |
} |
| 738 |
|
| 739 |
|
| 740 |
if (cm->sttype[v] == MP_st) { |
| 741 |
for (x = 0; x < cm->abc->K; x++) { |
| 742 |
for (y = 0; y < cm->abc->K; y++) { |
| 743 |
fprintf(fp, "%6s ", prob2ascii(cm->e[v][x*cm->abc->K+y], cm->null[x]*cm->null[y])); |
| 744 |
} |
| 745 |
} |
| 746 |
} |
| 747 |
else if (cm->sttype[v] == ML_st || cm->sttype[v] == MR_st || cm->sttype[v] == IL_st || cm->sttype[v] == IR_st) { |
| 748 |
for (x = 0; x < cm->abc->K; x++) { |
| 749 |
fprintf(fp, "%6s ", prob2ascii(cm->e[v][x], cm->null[x])); |
| 750 |
} |
| 751 |
} |
| 752 |
fputs("\n", fp); |
| 753 |
} |
| 754 |
fputs("//\n", fp); |
| 755 |
|
| 756 |
|
| 757 |
if(cm->flags & CMH_FP7 && cm->fp7 != NULL) { |
| 758 |
p7_hmmfile_WriteASCII(fp, -1, cm->fp7); |
| 759 |
} |
| 760 |
return eslOK; |
| 761 |
} |
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
|
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
|
| 784 |
|
| 785 |
|
| 786 |
int |
| 787 |
cm_file_WriteBinary(FILE *fp, int format, CM_t *cm, off_t *opt_fp7_offset) |
| 788 |
{ |
| 789 |
int v, z; |
| 790 |
off_t fp7_offset; |
| 791 |
|
| 792 |
if((cm->flags & CMH_LOCAL_BEGIN) || (cm->flags & CMH_LOCAL_END)) cm_Fail("cm_file_WriteASCII(): CM is in local mode"); |
| 793 |
|
| 794 |
if (format == -1) format = CM_FILE_1a; |
| 795 |
|
| 796 |
|
| 797 |
if (format == CM_FILE_1a) { if (fwrite((char *) &(v1a_magic), sizeof(uint32_t), 1, fp) != 1) return eslFAIL; } |
| 798 |
else ESL_EXCEPTION(eslEINVAL, "invalid CM file format code"); |
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
if (fwrite((char *) &(cm->flags), sizeof(int), 1, fp) != 1) return eslFAIL; |
| 803 |
if (fwrite((char *) &(cm->M), sizeof(int), 1, fp) != 1) return eslFAIL; |
| 804 |
if (fwrite((char *) &(cm->nodes), sizeof(int), 1, fp) != 1) return eslFAIL; |
| 805 |
if (fwrite((char *) &(cm->clen), sizeof(int), 1, fp) != 1) return eslFAIL; |
| 806 |
if (fwrite((char *) &(cm->abc->type), sizeof(int), 1, fp) != 1) return eslFAIL; |
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
if (fwrite((char *) cm->sttype, sizeof(char), cm->M, fp) != cm->M) return eslFAIL; |
| 812 |
if (fwrite((char *) cm->ndidx, sizeof(int), cm->M, fp) != cm->M) return eslFAIL; |
| 813 |
if (fwrite((char *) cm->stid, sizeof(char), cm->M, fp) != cm->M) return eslFAIL; |
| 814 |
if (fwrite((char *) cm->cfirst, sizeof(int), cm->M, fp) != cm->M) return eslFAIL; |
| 815 |
if (fwrite((char *) cm->cnum, sizeof(int), cm->M, fp) != cm->M) return eslFAIL; |
| 816 |
if (fwrite((char *) cm->plast, sizeof(int), cm->M, fp) != cm->M) return eslFAIL; |
| 817 |
if (fwrite((char *) cm->pnum, sizeof(int), cm->M, fp) != cm->M) return eslFAIL; |
| 818 |
if (fwrite((char *) cm->nodemap, sizeof(int), cm->nodes, fp) != cm->nodes) return eslFAIL; |
| 819 |
if (fwrite((char *) cm->ndtype, sizeof(char), cm->nodes, fp) != cm->nodes) return eslFAIL; |
| 820 |
if (fwrite((char *) cm->qdbinfo->dmin1, sizeof(int), cm->M, fp) != cm->M) return eslFAIL; |
| 821 |
if (fwrite((char *) cm->qdbinfo->dmax1, sizeof(int), cm->M, fp) != cm->M) return eslFAIL; |
| 822 |
if (fwrite((char *) cm->qdbinfo->dmin2, sizeof(int), cm->M, fp) != cm->M) return eslFAIL; |
| 823 |
if (fwrite((char *) cm->qdbinfo->dmax2, sizeof(int), cm->M, fp) != cm->M) return eslFAIL; |
| 824 |
|
| 825 |
for (v = 0; v < cm->M; v++) { |
| 826 |
if (fwrite((char *) cm->t[v], sizeof(float), MAXCONNECT, fp) != MAXCONNECT) return eslFAIL; |
| 827 |
if (fwrite((char *) cm->e[v], sizeof(float), cm->abc->K*cm->abc->K, fp) != (cm->abc->K*cm->abc->K)) return eslFAIL; |
| 828 |
} |
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
if ( write_bin_string(fp, cm->name) != eslOK) return eslFAIL; |
| 833 |
if ((cm->flags & CMH_ACC) && (write_bin_string(fp, cm->acc) != eslOK)) return eslFAIL; |
| 834 |
if ((cm->flags & CMH_DESC) && (write_bin_string(fp, cm->desc) != eslOK)) return eslFAIL; |
| 835 |
if ((cm->flags & CMH_RF) && (fwrite((char *) cm->rf, sizeof(char), cm->clen+2, fp) != cm->clen+2)) return eslFAIL; |
| 836 |
if ((cm->flags & CMH_CONS) && (fwrite((char *) cm->consensus, sizeof(char), cm->clen+2, fp) != cm->clen+2)) return eslFAIL; |
| 837 |
if ((cm->flags & CMH_MAP) && (fwrite((char *) cm->map, sizeof(int), cm->clen+1, fp) != cm->clen+1)) return eslFAIL; |
| 838 |
if (fwrite((char *) &(cm->W), sizeof(int), 1, fp) != 1) return eslFAIL; |
| 839 |
|
| 840 |
if ((write_bin_string(fp, cm->ctime)) != eslOK) return eslFAIL; |
| 841 |
if ((write_bin_string(fp, cm->comlog)) != eslOK) return eslFAIL; |
| 842 |
|
| 843 |
if (fwrite((char *) &(cm->pbegin), sizeof(float), 1, fp) != 1) return eslFAIL; |
| 844 |
if (fwrite((char *) &(cm->pend), sizeof(float), 1, fp) != 1) return eslFAIL; |
| 845 |
if (fwrite((char *) &(cm->beta_W), sizeof(double), 1, fp) != 1) return eslFAIL; |
| 846 |
if (fwrite((char *) &(cm->qdbinfo->beta1), sizeof(double), 1, fp) != 1) return eslFAIL; |
| 847 |
if (fwrite((char *) &(cm->qdbinfo->beta2), sizeof(double), 1, fp) != 1) return eslFAIL; |
| 848 |
if (fwrite((char *) &(cm->null2_omega), sizeof(float), 1, fp) != 1) return eslFAIL; |
| 849 |
if (fwrite((char *) &(cm->null3_omega), sizeof(float), 1, fp) != 1) return eslFAIL; |
| 850 |
if (fwrite((char *) &(cm->el_selfsc), sizeof(float), 1, fp) != 1) return eslFAIL; |
| 851 |
if (fwrite((char *) &(cm->nseq), sizeof(int), 1, fp) != 1) return eslFAIL; |
| 852 |
if (fwrite((char *) &(cm->eff_nseq), sizeof(float), 1, fp) != 1) return eslFAIL; |
| 853 |
if (fwrite((char *) &(cm->checksum), sizeof(uint32_t), 1, fp) != 1) return eslFAIL; |
| 854 |
if (fwrite((char *) cm->null, sizeof(float), cm->abc->K, fp) != cm->abc->K) return eslFAIL; |
| 855 |
|
| 856 |
|
| 857 |
|
| 858 |
if ((cm->flags & CMH_GA) && (fwrite((char *) &(cm->ga), sizeof(float), 1, fp) != 1)) return eslFAIL; |
| 859 |
if ((cm->flags & CMH_TC) && (fwrite((char *) &(cm->tc), sizeof(float), 1, fp) != 1)) return eslFAIL; |
| 860 |
if ((cm->flags & CMH_NC) && (fwrite((char *) &(cm->nc), sizeof(float), 1, fp) != 1)) return eslFAIL; |
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
if (cm->flags & CMH_FP7) { |
| 865 |
if (fwrite((char *) &(cm->fp7_evparam[CM_p7_GFMU]), sizeof(float), 1, fp) != 1) return eslFAIL; |
| 866 |
if (fwrite((char *) &(cm->fp7_evparam[CM_p7_GFLAMBDA]), sizeof(float), 1, fp) != 1) return eslFAIL; |
| 867 |
} |
| 868 |
if (cm->flags & CMH_EXPTAIL_STATS) { |
| 869 |
long dbsize_long; |
| 870 |
for(z = 0; z < EXP_NMODES; z++) { |
| 871 |
|
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
if(cm->expA[z]->dbsize > (2000. * 1000000.)) ESL_EXCEPTION(eslEINVAL, "invalid dbsize (too big)"); |
| 877 |
dbsize_long = (long) cm->expA[z]->dbsize + 0.5; |
| 878 |
if (fwrite((char *) &(cm->expA[z]->lambda), sizeof(double), 1, fp) != 1) return eslFAIL; |
| 879 |
if (fwrite((char *) &(cm->expA[z]->mu_extrap), sizeof(double), 1, fp) != 1) return eslFAIL; |
| 880 |
if (fwrite((char *) &(cm->expA[z]->mu_orig), sizeof(double), 1, fp) != 1) return eslFAIL; |
| 881 |
if (fwrite((char *) &(dbsize_long), sizeof(long), 1, fp) != 1) return eslFAIL; |
| 882 |
if (fwrite((char *) &(cm->expA[z]->nrandhits), sizeof(int), 1, fp) != 1) return eslFAIL; |
| 883 |
if (fwrite((char *) &(cm->expA[z]->tailp), sizeof(double), 1, fp) != 1) return eslFAIL; |
| 884 |
} |
| 885 |
} |
| 886 |
|
| 887 |
|
| 888 |
fp7_offset = 0; |
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
if(cm->flags & CMH_FP7 && cm->fp7 != NULL) { |
| 893 |
if(opt_fp7_offset != NULL) { |
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
if((fp7_offset = ftello(fp)) == -1) ESL_EXCEPTION(eslEINVAL, "failed to determine file position for p7 filter"); |
| 898 |
} |
| 899 |
p7_hmmfile_WriteBinary(fp, -1, cm->fp7); |
| 900 |
} |
| 901 |
|
| 902 |
if(opt_fp7_offset != NULL) *opt_fp7_offset = fp7_offset; |
| 903 |
return eslOK; |
| 904 |
} |
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
static int |
| 920 |
write_bin_string(FILE *fp, char *s) |
| 921 |
{ |
| 922 |
int len; |
| 923 |
if (s != NULL) |
| 924 |
{ |
| 925 |
len = strlen(s) + 1; |
| 926 |
if (fwrite((char *) &len, sizeof(int), 1, fp) != 1) return eslFAIL; |
| 927 |
if (fwrite((char *) s, sizeof(char), len, fp) != len) return eslFAIL; |
| 928 |
} |
| 929 |
else |
| 930 |
{ |
| 931 |
len = 0; |
| 932 |
if (fwrite((char *) &len, sizeof(int), 1, fp) != 1) return eslFAIL; |
| 933 |
} |
| 934 |
return eslOK; |
| 935 |
} |
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
|
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
|
| 979 |
|
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
|
| 985 |
|
| 986 |
|
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
int |
| 1009 |
cm_file_Read(CM_FILE *cmfp, int read_fp7, ESL_ALPHABET **ret_abc, CM_t **opt_cm) |
| 1010 |
{ |
| 1011 |
|
| 1012 |
return (*cmfp->parser)(cmfp, read_fp7, ret_abc, opt_cm); |
| 1013 |
} |
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
|
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
|
| 1033 |
|
| 1034 |
|
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
int |
| 1040 |
cm_file_PositionByKey(CM_FILE *cmfp, const char *key) |
| 1041 |
{ |
| 1042 |
uint16_t fh; |
| 1043 |
off_t offset; |
| 1044 |
int status; |
| 1045 |
|
| 1046 |
if (cmfp->ssi == NULL) ESL_EXCEPTION(eslEINVAL, "Need an open SSI index to call cm_file_PositionByKey()"); |
| 1047 |
if ((status = esl_ssi_FindName(cmfp->ssi, key, &fh, &offset, NULL, NULL)) != eslOK) return status; |
| 1048 |
if (fseeko(cmfp->f, offset, SEEK_SET) != 0) ESL_EXCEPTION(eslESYS, "fseek failed"); |
| 1049 |
|
| 1050 |
cmfp->newly_opened = FALSE; |
| 1051 |
return eslOK; |
| 1052 |
} |
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
int |
| 1071 |
cm_file_Position(CM_FILE *cmfp, const off_t offset) |
| 1072 |
{ |
| 1073 |
if (fseeko(cmfp->f, offset, SEEK_SET) != 0) ESL_EXCEPTION(eslESYS, "fseek failed"); |
| 1074 |
|
| 1075 |
cmfp->newly_opened = FALSE; |
| 1076 |
return eslOK; |
| 1077 |
} |
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
|
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
int |
| 1126 |
cm_p7_hmmfile_Read(CM_FILE *cmfp, ESL_ALPHABET *abc, off_t offset, P7_HMM **ret_hmm) |
| 1127 |
{ |
| 1128 |
int status; |
| 1129 |
P7_HMM *hmm = NULL; |
| 1130 |
char *tok1 = NULL; |
| 1131 |
uint32_t magic; |
| 1132 |
|
| 1133 |
#ifdef HMMER_THREADS |
| 1134 |
if(!cmfp->hfp->do_stdin && !cmfp->hfp->do_gzip) { |
| 1135 |
|
| 1136 |
if (cmfp->hfp->syncRead) { |
| 1137 |
if (pthread_mutex_lock (&cmfp->hfp->readMutex) != 0) ESL_EXCEPTION(eslESYS, "mutex lock failed"); |
| 1138 |
} |
| 1139 |
} |
| 1140 |
#endif |
| 1141 |
if(!cmfp->hfp->do_stdin && !cmfp->hfp->do_gzip) { |
| 1142 |
if (fseeko(cmfp->hfp->f, offset, SEEK_SET) != 0) ESL_XFAIL(eslEINCOMPAT, cmfp->errbuf, "Failed to set position for HMM file parser"); |
| 1143 |
} |
| 1144 |
|
| 1145 |
|
| 1146 |
if(cmfp->hfp->parser == NULL) { |
| 1147 |
if(cmfp->is_binary) { |
| 1148 |
if (! fread((char *) &(magic), sizeof(uint32_t), 1, cmfp->hfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Failed to read magic number at start of p7 additional filters"); |
| 1149 |
if (magic == v3a_magic) { cmfp->hfp->format = p7_HMMFILE_3a; cmfp->hfp->parser = read_bin30hmm; } |
| 1150 |
else if (magic == v3b_magic) { cmfp->hfp->format = p7_HMMFILE_3b; cmfp->hfp->parser = read_bin30hmm; } |
| 1151 |
else if (magic == v3c_magic) { cmfp->hfp->format = p7_HMMFILE_3c; cmfp->hfp->parser = read_bin30hmm; } |
| 1152 |
else if (magic == v3d_magic) { cmfp->hfp->format = p7_HMMFILE_3d; cmfp->hfp->parser = read_bin30hmm; } |
| 1153 |
else if (magic == v3e_magic) { cmfp->hfp->format = p7_HMMFILE_3e; cmfp->hfp->parser = read_bin30hmm; } |
| 1154 |
else if (magic == v3f_magic) { cmfp->hfp->format = p7_HMMFILE_3f; cmfp->hfp->parser = read_bin30hmm; } |
| 1155 |
else ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Unknown magic number for p7 HMM filter"); |
| 1156 |
} |
| 1157 |
else { |
| 1158 |
if(cmfp->hfp->efp != NULL) ESL_XFAIL(eslEINVAL, cmfp->errbuf, "HMM ascii file parsers are out of sync"); |
| 1159 |
if ((cmfp->hfp->efp = esl_fileparser_Create(cmfp->hfp->f)) == NULL) { status = eslEMEM; goto ERROR; } |
| 1160 |
if ((status = esl_fileparser_SetCommentChar(cmfp->hfp->efp, '#')) != eslOK) goto ERROR; |
| 1161 |
if ((status = esl_fileparser_GetToken(cmfp->hfp->efp, &tok1, NULL)) != eslOK) goto ERROR; |
| 1162 |
|
| 1163 |
if (strcmp("HMMER3/f", tok1) == 0) { cmfp->hfp->format = p7_HMMFILE_3f; cmfp->hfp->parser = read_asc30hmm; } |
| 1164 |
else if (strcmp("HMMER3/e", tok1) == 0) { cmfp->hfp->format = p7_HMMFILE_3e; cmfp->hfp->parser = read_asc30hmm; } |
| 1165 |
else if (strcmp("HMMER3/d", tok1) == 0) { cmfp->hfp->format = p7_HMMFILE_3d; cmfp->hfp->parser = read_asc30hmm; } |
| 1166 |
else if (strcmp("HMMER3/c", tok1) == 0) { cmfp->hfp->format = p7_HMMFILE_3c; cmfp->hfp->parser = read_asc30hmm; } |
| 1167 |
else if (strcmp("HMMER3/b", tok1) == 0) { cmfp->hfp->format = p7_HMMFILE_3b; cmfp->hfp->parser = read_asc30hmm; } |
| 1168 |
else if (strcmp("HMMER3/a", tok1) == 0) { cmfp->hfp->format = p7_HMMFILE_3a; cmfp->hfp->parser = read_asc30hmm; } |
| 1169 |
else ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Unknown format for p7 HMM filter"); |
| 1170 |
} |
| 1171 |
} |
| 1172 |
|
| 1173 |
|
| 1174 |
status = p7_hmmfile_Read(cmfp->hfp, &abc, &hmm); |
| 1175 |
if (status == eslEOF) ESL_XFAIL(status, cmfp->errbuf, "failed to read profile HMM piece, CM file may be truncated?"); |
| 1176 |
else if (status == eslEFORMAT) ESL_XFAIL(status, cmfp->errbuf, "bad file format for HMM filter"); |
| 1177 |
else if (status == eslEINCOMPAT) ESL_XFAIL(status, cmfp->errbuf, "HMM filters are of different alphabets"); |
| 1178 |
else if (status != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Unexpected error in reading HMM filters"); |
| 1179 |
|
| 1180 |
#ifdef HMMER_THREADS |
| 1181 |
if(!cmfp->hfp->do_stdin && !cmfp->hfp->do_gzip) { |
| 1182 |
if (cmfp->hfp->syncRead) { |
| 1183 |
if (pthread_mutex_unlock (&cmfp->hfp->readMutex) != 0) ESL_EXCEPTION(eslESYS, "mutex unlock failed"); |
| 1184 |
} |
| 1185 |
} |
| 1186 |
#endif |
| 1187 |
|
| 1188 |
*ret_hmm = hmm; |
| 1189 |
return status; |
| 1190 |
|
| 1191 |
ERROR: |
| 1192 |
#ifdef HMMER_THREADS |
| 1193 |
if(cmfp->hfp->f != NULL) { |
| 1194 |
if (cmfp->hfp->syncRead) { |
| 1195 |
if (pthread_mutex_unlock (&cmfp->hfp->readMutex) != 0) ESL_EXCEPTION(eslESYS, "mutex unlock failed"); |
| 1196 |
} |
| 1197 |
} |
| 1198 |
#endif |
| 1199 |
|
| 1200 |
if(hmm != NULL) p7_hmm_Destroy(hmm); |
| 1201 |
*ret_hmm = NULL; |
| 1202 |
return status; |
| 1203 |
} |
| 1204 |
|
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
|
| 1229 |
|
| 1230 |
|
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
int |
| 1255 |
cm_p7_oprofile_Write(FILE *ffp, FILE *pfp, off_t cm_offset, int cm_clen, int cm_W, int cm_nbp, float gfmu, float gflambda, P7_OPROFILE *om) |
| 1256 |
{ |
| 1257 |
|
| 1258 |
if (fwrite((char *) &(v1a_fmagic), sizeof(uint32_t), 1, ffp) != 1) return eslFAIL; |
| 1259 |
if (fwrite((char *) &(cm_offset), sizeof(off_t), 1, ffp) != 1) return eslFAIL; |
| 1260 |
if (fwrite((char *) &(cm_clen), sizeof(int), 1, ffp) != 1) return eslFAIL; |
| 1261 |
if (fwrite((char *) &(cm_W), sizeof(int), 1, ffp) != 1) return eslFAIL; |
| 1262 |
if (fwrite((char *) &(cm_nbp), sizeof(int), 1, ffp) != 1) return eslFAIL; |
| 1263 |
if (fwrite((char *) &(gfmu), sizeof(float), 1, ffp) != 1) return eslFAIL; |
| 1264 |
if (fwrite((char *) &(gflambda), sizeof(float), 1, ffp) != 1) return eslFAIL; |
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
return p7_oprofile_Write(ffp, pfp, om); |
| 1271 |
} |
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
|
| 1287 |
|
| 1288 |
|
| 1289 |
|
| 1290 |
int |
| 1291 |
cm_p7_oprofile_Position(CM_FILE *cmfp, off_t offset) |
| 1292 |
{ |
| 1293 |
if (cmfp->ffp == NULL) ESL_EXCEPTION(eslEFORMAT, cmfp->errbuf, "no MSV profile file; cmpress probably wasn't run"); |
| 1294 |
if (cmfp->do_stdin) ESL_EXCEPTION(eslEINVAL, "can't Position() in standard input"); |
| 1295 |
if (cmfp->do_gzip) ESL_EXCEPTION(eslEINVAL, "can't Position() in a gzipped file"); |
| 1296 |
if (offset < 0) ESL_EXCEPTION(eslEINVAL, "bad offset"); |
| 1297 |
|
| 1298 |
if (fseeko(cmfp->ffp, offset, SEEK_SET) != 0) ESL_EXCEPTION(eslESYS, "fseeko() failed"); |
| 1299 |
|
| 1300 |
return eslOK; |
| 1301 |
} |
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
|
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
|
| 1350 |
|
| 1351 |
|
| 1352 |
|
| 1353 |
|
| 1354 |
|
| 1355 |
|
| 1356 |
|
| 1357 |
|
| 1358 |
|
| 1359 |
|
| 1360 |
|
| 1361 |
|
| 1362 |
|
| 1363 |
|
| 1364 |
|
| 1365 |
|
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
int |
| 1370 |
cm_p7_oprofile_ReadMSV(CM_FILE *cmfp, int read_scores, ESL_ALPHABET **byp_abc, off_t *ret_cm_offset, int *ret_cm_clen, int *ret_cm_W, int *ret_cm_nbp, float *ret_gfmu, float *ret_gflambda, P7_OPROFILE **ret_om) |
| 1371 |
{ |
| 1372 |
int status = eslOK; |
| 1373 |
uint32_t magic; |
| 1374 |
off_t cm_offset; |
| 1375 |
int cm_clen; |
| 1376 |
int cm_W; |
| 1377 |
int cm_nbp; |
| 1378 |
float gfmu; |
| 1379 |
float gflambda; |
| 1380 |
P7_OPROFILE *om = NULL; |
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
cmfp->msv_errbuf[0] = '\0'; |
| 1387 |
if (cmfp->ffp == NULL) ESL_XFAIL(eslEFORMAT, cmfp->msv_errbuf, "no MSV profile file; cmpress probably wasn't run"); |
| 1388 |
|
| 1389 |
if (feof(cmfp->ffp)) { status = eslEOF; goto ERROR; } |
| 1390 |
if (! fread( (char *) &magic, sizeof(uint32_t), 1, cmfp->ffp)) { status = eslEOF; goto ERROR; } |
| 1391 |
if (magic != v1a_fmagic) ESL_XFAIL(eslEFORMAT, cmfp->msv_errbuf, "bad magic; not a CM database?"); |
| 1392 |
|
| 1393 |
if (! fread( (char *) &cm_offset, sizeof(off_t), 1, cmfp->ffp)) ESL_XFAIL(eslEFORMAT, cmfp->msv_errbuf, "failed to read CM offset"); |
| 1394 |
if (! fread( (char *) &cm_clen, sizeof(int), 1, cmfp->ffp)) ESL_XFAIL(eslEFORMAT, cmfp->msv_errbuf, "failed to read CM consensus length"); |
| 1395 |
if (! fread( (char *) &cm_W, sizeof(int), 1, cmfp->ffp)) ESL_XFAIL(eslEFORMAT, cmfp->msv_errbuf, "failed to read CM window length (W)"); |
| 1396 |
if (! fread( (char *) &cm_nbp, sizeof(int), 1, cmfp->ffp)) ESL_XFAIL(eslEFORMAT, cmfp->msv_errbuf, "failed to read CM number of bps"); |
| 1397 |
if (! fread( (char *) &gfmu, sizeof(int), 1, cmfp->ffp)) ESL_XFAIL(eslEFORMAT, cmfp->msv_errbuf, "failed to read glocal fwd mu parameter"); |
| 1398 |
if (! fread( (char *) &gflambda, sizeof(int), 1, cmfp->ffp)) ESL_XFAIL(eslEFORMAT, cmfp->msv_errbuf, "failed to read glocal fwd lambda parameter"); |
| 1399 |
|
| 1400 |
|
| 1401 |
if (fseeko(cmfp->hfp->ffp, ftello(cmfp->ffp), SEEK_SET) != 0) ESL_XFAIL(eslEINCOMPAT, cmfp->msv_errbuf, "failed to set position for HMM file parser (MSV)"); |
| 1402 |
if (read_scores) { |
| 1403 |
if ((status = p7_oprofile_ReadMSV(cmfp->hfp, byp_abc, &om)) != eslOK) ESL_XFAIL(status, cmfp->msv_errbuf, "failed to read MSV filter model"); |
| 1404 |
} |
| 1405 |
else { |
| 1406 |
if ((status = p7_oprofile_ReadInfoMSV(cmfp->hfp, byp_abc, &om)) != eslOK) ESL_XFAIL(status, cmfp->msv_errbuf, "failed to read MSV info"); |
| 1407 |
} |
| 1408 |
|
| 1409 |
if (fseeko(cmfp->ffp, ftello(cmfp->hfp->ffp), SEEK_SET) != 0) ESL_XFAIL(eslEINCOMPAT, cmfp->msv_errbuf, "Failed to set position for CM file parser (MSV)"); |
| 1410 |
|
| 1411 |
if(ret_cm_offset != NULL) *ret_cm_offset = cm_offset; |
| 1412 |
if(ret_cm_clen != NULL) *ret_cm_clen = cm_clen; |
| 1413 |
if(ret_cm_W != NULL) *ret_cm_W = cm_W; |
| 1414 |
if(ret_cm_nbp != NULL) *ret_cm_nbp = cm_nbp; |
| 1415 |
if(ret_gfmu != NULL) *ret_gfmu = gfmu; |
| 1416 |
if(ret_gflambda != NULL) *ret_gflambda = gflambda; |
| 1417 |
if(ret_om != NULL) *ret_om = om; |
| 1418 |
return eslOK; |
| 1419 |
|
| 1420 |
ERROR: |
| 1421 |
if (om != NULL) p7_oprofile_Destroy(om); |
| 1422 |
if (ret_om != NULL) *ret_om = NULL; |
| 1423 |
return status; |
| 1424 |
} |
| 1425 |
|
| 1426 |
|
| 1427 |
|
| 1428 |
|
| 1429 |
|
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
|
| 1437 |
|
| 1438 |
|
| 1439 |
|
| 1440 |
|
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
|
| 1456 |
|
| 1457 |
int |
| 1458 |
cm_p7_oprofile_ReadBlockMSV(CM_FILE *cmfp, int64_t idx0, ESL_ALPHABET **byp_abc, CM_P7_OM_BLOCK *hmmBlock) |
| 1459 |
{ |
| 1460 |
int status = eslOK; |
| 1461 |
int i; |
| 1462 |
|
| 1463 |
hmmBlock->count = 0; |
| 1464 |
hmmBlock->idx0 = idx0; |
| 1465 |
for (i = 0; i < hmmBlock->listSize; ++i) |
| 1466 |
{ |
| 1467 |
status = cm_p7_oprofile_ReadMSV(cmfp, TRUE, byp_abc, |
| 1468 |
&(hmmBlock->cm_offsetA[i]), |
| 1469 |
&(hmmBlock->cm_clenA[i]), |
| 1470 |
&(hmmBlock->cm_WA[i]), |
| 1471 |
&(hmmBlock->cm_nbpA[i]), |
| 1472 |
&(hmmBlock->gfmuA[i]), |
| 1473 |
&(hmmBlock->gflambdaA[i]), |
| 1474 |
&(hmmBlock->list[i])); |
| 1475 |
if (status != eslOK) break; |
| 1476 |
++hmmBlock->count; |
| 1477 |
} |
| 1478 |
|
| 1479 |
for (i = 0; i < hmmBlock->count; ++i) { |
| 1480 |
hmmBlock->msvdataA[i] = p7_hmm_ScoreDataCreate(hmmBlock->list[i], FALSE); |
| 1481 |
} |
| 1482 |
|
| 1483 |
for (i = 0; i < hmmBlock->count; ++i) { |
| 1484 |
hmmBlock->clan_idxA[i] = -1; |
| 1485 |
} |
| 1486 |
|
| 1487 |
|
| 1488 |
if (status == eslEOF && i > 0) status = eslOK; |
| 1489 |
|
| 1490 |
return status; |
| 1491 |
} |
| 1492 |
|
| 1493 |
|
| 1494 |
|
| 1495 |
|
| 1496 |
|
| 1497 |
|
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
|
| 1505 |
|
| 1506 |
|
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
|
| 1537 |
|
| 1538 |
static int |
| 1539 |
read_asc_1p1_cm(CM_FILE *cmfp, int read_fp7, ESL_ALPHABET **ret_abc, CM_t **opt_cm) |
| 1540 |
{ |
| 1541 |
int status; |
| 1542 |
ESL_ALPHABET *abc = NULL; |
| 1543 |
CM_t *cm = NULL; |
| 1544 |
P7_HMM *hmm = NULL; |
| 1545 |
char *tag = NULL; |
| 1546 |
char *tok1 = NULL; |
| 1547 |
char *tok2 = NULL; |
| 1548 |
char *tok3 = NULL; |
| 1549 |
char *tok4 = NULL; |
| 1550 |
char *tok5 = NULL; |
| 1551 |
char *tok6 = NULL; |
| 1552 |
int alphatype; |
| 1553 |
off_t offset = 0; |
| 1554 |
off_t fp7_offset = 0; |
| 1555 |
int v, x, y, nd; |
| 1556 |
int read_fp7_stats = FALSE; |
| 1557 |
uint32_t cm_statstracker = 0; |
| 1558 |
int exp_mode; |
| 1559 |
int read_el_selfsc = FALSE; |
| 1560 |
|
| 1561 |
|
| 1562 |
float *tmp_null = NULL; |
| 1563 |
float tmp_fp7_gfmu; |
| 1564 |
float tmp_fp7_gflambda; |
| 1565 |
double tmp_qdbbeta1; |
| 1566 |
double tmp_qdbbeta2; |
| 1567 |
|
| 1568 |
|
| 1569 |
|
| 1570 |
char *tmp_rf_left = NULL; |
| 1571 |
char *tmp_rf_right = NULL; |
| 1572 |
char *tmp_cons_left = NULL; |
| 1573 |
char *tmp_cons_right = NULL; |
| 1574 |
int *tmp_map_left = NULL; |
| 1575 |
int *tmp_map_right = NULL; |
| 1576 |
|
| 1577 |
cmfp->errbuf[0] = '\0'; |
| 1578 |
|
| 1579 |
if (cmfp->newly_opened) |
| 1580 |
{ |
| 1581 |
offset = 0; |
| 1582 |
cmfp->newly_opened = FALSE; |
| 1583 |
} |
| 1584 |
else |
| 1585 |
{ |
| 1586 |
|
| 1587 |
if ((! cmfp->do_stdin) && (! cmfp->do_gzip) && (offset = ftello(cmfp->f)) < 0) ESL_XEXCEPTION(eslESYS, "ftello() failed"); |
| 1588 |
|
| 1589 |
|
| 1590 |
if ((status = esl_fileparser_NextLine(cmfp->efp)) != eslOK) goto ERROR; |
| 1591 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tag, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "unexpected absence of tokens on data line"); |
| 1592 |
|
| 1593 |
if (cmfp->format == CM_FILE_1a) { if (strcmp(tag, "INFERNAL1/a") != 0) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Didn't find INFERNAL1/a tag: bad format or not an INFERNAL save file?"); } |
| 1594 |
else ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No such CM file format code: this shouldn't happen"); |
| 1595 |
} |
| 1596 |
|
| 1597 |
if ((cm = CreateCMShell()) == NULL) ESL_XFAIL(eslEMEM, cmfp->errbuf, "allocation failure, CM shell"); |
| 1598 |
cm->offset = offset; |
| 1599 |
|
| 1600 |
|
| 1601 |
while ((status = esl_fileparser_NextLine(cmfp->efp)) == eslOK) |
| 1602 |
{ |
| 1603 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tag, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Premature end of line"); |
| 1604 |
|
| 1605 |
if (strcmp(tag, "NAME") == 0) { |
| 1606 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "No name found on NAME line"); |
| 1607 |
cm_SetName(cm, tok1); |
| 1608 |
} |
| 1609 |
|
| 1610 |
else if (strcmp(tag, "ACC") == 0) { |
| 1611 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "No accession found on ACC line"); |
| 1612 |
cm_SetAccession(cm, tok1); |
| 1613 |
} |
| 1614 |
|
| 1615 |
else if (strcmp(tag, "DESC") == 0) { |
| 1616 |
if ((status = esl_fileparser_GetRemainingLine(cmfp->efp, &tok1)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "No description found on DESC line"); |
| 1617 |
cm_SetDescription(cm, tok1); |
| 1618 |
} |
| 1619 |
|
| 1620 |
else if (strcmp(tag, "STATES") == 0) { |
| 1621 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Number of model states not found on STATES line"); |
| 1622 |
if ((cm->M = atoi(tok1)) == 0) ESL_XFAIL(status, cmfp->errbuf, "Invalid number of states %s on STATES line", tok1); |
| 1623 |
} |
| 1624 |
|
| 1625 |
else if (strcmp(tag, "NODES") == 0) { |
| 1626 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Number of model nodes not found on NODES line"); |
| 1627 |
if ((cm->nodes = atoi(tok1)) == 0) ESL_XFAIL(status, cmfp->errbuf, "Invalid number of nodes %s on NODES line", tok1); |
| 1628 |
} |
| 1629 |
|
| 1630 |
else if (strcmp(tag, "CLEN") == 0) { |
| 1631 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "No consensus length found on CLEN line"); |
| 1632 |
if ((cm->clen = atoi(tok1)) == 0) ESL_XFAIL(status, cmfp->errbuf, "Invalid consensus length %s on CLEN line", tok1); |
| 1633 |
} |
| 1634 |
|
| 1635 |
else if (strcmp(tag, "W") == 0) { |
| 1636 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "No consensus length found on W line"); |
| 1637 |
if ((cm->W = atoi(tok1)) == 0) ESL_XFAIL(status, cmfp->errbuf, "Invalid consensus length %s on W line", tok1); |
| 1638 |
} |
| 1639 |
|
| 1640 |
else if (strcmp(tag, "ALPH") == 0) { |
| 1641 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "No alphabet type found on ALPH"); |
| 1642 |
if ((alphatype = esl_abc_EncodeType(tok1)) == eslUNKNOWN) ESL_XFAIL(status, cmfp->errbuf, "Unrecognized alphabet type %s", tok1); |
| 1643 |
if (*ret_abc == NULL) { |
| 1644 |
if ((abc = esl_alphabet_Create(alphatype)) == NULL) ESL_XFAIL(eslEMEM, cmfp->errbuf, "Failed to create alphabet"); |
| 1645 |
} else { |
| 1646 |
if ((*ret_abc)->type != alphatype) ESL_XFAIL(eslEINCOMPAT,cmfp->errbuf,"Alphabet type mismatch: was %s, but current CM says %s", esl_abc_DecodeType( (*ret_abc)->type), tok1); |
| 1647 |
abc = *ret_abc; |
| 1648 |
} |
| 1649 |
} |
| 1650 |
|
| 1651 |
else if (strcmp(tag, "RF") == 0) { |
| 1652 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "No yes/no found for RF line"); |
| 1653 |
if (strcasecmp(tok1, "yes") == 0) cm->flags |= CMH_RF; |
| 1654 |
else if (strcasecmp(tok1, "no") != 0) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "RF header line must say yes/no, not %s", tok1); |
| 1655 |
} |
| 1656 |
|
| 1657 |
else if (strcmp(tag, "CONS") == 0) { |
| 1658 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "No yes/no found for CONS line"); |
| 1659 |
if (strcasecmp(tok1, "yes") == 0) cm->flags |= CMH_CONS; |
| 1660 |
else if (strcasecmp(tok1, "no") != 0) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "CONS header line must say yes/no, not %s", tok1); |
| 1661 |
} |
| 1662 |
|
| 1663 |
else if (strcmp(tag, "MAP") == 0) { |
| 1664 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "No yes/no found for MAP line"); |
| 1665 |
if (strcasecmp(tok1, "yes") == 0) cm->flags |= CMH_MAP; |
| 1666 |
else if (strcasecmp(tok1, "no") != 0) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "MAP header line must say yes/no, not %s", tok1); |
| 1667 |
} |
| 1668 |
|
| 1669 |
else if (strcmp(tag, "DATE") == 0) { |
| 1670 |
if ((status = esl_fileparser_GetRemainingLine(cmfp->efp, &tok1)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "No date found on DATE line"); |
| 1671 |
if (esl_strdup(tok1, -1, &(cm->ctime)) != eslOK) ESL_XFAIL(eslEMEM, cmfp->errbuf, "strdup() failed to set date"); |
| 1672 |
} |
| 1673 |
|
| 1674 |
else if (strcmp(tag, "COM") == 0) { |
| 1675 |
|
| 1676 |
if ((status = esl_fileparser_GetTokenOnLine (cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "No command number on COM line"); |
| 1677 |
if ((status = esl_fileparser_GetRemainingLine(cmfp->efp, &tok1)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "No command on COM line"); |
| 1678 |
if (cm->comlog == NULL) { |
| 1679 |
if (esl_strdup(tok1, -1, &(cm->comlog)) != eslOK) ESL_XFAIL(eslEMEM, cmfp->errbuf, "esl_strdup() failed"); |
| 1680 |
} else { |
| 1681 |
if (esl_strcat(&(cm->comlog), -1, "\n", -1) != eslOK) ESL_XFAIL(eslEMEM, cmfp->errbuf, "esl_strcat() failed"); |
| 1682 |
if (esl_strcat(&(cm->comlog), -1, tok1, -1) != eslOK) ESL_XFAIL(eslEMEM, cmfp->errbuf, "esl_strcat() failed"); |
| 1683 |
} |
| 1684 |
} |
| 1685 |
|
| 1686 |
else if (strcmp(tag, "PBEGIN") == 0) { |
| 1687 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Nothing follows PBEGIN tag"); |
| 1688 |
if ((cm->pbegin = atof(tok1)) <= 0.0f) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid beta on PBEGIN line: should be a positive real number, not %s", tok1); |
| 1689 |
} |
| 1690 |
|
| 1691 |
else if (strcmp(tag, "PEND") == 0) { |
| 1692 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Nothing follows PEND tag"); |
| 1693 |
if ((cm->pend = atof(tok1)) <= 0.0f) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid beta on PEND line: should be a positive real number, not %s", tok1); |
| 1694 |
} |
| 1695 |
|
| 1696 |
else if (strcmp(tag, "WBETA") == 0) { |
| 1697 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Nothing follows WBETA tag"); |
| 1698 |
if ((cm->beta_W = atof(tok1)) <= 0.0f) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid beta on WBETA line: should be a positive real number, not %s", tok1); |
| 1699 |
} |
| 1700 |
|
| 1701 |
else if (strcmp(tag, "QDBBETA1") == 0) { |
| 1702 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Nothing follows QDBBETA tag"); |
| 1703 |
if ((tmp_qdbbeta1 = atof(tok1)) <= 0.0f) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid beta on QDBBETA line: should be a positive real number, not %s", tok1); |
| 1704 |
} |
| 1705 |
|
| 1706 |
else if (strcmp(tag, "QDBBETA2") == 0) { |
| 1707 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Nothing follows QDBBETA tag"); |
| 1708 |
if ((tmp_qdbbeta2 = atof(tok1)) <= 0.0f) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid beta on QDBBETA line: should be a positive real number, not %s", tok1); |
| 1709 |
} |
| 1710 |
|
| 1711 |
else if (strcmp(tag, "N2OMEGA") == 0) { |
| 1712 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Nothing follows N2OMEGA tag"); |
| 1713 |
if ((cm->null2_omega = atof(tok1)) <= 0.0f) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid omega on N2OMEGA line: should be a positive real number, not %s", tok1); |
| 1714 |
} |
| 1715 |
|
| 1716 |
else if (strcmp(tag, "N3OMEGA") == 0) { |
| 1717 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Nothing follows N3OMEGA tag"); |
| 1718 |
if ((cm->null3_omega = atof(tok1)) <= 0.0f) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid omega on N3OMEGA line: should be a positive real number, not %s", tok1); |
| 1719 |
} |
| 1720 |
|
| 1721 |
else if (strcmp(tag, "ELSELF") == 0) { |
| 1722 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Nothing follows ELSELF tag"); |
| 1723 |
cm->el_selfsc = atof(tok1); |
| 1724 |
read_el_selfsc = TRUE; |
| 1725 |
} |
| 1726 |
|
| 1727 |
else if (strcmp(tag, "NSEQ") == 0) { |
| 1728 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Nothing follows NSEQ tag"); |
| 1729 |
if ((cm->nseq = atoi(tok1)) == 0) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid nseq on NSEQ line: should be integer, not %s", tok1); |
| 1730 |
} |
| 1731 |
|
| 1732 |
else if (strcmp(tag, "EFFN") == 0) { |
| 1733 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Nothing follows EFFN tag"); |
| 1734 |
if ((cm->eff_nseq = atof(tok1)) < (-1.*eslSMALLX1)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid eff_nseq on EFFN line: should be a positive real number, not %s", tok1); |
| 1735 |
} |
| 1736 |
|
| 1737 |
else if (strcmp(tag, "CKSUM") == 0) { |
| 1738 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Nothing follows CKSUM tag"); |
| 1739 |
cm->checksum = atoll(tok1); |
| 1740 |
cm->flags |= CMH_CHKSUM; |
| 1741 |
} |
| 1742 |
|
| 1743 |
else if (strcmp(tag, "NULL") == 0) { |
| 1744 |
if(abc == NULL) ESL_XFAIL(status, cmfp->errbuf, "Read NULL line before ALPH line, ALPH line must come first"); |
| 1745 |
ESL_ALLOC(tmp_null, sizeof(float) * abc->K); |
| 1746 |
for (x = 0; x < abc->K; x++) { |
| 1747 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on NULL line"); |
| 1748 |
tmp_null[x] = ascii2prob(tok1, (1./(float) abc->K)); |
| 1749 |
} |
| 1750 |
} |
| 1751 |
|
| 1752 |
else if (strcmp(tag, "GA") == 0) { |
| 1753 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on GA line"); |
| 1754 |
cm->ga = atof(tok1); |
| 1755 |
cm->flags |= CMH_GA; |
| 1756 |
} |
| 1757 |
|
| 1758 |
else if (strcmp(tag, "TC") == 0) { |
| 1759 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on TC line"); |
| 1760 |
cm->tc = atof(tok1); |
| 1761 |
cm->flags |= CMH_TC; |
| 1762 |
} |
| 1763 |
|
| 1764 |
else if (strcmp(tag, "NC") == 0) { |
| 1765 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on NC line"); |
| 1766 |
cm->nc = atof(tok1); |
| 1767 |
cm->flags |= CMH_NC; |
| 1768 |
} |
| 1769 |
|
| 1770 |
else if (strcmp(tag, "EFP7GF") == 0) { |
| 1771 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on EFP7GF line"); |
| 1772 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok2, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on EFP7GF line"); |
| 1773 |
tmp_fp7_gfmu = atof(tok1); |
| 1774 |
tmp_fp7_gflambda = atof(tok2); |
| 1775 |
read_fp7_stats = TRUE; |
| 1776 |
} |
| 1777 |
|
| 1778 |
else if (strncmp(tag, "ECM", 3) == 0) { |
| 1779 |
|
| 1780 |
if (strncmp(tag+3, "LC", 2) == 0) { exp_mode = EXP_CM_LC; cm_statstracker += 1; } |
| 1781 |
else if (strncmp(tag+3, "GC", 2) == 0) { exp_mode = EXP_CM_GC; cm_statstracker += 2; } |
| 1782 |
else if (strncmp(tag+3, "LI", 2) == 0) { exp_mode = EXP_CM_LI; cm_statstracker += 4; } |
| 1783 |
else if (strncmp(tag+3, "GI", 2) == 0) { exp_mode = EXP_CM_GI; cm_statstracker += 8; } |
| 1784 |
else { ESL_XFAIL(status, cmfp->errbuf, "Invalid tag beginning with ECM"); } |
| 1785 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on ECM.. line"); |
| 1786 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok2, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on ECM.. line"); |
| 1787 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok3, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on ECM.. line"); |
| 1788 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok4, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on ECM.. line"); |
| 1789 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok5, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on ECM.. line"); |
| 1790 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok6, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on ECM.. line"); |
| 1791 |
if (cm->expA == NULL) { |
| 1792 |
ESL_ALLOC(cm->expA, sizeof(ExpInfo_t *) * EXP_NMODES); |
| 1793 |
for(x = 0; x < EXP_NMODES; x++) { cm->expA[x] = CreateExpInfo(); } |
| 1794 |
} |
| 1795 |
cm->expA[exp_mode]->lambda = atof(tok1); |
| 1796 |
cm->expA[exp_mode]->mu_extrap = atof(tok2); |
| 1797 |
cm->expA[exp_mode]->mu_orig = atof(tok3); |
| 1798 |
cm->expA[exp_mode]->dbsize = atof(tok4); |
| 1799 |
cm->expA[exp_mode]->nrandhits = atoi(tok5); |
| 1800 |
cm->expA[exp_mode]->tailp = atof(tok6); |
| 1801 |
cm->expA[exp_mode]->is_valid = TRUE; |
| 1802 |
} |
| 1803 |
else if (strcmp(tag, "CM") == 0) { |
| 1804 |
|
| 1805 |
if ((status = esl_fileparser_NextLine(cmfp->efp)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Premature end of data before main model section"); |
| 1806 |
break; |
| 1807 |
} |
| 1808 |
} |
| 1809 |
if (status != eslOK) goto ERROR; |
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
if (cm->M < 1) ESL_XFAIL(status, cmfp->errbuf, "Failed to read STATES line in header section"); |
| 1815 |
if (cm->nodes < 1) ESL_XFAIL(status, cmfp->errbuf, "Failed to read NODES line in header section"); |
| 1816 |
if (cm->clen < 1) ESL_XFAIL(status, cmfp->errbuf, "Failed to read CLEN line in header section"); |
| 1817 |
if (cm->W < 1) ESL_XFAIL(status, cmfp->errbuf, "Failed to read W line in header section"); |
| 1818 |
if (! read_el_selfsc) ESL_XFAIL(status, cmfp->errbuf, "Failed to read ELSELF line in header section"); |
| 1819 |
if (! read_fp7_stats) ESL_XFAIL(status, cmfp->errbuf, "Failed to read EFP7GF line in header section"); |
| 1820 |
if (cm->name == NULL) ESL_XFAIL(status, cmfp->errbuf, "Failed to read NAME line in header section"); |
| 1821 |
if (abc == NULL) ESL_XFAIL(status, cmfp->errbuf, "Failed to read ALPH line in header section"); |
| 1822 |
if (tmp_null == NULL) ESL_XFAIL(status, cmfp->errbuf, "Failed to read NULL line in header section"); |
| 1823 |
|
| 1824 |
|
| 1825 |
|
| 1826 |
if (cm->expA != NULL) { |
| 1827 |
if (cm_statstracker == 15) cm->flags |= CMH_EXPTAIL_STATS; |
| 1828 |
else if (cm_statstracker != 0) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Missing one or more ECM.. parameter lines"); |
| 1829 |
} |
| 1830 |
|
| 1831 |
|
| 1832 |
CreateCMBody(cm, cm->nodes, cm->M, cm->clen, abc); |
| 1833 |
|
| 1834 |
|
| 1835 |
esl_vec_FCopy(tmp_null, abc->K, cm->null); |
| 1836 |
cm->qdbinfo->beta1 = tmp_qdbbeta1; |
| 1837 |
cm->qdbinfo->beta2 = tmp_qdbbeta2; |
| 1838 |
|
| 1839 |
|
| 1840 |
|
| 1841 |
ESL_ALLOC(tmp_map_left, sizeof(int) * cm->nodes); |
| 1842 |
ESL_ALLOC(tmp_map_right, sizeof(int) * cm->nodes); |
| 1843 |
esl_vec_ISet(tmp_map_left, cm->nodes, -1); |
| 1844 |
esl_vec_ISet(tmp_map_right, cm->nodes, -1); |
| 1845 |
|
| 1846 |
ESL_ALLOC(tmp_rf_left, sizeof(char) * (cm->nodes+1)); |
| 1847 |
ESL_ALLOC(tmp_rf_right, sizeof(char) * (cm->nodes+1)); |
| 1848 |
tmp_rf_left[cm->nodes] = '\0'; |
| 1849 |
tmp_rf_right[cm->nodes] = '\0'; |
| 1850 |
|
| 1851 |
ESL_ALLOC(tmp_cons_left, sizeof(char) * (cm->nodes+1)); |
| 1852 |
ESL_ALLOC(tmp_cons_right, sizeof(char) * (cm->nodes+1)); |
| 1853 |
tmp_cons_left[cm->nodes] = '\0'; |
| 1854 |
tmp_cons_right[cm->nodes] = '\0'; |
| 1855 |
|
| 1856 |
nd = -1; |
| 1857 |
cm->clen = 0; |
| 1858 |
|
| 1859 |
for (v = 0; v < cm->M; v++) |
| 1860 |
{ |
| 1861 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Premature end of data before main model section"); |
| 1862 |
|
| 1863 |
|
| 1864 |
|
| 1865 |
if (*tok1 == '[') |
| 1866 |
{ |
| 1867 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on node line: expected %d, got %d", 10, 1); |
| 1868 |
if ((x = NodeCode(tok1)) == -1) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid node type %s", tok1); |
| 1869 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on node line: expected %d, got %d", 10, 2); |
| 1870 |
if (!is_integer(tok1)) ESL_XFAIL(status, cmfp->errbuf, "Invalid node index on node line: should be integer >= 0, not %s", tok1); |
| 1871 |
nd = atoi(tok1); |
| 1872 |
if (nd < 0) ESL_XFAIL(status, cmfp->errbuf, "Invalid node index on node line: should be integer >= 0, not %s", tok1); |
| 1873 |
if (nd >= cm->nodes) ESL_XFAIL(status, cmfp->errbuf, "Invalid node index on node line: should not exceed %d, read %s", cm->nodes, tok1); |
| 1874 |
cm->ndtype[nd] = x; |
| 1875 |
if (cm->ndtype[nd] == MATP_nd) cm->clen+=2; |
| 1876 |
else if(cm->ndtype[nd] == MATL_nd) cm->clen++; |
| 1877 |
else if(cm->ndtype[nd] == MATR_nd) cm->clen++; |
| 1878 |
cm->nodemap[nd] = v; |
| 1879 |
|
| 1880 |
|
| 1881 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on node line: expected %d, got %d", 10, 3); |
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
|
| 1886 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on node line: expected %d, got %d", 10, 4); |
| 1887 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok2, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on node line: expected %d, got %d", 10, 5); |
| 1888 |
if ((cm->flags & CMH_MAP) && cm->ndtype[nd] == MATP_nd) { |
| 1889 |
if (!is_integer(tok1)) ESL_XFAIL(status, cmfp->errbuf, "Invalid 1st MAP value on MATP node line: should be positive integer, not %s", tok1); |
| 1890 |
if (!is_integer(tok2)) ESL_XFAIL(status, cmfp->errbuf, "Invalid 2nd MAP value on MATP node line: should be positive integer, not %s", tok2); |
| 1891 |
tmp_map_left[nd] = atoi(tok1); |
| 1892 |
tmp_map_right[nd] = atoi(tok2); |
| 1893 |
} |
| 1894 |
else if((cm->flags & CMH_MAP) && cm->ndtype[nd] == MATL_nd) { |
| 1895 |
if (!is_integer(tok1)) ESL_XFAIL(status, cmfp->errbuf, "Invalid 1st MAP value on MATL node line: should be positive integer, not %s", tok1); |
| 1896 |
if (*tok2 != '-') ESL_XFAIL(status, cmfp->errbuf, "Invalid 2nd MAP value on MATL node line: should be '-', not %s", tok2); |
| 1897 |
tmp_map_left[nd] = atoi(tok1); |
| 1898 |
tmp_map_right[nd] = -1; |
| 1899 |
} |
| 1900 |
else if((cm->flags & CMH_MAP) && cm->ndtype[nd] == MATR_nd) { |
| 1901 |
if (*tok1 != '-') ESL_XFAIL(status, cmfp->errbuf, "Invalid 1st MAP value on MATR node line: should be '-', not %s", tok1); |
| 1902 |
if (!is_integer(tok2)) ESL_XFAIL(status, cmfp->errbuf, "Invalid 2nd MAP value on MATR node line: should be positive integer, not %s", tok2); |
| 1903 |
tmp_map_left[nd] = -1; |
| 1904 |
tmp_map_right[nd] = atoi(tok2); |
| 1905 |
} |
| 1906 |
else { |
| 1907 |
if (*tok1 != '-') ESL_XFAIL(status, cmfp->errbuf, "Invalid 1st MAP value on node line: should be '-', not %s", tok1); |
| 1908 |
if (*tok2 != '-') ESL_XFAIL(status, cmfp->errbuf, "Invalid 2nd MAP value on node line: should be '-', not %s", tok2); |
| 1909 |
tmp_map_left[nd] = -1; |
| 1910 |
tmp_map_right[nd] = -1; |
| 1911 |
} |
| 1912 |
|
| 1913 |
|
| 1914 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on node line: expected %d, got %d", 10, 6); |
| 1915 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok2, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on node line: expected %d, got %d", 10, 7); |
| 1916 |
if ((cm->flags & CMH_CONS) && (cm->ndtype[nd] == MATP_nd)) { |
| 1917 |
tmp_cons_left[nd] = *tok1; |
| 1918 |
tmp_cons_right[nd] = *tok2; |
| 1919 |
} |
| 1920 |
else if((cm->flags & CMH_CONS) && cm->ndtype[nd] == MATL_nd) { |
| 1921 |
if (*tok2 != '-') ESL_XFAIL(status, cmfp->errbuf, "Invalid 2nd consensus character on MATL node line: should be '-', not %s", tok2); |
| 1922 |
tmp_cons_left[nd] = *tok1; |
| 1923 |
tmp_cons_right[nd] = *tok2; |
| 1924 |
} |
| 1925 |
else if((cm->flags & CMH_CONS) && cm->ndtype[nd] == MATR_nd) { |
| 1926 |
if (*tok1 != '-') ESL_XFAIL(status, cmfp->errbuf, "Invalid 1st consensus character on MATR node line: should be '-', not %s", tok1); |
| 1927 |
tmp_cons_left[nd] = *tok1; |
| 1928 |
tmp_cons_right[nd] = *tok2; |
| 1929 |
} |
| 1930 |
else { |
| 1931 |
if (*tok1 != '-') ESL_XFAIL(status, cmfp->errbuf, "Invalid 1st consensus character on node line: should be '-', not %s", tok1); |
| 1932 |
if (*tok2 != '-') ESL_XFAIL(status, cmfp->errbuf, "Invalid 2nd consensus character on node line: should be '-', not %s", tok2); |
| 1933 |
tmp_cons_left[nd] = *tok1; |
| 1934 |
tmp_cons_right[nd] = *tok2; |
| 1935 |
} |
| 1936 |
|
| 1937 |
|
| 1938 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on node line: expected %d, got %d", 10, 8); |
| 1939 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok2, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on node line: expected %d, got %d", 10, 9); |
| 1940 |
if ((cm->flags & CMH_RF) && cm->ndtype[nd] == MATP_nd) { |
| 1941 |
tmp_rf_left[nd] = *tok1; |
| 1942 |
tmp_rf_right[nd] = *tok2; |
| 1943 |
} |
| 1944 |
else if((cm->flags & CMH_RF) && cm->ndtype[nd] == MATL_nd) { |
| 1945 |
if (*tok2 != '-') ESL_XFAIL(status, cmfp->errbuf, "Invalid 2nd RF character on MATL node line: should be '-', not %s", tok2); |
| 1946 |
tmp_rf_left[nd] = *tok1; |
| 1947 |
tmp_rf_right[nd] = *tok2; |
| 1948 |
} |
| 1949 |
else if((cm->flags & CMH_RF) && cm->ndtype[nd] == MATR_nd) { |
| 1950 |
if (*tok1 != '-') ESL_XFAIL(status, cmfp->errbuf, "Invalid 1st RF character on MATR node line: should be '-', not %s", tok1); |
| 1951 |
tmp_rf_left[nd] = *tok1; |
| 1952 |
tmp_rf_right[nd] = *tok2; |
| 1953 |
} |
| 1954 |
else { |
| 1955 |
if (*tok1 != '-') ESL_XFAIL(status, cmfp->errbuf, "Invalid 1st RF character on node line: should be '-', not %s", tok1); |
| 1956 |
if (*tok2 != '-') ESL_XFAIL(status, cmfp->errbuf, "Invalid 2nd RF character on node line: should be '-', not %s", tok2); |
| 1957 |
tmp_rf_left[nd] = *tok1; |
| 1958 |
tmp_rf_right[nd] = *tok2; |
| 1959 |
} |
| 1960 |
if ((status = esl_fileparser_NextLine(cmfp->efp)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Premature end of data in main model: no state %d line", v); |
| 1961 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on state line: expected at least %d, got %d", 8, 0); |
| 1962 |
} |
| 1963 |
|
| 1964 |
|
| 1965 |
|
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
if((cm->sttype[v] = StateCode(tok1)) == -1) ESL_XFAIL(status, cmfp->errbuf, "Invalid state type %s\n", tok1); |
| 1970 |
|
| 1971 |
|
| 1972 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on state %d line: expected at least %d, got %d", v, 8, 1); |
| 1973 |
if (! is_integer(tok1)) ESL_XFAIL(status, cmfp->errbuf, "Invalid state index on state line: should be integer >= 0, not %s", tok1); |
| 1974 |
if (atoi(tok1) != v) ESL_XFAIL(status, cmfp->errbuf, "Invalid state index on state line: should be %d, not %s", v, tok1); |
| 1975 |
|
| 1976 |
|
| 1977 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on state %d line: expected at least %d, got %d", v, 8, 2); |
| 1978 |
if (! is_integer(tok1)) ESL_XFAIL(status, cmfp->errbuf, "Invalid plast value on state line: should be integer, not %s", tok1); |
| 1979 |
cm->plast[v] = atoi(tok1); |
| 1980 |
|
| 1981 |
|
| 1982 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on state %d line: expected at least %d, got %d", v, 8, 3); |
| 1983 |
if (! is_integer(tok1)) ESL_XFAIL(status, cmfp->errbuf, "Invalid pnum value on state line: should be integer, not %s", tok1); |
| 1984 |
cm->pnum[v] = atoi(tok1); |
| 1985 |
|
| 1986 |
|
| 1987 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on state %d line: expected at least %d, got %d", v, 8, 4); |
| 1988 |
if (! is_integer(tok1)) ESL_XFAIL(status, cmfp->errbuf, "Invalid cfirst value on state line: should be integer, not %s", tok1); |
| 1989 |
cm->cfirst[v] = atoi(tok1); |
| 1990 |
|
| 1991 |
|
| 1992 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on state %d line: expected at least %d, got %d", v, 8, 5); |
| 1993 |
if (! is_integer(tok1)) ESL_XFAIL(status, cmfp->errbuf, "Invalid cnum value on state line: should be integer, not %s", tok1); |
| 1994 |
cm->cnum[v] = atoi(tok1); |
| 1995 |
|
| 1996 |
|
| 1997 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on state %d line: expected at least %d, got %d", v, 8, 6); |
| 1998 |
if (! is_integer(tok1)) ESL_XFAIL(status, cmfp->errbuf, "Invalid dmin2 value on state line: should be integer, not %s", tok1); |
| 1999 |
cm->qdbinfo->dmin2[v] = atoi(tok1); |
| 2000 |
|
| 2001 |
|
| 2002 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on state %d line: expected at least %d, got %d", v, 8, 6); |
| 2003 |
if (! is_integer(tok1)) ESL_XFAIL(status, cmfp->errbuf, "Invalid dmin1 value on state line: should be integer, not %s", tok1); |
| 2004 |
cm->qdbinfo->dmin1[v] = atoi(tok1); |
| 2005 |
|
| 2006 |
|
| 2007 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on state %d line: expected at least %d, got %d", v, 8, 7); |
| 2008 |
if (! is_integer(tok1)) ESL_XFAIL(status, cmfp->errbuf, "Invalid dmax1 value on state line: should be integer, not %s", tok1); |
| 2009 |
cm->qdbinfo->dmax1[v] = atoi(tok1); |
| 2010 |
|
| 2011 |
|
| 2012 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on state %d line: expected at least %d, got %d", v, 8, 7); |
| 2013 |
if (! is_integer(tok1)) ESL_XFAIL(status, cmfp->errbuf, "Invalid dmax2 value on state line: should be integer, not %s", tok1); |
| 2014 |
cm->qdbinfo->dmax2[v] = atoi(tok1); |
| 2015 |
|
| 2016 |
|
| 2017 |
if (cm->sttype[v] != B_st) { |
| 2018 |
for (x = 0; x < cm->cnum[v]; x++) { |
| 2019 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on state %d line: expected at least %d, got %d", v, 8+cm->cnum[v], 8+x); |
| 2020 |
if ((! is_real(tok1) && (*tok1 != '*'))) ESL_XFAIL(status, cmfp->errbuf, "Invalid transition score %d on state line: should be real number or '*', not %s", x+1, tok1); |
| 2021 |
cm->t[v][x] = ascii2prob(tok1, 1.); |
| 2022 |
} |
| 2023 |
} |
| 2024 |
|
| 2025 |
if (cm->sttype[v] == ML_st || cm->sttype[v] == MR_st || cm->sttype[v] == IL_st || cm->sttype[v] == IR_st) { |
| 2026 |
for (x = 0; x < cm->abc->K; x++) { |
| 2027 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on state %d line: expected %d, got %d", v, 8+cm->cnum[v]+cm->abc->K, 8+cm->cnum[v]+x); |
| 2028 |
if ((! is_real(tok1) && (*tok1 != '*'))) ESL_XFAIL(status, cmfp->errbuf, "Invalid emission score %d on state line: should be real number or '*', not %s", x+1, tok1); |
| 2029 |
cm->e[v][x] = ascii2prob(tok1, cm->null[x]); |
| 2030 |
} |
| 2031 |
} |
| 2032 |
else if (cm->sttype[v] == MP_st) { |
| 2033 |
for (x = 0; x < cm->abc->K; x++) { |
| 2034 |
for (y = 0; y < cm->abc->K; y++) { |
| 2035 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Too few fields on state %d line: expected %d, got %d", v, 8+cm->cnum[v]+(cm->abc->K*cm->abc->K), 8+cm->cnum[v]+(x*cm->abc->K)+y); |
| 2036 |
if ((! is_real(tok1) && (*tok1 != '*'))) ESL_XFAIL(status, cmfp->errbuf, "Invalid emission score %d on state line: should be real number or '*', not %s", (x*cm->abc->K)+y+1, tok1); |
| 2037 |
cm->e[v][x*cm->abc->K+y] = ascii2prob(tok1, cm->null[x]*cm->null[y]); |
| 2038 |
} |
| 2039 |
} |
| 2040 |
} |
| 2041 |
cm->ndidx[v] = nd; |
| 2042 |
cm->stid[v] = DeriveUniqueStateCode(cm->ndtype[nd], cm->sttype[v]); |
| 2043 |
if ((status = esl_fileparser_NextLine(cmfp->efp)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Premature end of data in main model: no state %d line", v+1); |
| 2044 |
} |
| 2045 |
|
| 2046 |
if ((status = esl_fileparser_GetTokenOnLine(cmfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Premature end of data: missing //?"); |
| 2047 |
if (strcmp(tok1, "//") != 0) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Expected closing //; found %s instead", tok1); |
| 2048 |
|
| 2049 |
|
| 2050 |
if(read_fp7) { |
| 2051 |
if(!cmfp->hfp->do_stdin && !cmfp->hfp->do_gzip) { |
| 2052 |
if((fp7_offset = ftello(cmfp->f)) < 0) ESL_XFAIL(eslESYS, cmfp->errbuf, "ftello() failed"); |
| 2053 |
} |
| 2054 |
else { |
| 2055 |
fp7_offset = -1; |
| 2056 |
} |
| 2057 |
if((status = cm_p7_hmmfile_Read(cmfp, abc, fp7_offset, &hmm)) != eslOK) goto ERROR; |
| 2058 |
if((status = cm_SetFilterHMM(cm, hmm, tmp_fp7_gfmu, tmp_fp7_gflambda)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Unable to set filter HMM for CM"); |
| 2059 |
if(!cmfp->hfp->do_stdin && !cmfp->hfp->do_gzip) { |
| 2060 |
|
| 2061 |
if (fseeko(cmfp->f, ftello(cmfp->hfp->f), SEEK_SET) != 0) ESL_XFAIL(eslESYS, cmfp->errbuf, "Failed to set position for CM file parser after reading filter HMMs"); |
| 2062 |
} |
| 2063 |
} |
| 2064 |
|
| 2065 |
CMRenormalize(cm); |
| 2066 |
cm->qdbinfo->setby = CM_QDBINFO_SETBY_CMFILE; |
| 2067 |
cm->W_setby = CM_W_SETBY_CMFILE; |
| 2068 |
|
| 2069 |
|
| 2070 |
cm->emap = CreateEmitMap(cm); |
| 2071 |
if(cm->emap == NULL) ESL_XFAIL(eslEINVAL, cmfp->errbuf, "After reading complete model, failed to create an emit map"); |
| 2072 |
|
| 2073 |
|
| 2074 |
if (cm->flags & CMH_RF) { |
| 2075 |
cm->rf[0] = ' '; |
| 2076 |
for(nd = 0; nd < cm->nodes; nd++) { |
| 2077 |
if(cm->ndtype[nd] == MATP_nd || cm->ndtype[nd] == MATL_nd) cm->rf[cm->emap->lpos[nd]] = tmp_rf_left[nd]; |
| 2078 |
if(cm->ndtype[nd] == MATP_nd || cm->ndtype[nd] == MATR_nd) cm->rf[cm->emap->rpos[nd]] = tmp_rf_right[nd]; |
| 2079 |
} |
| 2080 |
cm->rf[cm->clen+1] = '\0'; |
| 2081 |
} |
| 2082 |
if (cm->flags & CMH_CONS) { |
| 2083 |
cm->consensus[0] = ' '; |
| 2084 |
for(nd = 0; nd < cm->nodes; nd++) { |
| 2085 |
if(cm->ndtype[nd] == MATP_nd || cm->ndtype[nd] == MATL_nd) cm->consensus[cm->emap->lpos[nd]] = tmp_cons_left[nd]; |
| 2086 |
if(cm->ndtype[nd] == MATP_nd || cm->ndtype[nd] == MATR_nd) cm->consensus[cm->emap->rpos[nd]] = tmp_cons_right[nd]; |
| 2087 |
} |
| 2088 |
cm->consensus[cm->clen+1] = '\0'; |
| 2089 |
} |
| 2090 |
if (cm->flags & CMH_MAP) { |
| 2091 |
cm->map[0] = 0; |
| 2092 |
for(nd = 0; nd < cm->nodes; nd++) { |
| 2093 |
if(cm->ndtype[nd] == MATP_nd || cm->ndtype[nd] == MATL_nd) cm->map[cm->emap->lpos[nd]] = tmp_map_left[nd]; |
| 2094 |
if(cm->ndtype[nd] == MATP_nd || cm->ndtype[nd] == MATR_nd) cm->map[cm->emap->rpos[nd]] = tmp_map_right[nd]; |
| 2095 |
} |
| 2096 |
} |
| 2097 |
|
| 2098 |
if(tmp_null != NULL) free(tmp_null); |
| 2099 |
|
| 2100 |
|
| 2101 |
free(tmp_rf_left); |
| 2102 |
free(tmp_rf_right); |
| 2103 |
free(tmp_cons_left); |
| 2104 |
free(tmp_cons_right); |
| 2105 |
free(tmp_map_left); |
| 2106 |
free(tmp_map_right); |
| 2107 |
|
| 2108 |
if (*ret_abc == NULL) *ret_abc = abc; |
| 2109 |
if ( opt_cm != NULL) *opt_cm = cm; else FreeCM(cm); |
| 2110 |
return eslOK; |
| 2111 |
|
| 2112 |
ERROR: |
| 2113 |
if (*ret_abc == NULL && abc != NULL) esl_alphabet_Destroy(abc); |
| 2114 |
if (cm != NULL) FreeCM(cm); |
| 2115 |
if (opt_cm != NULL) *opt_cm = NULL; |
| 2116 |
if (status == eslEMEM || status == eslESYS) return status; |
| 2117 |
else if (status == eslEOF) return status; |
| 2118 |
else if (status == eslEINCOMPAT) return status; |
| 2119 |
else return eslEFORMAT; |
| 2120 |
} |
| 2121 |
|
| 2122 |
|
| 2123 |
static int |
| 2124 |
read_bin_1p1_cm(CM_FILE *cmfp, int read_fp7, ESL_ALPHABET **ret_abc, CM_t **opt_cm) |
| 2125 |
{ |
| 2126 |
ESL_ALPHABET *abc = NULL; |
| 2127 |
CM_t *cm = NULL; |
| 2128 |
P7_HMM *hmm = NULL; |
| 2129 |
uint32_t magic; |
| 2130 |
int alphabet_type; |
| 2131 |
int v, x; |
| 2132 |
off_t offset = 0; |
| 2133 |
off_t fp7_offset = 0; |
| 2134 |
int status; |
| 2135 |
float tmp_fp7_gfmu; |
| 2136 |
float tmp_fp7_gflambda; |
| 2137 |
|
| 2138 |
cmfp->errbuf[0] = '\0'; |
| 2139 |
if (feof(cmfp->f)) { status = eslEOF; goto ERROR; } |
| 2140 |
|
| 2141 |
if (cmfp->newly_opened) |
| 2142 |
{ |
| 2143 |
offset = 0; |
| 2144 |
cmfp->newly_opened = FALSE; |
| 2145 |
} |
| 2146 |
else |
| 2147 |
{ |
| 2148 |
if ((!cmfp->do_stdin) && (! cmfp->do_gzip)) { |
| 2149 |
if ((offset = ftello(cmfp->f)) < 0) ESL_XEXCEPTION(eslESYS, "ftello() failed"); |
| 2150 |
} |
| 2151 |
if (! fread((char *) &magic, sizeof(uint32_t), 1, cmfp->f)) { status = eslEOF; goto ERROR; } |
| 2152 |
|
| 2153 |
if (cmfp->format == CM_FILE_1a) { if (magic != v1a_magic) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "bad magic number at start of CM"); } |
| 2154 |
else ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "no such CM file format code"); |
| 2155 |
} |
| 2156 |
|
| 2157 |
|
| 2158 |
|
| 2159 |
|
| 2160 |
|
| 2161 |
if ((cm = CreateCMShell()) == NULL) ESL_XFAIL(eslEMEM, cmfp->errbuf, "allocation failure, CM shell"); |
| 2162 |
cm->offset = offset; |
| 2163 |
|
| 2164 |
|
| 2165 |
if (! fread((char *) &(cm->flags), sizeof(int), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read flags"); |
| 2166 |
|
| 2167 |
|
| 2168 |
|
| 2169 |
|
| 2170 |
|
| 2171 |
|
| 2172 |
cm->flags &= ~CMH_BITS; |
| 2173 |
cm->flags &= ~CMH_CP9; |
| 2174 |
cm->flags &= ~CMH_CP9_TRUNC; |
| 2175 |
cm->flags &= ~CMH_MLP7; |
| 2176 |
cm->flags &= ~CM_IS_CONFIGURED; |
| 2177 |
|
| 2178 |
if (! fread((char *) &(cm->M), sizeof(int), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read number of states"); |
| 2179 |
if (! fread((char *) &(cm->nodes), sizeof(int), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read number of nodes"); |
| 2180 |
if (! fread((char *) &(cm->clen), sizeof(int), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read consensus length"); |
| 2181 |
if (! fread((char *) &alphabet_type, sizeof(int), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read alphabet_type"); |
| 2182 |
|
| 2183 |
|
| 2184 |
if (*ret_abc == NULL) { |
| 2185 |
if ((abc = esl_alphabet_Create(alphabet_type)) == NULL) ESL_XFAIL(eslEMEM, cmfp->errbuf, "allocation failed, alphabet"); |
| 2186 |
} else { |
| 2187 |
abc = *ret_abc; |
| 2188 |
if (abc->type != alphabet_type) ESL_XFAIL(eslEINCOMPAT, cmfp->errbuf, "Alphabet type mismatch: was %s, but current HMM says %s", esl_abc_DecodeType( abc->type), esl_abc_DecodeType(alphabet_type)); |
| 2189 |
} |
| 2190 |
|
| 2191 |
|
| 2192 |
|
| 2193 |
CreateCMBody(cm, cm->nodes, cm->M, cm->clen, abc); |
| 2194 |
|
| 2195 |
|
| 2196 |
if (! fread((char *) cm->sttype, sizeof(char), cm->M, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read sttype array"); |
| 2197 |
if (! fread((char *) cm->ndidx, sizeof(int), cm->M, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read ndidx array"); |
| 2198 |
if (! fread((char *) cm->stid, sizeof(char), cm->M, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read stid array"); |
| 2199 |
if (! fread((char *) cm->cfirst, sizeof(int), cm->M, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read cfirst array"); |
| 2200 |
if (! fread((char *) cm->cnum, sizeof(int), cm->M, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read cnum array"); |
| 2201 |
if (! fread((char *) cm->plast, sizeof(int), cm->M, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read plast array"); |
| 2202 |
if (! fread((char *) cm->pnum, sizeof(int), cm->M, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read pnum array"); |
| 2203 |
if (! fread((char *) cm->nodemap, sizeof(int), cm->nodes, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read nodemap array"); |
| 2204 |
if (! fread((char *) cm->ndtype, sizeof(char), cm->nodes, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read ndtype array"); |
| 2205 |
if (! fread((char *) cm->qdbinfo->dmin1, sizeof(int), cm->M, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read dmin1 array"); |
| 2206 |
if (! fread((char *) cm->qdbinfo->dmax1, sizeof(int), cm->M, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read dmax1 array"); |
| 2207 |
if (! fread((char *) cm->qdbinfo->dmin2, sizeof(int), cm->M, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read dmin2 array"); |
| 2208 |
if (! fread((char *) cm->qdbinfo->dmax2, sizeof(int), cm->M, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read dmax2 array"); |
| 2209 |
|
| 2210 |
cm->qdbinfo->setby = CM_QDBINFO_SETBY_CMFILE; |
| 2211 |
cm->W_setby = CM_W_SETBY_CMFILE; |
| 2212 |
|
| 2213 |
|
| 2214 |
cm->emap = CreateEmitMap(cm); |
| 2215 |
if(cm->emap == NULL) ESL_XFAIL(eslEINVAL, cmfp->errbuf, "After reading complete model, failed to create an emit map"); |
| 2216 |
|
| 2217 |
for (v = 0; v < cm->M; v++) { |
| 2218 |
if (! fread((char *) cm->t[v], sizeof(float), MAXCONNECT, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read transitions for state %d", v); |
| 2219 |
if (! fread((char *) cm->e[v], sizeof(float), cm->abc->K*cm->abc->K,cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read emissions for state %d", v); |
| 2220 |
} |
| 2221 |
|
| 2222 |
|
| 2223 |
if (read_bin_string(cmfp->f, &(cm->name)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read name"); |
| 2224 |
if ((cm->flags & CMH_ACC) && read_bin_string(cmfp->f, &(cm->acc)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read acc"); |
| 2225 |
if ((cm->flags & CMH_DESC) && read_bin_string(cmfp->f, &(cm->desc)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read desc"); |
| 2226 |
if ((cm->flags & CMH_RF) && ! fread((char *) cm->rf, sizeof(char), cm->clen+2, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read rf"); |
| 2227 |
if ((cm->flags & CMH_CONS) && ! fread((char *) cm->consensus, sizeof(char), cm->clen+2, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read consensus"); |
| 2228 |
if ((cm->flags & CMH_MAP) && ! fread((char *) cm->map, sizeof(int), cm->clen+1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read map"); |
| 2229 |
if (! fread((char *) &(cm->W), sizeof(int), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read nseq"); |
| 2230 |
|
| 2231 |
if (read_bin_string(cmfp->f, &(cm->ctime)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read ctime"); |
| 2232 |
if (read_bin_string(cmfp->f, &(cm->comlog)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read comlog"); |
| 2233 |
|
| 2234 |
if (! fread((char *) &(cm->pbegin), sizeof(float), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read beta_W"); |
| 2235 |
if (! fread((char *) &(cm->pend), sizeof(float), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read beta_W"); |
| 2236 |
if (! fread((char *) &(cm->beta_W), sizeof(double), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read beta_W"); |
| 2237 |
if (! fread((char *) &(cm->qdbinfo->beta1), sizeof(double), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read betaqdb1"); |
| 2238 |
if (! fread((char *) &(cm->qdbinfo->beta2), sizeof(double), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read betaqdb2"); |
| 2239 |
if (! fread((char *) &(cm->null2_omega), sizeof(float), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read null2_omega"); |
| 2240 |
if (! fread((char *) &(cm->null3_omega), sizeof(float), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read null3_omega"); |
| 2241 |
if (! fread((char *) &(cm->el_selfsc), sizeof(float), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read el_selfsc"); |
| 2242 |
if (! fread((char *) &(cm->nseq), sizeof(int), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read nseq"); |
| 2243 |
if (! fread((char *) &(cm->eff_nseq), sizeof(float), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read eff_nseq"); |
| 2244 |
if (! fread((char *) &(cm->checksum), sizeof(uint32_t), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read checksum"); |
| 2245 |
if (! fread((char *) cm->null, sizeof(float), cm->abc->K, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read null vector"); |
| 2246 |
|
| 2247 |
|
| 2248 |
if ((cm->flags & CMH_GA) && (! fread((char *) &(cm->ga), sizeof(float), 1, cmfp->f))) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read GA cutoff"); |
| 2249 |
if ((cm->flags & CMH_TC) && (! fread((char *) &(cm->tc), sizeof(float), 1, cmfp->f))) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read TC cutoff"); |
| 2250 |
if ((cm->flags & CMH_NC) && (! fread((char *) &(cm->nc), sizeof(float), 1, cmfp->f))) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read NC cutoff"); |
| 2251 |
|
| 2252 |
|
| 2253 |
if (cm->flags & CMH_FP7) { |
| 2254 |
if (! fread((char *) &tmp_fp7_gfmu, sizeof(float), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read additional P7 E-value stats"); |
| 2255 |
if (! fread((char *) &tmp_fp7_gflambda, sizeof(float), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read additional P7 E-value stats"); |
| 2256 |
} |
| 2257 |
if (cm->flags & CMH_EXPTAIL_STATS) { |
| 2258 |
long dbsize_long; |
| 2259 |
ESL_ALLOC(cm->expA, sizeof(ExpInfo_t *) * EXP_NMODES); |
| 2260 |
for(x = 0; x < EXP_NMODES; x++) { |
| 2261 |
cm->expA[x] = CreateExpInfo(); |
| 2262 |
if (! fread((char *) &(cm->expA[x]->lambda), sizeof(double), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read CM E-value stats"); |
| 2263 |
if (! fread((char *) &(cm->expA[x]->mu_extrap), sizeof(double), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read CM E-value stats"); |
| 2264 |
if (! fread((char *) &(cm->expA[x]->mu_orig), sizeof(double), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read CM E-value stats"); |
| 2265 |
if (! fread((char *) &(dbsize_long), sizeof(long), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read CM E-value stats"); |
| 2266 |
cm->expA[x]->dbsize = (double) dbsize_long; |
| 2267 |
if (! fread((char *) &(cm->expA[x]->nrandhits), sizeof(int), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read CM E-value stats"); |
| 2268 |
if (! fread((char *) &(cm->expA[x]->tailp), sizeof(double), 1, cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "failed to read CM E-value stats"); |
| 2269 |
} |
| 2270 |
} |
| 2271 |
|
| 2272 |
|
| 2273 |
if(read_fp7) { |
| 2274 |
if(!cmfp->hfp->do_stdin && !cmfp->hfp->do_gzip) { |
| 2275 |
if((fp7_offset = ftello(cmfp->f)) < 0) ESL_XFAIL(eslESYS, cmfp->errbuf, "ftello() failed"); |
| 2276 |
} |
| 2277 |
else { |
| 2278 |
fp7_offset = -1; |
| 2279 |
} |
| 2280 |
if((status = cm_p7_hmmfile_Read(cmfp, abc, fp7_offset, &hmm)) != eslOK) goto ERROR; |
| 2281 |
if((status = cm_SetFilterHMM(cm, hmm, tmp_fp7_gfmu, tmp_fp7_gflambda)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Unable to set filter HMM for CM"); |
| 2282 |
if(!cmfp->hfp->do_stdin && !cmfp->hfp->do_gzip) { |
| 2283 |
|
| 2284 |
if (fseeko(cmfp->f, ftello(cmfp->hfp->f), SEEK_SET) != 0) ESL_XFAIL(eslESYS, cmfp->errbuf, "Failed to set position for CM file parser after reading filter HMMs"); |
| 2285 |
} |
| 2286 |
} |
| 2287 |
|
| 2288 |
if (*ret_abc == NULL) *ret_abc = abc; |
| 2289 |
if ( opt_cm != NULL) *opt_cm = cm; else FreeCM(cm); |
| 2290 |
return eslOK; |
| 2291 |
|
| 2292 |
ERROR: |
| 2293 |
if (*ret_abc == NULL && abc != NULL) esl_alphabet_Destroy(abc); |
| 2294 |
if (cm != NULL) FreeCM(cm); |
| 2295 |
if (opt_cm != NULL) *opt_cm = NULL; |
| 2296 |
return status; |
| 2297 |
} |
| 2298 |
|
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
|
| 2303 |
|
| 2304 |
|
| 2305 |
|
| 2306 |
|
| 2307 |
|
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
static int |
| 2312 |
read_asc_1p0_cm(CM_FILE *cmfp, int read_fp7, ESL_ALPHABET **ret_abc, CM_t **opt_cm) |
| 2313 |
{ |
| 2314 |
int status; |
| 2315 |
CM_t *cm; |
| 2316 |
char *buf; |
| 2317 |
int n; |
| 2318 |
char *s; |
| 2319 |
int M,N; |
| 2320 |
int v,x,y,nd; |
| 2321 |
char *tok; |
| 2322 |
int toklen; |
| 2323 |
int exp_flags[EXP_NMODES]; |
| 2324 |
int exp_mode; |
| 2325 |
int have_exps; |
| 2326 |
int have_ga = FALSE; |
| 2327 |
int have_tc = FALSE; |
| 2328 |
int have_nc = FALSE; |
| 2329 |
int p; |
| 2330 |
int i; |
| 2331 |
int alphabet_type; |
| 2332 |
ESL_ALPHABET *abc = NULL; |
| 2333 |
int read_nstates = FALSE; |
| 2334 |
int read_nnodes = FALSE; |
| 2335 |
int read_atype = FALSE; |
| 2336 |
int read_clen = FALSE; |
| 2337 |
int evalues_are_invalid = FALSE; |
| 2338 |
int clen = 0; |
| 2339 |
int npartitions = 0; |
| 2340 |
off_t offset = 0; |
| 2341 |
|
| 2342 |
cm = NULL; |
| 2343 |
buf = NULL; |
| 2344 |
n = 0; |
| 2345 |
for(i = 0; i < EXP_NMODES; i++) exp_flags[i] = FALSE; |
| 2346 |
|
| 2347 |
cmfp->errbuf[0] = '\0'; |
| 2348 |
|
| 2349 |
if (cmfp->newly_opened) |
| 2350 |
{ |
| 2351 |
offset = 0; |
| 2352 |
cmfp->newly_opened = FALSE; |
| 2353 |
} |
| 2354 |
else |
| 2355 |
{ |
| 2356 |
|
| 2357 |
if ((! cmfp->do_stdin) && (! cmfp->do_gzip) && (offset = ftello(cmfp->f)) < 0) ESL_XEXCEPTION(eslESYS, "ftello() failed"); |
| 2358 |
|
| 2359 |
|
| 2360 |
if (feof(cmfp->f) || esl_fgets(&buf, &n, cmfp->f) != eslOK) { |
| 2361 |
if(buf != NULL) free(buf); |
| 2362 |
return eslEOF; |
| 2363 |
} |
| 2364 |
if (cmfp->format == CM_FILE_1) { if (strncmp(buf, "INFERNAL-1", 10) != 0) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Didn't find INFERNAL-1 tag: bad format or not an INFERNAL save file?"); } |
| 2365 |
else ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No such CM file format code: this shouldn't happen"); |
| 2366 |
} |
| 2367 |
|
| 2368 |
|
| 2369 |
|
| 2370 |
|
| 2371 |
|
| 2372 |
|
| 2373 |
cm = CreateCMShell(); |
| 2374 |
M = N = -1; |
| 2375 |
while (esl_fgets(&buf, &n, cmfp->f) != eslEOF) |
| 2376 |
{ |
| 2377 |
s = buf; |
| 2378 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Premature end of data, prior to MODEL section"); |
| 2379 |
else if (strcmp(tok, "NAME") == 0) |
| 2380 |
{ |
| 2381 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No name found on NAME line"); |
| 2382 |
if ((status = esl_strdup(tok, toklen, &(cm->name))) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Problem setting name for CM"); |
| 2383 |
} |
| 2384 |
else if (strcmp(tok, "ACC") == 0) |
| 2385 |
{ |
| 2386 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No accession found on ACC line"); |
| 2387 |
if ((status = esl_strdup(tok, toklen, &(cm->acc))) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Problem setting accession for CM"); |
| 2388 |
} |
| 2389 |
else if (strcmp(tok, "DESC") == 0) |
| 2390 |
{ |
| 2391 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No description found on DESC line"); |
| 2392 |
if ((status = esl_strdup(tok, toklen, &(cm->desc))) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Problem setting description for CM"); |
| 2393 |
} |
| 2394 |
else if (strcmp(tok, "GA") == 0) |
| 2395 |
{ |
| 2396 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No GA threshold found on GA line"); |
| 2397 |
cm->ga = atof(tok); |
| 2398 |
have_ga = TRUE; |
| 2399 |
} |
| 2400 |
else if (strcmp(tok, "TC") == 0) |
| 2401 |
{ |
| 2402 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No TC threshold found on TC line"); |
| 2403 |
cm->tc = atof(tok); |
| 2404 |
have_tc = TRUE; |
| 2405 |
} |
| 2406 |
else if (strcmp(tok, "NC") == 0) |
| 2407 |
{ |
| 2408 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No NC threshold found on NC line"); |
| 2409 |
cm->nc = atof(tok); |
| 2410 |
have_nc = TRUE; |
| 2411 |
} |
| 2412 |
else if (strcmp(tok, "STATES") == 0) |
| 2413 |
{ |
| 2414 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No number of STATES found on STATES line"); |
| 2415 |
M = atoi(tok); |
| 2416 |
read_nstates = TRUE; |
| 2417 |
} |
| 2418 |
else if (strcmp(tok, "NODES") == 0) |
| 2419 |
{ |
| 2420 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No number of NODES found on NODES line"); |
| 2421 |
N = atoi(tok); |
| 2422 |
read_nnodes = TRUE; |
| 2423 |
} |
| 2424 |
else if (strcmp(tok, "ALPHABET") == 0) |
| 2425 |
{ |
| 2426 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No alphabet type found on ALPHABET line"); |
| 2427 |
alphabet_type = atoi(tok); |
| 2428 |
|
| 2429 |
if (*ret_abc == NULL) { |
| 2430 |
if ((abc = esl_alphabet_Create(alphabet_type)) == NULL) ESL_XFAIL(eslEMEM, cmfp->errbuf, "Failed to create alphabet"); |
| 2431 |
} else { |
| 2432 |
abc = *ret_abc; |
| 2433 |
if ((*ret_abc)->type != alphabet_type) ESL_XFAIL(eslEINCOMPAT,cmfp->errbuf,"Alphabet type mismatch"); |
| 2434 |
} |
| 2435 |
read_atype = TRUE; |
| 2436 |
} |
| 2437 |
else if (strcmp(tok, "ELSELF") == 0) |
| 2438 |
{ |
| 2439 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No ELSELF score found on ELSELF line"); |
| 2440 |
cm->el_selfsc = atof(tok); |
| 2441 |
} |
| 2442 |
else if (strcmp(tok, "WBETA") == 0) |
| 2443 |
{ |
| 2444 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No WBETA found on WBETA line"); |
| 2445 |
cm->beta_W = (double) atof(tok); |
| 2446 |
} |
| 2447 |
else if (strcmp(tok, "NSEQ") == 0) |
| 2448 |
{ |
| 2449 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No name found on NAME line"); |
| 2450 |
cm->nseq = atoi(tok); |
| 2451 |
} |
| 2452 |
else if (strcmp(tok, "EFFNSEQ") == 0) |
| 2453 |
{ |
| 2454 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No effective seq number found on EFFNSEQ line"); |
| 2455 |
cm->eff_nseq = atof(tok); |
| 2456 |
} |
| 2457 |
else if (strcmp(tok, "CLEN") == 0) |
| 2458 |
{ |
| 2459 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No consensus length found on CLEN line"); |
| 2460 |
clen = atoi(tok); |
| 2461 |
read_clen = TRUE; |
| 2462 |
|
| 2463 |
|
| 2464 |
|
| 2465 |
if(! (read_nstates && read_nnodes && read_atype)) |
| 2466 |
{ |
| 2467 |
ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "ERROR, ALPHABET, STATES and NODES lines should precede CLEN line"); |
| 2468 |
} |
| 2469 |
CreateCMBody(cm, N, M, clen, abc); |
| 2470 |
} |
| 2471 |
|
| 2472 |
|
| 2473 |
|
| 2474 |
|
| 2475 |
else if (strcmp(tok, "BCOM") == 0) |
| 2476 |
{ |
| 2477 |
while(isspace((int) (*s))) s++; |
| 2478 |
if ((status = esl_strtok_adv(&s, "\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No build command found on BCOM line"); |
| 2479 |
if(cm->comlog == NULL) { |
| 2480 |
if((status = esl_strdup(tok, toklen, &(cm->comlog))) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Problem setting build date"); |
| 2481 |
} |
| 2482 |
else { |
| 2483 |
if((status = esl_strcat(&(cm->comlog), -1,"\n", 1)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Problem setting build date"); |
| 2484 |
if((status = esl_strcat(&(cm->comlog), -1, tok, toklen)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Problem setting build date"); |
| 2485 |
} |
| 2486 |
} |
| 2487 |
else if (strcmp(tok, "BDATE") == 0) |
| 2488 |
{ |
| 2489 |
while(isspace((int) (*s))) s++; |
| 2490 |
if ((status = esl_strtok_adv(&s, "\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No date found on BDATE line"); |
| 2491 |
if (esl_strdup(tok, toklen, &(cm->ctime)) != eslOK) ESL_XFAIL(eslEMEM, cmfp->errbuf, "strdup() failed to set date"); |
| 2492 |
} |
| 2493 |
else if (strcmp(tok, "CCOM") == 0) |
| 2494 |
{ |
| 2495 |
while(isspace((int) (*s))) s++; |
| 2496 |
if ((status = esl_strtok_adv(&s, "\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No calibrate command found on CCOM line"); |
| 2497 |
if(cm->comlog == NULL) { |
| 2498 |
if((status = esl_strdup(tok, toklen, &(cm->comlog))) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Problem setting calibrate date"); |
| 2499 |
} |
| 2500 |
else { |
| 2501 |
if((status = esl_strcat(&(cm->comlog), -1,"\n", 1)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Problem setting calibrate date"); |
| 2502 |
if((status = esl_strcat(&(cm->comlog), -1, tok, toklen)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Problem setting calibrate date"); |
| 2503 |
} |
| 2504 |
} |
| 2505 |
else if (strcmp(tok, "CDATE") == 0) |
| 2506 |
{ |
| 2507 |
while(isspace((int) (*s))) s++; |
| 2508 |
if ((status = esl_strtok_adv(&s, "\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No date found on CDATE line"); |
| 2509 |
|
| 2510 |
} |
| 2511 |
else if (strcmp(tok, "NULL") == 0) |
| 2512 |
{ |
| 2513 |
if(cm->abc == NULL) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "NULL line must be preceded by ALPHABET line"); |
| 2514 |
|
| 2515 |
for (x = 0; x < abc->K; x++) |
| 2516 |
{ |
| 2517 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Problem reading NULL line"); |
| 2518 |
cm->null[x] = ascii2prob(tok, (1./(float) abc->K)); |
| 2519 |
} |
| 2520 |
} |
| 2521 |
|
| 2522 |
else if (strcmp(tok, "PART") == 0) |
| 2523 |
{ |
| 2524 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No number of partitions on PART line"); |
| 2525 |
if (! is_integer(tok)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "number of partitions is not an integer on PART line"); |
| 2526 |
npartitions = atoi(tok); |
| 2527 |
if(npartitions != 1) { |
| 2528 |
evalues_are_invalid = TRUE; |
| 2529 |
|
| 2530 |
} |
| 2531 |
|
| 2532 |
|
| 2533 |
|
| 2534 |
|
| 2535 |
|
| 2536 |
|
| 2537 |
if ((status = esl_strtok_adv(&s, "\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid PART- line"); |
| 2538 |
} |
| 2539 |
|
| 2540 |
else if ((strncmp(tok, "E-", 2) == 0) && (! evalues_are_invalid)) |
| 2541 |
{ |
| 2542 |
|
| 2543 |
if (strncmp(tok+2, "LC", 2) == 0) exp_mode = EXP_CM_LC; |
| 2544 |
else if (strncmp(tok+2, "GC", 2) == 0) exp_mode = EXP_CM_GC; |
| 2545 |
else if (strncmp(tok+2, "LI", 2) == 0) exp_mode = EXP_CM_LI; |
| 2546 |
else if (strncmp(tok+2, "GI", 2) == 0) exp_mode = EXP_CM_GI; |
| 2547 |
else if (strncmp(tok+2, "LV", 2) == 0) continue; |
| 2548 |
else if (strncmp(tok+2, "GV", 2) == 0) continue; |
| 2549 |
else if (strncmp(tok+2, "LF", 2) == 0) continue; |
| 2550 |
else if (strncmp(tok+2, "GF", 2) == 0) continue; |
| 2551 |
else ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid xx on E-xx line"); |
| 2552 |
|
| 2553 |
|
| 2554 |
if (cm->expA == NULL) { |
| 2555 |
ESL_ALLOC(cm->expA, sizeof(ExpInfo_t *) * EXP_NMODES); |
| 2556 |
for(x = 0; x < EXP_NMODES; x++) { cm->expA[x] = CreateExpInfo(); } |
| 2557 |
} |
| 2558 |
|
| 2559 |
|
| 2560 |
|
| 2561 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No partition read on E-xx line"); |
| 2562 |
p = atoi(tok); |
| 2563 |
if (p != 0) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid partition on E-xx line"); |
| 2564 |
|
| 2565 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No lambda read on E-xx line"); |
| 2566 |
if (! is_real(tok)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "lambda not real number on E-xx line"); |
| 2567 |
cm->expA[exp_mode]->lambda = atof(tok); |
| 2568 |
|
| 2569 |
if ((esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No mu_extrap read on E-xx line"); |
| 2570 |
if (! is_real(tok)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "mu_extrap not real number on E-xx line"); |
| 2571 |
cm->expA[exp_mode]->mu_extrap = atof(tok); |
| 2572 |
|
| 2573 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No mu_orig read on E-xx line"); |
| 2574 |
if (! is_real(tok)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "mu_orign is not real number on E-xx line"); |
| 2575 |
cm->expA[exp_mode]->mu_orig = atof(tok); |
| 2576 |
|
| 2577 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No dbsize read on E-xx line"); |
| 2578 |
if (! is_integer(tok)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "dbsize is not integer on E-xx line"); |
| 2579 |
cm->expA[exp_mode]->dbsize = atof(tok); |
| 2580 |
|
| 2581 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No nrandhits read on E-xx line"); |
| 2582 |
if (! is_integer(tok)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "nrandhits is not integer on E-xx line"); |
| 2583 |
cm->expA[exp_mode]->nrandhits = atoi(tok); |
| 2584 |
|
| 2585 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "No tailp read on E-xx line"); |
| 2586 |
if (! is_real(tok)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "tailp is not real number on E-xx line"); |
| 2587 |
cm->expA[exp_mode]->tailp = atof(tok); |
| 2588 |
|
| 2589 |
cm->expA[exp_mode]->cur_eff_dbsize = (double) (cm->expA[exp_mode]->nrandhits); |
| 2590 |
|
| 2591 |
|
| 2592 |
|
| 2593 |
|
| 2594 |
cm->expA[exp_mode]->is_valid = TRUE; |
| 2595 |
exp_flags[exp_mode] = TRUE; |
| 2596 |
} |
| 2597 |
else if (strncmp(tok, "FT-", 3) == 0) |
| 2598 |
{ |
| 2599 |
|
| 2600 |
if ((status = esl_strtok_adv(&s, "\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid FT- line"); |
| 2601 |
if (esl_fgets(&buf, &n, cmfp->f) == eslEOF) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Premature end to file, while reading FT- line 2"); |
| 2602 |
if (esl_fgets(&buf, &n, cmfp->f) == eslEOF) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Premature end to file, while reading FT- line 3"); |
| 2603 |
} |
| 2604 |
else if (strcmp(tok, "MODEL:") == 0) |
| 2605 |
break; |
| 2606 |
} |
| 2607 |
|
| 2608 |
|
| 2609 |
|
| 2610 |
|
| 2611 |
if (feof(cmfp->f)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Premature end to CM file, file truncated?"); |
| 2612 |
if (! read_nstates) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "MODEL: line precedes STATES line"); |
| 2613 |
if (! read_nnodes) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "MODEL: line precedes NODES line"); |
| 2614 |
if (! read_clen) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "MODEL: line precedes CLEN line"); |
| 2615 |
if (! read_atype) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "MODEL: line precedes ALPHABET line"); |
| 2616 |
if (cm->name == NULL) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "MODEL: line precedes NAME line"); |
| 2617 |
|
| 2618 |
|
| 2619 |
have_exps = exp_flags[0]; |
| 2620 |
for(exp_mode = 1; exp_mode < EXP_NMODES; exp_mode++) |
| 2621 |
if(((have_exps && (!exp_flags[exp_mode]))) || |
| 2622 |
((!have_exps) && (exp_flags[exp_mode]))) |
| 2623 |
ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Some but not all E-xx lines read, expected 8"); |
| 2624 |
|
| 2625 |
|
| 2626 |
|
| 2627 |
CMZero(cm); |
| 2628 |
if(have_exps) cm->flags |= CMH_EXPTAIL_STATS; |
| 2629 |
if(have_ga) cm->flags |= CMH_GA; |
| 2630 |
if(have_tc) cm->flags |= CMH_TC; |
| 2631 |
if(have_nc) cm->flags |= CMH_NC; |
| 2632 |
nd = -1; |
| 2633 |
clen = 0; |
| 2634 |
for (v = 0; v < cm->M; v++) |
| 2635 |
{ |
| 2636 |
if ((status = esl_fgets(&buf, &n, cmfp->f)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Premature end of data before main model section"); |
| 2637 |
s = buf; |
| 2638 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(status, cmfp->errbuf, "Premature end of data before main model section"); |
| 2639 |
|
| 2640 |
|
| 2641 |
|
| 2642 |
if (*tok == '[') |
| 2643 |
{ |
| 2644 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Too few fields on node line"); |
| 2645 |
if ((x = NodeCode(tok)) == -1) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid node type %s", tok); |
| 2646 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Too few fields on node line"); |
| 2647 |
if (!is_integer(tok)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid node index on node line"); |
| 2648 |
nd = atoi(tok); |
| 2649 |
cm->ndtype[nd] = x; |
| 2650 |
if(cm->ndtype[nd] == MATP_nd) clen+=2; |
| 2651 |
else if(cm->ndtype[nd] == MATL_nd) clen++; |
| 2652 |
else if(cm->ndtype[nd] == MATR_nd) clen++; |
| 2653 |
cm->nodemap[nd] = v; |
| 2654 |
|
| 2655 |
if ((status = esl_fgets(&buf, &n, cmfp->f)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Too few fields on NODE line"); |
| 2656 |
s = buf; |
| 2657 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Too few fields on NODE line"); |
| 2658 |
} |
| 2659 |
|
| 2660 |
|
| 2661 |
|
| 2662 |
cm->sttype[v] = StateCode(tok); |
| 2663 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid state line for cm: %s state: %d", cm->name, v); |
| 2664 |
if (! is_integer(tok)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid state line for cm: %s state: %d", cm->name, v); |
| 2665 |
if (atoi(tok) != v) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid state line for cm: %s state: %d", cm->name, v); |
| 2666 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid state line for cm: %s state: %d", cm->name, v); |
| 2667 |
if (! is_integer(tok)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid state line for cm: %s state: %d", cm->name, v); |
| 2668 |
cm->plast[v] = atoi(tok); |
| 2669 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid state line for cm: %s state: %d", cm->name, v); |
| 2670 |
if (! is_integer(tok)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid state line for cm: %s state: %d", cm->name, v); |
| 2671 |
cm->pnum[v] = atoi(tok); |
| 2672 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid state line for cm: %s state: %d", cm->name, v); |
| 2673 |
if (! is_integer(tok)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid state line for cm: %s state: %d", cm->name, v); |
| 2674 |
cm->cfirst[v] = atoi(tok); |
| 2675 |
if ((status= esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid state line for cm: %s state: %d", cm->name, v); |
| 2676 |
if (! is_integer(tok)) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid state line for cm: %s state: %d", cm->name, v); |
| 2677 |
cm->cnum[v] = atoi(tok); |
| 2678 |
|
| 2679 |
if (cm->sttype[v] != B_st) |
| 2680 |
{ |
| 2681 |
for (x = 0; x < cm->cnum[v]; x++) |
| 2682 |
{ |
| 2683 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid state line for cm: %s state: %d", cm->name, v); |
| 2684 |
if (! is_real(tok) && *tok != '*') ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid state line for cm: %s state: %d", cm->name, v); |
| 2685 |
cm->t[v][x] = ascii2prob(tok, 1.); |
| 2686 |
} |
| 2687 |
} |
| 2688 |
|
| 2689 |
if (cm->sttype[v] == ML_st || cm->sttype[v] == MR_st || |
| 2690 |
cm->sttype[v] == IL_st || cm->sttype[v] == IR_st) |
| 2691 |
{ |
| 2692 |
for (x = 0; x < cm->abc->K; x++) |
| 2693 |
{ |
| 2694 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid state line for cm: %s state: %d", cm->name, v); |
| 2695 |
if (! is_real(tok) && *tok != '*') ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid state line for cm: %s state: %d", cm->name, v); |
| 2696 |
cm->e[v][x] = ascii2prob(tok, cm->null[x]); |
| 2697 |
} |
| 2698 |
} |
| 2699 |
else if (cm->sttype[v] == MP_st) |
| 2700 |
{ |
| 2701 |
for (x = 0; x < cm->abc->K; x++) |
| 2702 |
for (y = 0; y < cm->abc->K; y++) |
| 2703 |
{ |
| 2704 |
if ((status = esl_strtok_adv(&s, " \t\n", &tok, &toklen, NULL)) != eslOK) ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid state line for cm: %s state: %d", cm->name, v); |
| 2705 |
if (! is_real(tok) && *tok != '*') ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "Invalid state line for cm: %s state: %d", cm->name, v); |
| 2706 |
cm->e[v][x*cm->abc->K+y] = ascii2prob(tok, cm->null[x]*cm->null[y]); |
| 2707 |
} |
| 2708 |
} |
| 2709 |
|
| 2710 |
cm->ndidx[v] = nd; |
| 2711 |
cm->stid[v] = DeriveUniqueStateCode(cm->ndtype[nd], cm->sttype[v]); |
| 2712 |
} |
| 2713 |
|
| 2714 |
|
| 2715 |
|
| 2716 |
while (esl_fgets(&buf, &n, cmfp->f) != eslEOF) |
| 2717 |
if (strncmp(buf, "//", 2) == 0) |
| 2718 |
break; |
| 2719 |
|
| 2720 |
|
| 2721 |
|
| 2722 |
cm_find_and_detach_dual_inserts(cm, |
| 2723 |
FALSE, |
| 2724 |
|
| 2725 |
|
| 2726 |
TRUE); |
| 2727 |
|
| 2728 |
|
| 2729 |
if (read_clen && clen != cm->clen) |
| 2730 |
{ |
| 2731 |
ESL_XFAIL(eslEFORMAT, cmfp->errbuf, "calculated consensus length %d does not equal read CLEN: %d.\n", clen, cm->clen); |
| 2732 |
} |
| 2733 |
|
| 2734 |
|
| 2735 |
|
| 2736 |
|
| 2737 |
CMRenormalize(cm); |
| 2738 |
|
| 2739 |
if (buf != NULL) free(buf); |
| 2740 |
if (*ret_abc == NULL) *ret_abc = abc; |
| 2741 |
if ( opt_cm != NULL) *opt_cm = cm; else FreeCM(cm); |
| 2742 |
return eslOK; |
| 2743 |
|
| 2744 |
ERROR: |
| 2745 |
if (buf != NULL) free(buf); |
| 2746 |
if (*ret_abc == NULL && abc != NULL) esl_alphabet_Destroy(abc); |
| 2747 |
if (cm != NULL) FreeCM(cm); |
| 2748 |
if (opt_cm != NULL) *opt_cm = NULL; |
| 2749 |
if (status == eslEMEM || status == eslESYS) return status; |
| 2750 |
else if (status == eslEOF) return status; |
| 2751 |
else if (status == eslEINCOMPAT) return status; |
| 2752 |
else return eslEFORMAT; |
| 2753 |
} |
| 2754 |
|
| 2755 |
|
| 2756 |
|
| 2757 |
|
| 2758 |
|
| 2759 |
|
| 2760 |
|
| 2761 |
|
| 2762 |
|
| 2763 |
|
| 2764 |
|
| 2765 |
|
| 2766 |
|
| 2767 |
|
| 2768 |
|
| 2769 |
|
| 2770 |
|
| 2771 |
|
| 2772 |
|
| 2773 |
|
| 2774 |
|
| 2775 |
|
| 2776 |
|
| 2777 |
|
| 2778 |
|
| 2779 |
|
| 2780 |
|
| 2781 |
|
| 2782 |
|
| 2783 |
|
| 2784 |
|
| 2785 |
|
| 2786 |
|
| 2787 |
|
| 2788 |
|
| 2789 |
|
| 2790 |
|
| 2791 |
|
| 2792 |
|
| 2793 |
|
| 2794 |
|
| 2795 |
|
| 2796 |
|
| 2797 |
|
| 2798 |
|
| 2799 |
|
| 2800 |
|
| 2801 |
|
| 2802 |
|
| 2803 |
|
| 2804 |
|
| 2805 |
|
| 2806 |
static int |
| 2807 |
read_asc30hmm(P7_HMMFILE *hfp, ESL_ALPHABET **ret_abc, P7_HMM **opt_hmm) |
| 2808 |
{ |
| 2809 |
ESL_ALPHABET *abc = NULL; |
| 2810 |
P7_HMM *hmm = NULL; |
| 2811 |
char *tag = NULL; |
| 2812 |
char *tok1 = NULL; |
| 2813 |
char *tok2 = NULL; |
| 2814 |
char *tok3 = NULL; |
| 2815 |
char *tok4 = NULL; |
| 2816 |
int alphatype; |
| 2817 |
int k,x; |
| 2818 |
off_t offset = 0; |
| 2819 |
int status; |
| 2820 |
uint32_t statstracker = 0; |
| 2821 |
|
| 2822 |
|
| 2823 |
|
| 2824 |
|
| 2825 |
|
| 2826 |
|
| 2827 |
|
| 2828 |
|
| 2829 |
|
| 2830 |
|
| 2831 |
|
| 2832 |
|
| 2833 |
|
| 2834 |
|
| 2835 |
|
| 2836 |
hfp->rr_errbuf[0] = '\0'; |
| 2837 |
|
| 2838 |
if (hfp->newly_opened) |
| 2839 |
{ |
| 2840 |
offset = 0; |
| 2841 |
hfp->newly_opened = FALSE; |
| 2842 |
} |
| 2843 |
else |
| 2844 |
{ |
| 2845 |
|
| 2846 |
if ((! hfp->do_stdin) && (! hfp->do_gzip) && (offset = ftello(hfp->f)) < 0) ESL_XEXCEPTION(eslESYS, "ftello() failed"); |
| 2847 |
|
| 2848 |
|
| 2849 |
if ((status = esl_fileparser_NextLine(hfp->efp)) != eslOK) goto ERROR; |
| 2850 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tag, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "unexpected absence of tokens on data line"); |
| 2851 |
|
| 2852 |
if (hfp->format == p7_HMMFILE_3f) { if (strcmp(tag, "HMMER3/f") != 0) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "Didn't find HMMER3/f tag: bad format or not a HMMER save file?"); } |
| 2853 |
else if (hfp->format == p7_HMMFILE_3e) { if (strcmp(tag, "HMMER3/e") != 0) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "Didn't find HMMER3/e tag: bad format or not a HMMER save file?"); } |
| 2854 |
else if (hfp->format == p7_HMMFILE_3d) { if (strcmp(tag, "HMMER3/d") != 0) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "Didn't find HMMER3/d tag: bad format or not a HMMER save file?"); } |
| 2855 |
else if (hfp->format == p7_HMMFILE_3c) { if (strcmp(tag, "HMMER3/c") != 0) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "Didn't find HMMER3/c tag: bad format or not a HMMER save file?"); } |
| 2856 |
else if (hfp->format == p7_HMMFILE_3b) { if (strcmp(tag, "HMMER3/b") != 0) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "Didn't find HMMER3/b tag: bad format or not a HMMER save file?"); } |
| 2857 |
else if (hfp->format == p7_HMMFILE_3a) { if (strcmp(tag, "HMMER3/a") != 0) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "Didn't find HMMER3/a tag: bad format or not a HMMER save file?"); } |
| 2858 |
else ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "No such HMM file format code: this shouldn't happen"); |
| 2859 |
} |
| 2860 |
|
| 2861 |
if ((hmm = p7_hmm_CreateShell()) == NULL) ESL_XFAIL(eslEMEM, hfp->rr_errbuf, "allocation failure, HMM shell"); |
| 2862 |
hmm->offset = offset; |
| 2863 |
|
| 2864 |
|
| 2865 |
while ((status = esl_fileparser_NextLine(hfp->efp)) == eslOK) |
| 2866 |
{ |
| 2867 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tag, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Premature end of line"); |
| 2868 |
|
| 2869 |
if (strcmp(tag, "NAME") == 0) { |
| 2870 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "No name found on NAME line"); |
| 2871 |
p7_hmm_SetName(hmm, tok1); |
| 2872 |
} |
| 2873 |
|
| 2874 |
else if (strcmp(tag, "ACC") == 0) { |
| 2875 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "No accession found on ACC line"); |
| 2876 |
p7_hmm_SetAccession(hmm, tok1); |
| 2877 |
} |
| 2878 |
|
| 2879 |
else if (strcmp(tag, "DESC") == 0) { |
| 2880 |
if ((status = esl_fileparser_GetRemainingLine(hfp->efp, &tok1)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "No description found on DESC line"); |
| 2881 |
p7_hmm_SetDescription(hmm, tok1); |
| 2882 |
} |
| 2883 |
|
| 2884 |
else if (strcmp(tag, "LENG") == 0) { |
| 2885 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "No model length found on LENG line"); |
| 2886 |
if ((hmm->M = atoi(tok1)) == 0) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "Invalid model length %s on LENG line", tok1); |
| 2887 |
} |
| 2888 |
|
| 2889 |
else if (hfp->format >= p7_HMMFILE_3c && strcmp(tag, "MAXL") == 0) { |
| 2890 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "No max length found on MAXL line"); |
| 2891 |
if ((hmm->max_length = atoi(tok1)) == 0) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "Invalid max length %s on MAXL line", tok1); |
| 2892 |
} |
| 2893 |
|
| 2894 |
else if (strcmp(tag, "ALPH") == 0) { |
| 2895 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "No alphabet type found on ALPH"); |
| 2896 |
if ((alphatype = esl_abc_EncodeType(tok1)) == eslUNKNOWN) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "Unrecognized alphabet type %s", tok1); |
| 2897 |
if (*ret_abc == NULL) { |
| 2898 |
if ((abc = esl_alphabet_Create(alphatype)) == NULL) ESL_XFAIL(eslEMEM, hfp->rr_errbuf, "Failed to create alphabet"); |
| 2899 |
} else { |
| 2900 |
if ((*ret_abc)->type != alphatype) ESL_XFAIL(eslEINCOMPAT, hfp->rr_errbuf,"Alphabet type mismatch: was %s, but current HMM says %s", esl_abc_DecodeType( (*ret_abc)->type), tok1); |
| 2901 |
abc = *ret_abc; |
| 2902 |
} |
| 2903 |
} |
| 2904 |
|
| 2905 |
else if (strcmp(tag, "RF") == 0) { |
| 2906 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "No yes/no found for RF line"); |
| 2907 |
if (strcasecmp(tok1, "yes") == 0) |
| 2908 |
hmm->flags |= p7H_RF; |
| 2909 |
else if (strcasecmp(tok1, "no") != 0) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "RF header line must say yes/no, not %s", tok1); |
| 2910 |
} |
| 2911 |
|
| 2912 |
else if (strcmp(tag, "MM") == 0) { |
| 2913 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "No yes/no found for MM line"); |
| 2914 |
if (strcasecmp(tok1, "yes") == 0) |
| 2915 |
hmm->flags |= p7H_MMASK; |
| 2916 |
else if (strcasecmp(tok1, "no") != 0) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "MM header line must say yes/no, not %s", tok1); |
| 2917 |
} |
| 2918 |
|
| 2919 |
|
| 2920 |
else if (strcmp(tag, "CONS") == 0) { |
| 2921 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "No yes/no found for CONS line"); |
| 2922 |
if (strcasecmp(tok1, "yes") == 0) |
| 2923 |
hmm->flags |= p7H_CONS; |
| 2924 |
else if (strcasecmp(tok1, "no") != 0) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "CONS header line must say yes/no, not %s", tok1); |
| 2925 |
} |
| 2926 |
|
| 2927 |
else if (strcmp(tag, "CS") == 0) { |
| 2928 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "No yes/no found for CS line"); |
| 2929 |
if (strcasecmp(tok1, "yes") == 0) |
| 2930 |
hmm->flags |= p7H_CS; |
| 2931 |
else if (strcasecmp(tok1, "no") != 0) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "CS header line must say yes/no, not %s", tok1); |
| 2932 |
} |
| 2933 |
|
| 2934 |
else if (strcmp(tag, "MAP") == 0) { |
| 2935 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "No yes/no found for MAP line"); |
| 2936 |
if (strcasecmp(tok1, "yes") == 0) |
| 2937 |
hmm->flags |= p7H_MAP; |
| 2938 |
else if (strcasecmp(tok1, "no") != 0) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "MAP header line must say yes/no, not %s", tok1); |
| 2939 |
} |
| 2940 |
|
| 2941 |
else if (strcmp(tag, "DATE") == 0) { |
| 2942 |
if ((status = esl_fileparser_GetRemainingLine(hfp->efp, &tok1)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "No date found on DATE line"); |
| 2943 |
if (esl_strdup(tok1, -1, &(hmm->ctime)) != eslOK) ESL_XFAIL(eslEMEM, hfp->rr_errbuf, "strdup() failed to set date"); |
| 2944 |
} |
| 2945 |
|
| 2946 |
else if (strcmp(tag, "COM") == 0) { |
| 2947 |
|
| 2948 |
if ((status = esl_fileparser_GetTokenOnLine (hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "No command number on COM line"); |
| 2949 |
if ((status = esl_fileparser_GetRemainingLine(hfp->efp, &tok1)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "No command on COM line"); |
| 2950 |
if (hmm->comlog == NULL) { |
| 2951 |
if (esl_strdup(tok1, -1, &(hmm->comlog)) != eslOK) ESL_XFAIL(eslEMEM, hfp->rr_errbuf, "esl_strdup() failed"); |
| 2952 |
} else { |
| 2953 |
if (esl_strcat(&(hmm->comlog), -1, "\n", -1) != eslOK) ESL_XFAIL(eslEMEM, hfp->rr_errbuf, "esl_strcat() failed"); |
| 2954 |
if (esl_strcat(&(hmm->comlog), -1, tok1, -1) != eslOK) ESL_XFAIL(eslEMEM, hfp->rr_errbuf, "esl_strcat() failed"); |
| 2955 |
} |
| 2956 |
} |
| 2957 |
|
| 2958 |
else if (strcmp(tag, "NSEQ") == 0) { |
| 2959 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Nothing follows NSEQ tag"); |
| 2960 |
if ((hmm->nseq = atoi(tok1)) == 0) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "Invalid nseq on NSEQ line: should be integer, not %s", tok1); |
| 2961 |
} |
| 2962 |
|
| 2963 |
else if (strcmp(tag, "EFFN") == 0) { |
| 2964 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Nothing follows EFFN tag"); |
| 2965 |
if ((hmm->eff_nseq = atof(tok1)) <= 0.0f) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "Invalid eff_nseq on EFFN line: should be a real number, not %s", tok1); |
| 2966 |
} |
| 2967 |
|
| 2968 |
else if (strcmp(tag, "CKSUM") == 0) { |
| 2969 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Nothing follows CKSUM tag"); |
| 2970 |
hmm->checksum = atoll(tok1); |
| 2971 |
hmm->flags |= p7H_CHKSUM; |
| 2972 |
} |
| 2973 |
|
| 2974 |
else if (strcmp(tag, "STATS") == 0) { |
| 2975 |
if (hfp->format >= p7_HMMFILE_3b) |
| 2976 |
{ |
| 2977 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Too few fields on STATS line"); |
| 2978 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok2, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Too few fields on STATS line"); |
| 2979 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok3, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Too few fields on STATS line"); |
| 2980 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok4, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Too few fields on STATS line"); |
| 2981 |
if (strcasecmp(tok1, "LOCAL") == 0) |
| 2982 |
{ |
| 2983 |
if (strcasecmp(tok2, "MSV") == 0) { hmm->evparam[p7_MMU] = atof(tok3); hmm->evparam[p7_MLAMBDA] = atof(tok4); statstracker |= 0x1; } |
| 2984 |
else if (strcasecmp(tok2, "VITERBI") == 0) { hmm->evparam[p7_VMU] = atof(tok3); hmm->evparam[p7_VLAMBDA] = atof(tok4); statstracker |= 0x2; } |
| 2985 |
else if (strcasecmp(tok2, "FORWARD") == 0) { hmm->evparam[p7_FTAU] = atof(tok3); hmm->evparam[p7_FLAMBDA] = atof(tok4); statstracker |= 0x4; } |
| 2986 |
else ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "Failed to parse STATS, %s unrecognized as field 3", tok2); |
| 2987 |
} else ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "Failed to parse STATS, %s unrecognized as field 2", tok1); |
| 2988 |
} |
| 2989 |
else if (hfp->format == p7_HMMFILE_3a) |
| 2990 |
{ |
| 2991 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Too few fields on STATS line"); |
| 2992 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok2, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Too few fields on STATS line"); |
| 2993 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok3, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Too few fields on STATS line"); |
| 2994 |
if (strcasecmp(tok1, "LOCAL") == 0) |
| 2995 |
{ |
| 2996 |
if (strcasecmp(tok2, "VLAMBDA") == 0) { hmm->evparam[p7_MLAMBDA] = hmm->evparam[p7_VLAMBDA] = hmm->evparam[p7_FLAMBDA] = atof(tok3); statstracker |= 0x1; } |
| 2997 |
else if (strcasecmp(tok2, "VMU") == 0) { hmm->evparam[p7_MMU] = hmm->evparam[p7_VMU] = atof(tok3); statstracker |= 0x2; } |
| 2998 |
else if (strcasecmp(tok2, "FTAU") == 0) { hmm->evparam[p7_FTAU] = atof(tok3); statstracker |= 0x4; } |
| 2999 |
else ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "Failed to parse STATS, %s unrecognized as field 3", tok2); |
| 3000 |
} else ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "Failed to parse STATS, %s unrecognized as field 2", tok1); |
| 3001 |
} |
| 3002 |
} |
| 3003 |
|
| 3004 |
else if (strcmp(tag, "GA") == 0) { |
| 3005 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Too few fields on GA line"); |
| 3006 |
hmm->cutoff[p7_GA1] = atof(tok1); |
| 3007 |
if ( (abc->type == eslDNA || abc->type == eslRNA) ) { |
| 3008 |
hmm->cutoff[p7_GA2] = hmm->cutoff[p7_GA1]; |
| 3009 |
} else { |
| 3010 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok2, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Too few fields on GA line"); |
| 3011 |
hmm->cutoff[p7_GA2] = atof(tok2); |
| 3012 |
} |
| 3013 |
hmm->flags |= p7H_GA; |
| 3014 |
} |
| 3015 |
|
| 3016 |
else if (strcmp(tag, "TC") == 0) { |
| 3017 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Too few fields on TC line"); |
| 3018 |
hmm->cutoff[p7_TC1] = atof(tok1); |
| 3019 |
if ( (abc->type == eslDNA || abc->type == eslRNA) ) { |
| 3020 |
hmm->cutoff[p7_TC2] = hmm->cutoff[p7_TC1]; |
| 3021 |
} else { |
| 3022 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok2, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Too few fields on TC line"); |
| 3023 |
hmm->cutoff[p7_TC2] = atof(tok2); |
| 3024 |
} |
| 3025 |
hmm->flags |= p7H_TC; |
| 3026 |
} |
| 3027 |
|
| 3028 |
else if (strcmp(tag, "NC") == 0) { |
| 3029 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Too few fields on NC line"); |
| 3030 |
hmm->cutoff[p7_NC1] = atof(tok1); |
| 3031 |
if ( (abc->type == eslDNA || abc->type == eslRNA) ) { |
| 3032 |
hmm->cutoff[p7_NC2] = hmm->cutoff[p7_NC1]; |
| 3033 |
} else { |
| 3034 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok2, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Too few fields on NC line"); |
| 3035 |
hmm->cutoff[p7_NC2] = atof(tok2); |
| 3036 |
} |
| 3037 |
hmm->flags |= p7H_NC; |
| 3038 |
} |
| 3039 |
|
| 3040 |
else if (strcmp(tag, "HMM") == 0) |
| 3041 |
break; |
| 3042 |
} |
| 3043 |
|
| 3044 |
if (status != eslOK) goto ERROR; |
| 3045 |
|
| 3046 |
|
| 3047 |
if (statstracker == 0x7) hmm->flags |= p7H_STATS; |
| 3048 |
else if (statstracker != 0x0) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "Missing one or more STATS parameter lines"); |
| 3049 |
|
| 3050 |
|
| 3051 |
|
| 3052 |
if ((status = esl_fileparser_NextLine(hfp->efp)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Premature end of data before main model section"); |
| 3053 |
if ((status = esl_fileparser_NextLine(hfp->efp)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Premature end of data before main model section"); |
| 3054 |
if ((status = p7_hmm_CreateBody(hmm, hmm->M, abc)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Failed to allocate body of the new HMM"); |
| 3055 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Premature end of data before main model section"); |
| 3056 |
|
| 3057 |
|
| 3058 |
if (strcmp(tok1, "COMPO") == 0) { |
| 3059 |
for (x = 0; x < abc->K; x++) { |
| 3060 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Too few fields on COMPO line"); |
| 3061 |
hmm->compo[x] = (*tok1 == '*' ? 0.0 : expf(-1.0 * atof(tok1))); |
| 3062 |
} |
| 3063 |
hmm->flags |= p7H_COMPO; |
| 3064 |
if ((status = esl_fileparser_NextLine(hfp->efp)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Premature end of data after COMPO line"); |
| 3065 |
if ((esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Premature end of data after COMPO line"); |
| 3066 |
} |
| 3067 |
|
| 3068 |
|
| 3069 |
|
| 3070 |
hmm->ins[0][0] = (*tok1 == '*' ? 0.0 : expf(-1.0 *atof(tok1))); |
| 3071 |
for (x = 1; x < abc->K; x++) { |
| 3072 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Too few fields on insert line, node 0: expected %d, got %d\n", abc->K, x); |
| 3073 |
hmm->ins[0][x] = (*tok1 == '*' ? 0.0 : expf(-1.0 *atof(tok1))); |
| 3074 |
} |
| 3075 |
if ((status = esl_fileparser_NextLine(hfp->efp)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Premature end of data in main model: no node 0 transition line"); |
| 3076 |
for (x = 0; x < p7H_NTRANSITIONS; x++) { |
| 3077 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Too few fields on begin (0) transition line"); |
| 3078 |
hmm->t[0][x] = (*tok1 == '*' ? 0.0 : expf(-1.0 *atof(tok1))); |
| 3079 |
} |
| 3080 |
|
| 3081 |
|
| 3082 |
for (k = 1; k <= hmm->M; k++) |
| 3083 |
{ |
| 3084 |
|
| 3085 |
if ((status = esl_fileparser_NextLine(hfp->efp)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Premature end of data in main model section, at node %d (expected %d)", k, hmm->M); |
| 3086 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Premature end of data in main model section, at node %d (expected %d)", k, hmm->M); |
| 3087 |
if (atoi(tok1) != k) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "Expected match line to start with %d (of %d); saw %s", k, hmm->M, tok1); |
| 3088 |
|
| 3089 |
for (x = 0; x < abc->K; x++) { |
| 3090 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Too few probability fields on match line, node %d: expected %d, got %d\n", k, abc->K, x); |
| 3091 |
hmm->mat[k][x] = (*tok1 == '*' ? 0.0 : expf(-1.0 *atof(tok1))); |
| 3092 |
} |
| 3093 |
|
| 3094 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Missing MAP field on match line for node %d: should at least be -", k); |
| 3095 |
if (hmm->flags & p7H_MAP) hmm->map[k] = atoi(tok1); |
| 3096 |
|
| 3097 |
if (hfp->format >= p7_HMMFILE_3e) { |
| 3098 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Missing CONS field on match line for node %d: should at least be -", k); |
| 3099 |
if (hmm->flags & p7H_CONS) hmm->consensus[k] = *tok1; |
| 3100 |
} |
| 3101 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Missing RF field on match line for node %d: should at least be -", k); |
| 3102 |
if (hmm->flags & p7H_RF) hmm->rf[k] = *tok1; |
| 3103 |
|
| 3104 |
if (hfp->format >= p7_HMMFILE_3f) { |
| 3105 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Missing MM field on match line for node %d: should at least be -", k); |
| 3106 |
if (hmm->flags & p7H_MMASK) hmm->mm[k] = *tok1; |
| 3107 |
} |
| 3108 |
|
| 3109 |
|
| 3110 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Missing CS field on match line for node %d: should at least be -", k); |
| 3111 |
if (hmm->flags & p7H_CS) hmm->cs[k] = *tok1; |
| 3112 |
|
| 3113 |
|
| 3114 |
if ((status = esl_fileparser_NextLine(hfp->efp)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Premature end of data in main model: no insert emission line, node %d", k); |
| 3115 |
for (x = 0; x < abc->K; x++) { |
| 3116 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Too few probability fields on insert line, node %d: expected %d, got %d\n", k, abc->K, x); |
| 3117 |
hmm->ins[k][x] = (*tok1 == '*' ? 0.0 : expf(-1.0 *atof(tok1))); |
| 3118 |
} |
| 3119 |
if ((status = esl_fileparser_NextLine(hfp->efp)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Premature end of data in main model: no transition line, node %d", k); |
| 3120 |
for (x = 0; x < p7H_NTRANSITIONS; x++) { |
| 3121 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Too few probability fields on transition line, node %d: expected %d, got %d\n", k, abc->K, x); |
| 3122 |
hmm->t[k][x] = (*tok1 == '*' ? 0.0 : expf(-1.0 *atof(tok1))); |
| 3123 |
} |
| 3124 |
} |
| 3125 |
|
| 3126 |
|
| 3127 |
if ((status = esl_fileparser_NextLine(hfp->efp)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Premature end of data: missing //?"); |
| 3128 |
if ((status = esl_fileparser_GetTokenOnLine(hfp->efp, &tok1, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Premature end of data: missing //?"); |
| 3129 |
if (strcmp(tok1, "//") != 0) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "Expected closing //; found %s instead", tok1); |
| 3130 |
|
| 3131 |
|
| 3132 |
if (hfp->format < p7_HMMFILE_3e && (status = p7_hmm_SetConsensus(hmm, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Failed to set consensus on legacy HMM format"); |
| 3133 |
|
| 3134 |
|
| 3135 |
if (hmm->flags & p7H_RF) { hmm->rf[0] = ' '; hmm->rf[hmm->M+1] = '\0'; } |
| 3136 |
if (hmm->flags & p7H_MMASK){ hmm->mm[0] = ' '; hmm->mm[hmm->M+1] = '\0'; } |
| 3137 |
if (hmm->flags & p7H_CONS) { hmm->consensus[0] = ' '; hmm->consensus[hmm->M+1] = '\0'; } |
| 3138 |
if (hmm->flags & p7H_CS) { hmm->cs[0] = ' '; hmm->cs[hmm->M+1] = '\0'; } |
| 3139 |
if (hmm->flags & p7H_MAP) { hmm->map[0] = 0; } |
| 3140 |
if (hmm->name == NULL) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "No NAME found for HMM"); |
| 3141 |
if (hmm->M <= 0) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "No LENG found for HMM (or LENG <= 0)"); |
| 3142 |
if (abc == NULL) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "No ALPH found for HMM"); |
| 3143 |
|
| 3144 |
if (*ret_abc == NULL) *ret_abc = abc; |
| 3145 |
if ( opt_hmm != NULL) *opt_hmm = hmm; else p7_hmm_Destroy(hmm); |
| 3146 |
return eslOK; |
| 3147 |
|
| 3148 |
ERROR: |
| 3149 |
if (*ret_abc == NULL && abc != NULL) esl_alphabet_Destroy(abc); |
| 3150 |
if (hmm != NULL) p7_hmm_Destroy(hmm); |
| 3151 |
if (opt_hmm != NULL) *opt_hmm = NULL; |
| 3152 |
if (status == eslEMEM || status == eslESYS) return status; |
| 3153 |
else if (status == eslEOF) return status; |
| 3154 |
else if (status == eslEINCOMPAT) return status; |
| 3155 |
else return eslEFORMAT; |
| 3156 |
} |
| 3157 |
|
| 3158 |
|
| 3159 |
static int |
| 3160 |
read_bin30hmm(P7_HMMFILE *hfp, ESL_ALPHABET **ret_abc, P7_HMM **opt_hmm) |
| 3161 |
{ |
| 3162 |
ESL_ALPHABET *abc = NULL; |
| 3163 |
P7_HMM *hmm = NULL; |
| 3164 |
uint32_t magic; |
| 3165 |
int alphabet_type; |
| 3166 |
int k; |
| 3167 |
off_t offset = 0; |
| 3168 |
int status; |
| 3169 |
|
| 3170 |
hfp->rr_errbuf[0] = '\0'; |
| 3171 |
if (feof(hfp->f)) { status = eslEOF; goto ERROR; } |
| 3172 |
|
| 3173 |
if (hfp->newly_opened) |
| 3174 |
{ |
| 3175 |
offset = 0; |
| 3176 |
hfp->newly_opened = FALSE; |
| 3177 |
} |
| 3178 |
else |
| 3179 |
{ |
| 3180 |
if ((!hfp->do_stdin) && (! hfp->do_gzip)) { |
| 3181 |
if ((offset = ftello(hfp->f)) < 0) ESL_XEXCEPTION(eslESYS, "ftello() failed"); |
| 3182 |
} |
| 3183 |
if (! fread((char *) &magic, sizeof(uint32_t), 1, hfp->f)) { status = eslEOF; goto ERROR; } |
| 3184 |
|
| 3185 |
if (hfp->format == p7_HMMFILE_3f) { if (magic != v3f_magic) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "bad magic number at start of HMM"); } |
| 3186 |
else if (hfp->format == p7_HMMFILE_3e) { if (magic != v3e_magic) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "bad magic number at start of HMM"); } |
| 3187 |
else if (hfp->format == p7_HMMFILE_3d) { if (magic != v3d_magic) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "bad magic number at start of HMM"); } |
| 3188 |
else if (hfp->format == p7_HMMFILE_3c) { if (magic != v3c_magic) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "bad magic number at start of HMM"); } |
| 3189 |
else if (hfp->format == p7_HMMFILE_3b) { if (magic != v3b_magic) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "bad magic number at start of HMM"); } |
| 3190 |
else if (hfp->format == p7_HMMFILE_3a) { if (magic != v3a_magic) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "bad magic number at start of HMM"); } |
| 3191 |
else ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "no such HMM file format code"); |
| 3192 |
} |
| 3193 |
|
| 3194 |
|
| 3195 |
|
| 3196 |
|
| 3197 |
|
| 3198 |
if ((hmm = p7_hmm_CreateShell()) == NULL) ESL_XFAIL(eslEMEM, hfp->rr_errbuf, "allocation failed, HMM shell"); |
| 3199 |
hmm->offset = offset; |
| 3200 |
|
| 3201 |
|
| 3202 |
|
| 3203 |
if (! fread((char *) &(hmm->flags), sizeof(int), 1, hfp->f)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read flags"); |
| 3204 |
if (! fread((char *) &(hmm->M), sizeof(int), 1, hfp->f)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read model size M"); |
| 3205 |
if (! fread((char *) &alphabet_type, sizeof(int), 1, hfp->f)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read alphabet_type"); |
| 3206 |
|
| 3207 |
|
| 3208 |
if (*ret_abc == NULL) { |
| 3209 |
if ((abc = esl_alphabet_Create(alphabet_type)) == NULL) ESL_XFAIL(eslEMEM, hfp->rr_errbuf, "allocation failed, alphabet"); |
| 3210 |
} else { |
| 3211 |
abc = *ret_abc; |
| 3212 |
if (abc->type != alphabet_type) ESL_XFAIL(eslEINCOMPAT, hfp->rr_errbuf, "Alphabet type mismatch: was %s, but current HMM says %s", esl_abc_DecodeType( abc->type), esl_abc_DecodeType(alphabet_type)); |
| 3213 |
} |
| 3214 |
|
| 3215 |
|
| 3216 |
|
| 3217 |
if ((status = p7_hmm_CreateBody(hmm, hmm->M, abc)) != eslOK) ESL_XFAIL(eslEMEM, hfp->rr_errbuf, "allocation failed, HMM body"); |
| 3218 |
|
| 3219 |
|
| 3220 |
for (k = 1; k <= hmm->M; k++) |
| 3221 |
if (! fread((char *) hmm->mat[k], sizeof(float), hmm->abc->K, hfp->f)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read mat[%d]", k); |
| 3222 |
for (k = 0; k <= hmm->M; k++) |
| 3223 |
if (! fread((char *) hmm->ins[k], sizeof(float), hmm->abc->K, hfp->f)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read ins[%d]", k); |
| 3224 |
for (k = 0; k <= hmm->M; k++) |
| 3225 |
if (! fread((char *) hmm->t[k], sizeof(float), p7H_NTRANSITIONS, hfp->f)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read t[%d]", k); |
| 3226 |
|
| 3227 |
|
| 3228 |
if (read_bin_string(hfp->f, &(hmm->name)) != eslOK) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read name"); |
| 3229 |
if ((hmm->flags & p7H_ACC) && read_bin_string(hfp->f, &(hmm->acc)) != eslOK) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read acc"); |
| 3230 |
if ((hmm->flags & p7H_DESC) && read_bin_string(hfp->f, &(hmm->desc)) != eslOK) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read desc"); |
| 3231 |
if ((hmm->flags & p7H_RF) && ! fread((char *) hmm->rf, sizeof(char), hmm->M+2, hfp->f)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read rf"); |
| 3232 |
if ((hmm->flags & p7H_MMASK)&& ! fread((char *) hmm->mm, sizeof(char), hmm->M+2, hfp->f)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read mm"); |
| 3233 |
if ((hmm->flags & p7H_CONS) && ! fread((char *) hmm->consensus, sizeof(char), hmm->M+2, hfp->f)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read consensus"); |
| 3234 |
if ((hmm->flags & p7H_CS) && ! fread((char *) hmm->cs, sizeof(char), hmm->M+2, hfp->f)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read cs"); |
| 3235 |
if ((hmm->flags & p7H_CA) && ! fread((char *) hmm->ca, sizeof(char), hmm->M+2, hfp->f)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read ca"); |
| 3236 |
if (read_bin_string(hfp->f, &(hmm->comlog)) != eslOK) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read comlog"); |
| 3237 |
if (! fread((char *) &(hmm->nseq), sizeof(int), 1, hfp->f)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read nseq"); |
| 3238 |
if (! fread((char *) &(hmm->eff_nseq), sizeof(float), 1, hfp->f)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read eff_nseq"); |
| 3239 |
if (hfp->format >= p7_HMMFILE_3c) { |
| 3240 |
if (! fread((char *) &(hmm->max_length), sizeof(int), 1, hfp->f)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read max_length"); |
| 3241 |
} |
| 3242 |
if (read_bin_string(hfp->f, &(hmm->ctime)) != eslOK) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read ctime"); |
| 3243 |
if ((hmm->flags & p7H_MAP) && ! fread((char *) hmm->map, sizeof(int), hmm->M+1, hfp->f)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read map"); |
| 3244 |
if (! fread((char *) &(hmm->checksum), sizeof(uint32_t),1,hfp->f)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read checksum"); |
| 3245 |
|
| 3246 |
|
| 3247 |
if (hfp->format >= p7_HMMFILE_3b) { |
| 3248 |
if (! fread((char *) hmm->evparam, sizeof(float), p7_NEVPARAM, hfp->f)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read statistical params"); |
| 3249 |
} else if (hfp->format == p7_HMMFILE_3a) { |
| 3250 |
|
| 3251 |
if (! fread((char *) hmm->evparam, sizeof(float), 3, hfp->f)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read statistical params"); |
| 3252 |
hmm->evparam[p7_FLAMBDA] = hmm->evparam[0]; |
| 3253 |
hmm->evparam[p7_FTAU] = hmm->evparam[2]; |
| 3254 |
hmm->evparam[p7_VLAMBDA] = hmm->evparam[0]; |
| 3255 |
hmm->evparam[p7_VMU] = hmm->evparam[1]; |
| 3256 |
hmm->evparam[p7_MLAMBDA] = hmm->evparam[p7_VLAMBDA]; |
| 3257 |
hmm->evparam[p7_MMU] = hmm->evparam[p7_VMU]; |
| 3258 |
} |
| 3259 |
if (! fread((char *) hmm->cutoff, sizeof(float), p7_NCUTOFFS, hfp->f)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read Pfam score cutoffs"); |
| 3260 |
if ((hmm->flags & p7H_COMPO) && ! fread((char *) hmm->compo, sizeof(float), hmm->abc->K, hfp->f)) ESL_XFAIL(eslEFORMAT, hfp->rr_errbuf, "failed to read model composition"); |
| 3261 |
|
| 3262 |
|
| 3263 |
if (hfp->format < p7_HMMFILE_3e && (status = p7_hmm_SetConsensus(hmm, NULL)) != eslOK) ESL_XFAIL(status, hfp->rr_errbuf, "Failed to set consensus on legacy HMM format"); |
| 3264 |
|
| 3265 |
if (*ret_abc == NULL) *ret_abc = abc; |
| 3266 |
if ( opt_hmm != NULL) *opt_hmm = hmm; else p7_hmm_Destroy(hmm); |
| 3267 |
return eslOK; |
| 3268 |
|
| 3269 |
ERROR: |
| 3270 |
if (*ret_abc == NULL && abc != NULL) esl_alphabet_Destroy(abc); |
| 3271 |
if (hmm != NULL) p7_hmm_Destroy(hmm); |
| 3272 |
if (opt_hmm != NULL) *opt_hmm = NULL; |
| 3273 |
return status; |
| 3274 |
} |
| 3275 |
|
| 3276 |
|
| 3277 |
|
| 3278 |
|
| 3279 |
|
| 3280 |
|
| 3281 |
|
| 3282 |
|
| 3283 |
|
| 3284 |
|
| 3285 |
|
| 3286 |
|
| 3287 |
|
| 3288 |
|
| 3289 |
|
| 3290 |
|
| 3291 |
|
| 3292 |
|
| 3293 |
|
| 3294 |
|
| 3295 |
|
| 3296 |
|
| 3297 |
|
| 3298 |
|
| 3299 |
|
| 3300 |
|
| 3301 |
|
| 3302 |
|
| 3303 |
|
| 3304 |
|
| 3305 |
|
| 3306 |
|
| 3307 |
|
| 3308 |
|
| 3309 |
|
| 3310 |
static int |
| 3311 |
read_bin_string(FILE *fp, char **ret_s) |
| 3312 |
{ |
| 3313 |
int status; |
| 3314 |
char *s = NULL; |
| 3315 |
int len; |
| 3316 |
|
| 3317 |
if (! fread((char *) &len, sizeof(int), 1, fp)) { status = eslEOD; goto ERROR; } |
| 3318 |
if (len > 0) { |
| 3319 |
ESL_ALLOC(s, (sizeof(char) * len)); |
| 3320 |
if (! fread((char *) s, sizeof(char), len, fp)) { status = eslEOD; goto ERROR; } |
| 3321 |
} |
| 3322 |
*ret_s = s; |
| 3323 |
return eslOK; |
| 3324 |
|
| 3325 |
ERROR: |
| 3326 |
if (s != NULL) free(s); |
| 3327 |
*ret_s = NULL; |
| 3328 |
return status; |
| 3329 |
} |
| 3330 |
|
| 3331 |
|
| 3332 |
|
| 3333 |
|
| 3334 |
|
| 3335 |
|
| 3336 |
|
| 3337 |
static char * |
| 3338 |
prob2ascii(float p, float null) |
| 3339 |
{ |
| 3340 |
static char buffer[32]; |
| 3341 |
|
| 3342 |
if (p == 0.0) return "*"; |
| 3343 |
snprintf(buffer, 32, "%.3f", sreLOG2(p/null)); |
| 3344 |
return buffer; |
| 3345 |
} |
| 3346 |
|
| 3347 |
|
| 3348 |
|
| 3349 |
|
| 3350 |
|
| 3351 |
|
| 3352 |
static float |
| 3353 |
ascii2prob(char *s, float null) |
| 3354 |
{ |
| 3355 |
return (*s == '*') ? 0. : exp(atof(s)/1.44269504)*null; |
| 3356 |
} |
| 3357 |
|
| 3358 |
|
| 3359 |
|
| 3360 |
|
| 3361 |
|
| 3362 |
|
| 3363 |
|
| 3364 |
|
| 3365 |
|
| 3366 |
|
| 3367 |
static int |
| 3368 |
is_integer(char *s) |
| 3369 |
{ |
| 3370 |
int hex = 0; |
| 3371 |
|
| 3372 |
if (s == NULL) return 0; |
| 3373 |
while (isspace((int) (*s))) s++; |
| 3374 |
if (*s == '-' || *s == '+') s++; |
| 3375 |
|
| 3376 |
if ((strncmp(s, "0x", 2) == 0 && (int) strlen(s) > 2) || |
| 3377 |
(strncmp(s, "0X", 2) == 0 && (int) strlen(s) > 2)) |
| 3378 |
{ |
| 3379 |
s += 2; |
| 3380 |
hex = 1; |
| 3381 |
} |
| 3382 |
else if (*s == '0' && (int) strlen(s) > 1) |
| 3383 |
s++; |
| 3384 |
|
| 3385 |
if (!hex) |
| 3386 |
while (*s != '\0') |
| 3387 |
{ |
| 3388 |
if (!isdigit((int) (*s))) return 0; |
| 3389 |
s++; |
| 3390 |
} |
| 3391 |
else |
| 3392 |
while (*s != '\0') |
| 3393 |
{ |
| 3394 |
if (!isxdigit((int) (*s))) return 0; |
| 3395 |
s++; |
| 3396 |
} |
| 3397 |
return 1; |
| 3398 |
} |
| 3399 |
|
| 3400 |
|
| 3401 |
|
| 3402 |
|
| 3403 |
|
| 3404 |
|
| 3405 |
|
| 3406 |
|
| 3407 |
static int |
| 3408 |
is_real(char *s) |
| 3409 |
{ |
| 3410 |
int gotdecimal = 0; |
| 3411 |
int gotexp = 0; |
| 3412 |
int gotreal = 0; |
| 3413 |
|
| 3414 |
if (s == NULL) return 0; |
| 3415 |
|
| 3416 |
while (isspace((int) (*s))) s++; |
| 3417 |
if (*s == '-' || *s == '+') s++; |
| 3418 |
|
| 3419 |
|
| 3420 |
|
| 3421 |
|
| 3422 |
|
| 3423 |
while (*s != '\0') |
| 3424 |
{ |
| 3425 |
if (isdigit((int) (*s))) gotreal++; |
| 3426 |
else if (*s == '.') |
| 3427 |
{ |
| 3428 |
if (gotdecimal) return 0; |
| 3429 |
if (gotexp) return 0; |
| 3430 |
else gotdecimal++; |
| 3431 |
} |
| 3432 |
else if (*s == 'e' || *s == 'E') |
| 3433 |
{ |
| 3434 |
if (gotexp) return 0; |
| 3435 |
else gotexp++; |
| 3436 |
} |
| 3437 |
else if (isspace((int) (*s))) |
| 3438 |
break; |
| 3439 |
s++; |
| 3440 |
} |
| 3441 |
|
| 3442 |
while (isspace((int) (*s))) s++; |
| 3443 |
if (*s == '\0' && gotreal) return 1; |
| 3444 |
else return 0; |
| 3445 |
} |
| 3446 |
|
| 3447 |
|
| 3448 |
|
| 3449 |
|
| 3450 |
|
| 3451 |
|
| 3452 |
|
| 3453 |
|
| 3454 |
|
| 3455 |
|
| 3456 |
|
| 3457 |
|
| 3458 |
|
| 3459 |
|
| 3460 |
|
| 3461 |
|
| 3462 |
|
| 3463 |
|
| 3464 |
|
| 3465 |
|
| 3466 |
|
| 3467 |
|
| 3468 |
int |
| 3469 |
cm_file_Write1p0ASCII(FILE *fp, CM_t *cm) |
| 3470 |
{ |
| 3471 |
int status; |
| 3472 |
int v,x,y,nd; |
| 3473 |
char *comlog2print = NULL; |
| 3474 |
|
| 3475 |
fprintf(fp, "INFERNAL-1 [converted from %s]\n", INFERNAL_VERSION); |
| 3476 |
|
| 3477 |
fprintf(fp, "NAME %s\n", cm->name); |
| 3478 |
if (cm->acc != NULL) fprintf(fp, "ACC %s\n", cm->acc); |
| 3479 |
if (cm->desc != NULL) fprintf(fp, "DESC %s\n", cm->desc); |
| 3480 |
|
| 3481 |
if (cm->flags & CMH_GA) fprintf(fp, "GA %.2f\n", cm->ga); |
| 3482 |
if (cm->flags & CMH_TC) fprintf(fp, "TC %.2f\n", cm->tc); |
| 3483 |
if (cm->flags & CMH_NC) fprintf(fp, "NC %.2f\n", cm->nc); |
| 3484 |
fprintf(fp, "STATES %d\n", cm->M); |
| 3485 |
fprintf(fp, "NODES %d\n", cm->nodes); |
| 3486 |
fprintf(fp, "ALPHABET %d\n", cm->abc->type); |
| 3487 |
fprintf(fp, "ELSELF %.8f\n", cm->el_selfsc); |
| 3488 |
fprintf(fp, "WBETA %g\n", cm->beta_W); |
| 3489 |
fprintf(fp, "NSEQ %d\n", cm->nseq); |
| 3490 |
fprintf(fp, "EFFNSEQ %.3f\n", cm->eff_nseq); |
| 3491 |
fprintf(fp, "CLEN %d\n", cm->clen); |
| 3492 |
|
| 3493 |
|
| 3494 |
|
| 3495 |
|
| 3496 |
|
| 3497 |
|
| 3498 |
|
| 3499 |
|
| 3500 |
|
| 3501 |
|
| 3502 |
if(cm->comlog != NULL) { |
| 3503 |
ESL_ALLOC(comlog2print, sizeof(char) * (strlen(cm->comlog)+1)); |
| 3504 |
x = 0; |
| 3505 |
while(x < strlen(cm->comlog) && cm->comlog[x] != '\n') { comlog2print[x] = cm->comlog[x]; x++; } |
| 3506 |
comlog2print[x] = '\0'; |
| 3507 |
fprintf(fp, "BCOM %s\n", comlog2print); |
| 3508 |
free(comlog2print); |
| 3509 |
} |
| 3510 |
if(cm->ctime != NULL) fprintf(fp, "BDATE %s\n", cm->ctime); |
| 3511 |
|
| 3512 |
fputs( "NULL ", fp); |
| 3513 |
for (x = 0; x < cm->abc->K; x++) |
| 3514 |
fprintf(fp, "%6s ", prob2ascii(cm->null[x], 1/(float)(cm->abc->K))); |
| 3515 |
fputs("\n", fp); |
| 3516 |
|
| 3517 |
|
| 3518 |
|
| 3519 |
|
| 3520 |
|
| 3521 |
|
| 3522 |
fputs("MODEL:\n", fp); |
| 3523 |
for (v = 0; v < cm->M; v++) |
| 3524 |
{ |
| 3525 |
nd = cm->ndidx[v]; |
| 3526 |
|
| 3527 |
|
| 3528 |
|
| 3529 |
if (cm->nodemap[nd] == v) |
| 3530 |
fprintf(fp, "\t\t\t\t[ %-4s %4d ]\n", Nodetype(cm->ndtype[nd]), nd); |
| 3531 |
|
| 3532 |
|
| 3533 |
|
| 3534 |
fprintf(fp, " %2s %5d %5d %1d %5d %5d ", |
| 3535 |
Statetype(cm->sttype[v]), v, |
| 3536 |
cm->plast[v], cm->pnum[v], |
| 3537 |
cm->cfirst[v], cm->cnum[v]); |
| 3538 |
if (cm->sttype[v] != B_st) |
| 3539 |
for (x = 0; x < cm->cnum[v]; x++) |
| 3540 |
fprintf(fp, "%7s ", prob2ascii(cm->t[v][x], 1.)); |
| 3541 |
else x = 0; |
| 3542 |
for (; x < 6; x++) |
| 3543 |
fprintf(fp, "%7s ", ""); |
| 3544 |
|
| 3545 |
|
| 3546 |
|
| 3547 |
if (cm->sttype[v] == MP_st) |
| 3548 |
{ |
| 3549 |
for (x = 0; x < cm->abc->K; x++) |
| 3550 |
for (y = 0; y < cm->abc->K; y++) |
| 3551 |
fprintf(fp, "%6s ", prob2ascii(cm->e[v][x*cm->abc->K+y], cm->null[x]*cm->null[y])); |
| 3552 |
} |
| 3553 |
else if (cm->sttype[v] == ML_st || cm->sttype[v] == MR_st || cm->sttype[v] == IL_st || cm->sttype[v] == IR_st) |
| 3554 |
{ |
| 3555 |
for (x = 0; x < cm->abc->K; x++) |
| 3556 |
fprintf(fp, "%6s ", prob2ascii(cm->e[v][x], cm->null[x])); |
| 3557 |
} |
| 3558 |
fputs("\n", fp); |
| 3559 |
} |
| 3560 |
fputs("//\n", fp); |
| 3561 |
return eslOK; |
| 3562 |
|
| 3563 |
ERROR: |
| 3564 |
ESL_EXCEPTION(eslEMEM, "out of memory"); |
| 3565 |
return status; |
| 3566 |
} |
| 3567 |
|
| 3568 |
|
| 3569 |
|
| 3570 |
|
| 3571 |
|
| 3572 |
|
| 3573 |
|
| 3574 |
|
| 3575 |
|
| 3576 |
|
| 3577 |
|
| 3578 |
|
| 3579 |
|
| 3580 |
|
| 3581 |
|
| 3582 |
|
| 3583 |
|
| 3584 |
|
| 3585 |
|
| 3586 |
|
| 3587 |
|
| 3588 |
|
| 3589 |
|
| 3590 |
|
| 3591 |
|
| 3592 |
|
| 3593 |
|
| 3594 |
|
| 3595 |
static int |
| 3596 |
multiline(FILE *fp, const char *pfx, char *s) |
| 3597 |
{ |
| 3598 |
char *sptr = s; |
| 3599 |
char *end = NULL; |
| 3600 |
int n = 0; |
| 3601 |
int nline = 1; |
| 3602 |
|
| 3603 |
do { |
| 3604 |
end = strchr(sptr, '\n'); |
| 3605 |
|
| 3606 |
if (end != NULL) |
| 3607 |
{ |
| 3608 |
n = end - sptr; |
| 3609 |
if (fprintf(fp, "%s [%d] ", pfx, nline++) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "hmm write failed"); |
| 3610 |
if (fwrite(sptr, sizeof(char), n, fp) != n) ESL_EXCEPTION_SYS(eslEWRITE, "hmm write failed"); |
| 3611 |
if (fprintf(fp, "\n") < 0) ESL_EXCEPTION_SYS(eslEWRITE, "hmm write failed"); |
| 3612 |
sptr += n + 1; |
| 3613 |
} |
| 3614 |
else |
| 3615 |
{ |
| 3616 |
if (fprintf(fp, "%s [%d] %s\n", pfx, nline++, sptr) < 0) ESL_EXCEPTION_SYS(eslEWRITE, "hmm write failed"); |
| 3617 |
} |
| 3618 |
} while (end != NULL && *sptr != '\0'); |
| 3619 |
return eslOK; |
| 3620 |
} |
| 3621 |
|
| 3622 |
|
| 3623 |
|
| 3624 |
|
| 3625 |
|
| 3626 |
#ifdef CM_FILE_BENCHMARK |
| 3627 |
|
| 3628 |
|
| 3629 |
|
| 3630 |
|
| 3631 |
|
| 3632 |
#include <esl_config.h> |
| 3633 |
#include <p7_config.h> |
| 3634 |
#include "config.h" |
| 3635 |
|
| 3636 |
#include <stdlib.h> |
| 3637 |
#include <stdio.h> |
| 3638 |
|
| 3639 |
#include "easel.h" |
| 3640 |
#include "esl_getopts.h" |
| 3641 |
#include "esl_stopwatch.h" |
| 3642 |
|
| 3643 |
#include "hmmer.h" |
| 3644 |
|
| 3645 |
#include "infernal.h" |
| 3646 |
|
| 3647 |
static ESL_OPTIONS options[] = { |
| 3648 |
|
| 3649 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 3650 |
{ "-a", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "include time of CM configuration", 0 }, |
| 3651 |
{ "-v", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "verbose: print model info as they're read", 0 }, |
| 3652 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 3653 |
}; |
| 3654 |
static char usage[] = "[-options] <CM file>"; |
| 3655 |
static char banner[] = "benchmark driver for CM input"; |
| 3656 |
|
| 3657 |
int |
| 3658 |
main(int argc, char **argv) |
| 3659 |
{ |
| 3660 |
ESL_GETOPTS *go = cm_CreateDefaultApp(options, 1, argc, argv, banner, usage); |
| 3661 |
ESL_STOPWATCH *w = esl_stopwatch_Create(); |
| 3662 |
ESL_STOPWATCH *w2 = esl_stopwatch_Create(); |
| 3663 |
ESL_ALPHABET *abc = NULL; |
| 3664 |
char *cmfile = esl_opt_GetArg(go, 1); |
| 3665 |
CM_FILE *cmfp = NULL; |
| 3666 |
CM_t *cm = NULL; |
| 3667 |
int nmodel = 0; |
| 3668 |
uint64_t tot_clen = 0; |
| 3669 |
int status; |
| 3670 |
int be_verbose = esl_opt_GetBoolean(go, "-v"); |
| 3671 |
char errbuf[eslERRBUFSIZE]; |
| 3672 |
|
| 3673 |
esl_stopwatch_Start(w); |
| 3674 |
|
| 3675 |
status = cm_file_Open(cmfile, NULL, FALSE, &cmfp, errbuf); |
| 3676 |
if (status == eslENOTFOUND) cm_Fail("File existence/permissions problem in trying to open CM file %s.\n%s\n", cmfile, errbuf); |
| 3677 |
else if (status == eslEFORMAT) cm_Fail("File format problem in trying to open CM file %s.\n%s\n", cmfile, errbuf); |
| 3678 |
else if (status != eslOK) cm_Fail("Unexpected error %d in opening CM file %s.\n%s\n", status, cmfile, errbuf); |
| 3679 |
if (cmfp->do_gzip) cm_Fail("Reading gzipped CM files is not supported"); |
| 3680 |
if (cmfp->do_stdin) cm_Fail("Reading CM files from stdin is not supported"); |
| 3681 |
|
| 3682 |
if(be_verbose) esl_stopwatch_Start(w2); |
| 3683 |
while ((status = cm_file_Read(cmfp, &abc, &cm)) == eslOK) |
| 3684 |
{ |
| 3685 |
nmodel++; |
| 3686 |
tot_clen += cm->clen; |
| 3687 |
|
| 3688 |
if (esl_opt_GetBoolean(go, "-a")) { |
| 3689 |
if((status = cm_Configure(cm, errbuf, -1)) != eslOK) cm_Fail(errbuf); |
| 3690 |
} |
| 3691 |
|
| 3692 |
if(be_verbose) { |
| 3693 |
esl_stopwatch_Stop(w2); |
| 3694 |
printf("%-30s ", cm->name); |
| 3695 |
esl_stopwatch_Display(stdout, w2, "CPU time: "); |
| 3696 |
esl_stopwatch_Start(w2); |
| 3697 |
} |
| 3698 |
FreeCM(cm); |
| 3699 |
} |
| 3700 |
if (status == eslEFORMAT) cm_Fail("bad file format in CM file %s\n%s", cmfile, cmfp->errbuf); |
| 3701 |
else if (status == eslEINCOMPAT) cm_Fail("CM file %s contains different alphabets\n%s", cmfile, cmfp->errbuf); |
| 3702 |
else if (status != eslEOF) cm_Fail("Unexpected error in reading CMs from %s\n%s", cmfile, cmfp->errbuf); |
| 3703 |
|
| 3704 |
esl_stopwatch_Stop(w); |
| 3705 |
esl_stopwatch_Display(stdout, w, "# CPU time: "); |
| 3706 |
printf("# number of models: %d\n", nmodel); |
| 3707 |
printf("# total clen: %" PRId64 "\n", tot_clen); |
| 3708 |
|
| 3709 |
cm_file_Close(cmfp); |
| 3710 |
esl_alphabet_Destroy(abc); |
| 3711 |
esl_stopwatch_Destroy(w); |
| 3712 |
esl_stopwatch_Destroy(w2); |
| 3713 |
esl_getopts_Destroy(go); |
| 3714 |
return 0; |
| 3715 |
} |
| 3716 |
#endif |
| 3717 |
|
| 3718 |
|
| 3719 |
|
| 3720 |
|
| 3721 |
|
| 3722 |
|
| 3723 |
|
| 3724 |
|
| 3725 |
|
| 3726 |
|
| 3727 |
|
| 3728 |
|
| 3729 |
|
| 3730 |
|
| 3731 |
|
| 3732 |
|
| 3733 |
|
| 3734 |
|
| 3735 |
|
| 3736 |
|
| 3737 |
#ifdef CMFILE_EXAMPLE |
| 3738 |
|
| 3739 |
|
| 3740 |
#include <esl_config.h> |
| 3741 |
#include <p7_config.h> |
| 3742 |
#include "config.h" |
| 3743 |
|
| 3744 |
#include "easel.h" |
| 3745 |
#include "esl_alphabet.h" |
| 3746 |
|
| 3747 |
#include "hmmer.h" |
| 3748 |
|
| 3749 |
#include "infernal.h" |
| 3750 |
|
| 3751 |
int |
| 3752 |
main(int argc, char **argv) |
| 3753 |
{ |
| 3754 |
char *cmfile = argv[1]; |
| 3755 |
CM_FILE *cmfp = NULL; |
| 3756 |
CM_t *cm = NULL; |
| 3757 |
ESL_ALPHABET *abc = NULL; |
| 3758 |
char errbuf[eslERRBUFSIZE]; |
| 3759 |
int status; |
| 3760 |
|
| 3761 |
|
| 3762 |
status = cm_file_Open(cmfile, NULL, FALSE, &cmfp, errbuf); |
| 3763 |
if (status == eslENOTFOUND) cm_Fail("File existence/permissions problem in trying to open CM file %s.\n%s\n", cmfile, errbuf); |
| 3764 |
else if (status == eslEFORMAT) cm_Fail("File format problem in trying to open CM file %s.\n%s\n", cmfile, errbuf); |
| 3765 |
else if (status != eslOK) cm_Fail("Unexpected error %d in opening CM file %s.\n%s\n", status, cmfile, errbuf); |
| 3766 |
|
| 3767 |
status = cm_file_Read(cmfp, TRUE, &abc, &cm); |
| 3768 |
if (status == eslEFORMAT) cm_Fail("Bad file format in CM file %s:\n%s\n", cmfp->fname, cmfp->errbuf); |
| 3769 |
else if (status == eslEINCOMPAT) cm_Fail("CM in %s is not in the expected %s alphabet\n", cmfp->fname, esl_abc_DecodeType(abc->type)); |
| 3770 |
else if (status == eslEOF) cm_Fail("Empty CM file %s? No CM data found.\n", cmfp->fname); |
| 3771 |
else if (status != eslOK) cm_Fail("Unexpected error in reading CMs from %s\n", cmfp->fname); |
| 3772 |
|
| 3773 |
status = cm_file_Read(cmfp, TRUE, &abc, NULL); |
| 3774 |
if (status != eslEOF) cm_Fail("CM file %s does not contain just one CM\n", cmfp->fname); |
| 3775 |
|
| 3776 |
cm_file_Close(cmfp); |
| 3777 |
|
| 3778 |
cm_file_WriteASCII(stdout, -1, cm); |
| 3779 |
|
| 3780 |
esl_alphabet_Destroy(abc); |
| 3781 |
FreeCM(cm); |
| 3782 |
return 0; |
| 3783 |
} |
| 3784 |
#endif |
| 3785 |
|
| 3786 |
|