| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#include <esl_config.h> |
| 20 |
|
| 21 |
#include <stdlib.h> |
| 22 |
#include <stdio.h> |
| 23 |
#include <string.h> |
| 24 |
#include <ctype.h> |
| 25 |
|
| 26 |
#include "easel.h" |
| 27 |
#include "esl_alphabet.h" |
| 28 |
#include "esl_arr2.h" |
| 29 |
#include "esl_arr3.h" |
| 30 |
#include "esl_keyhash.h" |
| 31 |
#include "esl_msa.h" |
| 32 |
#include "esl_msafile.h" |
| 33 |
#include "esl_ssi.h" |
| 34 |
#include "esl_vectorops.h" |
| 35 |
#include "esl_wuss.h" |
| 36 |
|
| 37 |
#include "esl_msafile2.h" |
| 38 |
|
| 39 |
|
| 40 |
static int msafile2_getline(ESL_MSAFILE2 *afp); |
| 41 |
static int is_blankline(char *s); |
| 42 |
static int parse_gf(ESL_MSA *msa, char *buf); |
| 43 |
static int parse_gc(ESL_MSA *msa, char *buf); |
| 44 |
static int parse_comment(ESL_MSA *msa, char *buf); |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
static int msafile2_open(const char *filename, const char *env, ESL_MSAFILE2 **ret_afp); |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
int |
| 88 |
esl_msafile2_Open(const char *filename, const char *env, ESL_MSAFILE2 **ret_afp) |
| 89 |
{ |
| 90 |
return msafile2_open(filename, env, ret_afp); |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
void |
| 99 |
esl_msafile2_Close(ESL_MSAFILE2 *afp) |
| 100 |
{ |
| 101 |
if (afp == NULL) return; |
| 102 |
|
| 103 |
#ifdef HAVE_POPEN |
| 104 |
if (afp->do_gzip && afp->f != NULL) pclose(afp->f); |
| 105 |
#endif |
| 106 |
if (!afp->do_gzip && ! afp->do_stdin && afp->f != NULL) fclose(afp->f); |
| 107 |
if (afp->fname) free(afp->fname); |
| 108 |
if (afp->buf) free(afp->buf); |
| 109 |
if (afp->ssi) esl_ssi_Close(afp->ssi); |
| 110 |
if (afp->msa_cache) esl_msa_Destroy(afp->msa_cache); |
| 111 |
free(afp); |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
int |
| 146 |
esl_msafile2_OpenDigital(const ESL_ALPHABET *abc, const char *filename, |
| 147 |
const char *env, ESL_MSAFILE2 **ret_msafp) |
| 148 |
{ |
| 149 |
ESL_MSAFILE2 *msafp; |
| 150 |
int status; |
| 151 |
|
| 152 |
if ((status = msafile2_open(filename, env, &msafp)) != eslOK) return status; |
| 153 |
|
| 154 |
msafp->abc = abc; |
| 155 |
msafp->do_digital = TRUE; |
| 156 |
|
| 157 |
*ret_msafp = msafp; |
| 158 |
return eslOK; |
| 159 |
} |
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
static int |
| 166 |
msafile2_open(const char *filename, const char *env, ESL_MSAFILE2 **ret_afp) |
| 167 |
{ |
| 168 |
ESL_MSAFILE2 *afp = NULL; |
| 169 |
char *ssifile = NULL; |
| 170 |
char *envfile = NULL; |
| 171 |
char *cmd = NULL; |
| 172 |
int n = strlen(filename); |
| 173 |
int nc; |
| 174 |
int status; |
| 175 |
|
| 176 |
ESL_ALLOC(afp, sizeof(ESL_MSAFILE2)); |
| 177 |
afp->f = NULL; |
| 178 |
afp->fname = NULL; |
| 179 |
afp->linenumber = 0; |
| 180 |
afp->errbuf[0] = '\0'; |
| 181 |
afp->buf = NULL; |
| 182 |
afp->buflen = 0; |
| 183 |
afp->do_gzip = FALSE; |
| 184 |
afp->do_stdin = FALSE; |
| 185 |
afp->format = eslMSAFILE_PFAM; |
| 186 |
afp->do_digital = FALSE; |
| 187 |
afp->abc = NULL; |
| 188 |
afp->ssi = NULL; |
| 189 |
afp->msa_cache = NULL; |
| 190 |
|
| 191 |
if (strcmp(filename, "-") == 0) |
| 192 |
{ |
| 193 |
afp->f = stdin; |
| 194 |
afp->do_stdin = TRUE; |
| 195 |
if ((status = esl_strdup("[STDIN]", -1, &(afp->fname))) != eslOK) goto ERROR; |
| 196 |
} |
| 197 |
#ifdef HAVE_POPEN |
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
else if (n > 3 && strcmp(filename+n-3, ".gz") == 0) |
| 206 |
{ |
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
if (! esl_FileExists(filename)) { status = eslENOTFOUND; goto ERROR; } |
| 213 |
nc = strlen("gzip -dc ") + n + 1; |
| 214 |
ESL_ALLOC(cmd, nc); |
| 215 |
snprintf(cmd, nc, "gzip -dc %s", filename); |
| 216 |
if ((afp->f = popen(cmd, "r")) == NULL) { status = eslENOTFOUND; goto ERROR; } |
| 217 |
if ((status = esl_strdup(filename, n, &(afp->fname))) != eslOK) goto ERROR; |
| 218 |
afp->do_gzip = TRUE; |
| 219 |
} |
| 220 |
#endif |
| 221 |
else |
| 222 |
{ |
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
if ((afp->f = fopen(filename, "r")) != NULL) |
| 228 |
{ |
| 229 |
if ((status = esl_strdup(filename, n, &ssifile)) != eslOK) goto ERROR; |
| 230 |
if ((status = esl_strcat(&ssifile, n, ".ssi", 4)) != eslOK) goto ERROR; |
| 231 |
if ((status = esl_strdup(filename, n, &(afp->fname))) != eslOK) goto ERROR; |
| 232 |
} |
| 233 |
else if (esl_FileEnvOpen(filename, env, &(afp->f), &envfile) == eslOK) |
| 234 |
{ |
| 235 |
if ((status = esl_strdup(envfile, n, &ssifile)) != eslOK) goto ERROR; |
| 236 |
if ((status = esl_strcat(&ssifile, n, ".ssi", 4)) != eslOK) goto ERROR; |
| 237 |
if ((status = esl_strdup(envfile, n, &(afp->fname))) != eslOK) goto ERROR; |
| 238 |
} |
| 239 |
else |
| 240 |
{ status = eslENOTFOUND; goto ERROR;} |
| 241 |
} |
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
esl_ssi_Open(ssifile, &(afp->ssi)); |
| 249 |
|
| 250 |
if (envfile != NULL) free(envfile); |
| 251 |
if (ssifile != NULL) free(ssifile); |
| 252 |
if (cmd != NULL) free(cmd); |
| 253 |
*ret_afp = afp; |
| 254 |
return eslOK; |
| 255 |
|
| 256 |
ERROR: |
| 257 |
if (envfile != NULL) free(envfile); |
| 258 |
if (ssifile != NULL) free(ssifile); |
| 259 |
if (cmd != NULL) free(cmd); |
| 260 |
if (afp != NULL) esl_msafile2_Close(afp); |
| 261 |
*ret_afp = NULL; |
| 262 |
return status; |
| 263 |
} |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
static int get_pp_idx(ESL_ALPHABET *abc, char ppchar); |
| 274 |
static int gapize_string(char *src_str, int64_t src_len, int64_t dst_len, int *ngapA, char gapchar, char **ret_dst_str); |
| 275 |
static void shrink_string(char *str, const int *useme, int len); |
| 276 |
static int determine_spacelen(char *s); |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
|
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
|
| 336 |
|
| 337 |
|
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
int |
| 354 |
esl_msafile2_ReadInfoPfam(ESL_MSAFILE2 *afp, FILE *listfp, ESL_ALPHABET *abc, int64_t known_alen, char *known_rf, char *known_ss_cons, ESL_MSA **ret_msa, |
| 355 |
int *opt_nseq, int64_t *opt_alen, int *opt_ngs, int *opt_maxname, int *opt_maxgf, int *opt_maxgc, int *opt_maxgr, |
| 356 |
double ***opt_abc_ct, double ***opt_pp_ct, double ****opt_bp_ct, int **opt_spos_ct, int **opt_epos_ct) |
| 357 |
{ |
| 358 |
char *s; |
| 359 |
int status; |
| 360 |
int status2; |
| 361 |
ESL_MSA *msa = NULL; |
| 362 |
int nseq = 0; |
| 363 |
int64_t alen = -1; |
| 364 |
int ngs = 0; |
| 365 |
int maxname = 0; |
| 366 |
int maxgf = 0; |
| 367 |
int maxgc = 0; |
| 368 |
int maxgr = 0; |
| 369 |
char *seqname; |
| 370 |
int namelen; |
| 371 |
char *first_seqname = NULL; |
| 372 |
char *gf, *gc, *gr; |
| 373 |
char *tag; |
| 374 |
int taglen; |
| 375 |
char *text; |
| 376 |
int textlen; |
| 377 |
int i, x; |
| 378 |
int j; |
| 379 |
int apos; |
| 380 |
double **abc_ct = NULL; |
| 381 |
double ***bp_ct = NULL; |
| 382 |
|
| 383 |
int nppvals = 12; |
| 384 |
double **pp_ct = NULL; |
| 385 |
int ppidx; |
| 386 |
int *spos_ct = NULL; |
| 387 |
int *epos_ct = NULL; |
| 388 |
ESL_DSQ *tmp_dsq = NULL; |
| 389 |
int *a2rf_map = NULL; |
| 390 |
|
| 391 |
int *ct = NULL; |
| 392 |
char *ss_nopseudo = NULL; |
| 393 |
|
| 394 |
if(afp->format != eslMSAFILE_PFAM) ESL_EXCEPTION(eslEINCONCEIVABLE, "only non-interleaved (1 line /seq, Pfam) Stockholm formatted files can be read in small memory mode"); |
| 395 |
if(opt_abc_ct != NULL && abc == NULL) ESL_FAIL(eslEINVAL, afp->errbuf, "contract violation, abc == NULL, opt_abc_ct != NULL"); |
| 396 |
if(opt_pp_ct != NULL && abc == NULL) ESL_FAIL(eslEINVAL, afp->errbuf, "contract violation, abc == NULL, opt_pp_ct != NULL"); |
| 397 |
if(opt_bp_ct != NULL && abc == NULL) ESL_FAIL(eslEINVAL, afp->errbuf, "contract violation, abc == NULL, opt_bp_ct != NULL"); |
| 398 |
if(opt_spos_ct != NULL && abc == NULL) ESL_FAIL(eslEINVAL, afp->errbuf, "contract violation, abc == NULL, opt_spos_ct != NULL"); |
| 399 |
if(opt_epos_ct != NULL && abc == NULL) ESL_FAIL(eslEINVAL, afp->errbuf, "contract violation, abc == NULL, opt_epos_ct != NULL"); |
| 400 |
if(opt_spos_ct != NULL && known_alen == -1) ESL_FAIL(eslEINVAL, afp->errbuf, "contract violation, opt_spos_ct != NULL, known_alen == -1"); |
| 401 |
if(opt_epos_ct != NULL && known_alen == -1) ESL_FAIL(eslEINVAL, afp->errbuf, "contract violation, opt_epos_ct != NULL, known_alen == -1"); |
| 402 |
if(opt_bp_ct != NULL && known_ss_cons == NULL) ESL_FAIL(eslEINVAL, afp->errbuf, "contract violation, known_ss_cons == NULL, opt_bp_ct != NULL"); |
| 403 |
if(known_rf != NULL && known_alen == -1) ESL_FAIL(eslEINVAL, afp->errbuf, "contract violation, known_rf != NULL, known_alen == -1"); |
| 404 |
if(known_ss_cons != NULL && known_alen == -1) ESL_FAIL(eslEINVAL, afp->errbuf, "contract violation, known_ss_cons != NULL, known_alen == -1"); |
| 405 |
|
| 406 |
if (feof(afp->f)) { status = eslEOF; goto ERROR; } |
| 407 |
afp->errbuf[0] = '\0'; |
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
if(opt_spos_ct != NULL || opt_epos_ct != NULL) { |
| 412 |
ESL_ALLOC(spos_ct, sizeof(int) * known_alen); |
| 413 |
ESL_ALLOC(epos_ct, sizeof(int) * known_alen); |
| 414 |
esl_vec_ISet(spos_ct, known_alen, 0); |
| 415 |
esl_vec_ISet(epos_ct, known_alen, 0); |
| 416 |
} |
| 417 |
|
| 418 |
|
| 419 |
if(opt_bp_ct != NULL) { |
| 420 |
|
| 421 |
ESL_ALLOC(ct, sizeof(int) * (known_alen+1)); |
| 422 |
ESL_ALLOC(ss_nopseudo, sizeof(char) * (known_alen+1)); |
| 423 |
esl_wuss_nopseudo(known_ss_cons, ss_nopseudo); |
| 424 |
if ((status = esl_wuss2ct(ss_nopseudo, known_alen, ct)) != eslOK) ESL_FAIL(status, afp->errbuf, "consensus structure string is inconsistent."); |
| 425 |
ESL_ALLOC(bp_ct, sizeof(double **) * known_alen); |
| 426 |
for(apos = 0; apos < known_alen; apos++) { |
| 427 |
|
| 428 |
if(ct[(apos+1)] > (apos+1)) { |
| 429 |
ESL_ALLOC(bp_ct[apos], sizeof(double *) * (abc->Kp)); |
| 430 |
for(x = 0; x < abc->Kp; x++) { |
| 431 |
ESL_ALLOC(bp_ct[apos][x], sizeof(double) * (abc->Kp)); |
| 432 |
esl_vec_DSet(bp_ct[apos][x], abc->Kp, 0.); |
| 433 |
} |
| 434 |
} |
| 435 |
else { |
| 436 |
bp_ct[apos] = NULL; |
| 437 |
} |
| 438 |
} |
| 439 |
} |
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
if (afp->do_digital == TRUE && (msa = esl_msa_CreateDigital(afp->abc, 16, -1)) == NULL) |
| 447 |
{ status = eslEMEM; goto ERROR; } |
| 448 |
if (afp->do_digital == FALSE && (msa = esl_msa_Create(16, -1)) == NULL) |
| 449 |
{ status = eslEMEM; goto ERROR; } |
| 450 |
if (msa == NULL) |
| 451 |
{ status = eslEMEM; goto ERROR; } |
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
do { |
| 459 |
if ((status = msafile2_getline(afp)) != eslOK) goto ERROR; |
| 460 |
} while (is_blankline(afp->buf)); |
| 461 |
|
| 462 |
if (strncmp(afp->buf, "# STOCKHOLM 1.", 14) != 0) |
| 463 |
ESL_XFAIL(eslEFORMAT, afp->errbuf, "parse failed (line %d): missing \"# STOCKHOLM\" header", afp->linenumber); |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
while ((status2 = msafile2_getline(afp)) == eslOK) |
| 468 |
{ |
| 469 |
s = afp->buf; |
| 470 |
while (*s == ' ' || *s == '\t') s++; |
| 471 |
|
| 472 |
if (*s == '#') { |
| 473 |
if(strncmp(s, "#=GF", 4) == 0) |
| 474 |
{ |
| 475 |
if (ret_msa != NULL) { |
| 476 |
if ((status = parse_gf(msa, s)) != eslOK) |
| 477 |
ESL_XFAIL(status, afp->errbuf, "parse failed (line %d): bad #=GF line", afp->linenumber); |
| 478 |
} |
| 479 |
else if (opt_maxgf != NULL) { |
| 480 |
s = afp->buf; |
| 481 |
if (esl_strtok (&s, " \t\n\r", &gf) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GF line", afp->linenumber); |
| 482 |
if (esl_strtok_adv(&s, " \t\n\r", &tag, &taglen, NULL) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GF line", afp->linenumber); |
| 483 |
maxgf = ESL_MAX(maxgf, taglen); |
| 484 |
} |
| 485 |
} |
| 486 |
|
| 487 |
else if (strncmp(s, "#=GC", 4) == 0) |
| 488 |
{ |
| 489 |
if (ret_msa != NULL) { |
| 490 |
if ((status = parse_gc(msa, s)) != eslOK) |
| 491 |
ESL_XFAIL(status, afp->errbuf, "parse failed (line %d): bad #=GC line", afp->linenumber); |
| 492 |
} |
| 493 |
else if (opt_maxgc != NULL) { |
| 494 |
s = afp->buf; |
| 495 |
if (esl_strtok (&s, " \t\n\r", &gc) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GC line", afp->linenumber); |
| 496 |
if (esl_strtok_adv(&s, " \t\n\r", &tag, &taglen, NULL) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GC line", afp->linenumber); |
| 497 |
maxgc = ESL_MAX(maxgc, taglen); |
| 498 |
} |
| 499 |
} |
| 500 |
else if (strncmp(s, "#=GS", 4) == 0) |
| 501 |
{ |
| 502 |
ngs++; |
| 503 |
} |
| 504 |
else if (strncmp(s, "#=GR", 4) == 0) |
| 505 |
{ |
| 506 |
if(opt_maxgr != NULL || opt_pp_ct != NULL) { |
| 507 |
s = afp->buf; |
| 508 |
if (esl_strtok (&s, " \t\n\r", &gr) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GR line", afp->linenumber); |
| 509 |
if (esl_strtok_adv(&s, " \t\n\r", &seqname, &namelen, NULL) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GR line", afp->linenumber); |
| 510 |
if (esl_strtok_adv(&s, " \t\n\r", &tag, &taglen, NULL) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GR line", afp->linenumber); |
| 511 |
maxgr = ESL_MAX(maxgr, taglen); |
| 512 |
if(opt_pp_ct != NULL) { |
| 513 |
if (strncmp(tag, "PP", 2) == 0) { |
| 514 |
if (esl_strtok_adv(&s, " \t\n\r", &text, &textlen, NULL) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GR PP line", afp->linenumber); |
| 515 |
|
| 516 |
if(alen == -1) { |
| 517 |
alen = textlen; |
| 518 |
if(known_alen != -1 && known_alen != textlen) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): known alen (%" PRId64 " passed in) != actual alen (%d)", afp->linenumber, known_alen, textlen); |
| 519 |
ESL_ALLOC(pp_ct, sizeof(double *) * alen); |
| 520 |
for(apos = 0; apos < alen; apos++) { |
| 521 |
ESL_ALLOC(pp_ct[apos], sizeof(double) * nppvals); |
| 522 |
esl_vec_DSet(pp_ct[apos], nppvals, 0.); |
| 523 |
} |
| 524 |
if(opt_abc_ct != NULL || opt_bp_ct != NULL) { |
| 525 |
ESL_ALLOC(tmp_dsq, (alen+2) * sizeof(ESL_DSQ)); |
| 526 |
} |
| 527 |
if(opt_abc_ct != NULL) { |
| 528 |
ESL_ALLOC(abc_ct, sizeof(double *) * alen); |
| 529 |
for(apos = 0; apos < alen; apos++) { |
| 530 |
ESL_ALLOC(abc_ct[apos], sizeof(double) * (abc->K+1)); |
| 531 |
esl_vec_DSet(abc_ct[apos], (abc->K+1), 0.); |
| 532 |
} |
| 533 |
} |
| 534 |
} |
| 535 |
else if(alen != textlen) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GR PP line, len %d, expected %" PRId64, afp->linenumber, textlen, alen); |
| 536 |
for(apos = 0; apos < alen; apos++) { |
| 537 |
if((ppidx = get_pp_idx(abc, text[apos])) == -1) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GR PP char: %c", afp->linenumber, text[apos]); |
| 538 |
pp_ct[apos][ppidx] += 1.; |
| 539 |
} |
| 540 |
} |
| 541 |
} |
| 542 |
} |
| 543 |
} |
| 544 |
else if (ret_msa != NULL && ((status = parse_comment(msa, s)) != eslOK)) { |
| 545 |
ESL_XFAIL(status, afp->errbuf, "parse failed (line %d): bad comment line", afp->linenumber); |
| 546 |
} |
| 547 |
} |
| 548 |
else if (strncmp(s, "//", 2) == 0) break; |
| 549 |
else if (*s == '\n' || *s == '\r') continue; |
| 550 |
else { |
| 551 |
if(listfp != NULL || opt_maxname != NULL || opt_alen != NULL || opt_abc_ct != NULL || opt_spos_ct != NULL || opt_epos_ct != NULL) { |
| 552 |
s = afp->buf; |
| 553 |
if (esl_strtok_adv(&s, " \t\n\r", &seqname, &namelen, NULL) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad sequence line", afp->linenumber); |
| 554 |
if (listfp != NULL) fprintf(listfp, "%s\n", seqname); |
| 555 |
maxname = ESL_MAX(maxname, namelen); |
| 556 |
if (opt_alen != NULL || opt_abc_ct != NULL || opt_spos_ct != NULL || opt_epos_ct != NULL) { |
| 557 |
if (esl_strtok_adv(&s, " \t\n\r", &text, &textlen, NULL) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad sequence line", afp->linenumber); |
| 558 |
|
| 559 |
if(nseq == 0) { |
| 560 |
if ((status = esl_strdup(seqname, -1, &(first_seqname))) != eslOK) goto ERROR; |
| 561 |
} |
| 562 |
else if(strcmp(first_seqname, seqname) == 0) { ESL_XFAIL(eslEFORMAT, afp->errbuf, "parse failed (line %d): two seqs with same name. Alignment may be in interleaved Stockholm. Reformat to Pfam with esl-reformat.", afp->linenumber); } |
| 563 |
if(alen == -1) { |
| 564 |
alen = textlen; |
| 565 |
if(known_alen != -1 && known_alen != textlen) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): known alen (%" PRId64 " passed in) != actual alen (%d)", afp->linenumber, known_alen, textlen); |
| 566 |
if(opt_abc_ct != NULL || opt_bp_ct != NULL) { |
| 567 |
ESL_ALLOC(tmp_dsq, (alen+2) * sizeof(ESL_DSQ)); |
| 568 |
} |
| 569 |
if(opt_abc_ct != NULL) { |
| 570 |
ESL_ALLOC(abc_ct, sizeof(double *) * alen); |
| 571 |
for(apos = 0; apos < alen; apos++) { |
| 572 |
ESL_ALLOC(abc_ct[apos], sizeof(double) * (abc->K+1)); |
| 573 |
esl_vec_DSet(abc_ct[apos], (abc->K+1), 0.); |
| 574 |
} |
| 575 |
} |
| 576 |
if(opt_pp_ct != NULL) { |
| 577 |
ESL_ALLOC(pp_ct, sizeof(double *) * alen); |
| 578 |
for(apos = 0; apos < alen; apos++) { |
| 579 |
ESL_ALLOC(pp_ct[apos], sizeof(double) * nppvals); |
| 580 |
esl_vec_DSet(pp_ct[apos], nppvals, 0.); |
| 581 |
} |
| 582 |
} |
| 583 |
} |
| 584 |
else if(alen != textlen) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad aligned seq line, len %d, expected %" PRId64, afp->linenumber, textlen, alen); |
| 585 |
if(opt_abc_ct != NULL || opt_bp_ct != NULL) { |
| 586 |
|
| 587 |
if((status = esl_abc_Digitize(abc, text, tmp_dsq)) != eslOK) ESL_XFAIL(status, afp->errbuf, "small mem parse failed (line %d): problem digitizing sequence", afp->linenumber); |
| 588 |
} |
| 589 |
if(opt_abc_ct != NULL) { |
| 590 |
for(apos = 0; apos < alen; apos++) { |
| 591 |
if((status = esl_abc_DCount(abc, abc_ct[apos], tmp_dsq[apos+1], 1.0)) != eslOK) ESL_XFAIL(status, afp->errbuf, "small mem parse failed (line %d): problem counting residue %d", afp->linenumber, apos+1); |
| 592 |
} |
| 593 |
} |
| 594 |
if(opt_bp_ct != NULL) { |
| 595 |
for(apos = 0; apos < alen; apos++) { |
| 596 |
if(bp_ct[apos] != NULL) { |
| 597 |
j = ct[apos+1] - 1; |
| 598 |
bp_ct[apos][tmp_dsq[(apos+1)]][tmp_dsq[(j+1)]]++; |
| 599 |
} |
| 600 |
} |
| 601 |
} |
| 602 |
if(opt_spos_ct != NULL) { |
| 603 |
for(apos = 0; apos < alen; apos++) { |
| 604 |
if(! esl_abc_XIsGap(abc, tmp_dsq[apos+1])) { |
| 605 |
spos_ct[apos]++; |
| 606 |
break; |
| 607 |
} |
| 608 |
} |
| 609 |
} |
| 610 |
if(opt_epos_ct != NULL) { |
| 611 |
for(apos = alen-1; apos >= 0; apos--) { |
| 612 |
if(! esl_abc_XIsGap(abc, tmp_dsq[apos+1])) { |
| 613 |
epos_ct[apos]++; |
| 614 |
break; |
| 615 |
} |
| 616 |
} |
| 617 |
} |
| 618 |
} |
| 619 |
} |
| 620 |
nseq++; |
| 621 |
} |
| 622 |
} |
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
if (status2 != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "parse failed (line %d): didn't find // at end of alignment", afp->linenumber); |
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
if(ret_msa != NULL && opt_maxgc != NULL) { |
| 632 |
for(i = 0; i < msa->ngc; i++) maxgc = ESL_MAX(maxgc, strlen(msa->gc_tag[i])); |
| 633 |
if (msa->rf != NULL) maxgc = ESL_MAX(maxgc, 2); |
| 634 |
if (msa->mm != NULL) maxgc = ESL_MAX(maxgc, 2); |
| 635 |
if (msa->ss_cons != NULL) maxgc = ESL_MAX(maxgc, 7); |
| 636 |
if (msa->sa_cons != NULL) maxgc = ESL_MAX(maxgc, 7); |
| 637 |
if (msa->pp_cons != NULL) maxgc = ESL_MAX(maxgc, 7); |
| 638 |
} |
| 639 |
|
| 640 |
if(ret_msa != NULL && opt_maxgf != NULL) { |
| 641 |
for(i = 0; i < msa->ngf; i++) maxgf = ESL_MAX(maxgf, strlen(msa->gf_tag[i])); |
| 642 |
if (msa->name != NULL) maxgf = ESL_MAX(maxgf, 2); |
| 643 |
if (msa->desc != NULL) maxgf = ESL_MAX(maxgf, 2); |
| 644 |
if (msa->acc != NULL) maxgf = ESL_MAX(maxgf, 2); |
| 645 |
if (msa->au != NULL) maxgf = ESL_MAX(maxgf, 2); |
| 646 |
} |
| 647 |
|
| 648 |
if (first_seqname) free(first_seqname); |
| 649 |
if (tmp_dsq) free(tmp_dsq); |
| 650 |
if (ct) free(ct); |
| 651 |
if (ss_nopseudo) free(ss_nopseudo); |
| 652 |
if (a2rf_map) free(a2rf_map); |
| 653 |
|
| 654 |
if (ret_msa) *ret_msa = msa; else esl_msa_Destroy(msa); |
| 655 |
if (opt_nseq) *opt_nseq = nseq; |
| 656 |
if (opt_alen) *opt_alen = alen; |
| 657 |
if (opt_ngs) *opt_ngs = ngs; |
| 658 |
if (opt_maxname) *opt_maxname = maxname; |
| 659 |
if (opt_maxgf) *opt_maxgf = maxgf; |
| 660 |
if (opt_maxgc) *opt_maxgc = maxgc; |
| 661 |
if (opt_maxgr) *opt_maxgr = maxgr; |
| 662 |
if (opt_abc_ct) *opt_abc_ct = abc_ct; else esl_arr2_Destroy((void **) abc_ct, alen); |
| 663 |
if (opt_pp_ct) *opt_pp_ct = pp_ct; else esl_arr2_Destroy((void **) pp_ct, alen); |
| 664 |
if (opt_bp_ct) *opt_bp_ct = bp_ct; else esl_arr3_Destroy((void ***) bp_ct, known_alen, abc ? abc->Kp : 0); |
| 665 |
if (opt_spos_ct) *opt_spos_ct = spos_ct; else esl_free(spos_ct); |
| 666 |
if (opt_epos_ct) *opt_epos_ct = epos_ct; else esl_free(epos_ct); |
| 667 |
return eslOK; |
| 668 |
|
| 669 |
ERROR: |
| 670 |
esl_free(first_seqname); |
| 671 |
esl_free(tmp_dsq); |
| 672 |
esl_free(ct); |
| 673 |
esl_free(ss_nopseudo); |
| 674 |
esl_free(a2rf_map); |
| 675 |
|
| 676 |
esl_msa_Destroy(msa); |
| 677 |
esl_arr2_Destroy((void **) pp_ct, alen); |
| 678 |
esl_arr2_Destroy((void **) abc_ct, alen); |
| 679 |
esl_arr3_Destroy((void ***) bp_ct, known_alen, abc ? abc->Kp : 0); |
| 680 |
esl_free(spos_ct); |
| 681 |
esl_free(epos_ct); |
| 682 |
|
| 683 |
if (ret_msa) *ret_msa = NULL; |
| 684 |
if (opt_nseq) *opt_nseq = 0; |
| 685 |
if (opt_alen) *opt_alen = 0; |
| 686 |
if (opt_ngs) *opt_ngs = 0; |
| 687 |
if (opt_maxname) *opt_maxname = 0; |
| 688 |
if (opt_maxgf) *opt_maxgf = 0; |
| 689 |
if (opt_maxgc) *opt_maxgc = 0; |
| 690 |
if (opt_maxgr) *opt_maxgr = 0; |
| 691 |
if (opt_pp_ct) *opt_pp_ct = NULL; |
| 692 |
if (opt_abc_ct) *opt_abc_ct = NULL; |
| 693 |
if (opt_bp_ct) *opt_bp_ct = NULL; |
| 694 |
if (opt_spos_ct) *opt_spos_ct = NULL; |
| 695 |
if (opt_epos_ct) *opt_epos_ct = NULL; |
| 696 |
return status; |
| 697 |
} |
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
|
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 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 |
|
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
|
| 795 |
int |
| 796 |
esl_msafile2_RegurgitatePfam(ESL_MSAFILE2 *afp, FILE *ofp, int maxname, int maxgf, int maxgc, int maxgr, |
| 797 |
int do_header, int do_trailer, int do_blanks, int do_comments, int do_gf, |
| 798 |
int do_gs, int do_gc, int do_gr, int do_aseq, ESL_KEYHASH *seqs2regurg, |
| 799 |
ESL_KEYHASH *seqs2skip, int *useme, int *add2me, int exp_alen, char gapchar2add, |
| 800 |
int *opt_nseq_read, int *opt_nseq_regurged) |
| 801 |
{ |
| 802 |
char *s = NULL; |
| 803 |
int status; |
| 804 |
int status2; |
| 805 |
char *seqname = NULL; |
| 806 |
char *first_seqname = NULL; |
| 807 |
char *text = NULL; |
| 808 |
char *gapped_text = NULL; |
| 809 |
char *tag = NULL; |
| 810 |
char *gf = NULL; |
| 811 |
char *gc = NULL; |
| 812 |
char *gs = NULL; |
| 813 |
char *gr = NULL; |
| 814 |
int curmargin, curmargin2, namelen, spacelen, spacelen2, textlen, taglen; |
| 815 |
int gaps2addlen; |
| 816 |
int margin; |
| 817 |
int flushpoint = 10000; |
| 818 |
int nseq_read = 0; |
| 819 |
int nseq_regurged = 0; |
| 820 |
|
| 821 |
|
| 822 |
if ( ofp == NULL) ESL_EXCEPTION(eslEINCONCEIVABLE, "ofp is NULL"); |
| 823 |
if ( afp->format != eslMSAFILE_PFAM) ESL_EXCEPTION(eslEINCONCEIVABLE, "only Pfam (1 line /seq) Stockholm formatted files allowed in small mem mode"); |
| 824 |
if(add2me != NULL && useme != NULL) ESL_EXCEPTION(eslEINCONCEIVABLE, "add2me and useme both non-NULL"); |
| 825 |
if((add2me != NULL || useme != NULL) && exp_alen == -1) ESL_EXCEPTION(eslEINCONCEIVABLE, "exp_alen == -1, but add2me or useme non-NULL"); |
| 826 |
if(seqs2regurg != NULL && seqs2skip != NULL) ESL_EXCEPTION(eslEINVAL, "seqs2regurg and seqs2skip both non-NULL, only one may be"); |
| 827 |
|
| 828 |
gaps2addlen = (add2me == NULL) ? 0 : esl_vec_ISum(add2me, (exp_alen+1)); |
| 829 |
|
| 830 |
margin = -1; |
| 831 |
if (maxgf != -1 && maxgf < 2) maxgf = 2; |
| 832 |
if (maxname != -1) margin = maxname+1; |
| 833 |
if (maxgc > 0 && maxgc+6 > margin) margin = maxgc+6; |
| 834 |
if (maxgr > 0 && maxname+maxgr+7 > margin) margin = maxname+maxgr+7; |
| 835 |
|
| 836 |
|
| 837 |
if (feof(afp->f)) { status = eslEOF; goto ERROR; } |
| 838 |
afp->errbuf[0] = '\0'; |
| 839 |
|
| 840 |
|
| 841 |
|
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
do { |
| 846 |
if ((status = msafile2_getline(afp)) != eslOK) goto ERROR; |
| 847 |
} while (is_blankline(afp->buf)); |
| 848 |
|
| 849 |
if (strncmp(afp->buf, "# STOCKHOLM 1.", 14) != 0) |
| 850 |
ESL_XFAIL(eslEFORMAT, afp->errbuf, "parse failed (line %d): missing \"# STOCKHOLM\" header", afp->linenumber); |
| 851 |
if(do_header) fprintf(ofp, "%s", afp->buf); |
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
while ((status2 = msafile2_getline(afp)) == eslOK) |
| 856 |
{ |
| 857 |
if(afp->linenumber % flushpoint == 0) fflush(ofp); |
| 858 |
s = afp->buf; |
| 859 |
while (*s == ' ' || *s == '\t') s++; |
| 860 |
|
| 861 |
if (*s == '#') { |
| 862 |
|
| 863 |
if (strncmp(s, "#=GF", 4) == 0) |
| 864 |
{ |
| 865 |
if (do_gf) { |
| 866 |
if(maxgf == -1) { |
| 867 |
fprintf(ofp, "%s", afp->buf); |
| 868 |
} |
| 869 |
else { |
| 870 |
s = afp->buf; |
| 871 |
if (esl_strtok(&s, " \t\n\r", &gf) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GF line", afp->linenumber); |
| 872 |
if (esl_strtok(&s, " \t\n\r", &tag) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GF line", afp->linenumber); |
| 873 |
if (esl_strtok(&s, "\n\r", &text) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GF line", afp->linenumber); |
| 874 |
fprintf(ofp, "#=GF %-*s %s\n", maxgf, tag, text); |
| 875 |
} |
| 876 |
} |
| 877 |
} |
| 878 |
else if (strncmp(s, "#=GC", 4) == 0) |
| 879 |
{ |
| 880 |
if(do_gc) { |
| 881 |
|
| 882 |
s = afp->buf; |
| 883 |
if (esl_strtok (&s, " \t\n\r", &gc) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GC line", afp->linenumber); |
| 884 |
if (esl_strtok_adv(&s, " \t\n\r", &tag, &taglen, NULL) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GC line", afp->linenumber); |
| 885 |
spacelen = determine_spacelen(s); |
| 886 |
if (esl_strtok_adv(&s, " \t\n\r", &text, &textlen, NULL) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GC line", afp->linenumber); |
| 887 |
|
| 888 |
|
| 889 |
if(exp_alen == -1) exp_alen = textlen; |
| 890 |
else if(exp_alen != textlen) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GC line, len %d, expected %d", afp->linenumber, textlen, exp_alen); |
| 891 |
|
| 892 |
|
| 893 |
curmargin = (margin == -1) ? taglen + spacelen : margin - 6; |
| 894 |
|
| 895 |
|
| 896 |
if(useme != NULL) { |
| 897 |
|
| 898 |
if (strncmp(tag, "SS_cons", 7) == 0 && afp->abc && (afp->abc->type == eslRNA || afp->abc->type == eslDNA)) { |
| 899 |
if((status = esl_msa_RemoveBrokenBasepairsFromSS(text, afp->errbuf, textlen, useme)) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GC SS_cons line", afp->linenumber); |
| 900 |
} |
| 901 |
shrink_string(text, useme, exp_alen); |
| 902 |
} |
| 903 |
if(add2me != NULL) { |
| 904 |
if((status = gapize_string(text, textlen, textlen + gaps2addlen, add2me, gapchar2add, &gapped_text)) != eslOK) goto ERROR; |
| 905 |
fprintf(ofp, "#=GC %-*s %s\n", curmargin, tag, gapped_text); |
| 906 |
free(gapped_text); |
| 907 |
} |
| 908 |
else { |
| 909 |
fprintf(ofp, "#=GC %-*s %s\n", curmargin, tag, text); |
| 910 |
} |
| 911 |
} |
| 912 |
} |
| 913 |
else if (strncmp(s, "#=GS", 4) == 0) |
| 914 |
{ |
| 915 |
|
| 916 |
if (do_gs) { |
| 917 |
if(maxname == -1 && seqs2regurg == NULL) { |
| 918 |
fprintf(ofp, "%s", afp->buf); |
| 919 |
} |
| 920 |
else { |
| 921 |
if((seqs2regurg == NULL && seqs2skip == NULL) || |
| 922 |
(seqs2regurg != NULL && (status = esl_keyhash_Lookup(seqs2regurg, seqname, -1, NULL)) == eslOK) || |
| 923 |
(seqs2skip != NULL && (status = esl_keyhash_Lookup(seqs2skip, seqname, -1, NULL)) == eslENOTFOUND)) |
| 924 |
{ |
| 925 |
s = afp->buf; |
| 926 |
if (esl_strtok(&s, " \t\n\r", &gs) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GS line", afp->linenumber); |
| 927 |
if (esl_strtok(&s, " \t\n\r", &seqname) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GS line", afp->linenumber); |
| 928 |
if (esl_strtok(&s, " \t\n\r", &tag) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GS line", afp->linenumber); |
| 929 |
if (esl_strtok(&s, "\n\r", &text) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GS line", afp->linenumber); |
| 930 |
fprintf(ofp, "#=GS %-*s %s %s\n", maxname, seqname, tag, text); |
| 931 |
} |
| 932 |
} |
| 933 |
} |
| 934 |
} |
| 935 |
else if (strncmp(s, "#=GR", 4) == 0) |
| 936 |
{ |
| 937 |
if(do_gr) { |
| 938 |
|
| 939 |
s = afp->buf; |
| 940 |
if (esl_strtok (&s, " \t\n\r", &gr) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GR line", afp->linenumber); |
| 941 |
if (esl_strtok_adv(&s, " \t\n\r", &seqname, &namelen, NULL) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GR line", afp->linenumber); |
| 942 |
spacelen = determine_spacelen(s); |
| 943 |
if (esl_strtok_adv(&s, " \t\n\r", &tag, &taglen, NULL) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GR line", afp->linenumber); |
| 944 |
spacelen2 = determine_spacelen(s); |
| 945 |
if (esl_strtok_adv(&s, " \t\n\r", &text, &textlen, NULL) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GR line", afp->linenumber); |
| 946 |
|
| 947 |
|
| 948 |
if(exp_alen == -1) exp_alen = textlen; |
| 949 |
else if(exp_alen != textlen) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GR line, len %d, expected %d", afp->linenumber, textlen, exp_alen); |
| 950 |
|
| 951 |
|
| 952 |
curmargin = (maxname == -1) ? namelen + spacelen : maxname; |
| 953 |
curmargin2 = (maxname == -1) ? taglen + spacelen2 : margin - maxname - 7; |
| 954 |
|
| 955 |
|
| 956 |
if((seqs2regurg == NULL && seqs2skip == NULL) || |
| 957 |
(seqs2regurg != NULL && (status = esl_keyhash_Lookup(seqs2regurg, seqname, -1, NULL)) == eslOK) || |
| 958 |
(seqs2skip != NULL && (status = esl_keyhash_Lookup(seqs2skip, seqname, -1, NULL)) == eslENOTFOUND)) |
| 959 |
{ |
| 960 |
|
| 961 |
if(useme != NULL) { |
| 962 |
|
| 963 |
if( strncmp(tag, "SS", 2) == 0 && afp->abc && (afp->abc->type == eslRNA || afp->abc->type == eslDNA)) { |
| 964 |
if((status = esl_msa_RemoveBrokenBasepairsFromSS(text, afp->errbuf, textlen, useme)) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad #=GR SS line", afp->linenumber); |
| 965 |
} |
| 966 |
shrink_string(text, useme, exp_alen); |
| 967 |
} |
| 968 |
if(add2me != NULL) { |
| 969 |
if((status = gapize_string(text, textlen, textlen + gaps2addlen, add2me, gapchar2add, &gapped_text)) != eslOK) goto ERROR; |
| 970 |
fprintf(ofp, "#=GR %-*s %-*s %s\n", curmargin, seqname, curmargin2, tag, gapped_text); |
| 971 |
free(gapped_text); |
| 972 |
} |
| 973 |
else { |
| 974 |
fprintf(ofp, "#=GR %-*s %-*s %s\n", curmargin, seqname, curmargin2, tag, text); |
| 975 |
} |
| 976 |
} |
| 977 |
} |
| 978 |
} |
| 979 |
else if (do_comments) fprintf(ofp, "%s", afp->buf); |
| 980 |
} |
| 981 |
else if (strncmp(s, "//", 2) == 0) { if(do_trailer) fprintf(ofp, "%s", afp->buf); break; } |
| 982 |
else if (*s == '\n' || *s == '\r') { if(do_blanks) { fprintf(ofp, "%s", afp->buf); } continue; } |
| 983 |
else { |
| 984 |
if(do_aseq) { |
| 985 |
|
| 986 |
s = afp->buf; |
| 987 |
if (esl_strtok_adv(&s, " \t\n\r", &seqname, &namelen, NULL) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad sequence line", afp->linenumber); |
| 988 |
spacelen = determine_spacelen(s); |
| 989 |
if (esl_strtok_adv(&s, " \t\n\r", &text, &textlen, NULL) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad sequence line", afp->linenumber); |
| 990 |
|
| 991 |
|
| 992 |
if((exp_alen != -1) && (exp_alen != textlen)) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): bad seq line, len %d, expected %d", afp->linenumber, textlen, exp_alen); |
| 993 |
|
| 994 |
|
| 995 |
curmargin = (margin == -1) ? namelen + spacelen : margin-1; |
| 996 |
|
| 997 |
|
| 998 |
if(nseq_read == 0) { if ((status = esl_strdup(seqname, -1, &(first_seqname))) != eslOK) goto ERROR; } |
| 999 |
else if(strcmp(first_seqname, seqname) == 0) { ESL_XFAIL(eslEFORMAT, afp->errbuf, "parse failed (line %d): two seqs named %s. Alignment appears to be in Stockholm format. Reformat to Pfam with esl-reformat.", afp->linenumber, seqname); } |
| 1000 |
nseq_read++; |
| 1001 |
|
| 1002 |
|
| 1003 |
if((seqs2regurg == NULL && seqs2skip == NULL) || |
| 1004 |
(seqs2regurg != NULL && (status = esl_keyhash_Lookup(seqs2regurg, seqname, -1, NULL)) == eslOK) || |
| 1005 |
(seqs2skip != NULL && (status = esl_keyhash_Lookup(seqs2skip, seqname, -1, NULL)) == eslENOTFOUND)) |
| 1006 |
{ |
| 1007 |
|
| 1008 |
nseq_regurged++; |
| 1009 |
if(useme != NULL) shrink_string(text, useme, exp_alen); |
| 1010 |
if(add2me != NULL) { |
| 1011 |
if((status = gapize_string(text, textlen, textlen + gaps2addlen, add2me, gapchar2add, &gapped_text)) != eslOK) goto ERROR; |
| 1012 |
fprintf(ofp, "%-*s %s\n", curmargin, seqname, gapped_text); |
| 1013 |
free(gapped_text); |
| 1014 |
} |
| 1015 |
else { |
| 1016 |
fprintf(ofp, "%-*s %s\n", curmargin, seqname, text); |
| 1017 |
} |
| 1018 |
} |
| 1019 |
} |
| 1020 |
} |
| 1021 |
} |
| 1022 |
|
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
if (status2 != eslOK) ESL_XFAIL(eslEFORMAT, afp->errbuf, "small mem parse failed (line %d): didn't find // at end of alignment", afp->linenumber); |
| 1027 |
if (first_seqname != NULL) free(first_seqname); |
| 1028 |
if (opt_nseq_read != NULL) *opt_nseq_read = nseq_read; |
| 1029 |
if (opt_nseq_regurged != NULL) *opt_nseq_regurged = nseq_regurged; |
| 1030 |
return eslOK; |
| 1031 |
|
| 1032 |
ERROR: |
| 1033 |
return status; |
| 1034 |
} |
| 1035 |
|
| 1036 |
|
| 1037 |
|
| 1038 |
|
| 1039 |
|
| 1040 |
|
| 1041 |
|
| 1042 |
|
| 1043 |
|
| 1044 |
|
| 1045 |
|
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
static int |
| 1060 |
get_pp_idx(ESL_ALPHABET *abc, char ppchar) |
| 1061 |
{ |
| 1062 |
if(esl_abc_CIsGap(abc, ppchar)) return 11; |
| 1063 |
if(ppchar == '*') return 10; |
| 1064 |
if(ppchar == '9') return 9; |
| 1065 |
if(ppchar == '8') return 8; |
| 1066 |
if(ppchar == '7') return 7; |
| 1067 |
if(ppchar == '6') return 6; |
| 1068 |
if(ppchar == '5') return 5; |
| 1069 |
if(ppchar == '4') return 4; |
| 1070 |
if(ppchar == '3') return 3; |
| 1071 |
if(ppchar == '2') return 2; |
| 1072 |
if(ppchar == '1') return 1; |
| 1073 |
if(ppchar == '0') return 0; |
| 1074 |
return -1; |
| 1075 |
} |
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
static int |
| 1094 |
gapize_string(char *src_str, int64_t src_len, int64_t dst_len, int *ngapA, char gapchar, char **ret_dst_str) |
| 1095 |
{ |
| 1096 |
int status; |
| 1097 |
int src_apos = 0; |
| 1098 |
int dst_apos = 0; |
| 1099 |
int i; |
| 1100 |
char *dst_str; |
| 1101 |
|
| 1102 |
ESL_ALLOC(dst_str, sizeof(char) * (dst_len+1)); |
| 1103 |
dst_str[dst_len] = '\0'; |
| 1104 |
|
| 1105 |
|
| 1106 |
for(i = 0; i < ngapA[0]; i++) dst_str[dst_apos++] = gapchar; |
| 1107 |
|
| 1108 |
|
| 1109 |
for(src_apos = 0; src_apos < src_len; src_apos++) { |
| 1110 |
dst_str[dst_apos++] = src_str[src_apos]; |
| 1111 |
for(i = 0; i < ngapA[(src_apos+1)]; i++) dst_str[dst_apos++] = gapchar; |
| 1112 |
} |
| 1113 |
|
| 1114 |
*ret_dst_str = dst_str; |
| 1115 |
return eslOK; |
| 1116 |
|
| 1117 |
ERROR: |
| 1118 |
return eslEMEM; |
| 1119 |
} |
| 1120 |
|
| 1121 |
|
| 1122 |
|
| 1123 |
|
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
static void |
| 1128 |
shrink_string(char *str, const int *useme, int len) |
| 1129 |
{ |
| 1130 |
int opos, npos; |
| 1131 |
|
| 1132 |
for (opos = 0, npos = 0; opos < len; opos++) { |
| 1133 |
if (useme[opos] == FALSE) continue; |
| 1134 |
str[npos++] = str[opos]; |
| 1135 |
} |
| 1136 |
str[npos] = '\0'; |
| 1137 |
return; |
| 1138 |
} |
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
static int |
| 1147 |
determine_spacelen(char *s) |
| 1148 |
{ |
| 1149 |
int spacelen = 0; |
| 1150 |
while (*s == ' ') { spacelen++; s++; } |
| 1151 |
return spacelen; |
| 1152 |
} |
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
|
| 1159 |
|
| 1160 |
|
| 1161 |
|
| 1162 |
|
| 1163 |
|
| 1164 |
|
| 1165 |
|
| 1166 |
static int |
| 1167 |
msafile2_getline(ESL_MSAFILE2 *afp) |
| 1168 |
{ |
| 1169 |
int status; |
| 1170 |
status = esl_fgets(&(afp->buf), &(afp->buflen), afp->f); |
| 1171 |
afp->linenumber++; |
| 1172 |
return status; |
| 1173 |
} |
| 1174 |
|
| 1175 |
|
| 1176 |
static int |
| 1177 |
is_blankline(char *s) |
| 1178 |
{ |
| 1179 |
for (; *s != '\0'; s++) |
| 1180 |
if (! isspace((int) *s)) return FALSE; |
| 1181 |
return TRUE; |
| 1182 |
} |
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
static int |
| 1190 |
parse_gf(ESL_MSA *msa, char *buf) |
| 1191 |
{ |
| 1192 |
char *gf; |
| 1193 |
char *tag; |
| 1194 |
char *text; |
| 1195 |
char *tok; |
| 1196 |
char *s; |
| 1197 |
int n; |
| 1198 |
int status; |
| 1199 |
|
| 1200 |
s = buf; |
| 1201 |
if (esl_strtok(&s, " \t\n\r", &gf) != eslOK) return eslEFORMAT; |
| 1202 |
if (esl_strtok(&s, " \t\n\r", &tag) != eslOK) return eslEFORMAT; |
| 1203 |
|
| 1204 |
|
| 1205 |
while (isspace(*s)) s++; |
| 1206 |
status = esl_strtok_adv(&s, "\n\r", &text, &n, NULL); |
| 1207 |
if (status == eslEOL) { if (strcmp(tag, "CC") != 0) return eslEFORMAT; } |
| 1208 |
else if (status != eslOK) { return eslEFORMAT; } |
| 1209 |
|
| 1210 |
if (strcmp(tag, "ID") == 0) status = esl_strdup(text, n, &(msa->name)); |
| 1211 |
else if (strcmp(tag, "AC") == 0) status = esl_strdup(text, n, &(msa->acc)); |
| 1212 |
else if (strcmp(tag, "DE") == 0) status = esl_strdup(text, n, &(msa->desc)); |
| 1213 |
else if (strcmp(tag, "AU") == 0) status = esl_strdup(text, n, &(msa->au)); |
| 1214 |
else if (strcmp(tag, "GA") == 0) |
| 1215 |
{ |
| 1216 |
s = text; |
| 1217 |
if ((esl_strtok(&s, " \t\n\r", &tok)) != eslOK) |
| 1218 |
return eslEFORMAT; |
| 1219 |
msa->cutoff[eslMSA_GA1] = atof(tok); |
| 1220 |
msa->cutset[eslMSA_GA1] = TRUE; |
| 1221 |
if ((esl_strtok(&s, " \t\n\r", &tok)) == eslOK) |
| 1222 |
{ |
| 1223 |
msa->cutoff[eslMSA_GA2] = atof(tok); |
| 1224 |
msa->cutset[eslMSA_GA2] = TRUE; |
| 1225 |
} |
| 1226 |
status = eslOK; |
| 1227 |
} |
| 1228 |
else if (strcmp(tag, "NC") == 0) |
| 1229 |
{ |
| 1230 |
s = text; |
| 1231 |
if ((esl_strtok(&s, " \t\n\r", &tok)) != eslOK) |
| 1232 |
return eslEFORMAT; |
| 1233 |
msa->cutoff[eslMSA_NC1] = atof(tok); |
| 1234 |
msa->cutset[eslMSA_NC1] = TRUE; |
| 1235 |
if ((esl_strtok(&s, " \t\n\r", &tok)) == eslOK) |
| 1236 |
{ |
| 1237 |
msa->cutoff[eslMSA_NC2] = atof(tok); |
| 1238 |
msa->cutset[eslMSA_NC2] = TRUE; |
| 1239 |
} |
| 1240 |
status = eslOK; |
| 1241 |
} |
| 1242 |
else if (strcmp(tag, "TC") == 0) |
| 1243 |
{ |
| 1244 |
s = text; |
| 1245 |
if ((esl_strtok(&s, " \t\n\r", &tok)) != eslOK) |
| 1246 |
return eslEFORMAT; |
| 1247 |
msa->cutoff[eslMSA_TC1] = atof(tok); |
| 1248 |
msa->cutset[eslMSA_TC1] = TRUE; |
| 1249 |
if ((esl_strtok(&s, "\t\n\r", &tok)) == eslOK) |
| 1250 |
{ |
| 1251 |
msa->cutoff[eslMSA_TC2] = atof(tok); |
| 1252 |
msa->cutset[eslMSA_TC2] = TRUE; |
| 1253 |
} |
| 1254 |
status = eslOK; |
| 1255 |
} |
| 1256 |
else if (strcmp(tag, "CC") == 0 && text == NULL) |
| 1257 |
status = esl_msa_AddGF (msa, tag, -1, "", -1); |
| 1258 |
else |
| 1259 |
status = esl_msa_AddGF(msa, tag, -1, text, -1); |
| 1260 |
|
| 1261 |
return status; |
| 1262 |
} |
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
static int |
| 1269 |
parse_gc(ESL_MSA *msa, char *buf) |
| 1270 |
{ |
| 1271 |
char *gc; |
| 1272 |
char *tag; |
| 1273 |
char *text; |
| 1274 |
char *s; |
| 1275 |
int len; |
| 1276 |
int status; |
| 1277 |
|
| 1278 |
s = buf; |
| 1279 |
if (esl_strtok (&s, " \t\n\r", &gc) != eslOK) return eslEFORMAT; |
| 1280 |
if (esl_strtok (&s, " \t\n\r", &tag) != eslOK) return eslEFORMAT; |
| 1281 |
if (esl_strtok_adv(&s, " \t\n\r", &text, &len, NULL) != eslOK) return eslEFORMAT; |
| 1282 |
|
| 1283 |
if (strcmp(tag, "SS_cons") == 0) status = esl_strcat(&(msa->ss_cons), -1, text, len); |
| 1284 |
else if (strcmp(tag, "SA_cons") == 0) status = esl_strcat(&(msa->sa_cons), -1, text, len); |
| 1285 |
else if (strcmp(tag, "PP_cons") == 0) status = esl_strcat(&(msa->pp_cons), -1, text, len); |
| 1286 |
else if (strcmp(tag, "RF") == 0) status = esl_strcat(&(msa->rf), -1, text, len); |
| 1287 |
else if (strcmp(tag, "MM") == 0) status = esl_strcat(&(msa->mm), -1, text, len); |
| 1288 |
else status = esl_msa_AppendGC(msa, tag, text); |
| 1289 |
|
| 1290 |
return status; |
| 1291 |
} |
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
static int |
| 1298 |
parse_comment(ESL_MSA *msa, char *buf) |
| 1299 |
{ |
| 1300 |
char *s; |
| 1301 |
char *comment; |
| 1302 |
|
| 1303 |
s = buf + 1; |
| 1304 |
if (*s == '\n' || *s == '\r') { *s = '\0'; comment = s; } |
| 1305 |
else if (esl_strtok(&s, "\n\r", &comment)!= eslOK) return eslEFORMAT; |
| 1306 |
return (esl_msa_AddComment(msa, comment, -1)); |
| 1307 |
} |
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
#ifdef eslMSAFILE2_TESTDRIVE |
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
static void |
| 1319 |
write_known_pfam_msa(FILE *ofp) |
| 1320 |
{ |
| 1321 |
fprintf(ofp, "# STOCKHOLM 1.0\n"); |
| 1322 |
fprintf(ofp, "#=GF ID pfam-test\n"); |
| 1323 |
fprintf(ofp, "#=GS seq2 DE seq2 is interesting\n"); |
| 1324 |
fprintf(ofp, "seq1 --ACDEFGHIK~LMNPQRS-TVWYACDEFGHIKLMNPQRSTVWY~~~\n"); |
| 1325 |
fprintf(ofp, "seq2 aaACDEFGHIK~LMNPQRS-TVWYACDEFGHIKLMNPQRSTVWYyyy\n"); |
| 1326 |
fprintf(ofp, "seq3 aaACDEFGHIK~LMNPQRS-TVWYACDEFGHIKLMNPQRSTVWYyyy\n"); |
| 1327 |
fprintf(ofp, "#=GC RF ..xxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...\n"); |
| 1328 |
fprintf(ofp, "//\n"); |
| 1329 |
return; |
| 1330 |
} |
| 1331 |
|
| 1332 |
|
| 1333 |
static void |
| 1334 |
utest_ReadInfoPfam(char *filename) |
| 1335 |
{ |
| 1336 |
char *msg = "ReadInfo() unit test failure"; |
| 1337 |
ESL_MSAFILE2 *mfp = NULL; |
| 1338 |
ESL_MSA *msa = NULL; |
| 1339 |
int nseq = 0; |
| 1340 |
int64_t alen = 0; |
| 1341 |
int ngs = 0; |
| 1342 |
int maxname = 0; |
| 1343 |
int maxgf = 0; |
| 1344 |
int maxgc = 0; |
| 1345 |
int maxgr = 0; |
| 1346 |
|
| 1347 |
if (esl_msafile2_Open(filename, NULL, &mfp) != eslOK) esl_fatal(msg); |
| 1348 |
if (esl_msafile2_ReadInfoPfam(mfp, NULL, NULL, -1, NULL, NULL, &msa, &nseq, &alen, &ngs, &maxname, &maxgf, &maxgc, &maxgr, NULL, NULL, NULL, NULL, NULL) != eslOK) esl_fatal(msg); |
| 1349 |
|
| 1350 |
if (msa->nseq != 0) esl_fatal("bad msa->nseq"); |
| 1351 |
if (msa->alen != -1) esl_fatal("bad msa->alen"); |
| 1352 |
if (nseq != 3) esl_fatal("bad nseq"); |
| 1353 |
if (alen != 47) esl_fatal("bad alen"); |
| 1354 |
if (ngs != 1) esl_fatal("bad ngs"); |
| 1355 |
if (maxname != 4) esl_fatal("bad maxname"); |
| 1356 |
if (maxgf != 2) esl_fatal("bad maxgf"); |
| 1357 |
if (maxgc != 2) esl_fatal("bad maxgc"); |
| 1358 |
if (maxgr != 0) esl_fatal("bad maxgr"); |
| 1359 |
esl_msa_Destroy(msa); |
| 1360 |
|
| 1361 |
if (esl_msafile2_ReadInfoPfam(mfp, NULL, NULL, -1, NULL, NULL, &msa, &nseq, &alen, &ngs, &maxname, &maxgf, &maxgc, &maxgr, NULL, NULL, NULL, NULL, NULL) != eslEOF) esl_fatal(msg); |
| 1362 |
if (msa != NULL) esl_fatal(msg); |
| 1363 |
if (nseq != 0 || alen != 0 || ngs != 0 || maxname != 0 || maxgf != 0 || maxgc != 0 || maxgr != 0) esl_fatal("bad nseq"); |
| 1364 |
|
| 1365 |
esl_msafile2_Close(mfp); |
| 1366 |
} |
| 1367 |
|
| 1368 |
static void |
| 1369 |
utest_RegurgitatePfam(char *filename) |
| 1370 |
{ |
| 1371 |
char *msg = "RegurgitatePfam() unit test failure"; |
| 1372 |
ESL_MSAFILE2 *mfp = NULL; |
| 1373 |
ESL_MSAFILE *afp = NULL; |
| 1374 |
char tmpfile[16] = "esltmpXXXXXX"; |
| 1375 |
FILE *fp = NULL; |
| 1376 |
ESL_MSA *msa1 = NULL; |
| 1377 |
ESL_MSA *msa2 = NULL; |
| 1378 |
|
| 1379 |
|
| 1380 |
if (esl_msafile2_Open(filename, NULL, &mfp) != eslOK) esl_fatal(msg); |
| 1381 |
if (esl_tmpfile_named(tmpfile, &fp) != eslOK) esl_fatal(msg); |
| 1382 |
if (esl_msafile2_RegurgitatePfam(mfp, fp, |
| 1383 |
-1, -1, -1, -1, |
| 1384 |
TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, |
| 1385 |
NULL, |
| 1386 |
NULL, |
| 1387 |
NULL, |
| 1388 |
NULL, |
| 1389 |
-1, |
| 1390 |
'.', |
| 1391 |
NULL, |
| 1392 |
NULL) |
| 1393 |
!= eslOK) esl_fatal(msg); |
| 1394 |
fclose(fp); |
| 1395 |
esl_msafile2_Close(mfp); |
| 1396 |
|
| 1397 |
|
| 1398 |
if (esl_msafile_Open(NULL, filename, NULL, eslMSAFILE_PFAM, NULL, &afp) != eslOK) esl_fatal(msg); |
| 1399 |
if (esl_msafile_Read(afp, &msa1) != eslOK) esl_fatal(msg); |
| 1400 |
esl_msafile_Close(afp); |
| 1401 |
|
| 1402 |
|
| 1403 |
if (esl_msafile_Open(NULL, tmpfile, NULL, eslMSAFILE_PFAM, NULL, &afp) != eslOK) esl_fatal(msg); |
| 1404 |
if (esl_msafile_Read(afp, &msa2) != eslOK) esl_fatal(msg); |
| 1405 |
esl_msafile_Close(afp); |
| 1406 |
|
| 1407 |
if (esl_msa_Compare(msa1, msa2) != eslOK) esl_fatal(msg); |
| 1408 |
|
| 1409 |
esl_msa_Destroy(msa1); |
| 1410 |
esl_msa_Destroy(msa2); |
| 1411 |
remove(tmpfile); |
| 1412 |
} |
| 1413 |
#endif |
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
#ifdef eslMSAFILE2_TESTDRIVE |
| 1421 |
|
| 1422 |
|
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
#include <esl_config.h> |
| 1427 |
|
| 1428 |
#include <stdio.h> |
| 1429 |
|
| 1430 |
#include "easel.h" |
| 1431 |
#include "esl_getopts.h" |
| 1432 |
#include "esl_msafile2.h" |
| 1433 |
|
| 1434 |
static ESL_OPTIONS options[] = { |
| 1435 |
|
| 1436 |
{"-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show help and usage", 0}, |
| 1437 |
{ 0,0,0,0,0,0,0,0,0,0}, |
| 1438 |
}; |
| 1439 |
static char usage[] = "[-options]"; |
| 1440 |
static char banner[] = "test driver for legacy memory-efficient Pfam format input/output"; |
| 1441 |
|
| 1442 |
int |
| 1443 |
main(int argc, char **argv) |
| 1444 |
{ |
| 1445 |
ESL_GETOPTS *go = esl_getopts_CreateDefaultApp(options, 0, argc, argv, banner, usage); |
| 1446 |
FILE *fp = NULL; |
| 1447 |
char tmpfile[16] = "esltmpXXXXXX"; |
| 1448 |
|
| 1449 |
if (esl_tmpfile_named(tmpfile, &fp) != eslOK) esl_fatal("failed to create tmpfile"); |
| 1450 |
write_known_pfam_msa(fp); |
| 1451 |
fclose(fp); |
| 1452 |
|
| 1453 |
utest_ReadInfoPfam(tmpfile); |
| 1454 |
utest_RegurgitatePfam(tmpfile); |
| 1455 |
|
| 1456 |
remove(tmpfile); |
| 1457 |
esl_getopts_Destroy(go); |
| 1458 |
exit(0); |
| 1459 |
} |
| 1460 |
#endif |
| 1461 |
|