| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
#include <esl_config.h> |
| 14 |
|
| 15 |
#include <stdio.h> |
| 16 |
#include <stdlib.h> |
| 17 |
#include <string.h> |
| 18 |
#include <ctype.h> |
| 19 |
|
| 20 |
#include "easel.h" |
| 21 |
#include "esl_alphabet.h" |
| 22 |
#include "esl_mem.h" |
| 23 |
#include "esl_msa.h" |
| 24 |
#include "esl_msafile.h" |
| 25 |
|
| 26 |
#include "esl_msafile_clustal.h" |
| 27 |
|
| 28 |
static int make_text_consensus_line(const ESL_MSA *msa, char **ret_consline); |
| 29 |
static int make_digital_consensus_line(const ESL_MSA *msa, char **ret_consline); |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
int |
| 44 |
esl_msafile_clustal_SetInmap(ESL_MSAFILE *afp) |
| 45 |
{ |
| 46 |
int sym; |
| 47 |
|
| 48 |
if (afp->abc) |
| 49 |
{ |
| 50 |
for (sym = 0; sym < 128; sym++) |
| 51 |
afp->inmap[sym] = afp->abc->inmap[sym]; |
| 52 |
afp->inmap[0] = esl_abc_XGetUnknown(afp->abc); |
| 53 |
} |
| 54 |
|
| 55 |
if (! afp->abc) |
| 56 |
{ |
| 57 |
for (sym = 1; sym < 128; sym++) |
| 58 |
afp->inmap[sym] = (isgraph(sym) ? sym : eslDSQ_ILLEGAL); |
| 59 |
afp->inmap[0] = '?'; |
| 60 |
} |
| 61 |
return eslOK; |
| 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 |
int |
| 87 |
esl_msafile_clustal_GuessAlphabet(ESL_MSAFILE *afp, int *ret_type) |
| 88 |
{ |
| 89 |
int alphatype = eslUNKNOWN; |
| 90 |
esl_pos_t anchor = -1; |
| 91 |
int threshold[3] = { 500, 5000, 50000 }; |
| 92 |
int nsteps = 3; |
| 93 |
int step = 0; |
| 94 |
int nres = 0; |
| 95 |
int x; |
| 96 |
int64_t ct[26]; |
| 97 |
char *p, *tok; |
| 98 |
esl_pos_t n, toklen, pos; |
| 99 |
int status; |
| 100 |
|
| 101 |
for (x = 0; x < 26; x++) ct[x] = 0; |
| 102 |
|
| 103 |
anchor = esl_buffer_GetOffset(afp->bf); |
| 104 |
if ((status = esl_buffer_SetAnchor(afp->bf, anchor)) != eslOK) { status = eslEINCONCEIVABLE; goto ERROR; } |
| 105 |
|
| 106 |
|
| 107 |
while ( (status = esl_buffer_GetLine(afp->bf, &p, &n)) == eslOK && esl_memspn(p, n, " \t") == n) ; |
| 108 |
if (status == eslEOF) ESL_XFAIL(eslENOALPHABET, afp->errmsg, "can't determine alphabet: no alignment data found"); |
| 109 |
else if (status != eslOK) goto ERROR; |
| 110 |
|
| 111 |
while ( (status = esl_buffer_GetLine(afp->bf, &p, &n)) == eslOK) |
| 112 |
{ |
| 113 |
if ((status = esl_memtok(&p, &n, " \t", &tok, &toklen)) != eslOK) continue; |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
for (pos = 0; pos < n; pos++) |
| 118 |
if (isalpha(p[pos])) { |
| 119 |
x = toupper(p[pos]) - 'A'; |
| 120 |
ct[x]++; |
| 121 |
nres++; |
| 122 |
} |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
if (step < nsteps && nres > threshold[step]) { |
| 129 |
if ((status = esl_abc_GuessAlphabet(ct, &alphatype)) == eslOK) goto DONE; |
| 130 |
step++; |
| 131 |
} |
| 132 |
} |
| 133 |
if (status != eslEOF) goto ERROR; |
| 134 |
status = esl_abc_GuessAlphabet(ct, &alphatype); |
| 135 |
|
| 136 |
DONE: |
| 137 |
esl_buffer_SetOffset(afp->bf, anchor); |
| 138 |
esl_buffer_RaiseAnchor(afp->bf, anchor); |
| 139 |
*ret_type = alphatype; |
| 140 |
return status; |
| 141 |
|
| 142 |
ERROR: |
| 143 |
if (anchor != -1) { |
| 144 |
esl_buffer_SetOffset(afp->bf, anchor); |
| 145 |
esl_buffer_RaiseAnchor(afp->bf, anchor); |
| 146 |
} |
| 147 |
*ret_type = eslUNKNOWN; |
| 148 |
return status; |
| 149 |
} |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 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 |
int |
| 188 |
esl_msafile_clustal_Read(ESL_MSAFILE *afp, ESL_MSA **ret_msa) |
| 189 |
{ |
| 190 |
ESL_MSA *msa = NULL; |
| 191 |
char *p = NULL; |
| 192 |
esl_pos_t n = 0; |
| 193 |
char *tok = NULL; |
| 194 |
esl_pos_t ntok = 0; |
| 195 |
int nblocks = 0; |
| 196 |
int idx = 0; |
| 197 |
int nseq = 0; |
| 198 |
int64_t alen = 0; |
| 199 |
int64_t cur_alen; |
| 200 |
esl_pos_t pos; |
| 201 |
esl_pos_t name_start, name_len; |
| 202 |
esl_pos_t seq_start, seq_len; |
| 203 |
esl_pos_t block_seq_start, block_seq_len; |
| 204 |
int status; |
| 205 |
|
| 206 |
ESL_DASSERT1( (afp->format == eslMSAFILE_CLUSTAL || afp->format == eslMSAFILE_CLUSTALLIKE) ); |
| 207 |
|
| 208 |
afp->errmsg[0] = '\0'; |
| 209 |
|
| 210 |
if (afp->abc && (msa = esl_msa_CreateDigital(afp->abc, 16, -1)) == NULL) { status = eslEMEM; goto ERROR; } |
| 211 |
if (! afp->abc && (msa = esl_msa_Create( 16, -1)) == NULL) { status = eslEMEM; goto ERROR; } |
| 212 |
|
| 213 |
|
| 214 |
while ( (status = esl_msafile_GetLine(afp, &p, &n)) == eslOK && esl_memspn(afp->line, afp->n, " \t") == afp->n) ; |
| 215 |
if (status != eslOK) goto ERROR; |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
if (esl_memtok(&p, &n, " \t", &tok, &ntok) != eslOK) ESL_XFAIL(eslEFORMAT, afp->errmsg, "missing CLUSTAL header"); |
| 223 |
if (afp->format == eslMSAFILE_CLUSTAL && ! esl_memstrpfx(tok, ntok, "CLUSTAL")) ESL_XFAIL(eslEFORMAT, afp->errmsg, "missing CLUSTAL header"); |
| 224 |
if (! esl_memstrcontains(p, n, "alignment")) ESL_XFAIL(eslEFORMAT, afp->errmsg, "missing CLUSTAL header"); |
| 225 |
|
| 226 |
|
| 227 |
do { |
| 228 |
status = esl_msafile_GetLine(afp, &p, &n); |
| 229 |
if (status == eslEOF) ESL_XFAIL(eslEFORMAT, afp->errmsg, "no alignment data following header"); |
| 230 |
else if (status != eslOK) goto ERROR; |
| 231 |
} while (esl_memspn(afp->line, afp->n, " \t") == afp->n); |
| 232 |
|
| 233 |
|
| 234 |
do { |
| 235 |
idx = 0; |
| 236 |
do { |
| 237 |
for (pos = 0; pos < n; pos++) if (! isspace(p[pos])) break; |
| 238 |
name_start = pos; |
| 239 |
for (pos = pos+1; pos < n; pos++) if ( isspace(p[pos])) break; |
| 240 |
name_len = pos - name_start; |
| 241 |
for (pos = pos+1; pos < n; pos++) if (! isspace(p[pos])) break; |
| 242 |
seq_start = pos; |
| 243 |
if (pos >= n) ESL_XFAIL(eslEFORMAT, afp->errmsg, "invalid alignment line"); |
| 244 |
for (pos = pos+1; pos < n; pos++) if ( isspace(p[pos])) break; |
| 245 |
seq_len = pos - seq_start; |
| 246 |
|
| 247 |
if (idx == 0) { |
| 248 |
block_seq_start = seq_start; |
| 249 |
block_seq_len = seq_len; |
| 250 |
} else { |
| 251 |
if (seq_start != block_seq_start) ESL_XFAIL(eslEFORMAT, afp->errmsg, "sequence start is misaligned"); |
| 252 |
if (seq_len != block_seq_len) ESL_XFAIL(eslEFORMAT, afp->errmsg, "sequence end is misaligned"); |
| 253 |
} |
| 254 |
|
| 255 |
|
| 256 |
if (nblocks == 0) { |
| 257 |
|
| 258 |
if (idx >= msa->sqalloc && (status = esl_msa_Expand(msa)) != eslOK) goto ERROR; |
| 259 |
if ( (status = esl_msa_SetSeqName(msa, idx, p+name_start, name_len)) != eslOK) goto ERROR; |
| 260 |
nseq++; |
| 261 |
} else { |
| 262 |
if (! esl_memstrcmp(p+name_start, name_len, msa->sqname[idx])) |
| 263 |
ESL_XFAIL(eslEFORMAT, afp->errmsg, "expected sequence %s on this line, but saw %.*s", msa->sqname[idx], (int) name_len, p+name_start); |
| 264 |
} |
| 265 |
|
| 266 |
|
| 267 |
cur_alen = alen; |
| 268 |
if (msa->abc) { status = esl_abc_dsqcat(afp->inmap, &(msa->ax[idx]), &(cur_alen), p+seq_start, seq_len); } |
| 269 |
if (! msa->abc) { status = esl_strmapcat (afp->inmap, &(msa->aseq[idx]), &(cur_alen), p+seq_start, seq_len); } |
| 270 |
if (status == eslEINVAL) ESL_XFAIL(eslEFORMAT, afp->errmsg, "one or more invalid sequence characters"); |
| 271 |
else if (status != eslOK) goto ERROR; |
| 272 |
if (cur_alen - alen != seq_len) ESL_XFAIL(eslEFORMAT, afp->errmsg, "unexpected number of seq characters"); |
| 273 |
|
| 274 |
|
| 275 |
status = esl_msafile_GetLine(afp, &p, &n); |
| 276 |
if (status == eslEOF) ESL_XFAIL(eslEFORMAT, afp->errmsg, "alignment block did not end with consensus line"); |
| 277 |
else if (status != eslOK) goto ERROR; |
| 278 |
|
| 279 |
idx++; |
| 280 |
} while (esl_memspn(afp->line, afp->n, " .:*") < afp->n); |
| 281 |
|
| 282 |
if (idx != nseq) ESL_XFAIL(eslEFORMAT, afp->errmsg, "last block didn't contain same # of seqs as earlier blocks"); |
| 283 |
|
| 284 |
|
| 285 |
do { |
| 286 |
status = esl_msafile_GetLine(afp, &p, &n); |
| 287 |
if (status == eslEOF) break; |
| 288 |
else if (status != eslOK) goto ERROR; |
| 289 |
} while (esl_memspn(p, n, " \t") == n); |
| 290 |
|
| 291 |
alen += block_seq_len; |
| 292 |
nblocks++; |
| 293 |
} while (status == eslOK); |
| 294 |
|
| 295 |
msa->nseq = nseq; |
| 296 |
msa->alen = alen; |
| 297 |
if (( status = esl_msa_SetDefaultWeights(msa)) != eslOK) goto ERROR; |
| 298 |
*ret_msa = msa; |
| 299 |
return eslOK; |
| 300 |
|
| 301 |
ERROR: |
| 302 |
if (msa) esl_msa_Destroy(msa); |
| 303 |
*ret_msa = NULL; |
| 304 |
return status; |
| 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 |
int |
| 342 |
esl_msafile_clustal_Write(FILE *fp, const ESL_MSA *msa, int fmt) |
| 343 |
{ |
| 344 |
int cpl = 60; |
| 345 |
int maxnamelen = 0; |
| 346 |
int namelen; |
| 347 |
char *consline = NULL; |
| 348 |
char *buf = NULL; |
| 349 |
int64_t apos; |
| 350 |
int i; |
| 351 |
int status; |
| 352 |
|
| 353 |
ESL_ALLOC(buf, sizeof(char) * (cpl+1)); |
| 354 |
buf[cpl] = '\0'; |
| 355 |
for (i = 0; i < msa->nseq; i++) |
| 356 |
{ |
| 357 |
namelen = strlen(msa->sqname[i]); |
| 358 |
maxnamelen = ESL_MAX(namelen, maxnamelen); |
| 359 |
} |
| 360 |
|
| 361 |
|
| 362 |
if ( msa->abc && (status = make_digital_consensus_line(msa, &consline)) != eslOK) goto ERROR; |
| 363 |
if (! msa->abc && (status = make_text_consensus_line (msa, &consline)) != eslOK) goto ERROR; |
| 364 |
|
| 365 |
|
| 366 |
if (fmt == eslMSAFILE_CLUSTAL) { if (fprintf(fp, "CLUSTAL 2.1 multiple sequence alignment\n") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "clustal msa write failed"); } |
| 367 |
else if (fmt == eslMSAFILE_CLUSTALLIKE) { if (fprintf(fp, "EASEL (%s) multiple sequence alignment\n", EASEL_VERSION) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "clustal msa write failed"); } |
| 368 |
|
| 369 |
|
| 370 |
for (apos = 0; apos < msa->alen; apos += cpl) |
| 371 |
{ |
| 372 |
if (fprintf(fp, "\n") < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "clustal msa write failed"); |
| 373 |
for (i = 0; i < msa->nseq; i++) |
| 374 |
{ |
| 375 |
if (msa->abc) esl_abc_TextizeN(msa->abc, msa->ax[i]+apos+1, cpl, buf); |
| 376 |
if (! msa->abc) strncpy(buf, msa->aseq[i]+apos, cpl); |
| 377 |
if (fprintf(fp, "%-*s %s\n", maxnamelen, msa->sqname[i], buf) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "clustal msa write failed"); |
| 378 |
} |
| 379 |
strncpy(buf, consline+apos, cpl); |
| 380 |
if (fprintf(fp, "%-*s %s\n", maxnamelen, "", buf) < 0) ESL_XEXCEPTION_SYS(eslEWRITE, "clustal msa write failed"); |
| 381 |
} |
| 382 |
|
| 383 |
free(buf); |
| 384 |
free(consline); |
| 385 |
return eslOK; |
| 386 |
|
| 387 |
ERROR: |
| 388 |
if (buf) free(buf); |
| 389 |
if (consline) free(consline); |
| 390 |
return status; |
| 391 |
} |
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
|
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
|
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
static int |
| 459 |
make_text_consensus_line(const ESL_MSA *msa, char **ret_consline) |
| 460 |
{ |
| 461 |
char *consline = NULL; |
| 462 |
uint32_t *v = NULL; |
| 463 |
uint32_t tmpv, maxv; |
| 464 |
int n; |
| 465 |
int idx, apos, x; |
| 466 |
int status; |
| 467 |
|
| 468 |
ESL_ALLOC(consline, sizeof(char) * (msa->alen+1)); |
| 469 |
ESL_ALLOC(v, sizeof(uint32_t) * (msa->alen)); |
| 470 |
for (apos = 0; apos < msa->alen; apos++) |
| 471 |
v[apos] = 0; |
| 472 |
|
| 473 |
for (idx = 0; idx < msa->nseq; idx++) |
| 474 |
for (apos = 0; apos < msa->alen; apos++) |
| 475 |
{ |
| 476 |
x = toupper(msa->aseq[idx][apos]) - 'A'; |
| 477 |
if (x >= 0 && x < 26) v[apos] |= (1 << x); |
| 478 |
else v[apos] |= (1 << 26); |
| 479 |
} |
| 480 |
maxv = (1 << 26) - 1; |
| 481 |
|
| 482 |
for (apos = 0; apos < msa->alen; apos++) |
| 483 |
{ |
| 484 |
for (n = 0, tmpv = v[apos]; tmpv; n++) tmpv &= tmpv-1; |
| 485 |
consline[apos] = ((n == 1 && v[apos] < maxv) ? '*' : ' '); |
| 486 |
} |
| 487 |
consline[msa->alen] = '\0'; |
| 488 |
|
| 489 |
*ret_consline = consline; |
| 490 |
free(v); |
| 491 |
return eslOK; |
| 492 |
|
| 493 |
ERROR: |
| 494 |
if (v) free(v); |
| 495 |
if (consline) free(consline); |
| 496 |
*ret_consline = NULL; |
| 497 |
return status; |
| 498 |
} |
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
static int |
| 507 |
matches_group_digital(ESL_ALPHABET *abc, uint32_t v, char *group) |
| 508 |
{ |
| 509 |
uint32_t gv = 0; |
| 510 |
ESL_DSQ sym; |
| 511 |
char *c; |
| 512 |
|
| 513 |
for (c = group; *c; c++) { |
| 514 |
sym = esl_abc_DigitizeSymbol(abc, *c); |
| 515 |
gv |= (1 << sym); |
| 516 |
} |
| 517 |
return ( ((v & gv) == v) ? TRUE : FALSE); |
| 518 |
} |
| 519 |
|
| 520 |
static int |
| 521 |
make_digital_consensus_line(const ESL_MSA *msa, char **ret_consline) |
| 522 |
{ |
| 523 |
char *consline = NULL; |
| 524 |
uint32_t *v = NULL; |
| 525 |
uint32_t tmpv, maxv; |
| 526 |
int n; |
| 527 |
int idx, apos; |
| 528 |
int status; |
| 529 |
|
| 530 |
|
| 531 |
if (msa->abc->Kp > 32) ESL_EXCEPTION(eslEINVAL, "Clustal format writer cannot handle digital alphabets of Kp>32 residues"); |
| 532 |
|
| 533 |
ESL_ALLOC(v, sizeof(uint32_t) * (msa->alen+1)); |
| 534 |
ESL_ALLOC(consline, sizeof(char) * (msa->alen+1)); |
| 535 |
for (apos = 0; apos <= msa->alen; apos++) |
| 536 |
v[apos] = 0; |
| 537 |
|
| 538 |
for (idx = 0; idx < msa->nseq; idx++) |
| 539 |
for (apos = 1; apos <= msa->alen; apos++) |
| 540 |
v[apos] |= (1 << msa->ax[idx][apos]); |
| 541 |
|
| 542 |
maxv = (1 << msa->abc->K) - 1; |
| 543 |
|
| 544 |
for (apos = 1; apos <= msa->alen; apos++) |
| 545 |
{ |
| 546 |
consline[apos-1] = ' '; |
| 547 |
|
| 548 |
for (n = 0, tmpv = v[apos]; tmpv; n++) tmpv &= tmpv-1; |
| 549 |
|
| 550 |
if (n == 0 || n > 6) continue; |
| 551 |
else if (v[apos] > maxv) continue; |
| 552 |
else if (n == 1) consline[apos-1] = '*'; |
| 553 |
else if (msa->abc->type == eslAMINO) |
| 554 |
{ |
| 555 |
if (matches_group_digital(msa->abc, v[apos], "STA")) consline[apos-1] = ':'; |
| 556 |
else if (matches_group_digital(msa->abc, v[apos], "NEQK")) consline[apos-1] = ':'; |
| 557 |
else if (matches_group_digital(msa->abc, v[apos], "NHQK")) consline[apos-1] = ':'; |
| 558 |
else if (matches_group_digital(msa->abc, v[apos], "NDEQ")) consline[apos-1] = ':'; |
| 559 |
else if (matches_group_digital(msa->abc, v[apos], "QHRK")) consline[apos-1] = ':'; |
| 560 |
else if (matches_group_digital(msa->abc, v[apos], "MILV")) consline[apos-1] = ':'; |
| 561 |
else if (matches_group_digital(msa->abc, v[apos], "MILF")) consline[apos-1] = ':'; |
| 562 |
else if (matches_group_digital(msa->abc, v[apos], "HY")) consline[apos-1] = ':'; |
| 563 |
else if (matches_group_digital(msa->abc, v[apos], "FYW")) consline[apos-1] = ':'; |
| 564 |
|
| 565 |
else if (matches_group_digital(msa->abc, v[apos], "CSA")) consline[apos-1] = '.'; |
| 566 |
else if (matches_group_digital(msa->abc, v[apos], "ATV")) consline[apos-1] = '.'; |
| 567 |
else if (matches_group_digital(msa->abc, v[apos], "SAG")) consline[apos-1] = '.'; |
| 568 |
else if (matches_group_digital(msa->abc, v[apos], "STNK")) consline[apos-1] = '.'; |
| 569 |
else if (matches_group_digital(msa->abc, v[apos], "STPA")) consline[apos-1] = '.'; |
| 570 |
else if (matches_group_digital(msa->abc, v[apos], "SGND")) consline[apos-1] = '.'; |
| 571 |
else if (matches_group_digital(msa->abc, v[apos], "SNDEQK")) consline[apos-1] = '.'; |
| 572 |
else if (matches_group_digital(msa->abc, v[apos], "NDEQHK")) consline[apos-1] = '.'; |
| 573 |
else if (matches_group_digital(msa->abc, v[apos], "NEQHRK")) consline[apos-1] = '.'; |
| 574 |
else if (matches_group_digital(msa->abc, v[apos], "FVLIM")) consline[apos-1] = '.'; |
| 575 |
else if (matches_group_digital(msa->abc, v[apos], "HFY")) consline[apos-1] = '.'; |
| 576 |
} |
| 577 |
} |
| 578 |
consline[apos-1] = '\0'; |
| 579 |
|
| 580 |
*ret_consline = consline; |
| 581 |
free(v); |
| 582 |
return eslOK; |
| 583 |
|
| 584 |
ERROR: |
| 585 |
if (v) free(v); |
| 586 |
if (consline) free(consline); |
| 587 |
*ret_consline = NULL; |
| 588 |
return eslOK; |
| 589 |
} |
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
#ifdef eslMSAFILE_CLUSTAL_TESTDRIVE |
| 597 |
|
| 598 |
static void |
| 599 |
utest_write_good1(FILE *ofp, int *ret_format, int *ret_alphatype, int *ret_nseq, int *ret_alen) |
| 600 |
{ |
| 601 |
fputs("MUSCLE (3.7) multiple sequence alignment\n", ofp); |
| 602 |
fputs("\n", ofp); |
| 603 |
fputs("\n", ofp); |
| 604 |
fputs("MYG_PHYCA --------V-LSEGEWQLVLHVWAKVEADVAGHGQDILIRLFKSHPETLEKFDRFKHLKT\n", ofp); |
| 605 |
fputs("GLB5_PETMA PIVDTGSVAPLSAAEKTKIRSAWAPVYSTYETSGVDILVKFFTSTPAAQEFFPKFKGLTT\n", ofp); |
| 606 |
fputs("HBB_HUMAN --------VHLTPEEKSAVTALWGKV--NVDEVGGEALGRLLVVYPWTQRFFESFGDLST\n", ofp); |
| 607 |
fputs("HBA_HUMAN --------V-LSPADKTNVKAAWGKVGAHAGEYGAEALERMFLSFPTTKTYFPHF-----\n", ofp); |
| 608 |
fputs(" . *: :. : *. * * : * .:: * : * * \n", ofp); |
| 609 |
fputs("\n", ofp); |
| 610 |
fputs("MYG_PHYCA EAEMKASEDLKKHGVTVLTALGAILKKKGH---HEAELKPLAQSHATKHKIPIKYLEFIS\n", ofp); |
| 611 |
fputs("GLB5_PETMA ADQLKKSADVRWHAERIINAVNDAVASMDDTEKMSMKLRDLSGKHAKSFQVDPQYFKVLA\n", ofp); |
| 612 |
fputs("HBB_HUMAN PDAVMGNPKVKAHGKKVLGAFSDGLAHLDN---LKGTFATLSELHCDKLHVDPENFRLLG\n", ofp); |
| 613 |
fputs("HBA_HUMAN -DLSHGSAQVKGHGKKVADALTNAVAHVDD---MPNALSALSDLHAHKLRVDPVNFKLLS\n", ofp); |
| 614 |
fputs(" \n", ofp); |
| 615 |
fputs("\n", ofp); |
| 616 |
fputs("MYG_PHYCA EAIIHVLHSRHPGDFGADAQGAMNKALELFRKDIAAKYKELGYQG\n", ofp); |
| 617 |
fputs("GLB5_PETMA AVI---------ADTVAAGDAGFEKLMSMICILLRSAY-------\n", ofp); |
| 618 |
fputs("HBB_HUMAN NVLVCVLAHHFGKEFTPPVQAAYQKVVAGVANALAHKYH------\n", ofp); |
| 619 |
fputs("HBA_HUMAN HCLLVTLAAHLPAEFTPAVHASLDKFLASVSTVLTSKYR------\n", ofp); |
| 620 |
fputs(" : : . .. :* : . : * \n", ofp); |
| 621 |
fputs("\n", ofp); |
| 622 |
|
| 623 |
*ret_format = eslMSAFILE_CLUSTALLIKE; |
| 624 |
*ret_alphatype = eslAMINO; |
| 625 |
*ret_nseq = 4; |
| 626 |
*ret_alen = 165; |
| 627 |
} |
| 628 |
|
| 629 |
static void |
| 630 |
utest_write_good2(FILE *ofp, int *ret_format, int *ret_alphatype, int *ret_nseq, int *ret_alen) |
| 631 |
{ |
| 632 |
fputs("CLUSTAL W (1.81) multiple sequence alignment\n", ofp); |
| 633 |
fputs("\n", ofp); |
| 634 |
fputs("tRNA2 UCCGAUAUAGUGUAACGGCUAUCACAUCACGCUUUCACCGUGG-AGACCGGGGUUCGACU\n", ofp); |
| 635 |
fputs("tRNA3 UCCGUGAUAGUUUAAUGGUCAGAAUGG-GCGCUUGUCGCGUGCCAGAUCGGGGUUCAAUU\n", ofp); |
| 636 |
fputs("tRNA5 GGGCACAUGGCGCAGUUGGUAGCGCGCUUCCCUUGCAAGGAAGAGGUCAUCGGUUCGAUU\n", ofp); |
| 637 |
fputs("tRNA1 GCGGAUUUAGCUCAGUUGGGAGAGCGCCAGACUGAAGAUCUGGAGGUCCUGUGUUCGAUC\n", ofp); |
| 638 |
fputs("tRNA4 GCUCGUAUGGCGCAGUGG-UAGCGCAGCAGAUUGCAAAUCUGUUGGUCCUUAGUUCGAUC\n", ofp); |
| 639 |
fputs(" * * * * * * * **** * \n", ofp); |
| 640 |
fputs("\n", ofp); |
| 641 |
fputs("tRNA2 CCCCGUAUCGGAG\n", ofp); |
| 642 |
fputs("tRNA3 CCCCGUCGCGGAG\n", ofp); |
| 643 |
fputs("tRNA5 CCGGUUGCGUCCA\n", ofp); |
| 644 |
fputs("tRNA1 CACAGAAUUCGCA\n", ofp); |
| 645 |
fputs("tRNA4 CUGAGUGCGAGCU\n", ofp); |
| 646 |
fputs(" * \n", ofp); |
| 647 |
|
| 648 |
*ret_format = eslMSAFILE_CLUSTAL; |
| 649 |
*ret_alphatype = eslRNA; |
| 650 |
*ret_nseq = 5; |
| 651 |
*ret_alen = 73; |
| 652 |
} |
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
static void |
| 658 |
utest_write_good3(FILE *ofp, int *ret_format, int *ret_alphatype, int *ret_nseq, int *ret_alen) |
| 659 |
{ |
| 660 |
fputs("CLUSTAL 2.1 multiple sequence alignment\n", ofp); |
| 661 |
fputs("\n", ofp); |
| 662 |
fputs("gi|85091828|ref|XP_959093.1| MSDFTSKVKVLRDGQKPEFPSN----ANTLEYAQSLDAQDELRHFRNEFI 46\n", ofp); |
| 663 |
fputs("gi|70993990|ref|XP_751842.1| ----MSTNGTLS---KPEFPAN----AASKEYAASLDAADPFAGFREKFI 39\n", ofp); |
| 664 |
fputs("gi|71001376|ref|XP_755369.1| ---MGSRLHVQVIHGGPPLPYKDDIRAFGKEYAEQLDAQDPLRRFRDEFI 47\n", ofp); |
| 665 |
fputs("gi|71744026|ref|XP_803513.1| -----------------------------------MDRNDPLQVHRDAFN 15\n", ofp); |
| 666 |
fputs(" : : \n", ofp); |
| 667 |
fputs("\n", ofp); |
| 668 |
fputs("gi|85091828|ref|XP_959093.1| IPTRASLKKKALDGI--------------IPGTQANGTTTSTDADTPCIY 82\n", ofp); |
| 669 |
fputs("gi|70993990|ref|XP_751842.1| IPSKANIASTKLA----------------KPGLSSE----------PCIY 63\n", ofp); |
| 670 |
fputs("gi|71001376|ref|XP_755369.1| IPSKKDLKRKTLFPNDGMYSCGHPICFANTSCACVHAAETEETSDEKCIY 97\n", ofp); |
| 671 |
fputs("gi|71744026|ref|XP_803513.1| IPKRRDGS--------------------------------------DHVY 27\n", ofp); |
| 672 |
fputs(" *\n", ofp); |
| 673 |
|
| 674 |
*ret_format = eslMSAFILE_CLUSTAL; |
| 675 |
*ret_alphatype = eslAMINO; |
| 676 |
*ret_nseq = 4; |
| 677 |
*ret_alen = 100; |
| 678 |
} |
| 679 |
|
| 680 |
|
| 681 |
static void |
| 682 |
utest_goodfile(char *filename, int testnumber, int expected_format, int expected_alphatype, int expected_nseq, int expected_alen) |
| 683 |
{ |
| 684 |
ESL_ALPHABET *abc = NULL; |
| 685 |
ESL_MSAFILE *afp = NULL; |
| 686 |
ESL_MSA *msa1 = NULL; |
| 687 |
ESL_MSA *msa2 = NULL; |
| 688 |
char tmpfile1[32] = "esltmpXXXXXX"; |
| 689 |
char tmpfile2[32] = "esltmpXXXXXX"; |
| 690 |
FILE *ofp = NULL; |
| 691 |
int status; |
| 692 |
|
| 693 |
|
| 694 |
if ( (status = esl_msafile_Open(&abc, filename, NULL, eslMSAFILE_UNKNOWN, NULL, &afp)) != eslOK) esl_fatal("clustal good file test %d failed: digital open", testnumber); |
| 695 |
if (afp->format != expected_format) esl_fatal("clustal good file test %d failed: format autodetection", testnumber); |
| 696 |
if (abc->type != expected_alphatype) esl_fatal("clustal good file test %d failed: alphabet autodetection", testnumber); |
| 697 |
|
| 698 |
|
| 699 |
if ( (status = esl_msafile_clustal_Read(afp, &msa1)) != eslOK) esl_fatal("clustal good file test %d failed: msa read, digital", testnumber); |
| 700 |
if (msa1->nseq != expected_nseq || msa1->alen != expected_alen) esl_fatal("clustal good file test %d failed: nseq/alen", testnumber); |
| 701 |
if (esl_msa_Validate(msa1, NULL) != eslOK) esl_fatal("clustal good file test %d failed: msa1 invalid", testnumber); |
| 702 |
esl_msafile_Close(afp); |
| 703 |
|
| 704 |
|
| 705 |
if ( (status = esl_tmpfile_named(tmpfile1, &ofp)) != eslOK) esl_fatal("clustal good file test %d failed: tmpfile creation", testnumber); |
| 706 |
if ( (status = esl_msafile_clustal_Write(ofp, msa1, expected_format)) != eslOK) esl_fatal("clustal good file test %d failed: msa write, digital", testnumber); |
| 707 |
fclose(ofp); |
| 708 |
|
| 709 |
|
| 710 |
if ( (status = esl_msafile_Open(NULL, tmpfile1, NULL, expected_format, NULL, &afp)) != eslOK) esl_fatal("clustal good file test %d failed: text mode open", testnumber); |
| 711 |
if ( (status = esl_msafile_clustal_Read(afp, &msa2)) != eslOK) esl_fatal("clustal good file test %d failed: msa read, text", testnumber); |
| 712 |
if (msa2->nseq != expected_nseq || msa2->alen != expected_alen) esl_fatal("clustal good file test %d failed: nseq/alen", testnumber); |
| 713 |
if (esl_msa_Validate(msa2, NULL) != eslOK) esl_fatal("clustal good file test %d failed: msa2 invalid", testnumber); |
| 714 |
esl_msafile_Close(afp); |
| 715 |
|
| 716 |
|
| 717 |
if ( (status = esl_tmpfile_named(tmpfile2, &ofp)) != eslOK) esl_fatal("clustal good file test %d failed: tmpfile creation", testnumber); |
| 718 |
if ( (status = esl_msafile_clustal_Write(ofp, msa2, expected_format)) != eslOK) esl_fatal("clustal good file test %d failed: msa write, text", testnumber); |
| 719 |
fclose(ofp); |
| 720 |
esl_msa_Destroy(msa2); |
| 721 |
|
| 722 |
|
| 723 |
if ( (status = esl_msafile_Open(&abc, tmpfile1, NULL, expected_format, NULL, &afp)) != eslOK) esl_fatal("clustal good file test %d failed: 2nd digital mode open", testnumber); |
| 724 |
if ( (status = esl_msafile_clustal_Read(afp, &msa2)) != eslOK) esl_fatal("clustal good file test %d failed: 2nd digital msa read", testnumber); |
| 725 |
if (esl_msa_Validate(msa2, NULL) != eslOK) esl_fatal("clustal good file test %d failed: msa2 invalid", testnumber); |
| 726 |
esl_msafile_Close(afp); |
| 727 |
|
| 728 |
|
| 729 |
if (esl_msa_Compare(msa1, msa2) != eslOK) esl_fatal("clustal good file test %d failed: msa compare", testnumber); |
| 730 |
|
| 731 |
remove(tmpfile1); |
| 732 |
remove(tmpfile2); |
| 733 |
esl_msa_Destroy(msa1); |
| 734 |
esl_msa_Destroy(msa2); |
| 735 |
esl_alphabet_Destroy(abc); |
| 736 |
} |
| 737 |
|
| 738 |
static void |
| 739 |
write_test_msas(FILE *ofp1, FILE *ofp2) |
| 740 |
{ |
| 741 |
fprintf(ofp1, "EASEL (X.x) multiple sequence alignment\n"); |
| 742 |
fprintf(ofp1, "\n"); |
| 743 |
fprintf(ofp1, "seq1 ..acdefghiklmnpqrstvwy\n"); |
| 744 |
fprintf(ofp1, "seq2 ..acdefghiklmnpqrstv--\n"); |
| 745 |
fprintf(ofp1, "seq3 aaacdefghiklmnpqrstv--\n"); |
| 746 |
fprintf(ofp1, "seq4 ..acdefghiklmnpqrstvwy\n"); |
| 747 |
fprintf(ofp1, " ****************** \n"); |
| 748 |
fprintf(ofp1, "\n"); |
| 749 |
fprintf(ofp1, "seq1 ACDEFGHIKLMNPQRSTVWY\n"); |
| 750 |
fprintf(ofp1, "seq2 ACDEFGHIKLMNPQRSTVWY\n"); |
| 751 |
fprintf(ofp1, "seq3 ACDEFGHIKLMNPQRSTVWY\n"); |
| 752 |
fprintf(ofp1, "seq4 ACDEFGHIKLMNPQRSTVWY\n"); |
| 753 |
fprintf(ofp1, " ********************\n"); |
| 754 |
fprintf(ofp1, "\n"); |
| 755 |
fprintf(ofp1, "seq1 ..\n"); |
| 756 |
fprintf(ofp1, "seq2 YY\n"); |
| 757 |
fprintf(ofp1, "seq3 ..\n"); |
| 758 |
fprintf(ofp1, "seq4 ..\n"); |
| 759 |
fprintf(ofp1, "\n"); |
| 760 |
|
| 761 |
fprintf(ofp2, "# STOCKHOLM 1.0\n"); |
| 762 |
fprintf(ofp2, "\n"); |
| 763 |
fprintf(ofp2, "seq1 ..acdefghiklmnpqrstvwyACDEFGHIKLMNPQRSTVWY..\n"); |
| 764 |
fprintf(ofp2, "seq2 ..acdefghiklmnpqrstv--ACDEFGHIKLMNPQRSTVWYYY\n"); |
| 765 |
fprintf(ofp2, "seq3 aaacdefghiklmnpqrstv--ACDEFGHIKLMNPQRSTVWY..\n"); |
| 766 |
fprintf(ofp2, "seq4 ..acdefghiklmnpqrstvwyACDEFGHIKLMNPQRSTVWY..\n"); |
| 767 |
fprintf(ofp2, "//\n"); |
| 768 |
} |
| 769 |
|
| 770 |
static void |
| 771 |
read_test_msas_digital(char *alnfile, char *stkfile) |
| 772 |
{ |
| 773 |
char msg[] = "CLUSTAL msa digital read unit test failed"; |
| 774 |
ESL_ALPHABET *abc = NULL; |
| 775 |
ESL_MSAFILE *afp1 = NULL; |
| 776 |
ESL_MSAFILE *afp2 = NULL; |
| 777 |
ESL_MSA *msa1, *msa2, *msa3, *msa4; |
| 778 |
FILE *alnfp, *stkfp; |
| 779 |
char alnfile2[32] = "esltmpaln2XXXXXX"; |
| 780 |
char stkfile2[32] = "esltmpstk2XXXXXX"; |
| 781 |
|
| 782 |
if ( esl_msafile_Open(&abc, alnfile, NULL, eslMSAFILE_CLUSTALLIKE, NULL, &afp1) != eslOK) esl_fatal(msg); |
| 783 |
if ( !abc || abc->type != eslAMINO) esl_fatal(msg); |
| 784 |
if ( esl_msafile_Open(&abc, stkfile, NULL, eslMSAFILE_STOCKHOLM, NULL, &afp2) != eslOK) esl_fatal(msg); |
| 785 |
if ( esl_msafile_clustal_Read (afp1, &msa1) != eslOK) esl_fatal(msg); |
| 786 |
if ( esl_msafile_stockholm_Read(afp2, &msa2) != eslOK) esl_fatal(msg); |
| 787 |
if ( esl_msa_Compare(msa1, msa2) != eslOK) esl_fatal(msg); |
| 788 |
|
| 789 |
if ( esl_msafile_clustal_Read (afp1, &msa3) != eslEOF) esl_fatal(msg); |
| 790 |
if ( esl_msafile_stockholm_Read(afp2, &msa3) != eslEOF) esl_fatal(msg); |
| 791 |
|
| 792 |
esl_msafile_Close(afp2); |
| 793 |
esl_msafile_Close(afp1); |
| 794 |
|
| 795 |
|
| 796 |
if ( esl_tmpfile_named(alnfile2, &alnfp) != eslOK) esl_fatal(msg); |
| 797 |
if ( esl_tmpfile_named(stkfile2, &stkfp) != eslOK) esl_fatal(msg); |
| 798 |
if ( esl_msafile_clustal_Write (alnfp, msa2, eslMSAFILE_CLUSTAL) != eslOK) esl_fatal(msg); |
| 799 |
if ( esl_msafile_stockholm_Write(stkfp, msa1, eslMSAFILE_STOCKHOLM) != eslOK) esl_fatal(msg); |
| 800 |
fclose(alnfp); |
| 801 |
fclose(stkfp); |
| 802 |
if ( esl_msafile_Open(&abc, alnfile2, NULL, eslMSAFILE_CLUSTAL, NULL, &afp1) != eslOK) esl_fatal(msg); |
| 803 |
if ( esl_msafile_Open(&abc, stkfile2, NULL, eslMSAFILE_STOCKHOLM, NULL, &afp2) != eslOK) esl_fatal(msg); |
| 804 |
if ( esl_msafile_clustal_Read (afp1, &msa3) != eslOK) esl_fatal(msg); |
| 805 |
if ( esl_msafile_stockholm_Read(afp2, &msa4) != eslOK) esl_fatal(msg); |
| 806 |
if ( esl_msa_Compare(msa3, msa4) != eslOK) esl_fatal(msg); |
| 807 |
|
| 808 |
remove(alnfile2); |
| 809 |
remove(stkfile2); |
| 810 |
esl_msafile_Close(afp2); |
| 811 |
esl_msafile_Close(afp1); |
| 812 |
|
| 813 |
esl_msa_Destroy(msa1); |
| 814 |
esl_msa_Destroy(msa2); |
| 815 |
esl_msa_Destroy(msa3); |
| 816 |
esl_msa_Destroy(msa4); |
| 817 |
esl_alphabet_Destroy(abc); |
| 818 |
} |
| 819 |
|
| 820 |
static void |
| 821 |
read_test_msas_text(char *alnfile, char *stkfile) |
| 822 |
{ |
| 823 |
char msg[] = "CLUSTAL msa text-mode read unit test failed"; |
| 824 |
ESL_MSAFILE *afp1 = NULL; |
| 825 |
ESL_MSAFILE *afp2 = NULL; |
| 826 |
ESL_MSA *msa1, *msa2, *msa3, *msa4; |
| 827 |
FILE *alnfp, *stkfp; |
| 828 |
char alnfile2[32] = "esltmpaln2XXXXXX"; |
| 829 |
char stkfile2[32] = "esltmpstk2XXXXXX"; |
| 830 |
|
| 831 |
|
| 832 |
if ( esl_msafile_Open(NULL, alnfile, NULL, eslMSAFILE_CLUSTALLIKE, NULL, &afp1) != eslOK) esl_fatal(msg); |
| 833 |
if ( esl_msafile_Open(NULL, stkfile, NULL, eslMSAFILE_STOCKHOLM, NULL, &afp2) != eslOK) esl_fatal(msg); |
| 834 |
if ( esl_msafile_clustal_Read (afp1, &msa1) != eslOK) esl_fatal(msg); |
| 835 |
if ( esl_msafile_stockholm_Read(afp2, &msa2) != eslOK) esl_fatal(msg); |
| 836 |
if ( esl_msa_Compare(msa1, msa2) != eslOK) esl_fatal(msg); |
| 837 |
if ( esl_msafile_clustal_Read (afp1, &msa3) != eslEOF) esl_fatal(msg); |
| 838 |
if ( esl_msafile_stockholm_Read(afp2, &msa3) != eslEOF) esl_fatal(msg); |
| 839 |
esl_msafile_Close(afp2); |
| 840 |
esl_msafile_Close(afp1); |
| 841 |
|
| 842 |
if ( esl_tmpfile_named(alnfile2, &alnfp) != eslOK) esl_fatal(msg); |
| 843 |
if ( esl_tmpfile_named(stkfile2, &stkfp) != eslOK) esl_fatal(msg); |
| 844 |
if ( esl_msafile_clustal_Write (alnfp, msa2, eslMSAFILE_CLUSTAL) != eslOK) esl_fatal(msg); |
| 845 |
if ( esl_msafile_stockholm_Write(stkfp, msa1, eslMSAFILE_STOCKHOLM) != eslOK) esl_fatal(msg); |
| 846 |
fclose(alnfp); |
| 847 |
fclose(stkfp); |
| 848 |
if ( esl_msafile_Open(NULL, alnfile2, NULL, eslMSAFILE_CLUSTAL, NULL, &afp1) != eslOK) esl_fatal(msg); |
| 849 |
if ( esl_msafile_Open(NULL, stkfile2, NULL, eslMSAFILE_STOCKHOLM, NULL, &afp2) != eslOK) esl_fatal(msg); |
| 850 |
if ( esl_msafile_clustal_Read (afp1, &msa3) != eslOK) esl_fatal(msg); |
| 851 |
if ( esl_msafile_stockholm_Read(afp2, &msa4) != eslOK) esl_fatal(msg); |
| 852 |
if ( esl_msa_Compare(msa3, msa4) != eslOK) esl_fatal(msg); |
| 853 |
|
| 854 |
remove(alnfile2); |
| 855 |
remove(stkfile2); |
| 856 |
esl_msafile_Close(afp2); |
| 857 |
esl_msafile_Close(afp1); |
| 858 |
|
| 859 |
esl_msa_Destroy(msa1); |
| 860 |
esl_msa_Destroy(msa2); |
| 861 |
esl_msa_Destroy(msa3); |
| 862 |
esl_msa_Destroy(msa4); |
| 863 |
} |
| 864 |
#endif |
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
|
| 870 |
|
| 871 |
#ifdef eslMSAFILE_CLUSTAL_TESTDRIVE |
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
#include <esl_config.h> |
| 877 |
|
| 878 |
#include <stdio.h> |
| 879 |
|
| 880 |
#include "easel.h" |
| 881 |
#include "esl_getopts.h" |
| 882 |
#include "esl_random.h" |
| 883 |
#include "esl_msafile.h" |
| 884 |
#include "esl_msafile_clustal.h" |
| 885 |
|
| 886 |
static ESL_OPTIONS options[] = { |
| 887 |
|
| 888 |
{"-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show help and usage", 0}, |
| 889 |
{ 0,0,0,0,0,0,0,0,0,0}, |
| 890 |
}; |
| 891 |
static char usage[] = "[-options]"; |
| 892 |
static char banner[] = "test driver for CLUSTAL MSA format module"; |
| 893 |
|
| 894 |
int |
| 895 |
main(int argc, char **argv) |
| 896 |
{ |
| 897 |
char msg[] = "CLUSTAL MSA i/o module test driver failed"; |
| 898 |
ESL_GETOPTS *go = esl_getopts_CreateDefaultApp(options, 0, argc, argv, banner, usage); |
| 899 |
char alnfile[32] = "esltmpalnXXXXXX"; |
| 900 |
char stkfile[32] = "esltmpstkXXXXXX"; |
| 901 |
FILE *alnfp, *stkfp; |
| 902 |
int testnumber; |
| 903 |
int ngoodtests = 3; |
| 904 |
char tmpfile[32]; |
| 905 |
FILE *ofp; |
| 906 |
int expected_format; |
| 907 |
int expected_alphatype; |
| 908 |
int expected_nseq; |
| 909 |
int expected_alen; |
| 910 |
|
| 911 |
if ( esl_tmpfile_named(alnfile, &alnfp) != eslOK) esl_fatal(msg); |
| 912 |
if ( esl_tmpfile_named(stkfile, &stkfp) != eslOK) esl_fatal(msg); |
| 913 |
write_test_msas(alnfp, stkfp); |
| 914 |
fclose(alnfp); |
| 915 |
fclose(stkfp); |
| 916 |
|
| 917 |
read_test_msas_digital(alnfile, stkfile); |
| 918 |
read_test_msas_text (alnfile, stkfile); |
| 919 |
|
| 920 |
|
| 921 |
for (testnumber = 1; testnumber <= ngoodtests; testnumber++) |
| 922 |
{ |
| 923 |
strcpy(tmpfile, "esltmpXXXXXX"); |
| 924 |
if (esl_tmpfile_named(tmpfile, &ofp) != eslOK) esl_fatal(msg); |
| 925 |
switch (testnumber) { |
| 926 |
case 1: utest_write_good1 (ofp, &expected_format, &expected_alphatype, &expected_nseq, &expected_alen); break; |
| 927 |
case 2: utest_write_good2 (ofp, &expected_format, &expected_alphatype, &expected_nseq, &expected_alen); break; |
| 928 |
case 3: utest_write_good3 (ofp, &expected_format, &expected_alphatype, &expected_nseq, &expected_alen); break; |
| 929 |
} |
| 930 |
fclose(ofp); |
| 931 |
utest_goodfile(tmpfile, testnumber, expected_format, expected_alphatype, expected_nseq, expected_alen); |
| 932 |
remove(tmpfile); |
| 933 |
} |
| 934 |
|
| 935 |
remove(alnfile); |
| 936 |
remove(stkfile); |
| 937 |
esl_getopts_Destroy(go); |
| 938 |
return 0; |
| 939 |
} |
| 940 |
#endif |
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
#ifdef eslMSAFILE_CLUSTAL_EXAMPLE |
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
#include <stdio.h> |
| 956 |
|
| 957 |
#include "easel.h" |
| 958 |
#include "esl_alphabet.h" |
| 959 |
#include "esl_getopts.h" |
| 960 |
#include "esl_msa.h" |
| 961 |
#include "esl_msafile.h" |
| 962 |
#include "esl_msafile_clustal.h" |
| 963 |
|
| 964 |
static ESL_OPTIONS options[] = { |
| 965 |
|
| 966 |
{ "-h", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "show brief help on version and usage", 0 }, |
| 967 |
{ "-1", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "no autodetection; use CLUSTAL format", 0 }, |
| 968 |
{ "-2", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "no autodetection; use CLUSTALLIKE format", 0 }, |
| 969 |
{ "-q", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "quieter: don't write msa back, just summary", 0 }, |
| 970 |
{ "-t", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, NULL, "use text mode: no digital alphabet", 0 }, |
| 971 |
{ "--dna", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "-t", "specify that alphabet is DNA", 0 }, |
| 972 |
{ "--rna", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "-t", "specify that alphabet is RNA", 0 }, |
| 973 |
{ "--amino", eslARG_NONE, FALSE, NULL, NULL, NULL, NULL, "-t", "specify that alphabet is protein", 0 }, |
| 974 |
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, |
| 975 |
}; |
| 976 |
static char usage[] = "[-options] <msafile>"; |
| 977 |
static char banner[] = "example of guessing, reading, writing Clustal formats"; |
| 978 |
|
| 979 |
int |
| 980 |
main(int argc, char **argv) |
| 981 |
{ |
| 982 |
ESL_GETOPTS *go = esl_getopts_CreateDefaultApp(options, 1, argc, argv, banner, usage); |
| 983 |
char *filename = esl_opt_GetArg(go, 1); |
| 984 |
int infmt = eslMSAFILE_UNKNOWN; |
| 985 |
ESL_ALPHABET *abc = NULL; |
| 986 |
ESL_MSAFILE *afp = NULL; |
| 987 |
ESL_MSA *msa = NULL; |
| 988 |
int status; |
| 989 |
|
| 990 |
if (esl_opt_GetBoolean(go, "-1")) infmt = eslMSAFILE_CLUSTAL; |
| 991 |
else if (esl_opt_GetBoolean(go, "-2")) infmt = eslMSAFILE_CLUSTALLIKE; |
| 992 |
|
| 993 |
if (esl_opt_GetBoolean(go, "--rna")) abc = esl_alphabet_Create(eslRNA); |
| 994 |
else if (esl_opt_GetBoolean(go, "--dna")) abc = esl_alphabet_Create(eslDNA); |
| 995 |
else if (esl_opt_GetBoolean(go, "--amino")) abc = esl_alphabet_Create(eslAMINO); |
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
if (esl_opt_GetBoolean(go, "-t")) status = esl_msafile_Open(NULL, filename, NULL, infmt, NULL, &afp); |
| 1001 |
else status = esl_msafile_Open(&abc, filename, NULL, infmt, NULL, &afp); |
| 1002 |
if (status != eslOK) esl_msafile_OpenFailure(afp, status); |
| 1003 |
|
| 1004 |
if ( (status = esl_msafile_clustal_Read(afp, &msa)) != eslOK) |
| 1005 |
esl_msafile_ReadFailure(afp, status); |
| 1006 |
|
| 1007 |
printf("format variant: %s\n", esl_msafile_DecodeFormat(afp->format)); |
| 1008 |
printf("alphabet: %s\n", (abc ? esl_abc_DecodeType(abc->type) : "none (text mode)")); |
| 1009 |
printf("# of seqs: %d\n", msa->nseq); |
| 1010 |
printf("# of cols: %d\n", (int) msa->alen); |
| 1011 |
printf("\n"); |
| 1012 |
|
| 1013 |
if (! esl_opt_GetBoolean(go, "-q")) |
| 1014 |
esl_msafile_clustal_Write(stdout, msa, eslMSAFILE_CLUSTAL); |
| 1015 |
|
| 1016 |
esl_msa_Destroy(msa); |
| 1017 |
esl_msafile_Close(afp); |
| 1018 |
if (abc) esl_alphabet_Destroy(abc); |
| 1019 |
esl_getopts_Destroy(go); |
| 1020 |
exit(0); |
| 1021 |
} |
| 1022 |
|
| 1023 |
#endif |
| 1024 |
|
| 1025 |
#ifdef eslMSAFILE_CLUSTAL_EXAMPLE2 |
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
|
| 1032 |
#include <stdio.h> |
| 1033 |
|
| 1034 |
#include "easel.h" |
| 1035 |
#include "esl_msa.h" |
| 1036 |
#include "esl_msafile.h" |
| 1037 |
#include "esl_msafile_clustal.h" |
| 1038 |
|
| 1039 |
int |
| 1040 |
main(int argc, char **argv) |
| 1041 |
{ |
| 1042 |
char *filename = argv[1]; |
| 1043 |
int fmt = eslMSAFILE_CLUSTAL; |
| 1044 |
ESL_MSAFILE *afp = NULL; |
| 1045 |
ESL_MSA *msa = NULL; |
| 1046 |
int status; |
| 1047 |
|
| 1048 |
if ( (status = esl_msafile_Open(NULL, filename, NULL, fmt, NULL, &afp)) != eslOK) esl_msafile_OpenFailure(afp, status); |
| 1049 |
if ( (status = esl_msafile_clustal_Read(afp, &msa)) != eslOK) esl_msafile_ReadFailure(afp, status); |
| 1050 |
|
| 1051 |
printf("%6d seqs, %5d columns\n", msa->nseq, (int) msa->alen); |
| 1052 |
|
| 1053 |
esl_msafile_clustal_Write(stdout, msa, eslMSAFILE_CLUSTAL); |
| 1054 |
|
| 1055 |
esl_msa_Destroy(msa); |
| 1056 |
esl_msafile_Close(afp); |
| 1057 |
exit(0); |
| 1058 |
} |
| 1059 |
|
| 1060 |
#endif |
| 1061 |
|
| 1062 |
|