| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
#include <esl_config.h> |
| 10 |
#include <p7_config.h> |
| 11 |
#include "config.h" |
| 12 |
|
| 13 |
#include <stdlib.h> |
| 14 |
#include <stdio.h> |
| 15 |
#include <string.h> |
| 16 |
#include <ctype.h> |
| 17 |
|
| 18 |
#include "easel.h" |
| 19 |
#include "esl_stack.h" |
| 20 |
#include "esl_vectorops.h" |
| 21 |
|
| 22 |
#include "hmmer.h" |
| 23 |
|
| 24 |
#include "infernal.h" |
| 25 |
|
| 26 |
static int bp_is_canonical(char lseq, char rseq); |
| 27 |
static float post_code_to_avg_pp(char postcode); |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
int |
| 57 |
cm_alidisplay_Create(CM_t *cm, char *errbuf, CM_ALNDATA *adata, const ESL_SQ *sq, int64_t seqoffset, |
| 58 |
double tau, double elapsed_secs, CM_ALIDISPLAY **ret_ad) |
| 59 |
{ |
| 60 |
int status; |
| 61 |
CM_ALIDISPLAY *ad = NULL; |
| 62 |
ESL_STACK *pda = NULL; |
| 63 |
float *act = NULL; |
| 64 |
int type; |
| 65 |
int v; |
| 66 |
int nd; |
| 67 |
int ti; |
| 68 |
int x; |
| 69 |
int qinset, tinset; |
| 70 |
int ninset; |
| 71 |
int pos; |
| 72 |
int lc, rc; |
| 73 |
int symi, symj; |
| 74 |
char mode; |
| 75 |
int lrf, rrf; |
| 76 |
int lstr, rstr; |
| 77 |
int lcons, rcons; |
| 78 |
int lmid, rmid; |
| 79 |
int lnnc, rnnc; |
| 80 |
int lseq, rseq; |
| 81 |
int lpost, rpost; |
| 82 |
int do_left, do_right; |
| 83 |
float tmpsc; |
| 84 |
float ppavg; |
| 85 |
int cm_namelen, cm_acclen, cm_desclen; |
| 86 |
int sq_namelen, sq_acclen, sq_desclen; |
| 87 |
int len, n; |
| 88 |
int len_el; |
| 89 |
int nw; |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
ESL_SQ **tmpsqA = NULL; |
| 97 |
Parsetree_t **tmptrA = NULL; |
| 98 |
char **tmpppA = NULL; |
| 99 |
ESL_MSA *tmpmsa = NULL; |
| 100 |
|
| 101 |
|
| 102 |
Parsetree_t *tr = adata->tr; |
| 103 |
char *ppstr = adata->ppstr; |
| 104 |
|
| 105 |
|
| 106 |
int cfrom_span; |
| 107 |
int cto_span; |
| 108 |
int cfrom_emit; |
| 109 |
|
| 110 |
int cto_emit; |
| 111 |
|
| 112 |
int have_i0; |
| 113 |
int have_j0; |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
int ntrunc_R = 0; |
| 119 |
int wtrunc_R = 0; |
| 120 |
int ntrunc_L = 0; |
| 121 |
int wtrunc_L = 0; |
| 122 |
int numwidth; |
| 123 |
int is_left, is_right; |
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
if(cm->cmcons == NULL) ESL_FAIL(eslEINCOMPAT, errbuf, "cm_alidisplay_Create(): cm->cmcons is NULL"); |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
len = 0; |
| 149 |
for (ti = 0; ti < tr->n; ti++) { |
| 150 |
v = tr->state[ti]; |
| 151 |
mode = tr->mode[ti]; |
| 152 |
if (v == cm->M) { |
| 153 |
nd = 1 + cm->ndidx[tr->state[ti-1]]; |
| 154 |
qinset = cm->cmcons->rpos[nd] - cm->cmcons->lpos[nd] + 1; |
| 155 |
tinset = tr->emitr[ti] - tr->emitl[ti] + 1; |
| 156 |
ninset = ESL_MAX(qinset,tinset); |
| 157 |
len += 4; |
| 158 |
do { len++; ninset/=10; } while (ninset); |
| 159 |
continue; |
| 160 |
} |
| 161 |
else { |
| 162 |
nd = cm->ndidx[v]; |
| 163 |
|
| 164 |
if (cm->sttype[v] == IL_st) { is_left = TRUE; is_right = FALSE; } |
| 165 |
else if(cm->sttype[v] == IR_st) { is_left = FALSE; is_right = TRUE; } |
| 166 |
else if(cm->ndtype[nd] == MATP_nd) { is_left = TRUE; is_right = TRUE; } |
| 167 |
else if(cm->ndtype[nd] == MATL_nd) { is_left = TRUE; is_right = FALSE; } |
| 168 |
else if(cm->ndtype[nd] == MATR_nd) { is_left = FALSE; is_right = TRUE; } |
| 169 |
else { is_left = FALSE; is_right = FALSE; } |
| 170 |
|
| 171 |
if((is_left) && (mode == TRMODE_J || mode == TRMODE_L)) len++; |
| 172 |
if((is_right) && (mode == TRMODE_J || mode == TRMODE_R)) len++; |
| 173 |
} |
| 174 |
|
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
have_i0 = (seqoffset == 1) ? TRUE : FALSE; |
| 189 |
have_j0 = ((seqoffset + tr->emitr[0] - 1) == sq->n) ? TRUE : FALSE; |
| 190 |
if((status = ParsetreeToCMBounds(cm, tr, have_i0, have_j0, errbuf, &cfrom_span, &cto_span, &cfrom_emit, &cto_emit, NULL, NULL)) != eslOK) return status; |
| 191 |
|
| 192 |
|
| 193 |
ntrunc_R = wtrunc_R = 0; |
| 194 |
ntrunc_L = wtrunc_L = 0; |
| 195 |
if (cfrom_span != cfrom_emit) { |
| 196 |
|
| 197 |
ntrunc_R = cfrom_emit - cfrom_span; |
| 198 |
ninset = ntrunc_R; |
| 199 |
wtrunc_R = 0; do { wtrunc_R++; ninset/=10; } while (ninset); |
| 200 |
wtrunc_R += 4; |
| 201 |
len += wtrunc_R; |
| 202 |
} |
| 203 |
if (cto_span != cto_emit) { |
| 204 |
|
| 205 |
ntrunc_L = cto_span - cto_emit; |
| 206 |
ninset = ntrunc_L; |
| 207 |
wtrunc_L = 0; do { wtrunc_L++; ninset/=10; } while (ninset); |
| 208 |
wtrunc_L += 4; |
| 209 |
len += wtrunc_L; |
| 210 |
} |
| 211 |
#if eslDEBUGLEVEL >= 1 |
| 212 |
printf("#DEBUG: cfrom_span: %4d\n", cfrom_span); |
| 213 |
printf("#DEBUG: cfrom_emit: %4d\n", cfrom_emit); |
| 214 |
printf("#DEBUG: cto_emit: %4d\n", cto_emit); |
| 215 |
printf("#DEBUG: cto_span: %4d\n", cto_span); |
| 216 |
#endif |
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
ESL_ALLOC(tmpsqA, sizeof(ESL_SQ *) * 1); |
| 224 |
if((tmpsqA[0] = esl_sq_CreateDigitalFrom(cm->abc, "i", sq->dsq + seqoffset - 1, tr->emitr[0] - tr->emitl[0] + 1, NULL, NULL, NULL)) == NULL) { |
| 225 |
goto ERROR; |
| 226 |
} |
| 227 |
ESL_ALLOC(tmptrA, sizeof(Parsetree_t *) * 1); |
| 228 |
tmptrA[0] = tr; |
| 229 |
if(adata->ppstr) { |
| 230 |
ESL_ALLOC(tmpppA, sizeof(char *) * 1); |
| 231 |
tmpppA[0] = adata->ppstr; |
| 232 |
} |
| 233 |
if((status = Parsetrees2Alignment(cm, errbuf, cm->abc, tmpsqA, NULL, tmptrA, tmpppA, 1, NULL, NULL, TRUE, FALSE, FALSE, &tmpmsa)) != eslOK) goto ERROR; |
| 234 |
esl_sq_Destroy(tmpsqA[0]); |
| 235 |
free(tmpsqA); tmpsqA = NULL; |
| 236 |
free(tmptrA); tmptrA = NULL; |
| 237 |
if(adata->ppstr) { free(tmpppA); tmpppA = NULL; } |
| 238 |
len_el = tmpmsa->alen; |
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
n = (len+1) * 5; |
| 244 |
n += 2 * (len_el+1); |
| 245 |
if(adata->ppstr != NULL) n += len+1 + len_el+1; |
| 246 |
if(cm->rf != NULL) n += len+1; |
| 247 |
cm_namelen = strlen(cm->name); n += cm_namelen + 1; |
| 248 |
cm_acclen = (cm->acc != NULL ? strlen(cm->acc) : 0); n += cm_acclen + 1; |
| 249 |
cm_desclen = (cm->desc != NULL ? strlen(cm->desc) : 0); n += cm_desclen + 1; |
| 250 |
sq_namelen = strlen(sq->name); n += sq_namelen + 1; |
| 251 |
sq_acclen = strlen(sq->acc); n += sq_acclen + 1; |
| 252 |
sq_desclen = strlen(sq->desc); n += sq_desclen + 1; |
| 253 |
|
| 254 |
ESL_ALLOC(ad, sizeof(CM_ALIDISPLAY)); |
| 255 |
ad->mem = NULL; |
| 256 |
ad->memsize = sizeof(char) * n; |
| 257 |
ad->sc = adata->sc; |
| 258 |
ad->avgpp = adata->pp; |
| 259 |
ad->tau = tau; |
| 260 |
ad->matrix_Mb = adata->mb_tot; |
| 261 |
ad->elapsed_secs = elapsed_secs; |
| 262 |
ad->hmmonly = FALSE; |
| 263 |
ad->N = len; |
| 264 |
ad->N_el = len_el; |
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
pos = 0; |
| 271 |
ESL_ALLOC(ad->mem, ad->memsize); |
| 272 |
if (cm->rf != NULL) { ad->rfline = ad->mem + pos; pos += len+1;} else { ad->rfline = NULL; } |
| 273 |
ad->ncline = ad->mem + pos; pos += len+1; |
| 274 |
ad->csline = ad->mem + pos; pos += len+1; |
| 275 |
ad->model = ad->mem + pos; pos += len+1; |
| 276 |
ad->mline = ad->mem + pos; pos += len+1; |
| 277 |
ad->aseq = ad->mem + pos; pos += len+1; |
| 278 |
if (adata->ppstr != NULL) { ad->ppline = ad->mem + pos; pos += len+1;} else { ad->ppline = NULL; } |
| 279 |
ad->aseq_el = ad->mem + pos; pos += len_el+1; |
| 280 |
ad->rfline_el = ad->mem + pos; pos += len_el+1; |
| 281 |
if (adata->ppstr != NULL) { ad->ppline_el = ad->mem + pos; pos += len_el+1;} else { ad->ppline_el = NULL; } |
| 282 |
ad->cmname = ad->mem + pos; pos += cm_namelen +1; |
| 283 |
ad->cmacc = ad->mem + pos; pos += cm_acclen +1; |
| 284 |
ad->cmdesc = ad->mem + pos; pos += cm_desclen +1; |
| 285 |
ad->sqname = ad->mem + pos; pos += sq_namelen +1; |
| 286 |
ad->sqacc = ad->mem + pos; pos += sq_acclen +1; |
| 287 |
ad->sqdesc = ad->mem + pos; pos += sq_desclen +1; |
| 288 |
|
| 289 |
|
| 290 |
strcpy(ad->cmname, cm->name); |
| 291 |
if (cm->acc != NULL) strcpy(ad->cmacc, cm->acc); else ad->cmacc[0] = 0; |
| 292 |
if (cm->desc != NULL) strcpy(ad->cmdesc, cm->desc); else ad->cmdesc[0] = 0; |
| 293 |
strcpy(ad->sqname, sq->name); |
| 294 |
strcpy(ad->sqacc, sq->acc); |
| 295 |
strcpy(ad->sqdesc, sq->desc); |
| 296 |
|
| 297 |
|
| 298 |
strcpy(ad->aseq_el, tmpmsa->aseq[0]); |
| 299 |
strcpy(ad->rfline_el, tmpmsa->rf); |
| 300 |
if(adata->ppstr) strcpy(ad->ppline_el, tmpmsa->pp[0]); |
| 301 |
|
| 302 |
|
| 303 |
ad->clen = cm->clen; |
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
if (cm->rf != NULL) memset(ad->rfline, ' ', ad->N); |
| 310 |
memset(ad->ncline, ' ', ad->N); |
| 311 |
memset(ad->csline, ' ', ad->N); |
| 312 |
memset(ad->model, ' ', ad->N); |
| 313 |
memset(ad->mline, ' ', ad->N); |
| 314 |
memset(ad->aseq, ' ', ad->N); |
| 315 |
if(adata->ppstr != NULL) memset(ad->ppline, ' ', ad->N); |
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
pos = 0; |
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
if(ntrunc_R > 0) { |
| 326 |
|
| 327 |
memset(ad->csline+pos, '~', wtrunc_R); |
| 328 |
if((nw = snprintf(ad->model+pos, wtrunc_R+1, "<[%*d]*", wtrunc_R-4, ntrunc_R)) != wtrunc_R) goto ERROR; |
| 329 |
if((nw = snprintf(ad->aseq+pos, wtrunc_R+1, "<[%*s]*", wtrunc_R-4, "0")) != wtrunc_R) goto ERROR; |
| 330 |
if(adata->ppstr != NULL) { |
| 331 |
for(x = 0; x < wtrunc_R; x++) ad->ppline[pos+x] = '.'; |
| 332 |
} |
| 333 |
pos += wtrunc_R; |
| 334 |
} |
| 335 |
|
| 336 |
if((pda = esl_stack_ICreate()) == NULL) goto ERROR; |
| 337 |
if((status = esl_stack_IPush(pda, 0)) != eslOK) goto ERROR; |
| 338 |
if((status = esl_stack_IPush(pda, PDA_STATE)) != eslOK) goto ERROR; |
| 339 |
while (esl_stack_IPop(pda, &type) != eslEOD) |
| 340 |
{ |
| 341 |
if (type == PDA_RESIDUE) { |
| 342 |
if (cm->rf != NULL) { |
| 343 |
esl_stack_IPop(pda, &rrf); |
| 344 |
ad->rfline[pos] = rrf; |
| 345 |
} |
| 346 |
esl_stack_IPop(pda, &rnnc); ad->ncline[pos] = rnnc; |
| 347 |
esl_stack_IPop(pda, &rstr); ad->csline[pos] = rstr; |
| 348 |
esl_stack_IPop(pda, &rcons); ad->model[pos] = rcons; |
| 349 |
esl_stack_IPop(pda, &rmid); ad->mline[pos] = rmid; |
| 350 |
esl_stack_IPop(pda, &rseq); ad->aseq[pos] = rseq; |
| 351 |
if(ppstr != NULL) { |
| 352 |
esl_stack_IPop(pda, &rpost); ad->ppline[pos] = rpost; |
| 353 |
} |
| 354 |
pos++; |
| 355 |
continue; |
| 356 |
} |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
esl_stack_IPop(pda, &ti); |
| 361 |
v = tr->state[ti]; |
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
if (v == cm->M) { |
| 366 |
nd = 1 + cm->ndidx[tr->state[ti-1]]; |
| 367 |
qinset = cm->cmcons->rpos[nd] - cm->cmcons->lpos[nd] + 1; |
| 368 |
tinset = tr->emitr[ti] - tr->emitl[ti] + 1; |
| 369 |
ninset = ESL_MAX(qinset,tinset); |
| 370 |
numwidth = 0; do { numwidth++; ninset/=10; } while (ninset); |
| 371 |
memset(ad->csline+pos, '~', numwidth+4); |
| 372 |
if((nw = snprintf(ad->model+pos, numwidth+5, "*[%*d]*", numwidth, qinset)) != (numwidth+4)) goto ERROR; |
| 373 |
if((nw = snprintf(ad->aseq+pos, numwidth+5, "*[%*d]*", numwidth, tinset)) != (numwidth+4)) goto ERROR; |
| 374 |
if(cm->rf != NULL) memset(ad->rfline+pos, '~', numwidth+4); |
| 375 |
if(adata->ppstr != NULL) { |
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
ppavg = 0.; |
| 383 |
for(x = tr->emitl[ti]; x <= tr->emitr[ti]; x++) { |
| 384 |
ppavg += post_code_to_avg_pp(adata->ppstr[x-1]); |
| 385 |
} |
| 386 |
ppavg /= (float) (tr->emitr[ti] - tr->emitl[ti] + 1); |
| 387 |
ad->ppline[pos] = '.'; |
| 388 |
ad->ppline[pos+1] = '.'; |
| 389 |
for(x = 0; x < (numwidth-1); x++) ad->ppline[pos+2+x] = '.'; |
| 390 |
if(tr->emitl[ti] <= tr->emitr[ti]) { |
| 391 |
ad->ppline[pos+numwidth+1] = (ppavg + 0.05 >= 1.0) ? '*' : (char) ((ppavg + 0.05) * 10.0) + '0'; |
| 392 |
} |
| 393 |
else { |
| 394 |
ad->ppline[pos+numwidth+1] = '.'; |
| 395 |
} |
| 396 |
ad->ppline[pos+numwidth+2] = '.'; |
| 397 |
ad->ppline[pos+numwidth+3] = '.'; |
| 398 |
} |
| 399 |
pos += 4 + numwidth; |
| 400 |
continue; |
| 401 |
} |
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
nd = cm->ndidx[v]; |
| 406 |
lc = cm->cmcons->lpos[nd]; |
| 407 |
rc = cm->cmcons->rpos[nd]; |
| 408 |
symi = sq->dsq[tr->emitl[ti] + (seqoffset-1)]; |
| 409 |
symj = sq->dsq[tr->emitr[ti] + (seqoffset-1)]; |
| 410 |
if(ppstr != NULL) { |
| 411 |
lpost = '.'; |
| 412 |
rpost = '.'; |
| 413 |
} |
| 414 |
mode = tr->mode[ti]; |
| 415 |
|
| 416 |
|
| 417 |
|
| 418 |
do_left = do_right = FALSE; |
| 419 |
if (cm->sttype[v] == IL_st) { |
| 420 |
if(mode == TRMODE_J || mode == TRMODE_L) { |
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
do_left = TRUE; |
| 426 |
if (cm->rf != NULL) lrf = '.'; |
| 427 |
lstr = '.'; |
| 428 |
lcons = '.'; |
| 429 |
lseq = tolower((int) cm->abc->sym[symi]); |
| 430 |
if(ppstr != NULL) lpost = ppstr[tr->emitl[ti]-1]; |
| 431 |
} |
| 432 |
} |
| 433 |
else if (cm->sttype[v] == IR_st) { |
| 434 |
if (mode == TRMODE_J || mode == TRMODE_R) { |
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
do_right = TRUE; |
| 440 |
if (cm->rf != NULL) rrf = '.'; |
| 441 |
rstr = '.'; |
| 442 |
rcons = '.'; |
| 443 |
rseq = tolower((int) cm->abc->sym[symj]); |
| 444 |
if(ppstr != NULL) rpost = ppstr[tr->emitr[ti]-1]; |
| 445 |
} |
| 446 |
} |
| 447 |
else { |
| 448 |
if ((cm->ndtype[nd] == MATP_nd || cm->ndtype[nd] == MATL_nd) && (mode == TRMODE_J || mode == TRMODE_L)) { |
| 449 |
do_left = TRUE; |
| 450 |
if (cm->rf != NULL) lrf = cm->rf[lc+1]; |
| 451 |
lstr = cm->cmcons->cstr[lc]; |
| 452 |
lcons = (cm->flags & CMH_CONS) ? cm->consensus[(lc+1)] : cm->cmcons->cseq[lc]; |
| 453 |
if (cm->sttype[v] == MP_st || cm->sttype[v] == ML_st) { |
| 454 |
lseq = cm->abc->sym[symi]; |
| 455 |
if(ppstr != NULL) lpost = ppstr[tr->emitl[ti]-1]; |
| 456 |
} |
| 457 |
else { |
| 458 |
lseq = '-'; |
| 459 |
if(ppstr != NULL) lpost = '.'; |
| 460 |
} |
| 461 |
} |
| 462 |
if ((cm->ndtype[nd] == MATP_nd || cm->ndtype[nd] == MATR_nd) && (mode == TRMODE_J || mode == TRMODE_R)) { |
| 463 |
do_right = TRUE; |
| 464 |
if (cm->rf != NULL) rrf = cm->rf[rc+1]; |
| 465 |
rstr = cm->cmcons->cstr[rc]; |
| 466 |
rcons = (cm->flags & CMH_CONS) ? cm->consensus[(rc+1)] : cm->cmcons->cseq[rc]; |
| 467 |
if (cm->sttype[v] == MP_st || cm->sttype[v] == MR_st) { |
| 468 |
rseq = cm->abc->sym[symj]; |
| 469 |
if(ppstr != NULL) rpost = ppstr[tr->emitr[ti]-1]; |
| 470 |
} |
| 471 |
else { |
| 472 |
rseq = '-'; |
| 473 |
if(ppstr != NULL) rpost = '.'; |
| 474 |
} |
| 475 |
} |
| 476 |
} |
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
lmid = rmid = ' '; |
| 481 |
lnnc = rnnc = ' '; |
| 482 |
if (cm->sttype[v] == MP_st) { |
| 483 |
if (mode == TRMODE_L) { |
| 484 |
if(lseq == toupper(lcons)) lmid = lseq; |
| 485 |
lnnc = '?'; |
| 486 |
} |
| 487 |
else if (mode == TRMODE_R) { |
| 488 |
if(rseq == toupper(rcons)) rmid = rseq; |
| 489 |
rnnc = '?'; |
| 490 |
} |
| 491 |
else if (mode == TRMODE_J) { |
| 492 |
tmpsc = DegeneratePairScore(cm->abc, cm->esc[v], symi, symj); |
| 493 |
if (lseq == toupper(lcons) && rseq == toupper(rcons)) { |
| 494 |
lmid = lseq; |
| 495 |
rmid = rseq; |
| 496 |
} |
| 497 |
else if (tmpsc >= 0) { |
| 498 |
lmid = rmid = ':'; |
| 499 |
} |
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
if (tmpsc < 0 && (! bp_is_canonical(lseq, rseq))) { |
| 506 |
lnnc = rnnc = 'v'; |
| 507 |
} |
| 508 |
} |
| 509 |
} |
| 510 |
else if ((cm->sttype[v] == ML_st || cm->sttype[v] == IL_st) && |
| 511 |
(mode == TRMODE_J || mode == TRMODE_L)) { |
| 512 |
if (lseq == toupper(lcons)) { |
| 513 |
lmid = lseq; |
| 514 |
} |
| 515 |
else if(esl_abc_FAvgScore(cm->abc, symi, cm->esc[v]) > 0) { |
| 516 |
lmid = '+'; |
| 517 |
} |
| 518 |
} |
| 519 |
else if ((cm->sttype[v] == MR_st || cm->sttype[v] == IR_st) && |
| 520 |
(mode == TRMODE_J || mode == TRMODE_R)) { |
| 521 |
if (rseq == toupper(rcons)) { |
| 522 |
rmid = rseq; |
| 523 |
} |
| 524 |
else if(esl_abc_FAvgScore(cm->abc, symj, cm->esc[v]) > 0) { |
| 525 |
rmid = '+'; |
| 526 |
} |
| 527 |
} |
| 528 |
if((cm->stid[v] == MATP_ML || cm->stid[v] == MATP_MR) && mode == TRMODE_J) { |
| 529 |
lnnc = rnnc = 'v'; |
| 530 |
} |
| 531 |
if(cm->stid[v] == MATP_ML && mode == TRMODE_L) { |
| 532 |
lnnc = '?'; |
| 533 |
} |
| 534 |
if(cm->stid[v] == MATP_MR && mode == TRMODE_R) { |
| 535 |
rnnc = '?'; |
| 536 |
} |
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
if (do_left) { |
| 541 |
if (cm->rf != NULL) ad->rfline[pos] = lrf; |
| 542 |
ad->ncline[pos] = lnnc; |
| 543 |
ad->csline[pos] = lstr; |
| 544 |
ad->model[pos] = lcons; |
| 545 |
ad->mline[pos] = lmid; |
| 546 |
ad->aseq[pos] = lseq; |
| 547 |
if(ppstr != NULL) ad->ppline[pos] = lpost; |
| 548 |
pos++; |
| 549 |
} |
| 550 |
if (do_right) { |
| 551 |
if(ppstr != NULL) { |
| 552 |
if ((status = esl_stack_IPush(pda, (int) rpost)) != eslOK) goto ERROR; |
| 553 |
} |
| 554 |
if ((status = esl_stack_IPush(pda, (int) rseq)) != eslOK) goto ERROR; |
| 555 |
if ((status = esl_stack_IPush(pda, (int) rmid)) != eslOK) goto ERROR; |
| 556 |
if ((status = esl_stack_IPush(pda, (int) rcons)) != eslOK) goto ERROR; |
| 557 |
if ((status = esl_stack_IPush(pda, (int) rstr)) != eslOK) goto ERROR; |
| 558 |
if ((status = esl_stack_IPush(pda, (int) rnnc)) != eslOK) goto ERROR; |
| 559 |
if (cm->rf != NULL) if ((status = esl_stack_IPush(pda, (int) rrf)) != eslOK) goto ERROR; |
| 560 |
if ((status = esl_stack_IPush(pda, PDA_RESIDUE)) != eslOK) goto ERROR; |
| 561 |
} |
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
|
| 566 |
if (tr->nxtr[ti] != -1) { |
| 567 |
if ((status = esl_stack_IPush(pda, tr->nxtr[ti])) != eslOK) goto ERROR; |
| 568 |
if ((status = esl_stack_IPush(pda, PDA_STATE)) != eslOK) goto ERROR; |
| 569 |
} |
| 570 |
if (tr->nxtl[ti] != -1) { |
| 571 |
if ((status = esl_stack_IPush(pda, tr->nxtl[ti])) != eslOK) goto ERROR; |
| 572 |
if ((status = esl_stack_IPush(pda, PDA_STATE)) != eslOK) goto ERROR; |
| 573 |
} |
| 574 |
else if (cm->sttype[v] != E_st) { |
| 575 |
; |
| 576 |
} |
| 577 |
} |
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
if(ntrunc_L > 0) { |
| 583 |
|
| 584 |
memset(ad->csline+pos, '~', wtrunc_L); |
| 585 |
if((nw = snprintf(ad->model+pos, wtrunc_L+1, "*[%*d]>", wtrunc_L-4, ntrunc_L)) != wtrunc_L) goto ERROR; |
| 586 |
if((nw = snprintf(ad->aseq+pos, wtrunc_L+1, "*[%*s]>", wtrunc_L-4, "0")) != wtrunc_L) goto ERROR; |
| 587 |
if(adata->ppstr != NULL) { |
| 588 |
for(x = 0; x < wtrunc_L; x++) ad->ppline[pos+x] = '.'; |
| 589 |
} |
| 590 |
pos += wtrunc_L; |
| 591 |
} |
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
ESL_ALLOC(act, sizeof(float) * cm->abc->K); |
| 599 |
esl_vec_FSet(act, cm->abc->K, 0.); |
| 600 |
for(x = tr->emitl[0] + seqoffset - 1; x <= tr->emitr[0] + seqoffset - 1; x++) { |
| 601 |
esl_abc_FCount(cm->abc, act, sq->dsq[x], 1.0); |
| 602 |
} |
| 603 |
|
| 604 |
if(cm->rf != NULL) ad->rfline[ad->N] = '\0'; |
| 605 |
ad->ncline[ad->N] = '\0'; |
| 606 |
ad->csline[ad->N] = '\0'; |
| 607 |
ad->model[ad->N] = '\0'; |
| 608 |
ad->mline[ad->N] = '\0'; |
| 609 |
ad->aseq[ad->N] = '\0'; |
| 610 |
if(ppstr != NULL) ad->ppline[ad->N] = '\0'; |
| 611 |
ad->sqfrom = tr->emitl[0] + seqoffset-1; |
| 612 |
ad->sqto = tr->emitr[0] + seqoffset-1; |
| 613 |
ad->cfrom_emit = cfrom_emit; |
| 614 |
ad->cto_emit = cto_emit; |
| 615 |
ad->cfrom_span = cfrom_span; |
| 616 |
ad->cto_span = cto_span; |
| 617 |
ad->gc = (act[1] + act[2]) / (float) (tr->emitr[0]- tr->emitl[0] + 1); |
| 618 |
|
| 619 |
esl_stack_Destroy(pda); |
| 620 |
if(tmpmsa != NULL) esl_msa_Destroy(tmpmsa); |
| 621 |
if(act != NULL) free(act); |
| 622 |
if(ret_ad != NULL) *ret_ad = ad; |
| 623 |
return eslOK; |
| 624 |
|
| 625 |
ERROR: |
| 626 |
if(pda != NULL) esl_stack_Destroy(pda); |
| 627 |
if(ad != NULL) cm_alidisplay_Destroy(ad); |
| 628 |
if(act != NULL) free(act); |
| 629 |
if(ret_ad != NULL) *ret_ad = NULL; |
| 630 |
if(status == eslEMEM) ESL_FAIL(status, errbuf, "cm_alidisplay_Create() out of memory"); |
| 631 |
return status; |
| 632 |
} |
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
int |
| 659 |
cm_alidisplay_CreateFromP7(CM_t *cm, char *errbuf, const ESL_SQ *sq, int64_t seqoffset, float p7sc, float p7pp, P7_ALIDISPLAY *p7ad, CM_ALIDISPLAY **ret_ad) |
| 660 |
{ |
| 661 |
int status; |
| 662 |
CM_ALIDISPLAY *ad = NULL; |
| 663 |
int n; |
| 664 |
int cm_namelen, cm_acclen, cm_desclen; |
| 665 |
int sq_namelen, sq_acclen, sq_desclen; |
| 666 |
int len; |
| 667 |
int len_el; |
| 668 |
int pos; |
| 669 |
int x; |
| 670 |
float *act = NULL; |
| 671 |
int n5p_skipped = 0; |
| 672 |
int n3p_skipped = 0; |
| 673 |
|
| 674 |
len = p7ad->N; |
| 675 |
n5p_skipped = p7ad->hmmfrom -1; |
| 676 |
n3p_skipped = p7ad->M - p7ad->hmmto; |
| 677 |
len_el = len + n5p_skipped + n3p_skipped; |
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
n = (len+1) * 4; |
| 684 |
n += 2 * (len_el+1); |
| 685 |
if(p7ad->ppline != NULL) n += len+1 + len_el+1; |
| 686 |
if(p7ad->rfline != NULL) n += len+1; |
| 687 |
cm_namelen = strlen(cm->name); n += cm_namelen + 1; |
| 688 |
cm_acclen = (cm->acc != NULL ? strlen(cm->acc) : 0); n += cm_acclen + 1; |
| 689 |
cm_desclen = (cm->desc != NULL ? strlen(cm->desc) : 0); n += cm_desclen + 1; |
| 690 |
sq_namelen = strlen(sq->name); n += sq_namelen + 1; |
| 691 |
sq_acclen = strlen(sq->acc); n += sq_acclen + 1; |
| 692 |
sq_desclen = strlen(sq->desc); n += sq_desclen + 1; |
| 693 |
|
| 694 |
ESL_ALLOC(ad, sizeof(CM_ALIDISPLAY)); |
| 695 |
ad->mem = NULL; |
| 696 |
ad->memsize = sizeof(char) * n; |
| 697 |
ad->sc = p7sc; |
| 698 |
ad->avgpp = p7pp; |
| 699 |
ad->tau = -1.0; |
| 700 |
ad->matrix_Mb = 0.0; |
| 701 |
ad->elapsed_secs = 0.0; |
| 702 |
ad->hmmonly = TRUE; |
| 703 |
ad->N = len; |
| 704 |
ad->N_el = len + n5p_skipped + n3p_skipped; |
| 705 |
|
| 706 |
ad->clen = cm->clen; |
| 707 |
|
| 708 |
ad->sqfrom = p7ad->sqfrom; |
| 709 |
ad->sqto = p7ad->sqto; |
| 710 |
ad->cfrom_emit = p7ad->hmmfrom; |
| 711 |
ad->cto_emit = p7ad->hmmto; |
| 712 |
ad->cfrom_span = p7ad->hmmfrom; |
| 713 |
ad->cto_span = p7ad->hmmto; |
| 714 |
|
| 715 |
|
| 716 |
ESL_ALLOC(act, sizeof(float) * cm->abc->K); |
| 717 |
esl_vec_FSet(act, cm->abc->K, 0.); |
| 718 |
for(x = p7ad->sqfrom; x <= p7ad->sqto; x++) esl_abc_FCount(cm->abc, act, sq->dsq[x], 1.0); |
| 719 |
ad->gc = (act[1] + act[2]) / (float) (p7ad->sqto - p7ad->sqfrom + 1); |
| 720 |
|
| 721 |
pos = 0; |
| 722 |
ESL_ALLOC(ad->mem, ad->memsize); |
| 723 |
if (p7ad->rfline != NULL) { ad->rfline = ad->mem + pos; pos += len+1;} else { ad->rfline = NULL; } |
| 724 |
ad->ncline = NULL; |
| 725 |
ad->csline = ad->mem + pos; pos += len+1; |
| 726 |
ad->model = ad->mem + pos; pos += len+1; |
| 727 |
ad->mline = ad->mem + pos; pos += len+1; |
| 728 |
ad->aseq = ad->mem + pos; pos += len+1; |
| 729 |
if (p7ad->ppline != NULL) { ad->ppline = ad->mem + pos; pos += len+1;} else { ad->ppline = NULL; } |
| 730 |
ad->aseq_el = ad->mem + pos; pos += len_el+1; |
| 731 |
ad->rfline_el = ad->mem + pos; pos += len_el+1; |
| 732 |
if (p7ad->ppline != NULL) { ad->ppline_el = ad->mem + pos; pos += len_el+1;} else { ad->ppline_el = NULL; } |
| 733 |
ad->cmname = ad->mem + pos; pos += cm_namelen +1; |
| 734 |
ad->cmacc = ad->mem + pos; pos += cm_acclen +1; |
| 735 |
ad->cmdesc = ad->mem + pos; pos += cm_desclen +1; |
| 736 |
ad->sqname = ad->mem + pos; pos += sq_namelen +1; |
| 737 |
ad->sqacc = ad->mem + pos; pos += sq_acclen +1; |
| 738 |
ad->sqdesc = ad->mem + pos; pos += sq_desclen +1; |
| 739 |
|
| 740 |
|
| 741 |
strcpy(ad->cmname, cm->name); |
| 742 |
if (cm->acc != NULL) strcpy(ad->cmacc, cm->acc); else ad->cmacc[0] = 0; |
| 743 |
if (cm->desc != NULL) strcpy(ad->cmdesc, cm->desc); else ad->cmdesc[0] = 0; |
| 744 |
strcpy(ad->sqname, sq->name); |
| 745 |
strcpy(ad->sqacc, sq->acc); |
| 746 |
strcpy(ad->sqdesc, sq->desc); |
| 747 |
|
| 748 |
|
| 749 |
if(p7ad->rfline) strcpy(ad->rfline, p7ad->rfline); |
| 750 |
strcpy(ad->csline, p7ad->csline); |
| 751 |
strcpy(ad->model, p7ad->model); |
| 752 |
strcpy(ad->mline, p7ad->mline); |
| 753 |
strcpy(ad->aseq, p7ad->aseq); |
| 754 |
if(p7ad->ppline) strcpy(ad->ppline, p7ad->ppline); |
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
for(x = 0; x < n5p_skipped; x++) ad->aseq_el[x] = '-'; |
| 763 |
memcpy(ad->aseq_el + n5p_skipped, p7ad->aseq, ad->N); |
| 764 |
for(x = ad->N + n5p_skipped; x < ad->N_el; x++) ad->aseq_el[x] = '-'; |
| 765 |
ad->aseq_el[ad->N_el] = '\0'; |
| 766 |
|
| 767 |
for(x = 0; x < n5p_skipped; x++) ad->rfline_el[x] = 'x'; |
| 768 |
|
| 769 |
memcpy(ad->rfline_el + n5p_skipped, p7ad->model, ad->N); |
| 770 |
for(x = ad->N + n5p_skipped; x < ad->N_el; x++) ad->rfline_el[x] = 'x'; |
| 771 |
ad->rfline_el[ad->N_el] = '\0'; |
| 772 |
|
| 773 |
if(p7ad->ppline) { |
| 774 |
for(x = 0; x < n5p_skipped; x++) ad->ppline_el[x] = '-'; |
| 775 |
memcpy(ad->ppline_el + n5p_skipped, p7ad->ppline, ad->N); |
| 776 |
for(x = ad->N + n5p_skipped; x < ad->N_el; x++) ad->ppline_el[x] = '-'; |
| 777 |
ad->ppline_el[ad->N_el] = '\0'; |
| 778 |
} |
| 779 |
else { |
| 780 |
ad->ppline_el[0] = '\0'; |
| 781 |
} |
| 782 |
|
| 783 |
if(act != NULL) free(act); |
| 784 |
if(ret_ad != NULL) *ret_ad = ad; |
| 785 |
return eslOK; |
| 786 |
|
| 787 |
ERROR: |
| 788 |
if(act != NULL) free(act); |
| 789 |
if(ret_ad != NULL) *ret_ad = NULL; |
| 790 |
if(status == eslEMEM) ESL_FAIL(status, errbuf, "cm_alidisplay_CreateFromP7() out of memory"); |
| 791 |
return status; |
| 792 |
} |
| 793 |
|
| 794 |
|
| 795 |
|
| 796 |
|
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
|
| 805 |
CM_ALIDISPLAY * |
| 806 |
cm_alidisplay_Clone(const CM_ALIDISPLAY *ad) |
| 807 |
{ |
| 808 |
CM_ALIDISPLAY *ad2 = NULL; |
| 809 |
int status; |
| 810 |
|
| 811 |
ESL_ALLOC(ad2, sizeof(CM_ALIDISPLAY)); |
| 812 |
ad2->rfline = ad2->ncline = ad2->csline = ad2->model = ad2->mline = ad2->aseq = ad2->ppline = NULL; |
| 813 |
ad2->cmname = ad2->cmacc = ad2->cmdesc = NULL; |
| 814 |
ad2->sqname = ad2->sqacc = ad2->sqdesc = NULL; |
| 815 |
ad2->aseq_el = ad2->rfline_el = ad2->ppline_el = NULL; |
| 816 |
ad2->mem = NULL; |
| 817 |
ad2->memsize = 0; |
| 818 |
|
| 819 |
if (ad->memsize) |
| 820 |
{ |
| 821 |
ESL_ALLOC(ad2->mem, sizeof(char) * ad->memsize); |
| 822 |
ad2->memsize = ad->memsize; |
| 823 |
memcpy(ad2->mem, ad->mem, ad->memsize); |
| 824 |
|
| 825 |
ad2->rfline = (ad->rfline ? ad2->mem + (ad->rfline - ad->mem) : NULL ); |
| 826 |
ad2->ncline = (ad->ncline ? ad2->mem + (ad->ncline - ad->mem) : NULL ); |
| 827 |
ad2->csline = ad2->mem + (ad->csline - ad->mem); |
| 828 |
ad2->model = ad2->mem + (ad->model - ad->mem); |
| 829 |
ad2->mline = ad2->mem + (ad->mline - ad->mem); |
| 830 |
ad2->aseq = ad2->mem + (ad->aseq - ad->mem); |
| 831 |
ad2->ppline = (ad->ppline ? ad2->mem + (ad->ppline - ad->mem) : NULL ); |
| 832 |
ad2->aseq_el = ad2->mem + (ad->aseq_el - ad->mem); |
| 833 |
ad2->rfline_el = ad2->mem + (ad->rfline_el - ad->mem); |
| 834 |
ad2->ppline_el = (ad->ppline_el ? ad2->mem + (ad->ppline_el - ad->mem) : NULL ); |
| 835 |
ad2->N = ad->N; |
| 836 |
ad2->N_el = ad->N_el; |
| 837 |
|
| 838 |
ad2->cmname = ad2->mem + (ad->cmname - ad->mem); |
| 839 |
ad2->cmacc = ad2->mem + (ad->cmacc - ad->mem); |
| 840 |
ad2->cmdesc = ad2->mem + (ad->cmdesc - ad->mem); |
| 841 |
ad2->cfrom_emit = ad->cfrom_emit; |
| 842 |
ad2->cto_emit = ad->cto_emit; |
| 843 |
ad2->cfrom_span = ad->cfrom_span; |
| 844 |
ad2->cto_span = ad->cto_span; |
| 845 |
ad2->clen = ad->clen; |
| 846 |
|
| 847 |
ad2->sqname = ad2->mem + (ad->sqname - ad->mem); |
| 848 |
ad2->sqacc = ad2->mem + (ad->sqacc - ad->mem); |
| 849 |
ad2->sqdesc = ad2->mem + (ad->sqdesc - ad->mem); |
| 850 |
ad2->sqfrom = ad->sqfrom; |
| 851 |
ad2->sqto = ad->sqto; |
| 852 |
} |
| 853 |
else |
| 854 |
{ |
| 855 |
if ( esl_strdup(ad->rfline, -1, &(ad2->rfline)) != eslOK) goto ERROR; |
| 856 |
if ( esl_strdup(ad->ncline, -1, &(ad2->ncline)) != eslOK) goto ERROR; |
| 857 |
if ( esl_strdup(ad->csline, -1, &(ad2->csline)) != eslOK) goto ERROR; |
| 858 |
if ( esl_strdup(ad->model, -1, &(ad2->model)) != eslOK) goto ERROR; |
| 859 |
if ( esl_strdup(ad->mline, -1, &(ad2->mline)) != eslOK) goto ERROR; |
| 860 |
if ( esl_strdup(ad->aseq, -1, &(ad2->aseq)) != eslOK) goto ERROR; |
| 861 |
if ( esl_strdup(ad->ppline, -1, &(ad2->ppline)) != eslOK) goto ERROR; |
| 862 |
if ( esl_strdup(ad->aseq_el, -1, &(ad2->aseq_el)) != eslOK) goto ERROR; |
| 863 |
if ( esl_strdup(ad->rfline_el, -1, &(ad2->rfline_el)) != eslOK) goto ERROR; |
| 864 |
if ( esl_strdup(ad->ppline_el, -1, &(ad2->ppline_el)) != eslOK) goto ERROR; |
| 865 |
ad2->N = ad->N; |
| 866 |
ad2->N_el = ad->N_el; |
| 867 |
|
| 868 |
if ( esl_strdup(ad->cmname, -1, &(ad2->cmname)) != eslOK) goto ERROR; |
| 869 |
if ( esl_strdup(ad->cmacc, -1, &(ad2->cmacc)) != eslOK) goto ERROR; |
| 870 |
if ( esl_strdup(ad->cmdesc, -1, &(ad2->cmdesc)) != eslOK) goto ERROR; |
| 871 |
ad2->cfrom_emit = ad->cfrom_emit; |
| 872 |
ad2->cto_emit = ad->cto_emit; |
| 873 |
ad2->cfrom_span = ad->cfrom_span; |
| 874 |
ad2->cto_span = ad->cto_span; |
| 875 |
ad2->clen = ad->clen; |
| 876 |
|
| 877 |
if ( esl_strdup(ad->sqname, -1, &(ad2->sqname)) != eslOK) goto ERROR; |
| 878 |
if ( esl_strdup(ad->sqacc, -1, &(ad2->sqacc)) != eslOK) goto ERROR; |
| 879 |
if ( esl_strdup(ad->sqdesc, -1, &(ad2->sqdesc)) != eslOK) goto ERROR; |
| 880 |
ad2->sqfrom = ad->sqfrom; |
| 881 |
ad2->sqto = ad->sqto; |
| 882 |
} |
| 883 |
|
| 884 |
|
| 885 |
ad2->sc = ad->sc; |
| 886 |
ad2->avgpp = ad->avgpp; |
| 887 |
ad2->gc = ad->gc; |
| 888 |
ad2->tau = ad->tau; |
| 889 |
ad2->matrix_Mb = ad->matrix_Mb; |
| 890 |
ad2->elapsed_secs = ad->elapsed_secs; |
| 891 |
ad2->hmmonly = ad->hmmonly; |
| 892 |
|
| 893 |
return ad2; |
| 894 |
|
| 895 |
ERROR: |
| 896 |
if (ad2) cm_alidisplay_Destroy(ad2); |
| 897 |
return NULL; |
| 898 |
} |
| 899 |
|
| 900 |
|
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
|
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
size_t |
| 915 |
cm_alidisplay_Sizeof(const CM_ALIDISPLAY *ad) |
| 916 |
{ |
| 917 |
size_t n = sizeof(CM_ALIDISPLAY); |
| 918 |
|
| 919 |
if (ad->rfline) n += ad->N+1; |
| 920 |
n += 4 * (ad->N+1); |
| 921 |
if (ad->ppline) n += ad->N+1; |
| 922 |
if (ad->ncline) n += ad->N+1; |
| 923 |
n += ad->N_el+1; |
| 924 |
n += ad->N_el+1; |
| 925 |
if (ad->ppline_el) n += ad->N_el+1; |
| 926 |
n += 1 + strlen(ad->cmname); |
| 927 |
n += 1 + strlen(ad->cmacc); |
| 928 |
n += 1 + strlen(ad->cmdesc); |
| 929 |
n += 1 + strlen(ad->sqname); |
| 930 |
n += 1 + strlen(ad->sqacc); |
| 931 |
n += 1 + strlen(ad->sqdesc); |
| 932 |
|
| 933 |
return n; |
| 934 |
} |
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
void |
| 940 |
cm_alidisplay_Destroy(CM_ALIDISPLAY *ad) |
| 941 |
{ |
| 942 |
if (ad == NULL) return; |
| 943 |
if (ad->mem) |
| 944 |
{ |
| 945 |
free(ad->mem); |
| 946 |
} |
| 947 |
else |
| 948 |
{ |
| 949 |
if (ad->rfline) free(ad->rfline); |
| 950 |
if (ad->ncline) free(ad->ncline); |
| 951 |
if (ad->csline) free(ad->csline); |
| 952 |
if (ad->model) free(ad->model); |
| 953 |
if (ad->mline) free(ad->mline); |
| 954 |
if (ad->aseq) free(ad->aseq); |
| 955 |
if (ad->ppline) free(ad->ppline); |
| 956 |
if (ad->aseq_el) free(ad->aseq_el); |
| 957 |
if (ad->rfline_el) free(ad->rfline_el); |
| 958 |
if (ad->ppline_el) free(ad->ppline_el); |
| 959 |
if (ad->cmname) free(ad->cmname); |
| 960 |
if (ad->cmacc) free(ad->cmacc); |
| 961 |
if (ad->cmdesc) free(ad->cmdesc); |
| 962 |
if (ad->sqname) free(ad->sqname); |
| 963 |
if (ad->sqacc) free(ad->sqacc); |
| 964 |
if (ad->sqdesc) free(ad->sqdesc); |
| 965 |
} |
| 966 |
free(ad); |
| 967 |
} |
| 968 |
|
| 969 |
|
| 970 |
|
| 971 |
|
| 972 |
|
| 973 |
|
| 974 |
|
| 975 |
|
| 976 |
|
| 977 |
|
| 978 |
float |
| 979 |
post_code_to_avg_pp(char postcode) |
| 980 |
{ |
| 981 |
switch (postcode) { |
| 982 |
case '*': return 0.975; break; |
| 983 |
case '9': return 0.9; break; |
| 984 |
case '8': return 0.8; break; |
| 985 |
case '7': return 0.7; break; |
| 986 |
case '6': return 0.6; break; |
| 987 |
case '5': return 0.5; break; |
| 988 |
case '4': return 0.4; break; |
| 989 |
case '3': return 0.3; break; |
| 990 |
case '2': return 0.2; break; |
| 991 |
case '1': return 0.1; break; |
| 992 |
case '0': return 0.025; break; |
| 993 |
default: return 0.0; |
| 994 |
} |
| 995 |
return 0.; |
| 996 |
} |
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
int |
| 1021 |
bp_is_canonical(char lseq, char rseq) |
| 1022 |
{ |
| 1023 |
switch (toupper(lseq)) { |
| 1024 |
case 'A': |
| 1025 |
switch (toupper(rseq)) { |
| 1026 |
case 'U': return TRUE; break; |
| 1027 |
case 'T': return TRUE; break; |
| 1028 |
default: break; |
| 1029 |
} |
| 1030 |
break; |
| 1031 |
case 'C': |
| 1032 |
switch (toupper(rseq)) { |
| 1033 |
case 'G': return TRUE; break; |
| 1034 |
default: break; |
| 1035 |
} |
| 1036 |
break; |
| 1037 |
case 'G': |
| 1038 |
switch (toupper(rseq)) { |
| 1039 |
case 'C': return TRUE; break; |
| 1040 |
case 'U': return TRUE; break; |
| 1041 |
case 'T': return TRUE; break; |
| 1042 |
default: break; |
| 1043 |
} |
| 1044 |
break; |
| 1045 |
case 'U': |
| 1046 |
switch (toupper(rseq)) { |
| 1047 |
case 'A': return TRUE; break; |
| 1048 |
case 'G': return TRUE; break; |
| 1049 |
default: break; |
| 1050 |
} |
| 1051 |
break; |
| 1052 |
case 'T': |
| 1053 |
switch (toupper(rseq)) { |
| 1054 |
case 'A': return TRUE; break; |
| 1055 |
case 'G': return TRUE; break; |
| 1056 |
default: break; |
| 1057 |
} |
| 1058 |
break; |
| 1059 |
default: break; |
| 1060 |
} |
| 1061 |
|
| 1062 |
return FALSE; |
| 1063 |
} |
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
|
| 1069 |
|
| 1070 |
|
| 1071 |
|
| 1072 |
|
| 1073 |
static int |
| 1074 |
integer_textwidth(long n) |
| 1075 |
{ |
| 1076 |
int w = (n < 0)? 1 : 0; |
| 1077 |
while (n != 0) { n /= 10; w++; } |
| 1078 |
return w; |
| 1079 |
} |
| 1080 |
|
| 1081 |
|
| 1082 |
|
| 1083 |
|
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
|
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
char |
| 1099 |
cm_alidisplay_EncodePostProb(float p) |
| 1100 |
{ |
| 1101 |
return (p + 0.05 >= 1.0) ? '*' : (char) ((p + 0.05) * 10.0) + '0'; |
| 1102 |
} |
| 1103 |
|
| 1104 |
|
| 1105 |
|
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
|
| 1119 |
float |
| 1120 |
cm_alidisplay_DecodePostProb(char pc) |
| 1121 |
{ |
| 1122 |
if (pc == '0') return 0.01; |
| 1123 |
else if (pc == '*') return 1.0; |
| 1124 |
else if (pc == '.') return 0.0; |
| 1125 |
else return ((float) (pc - '0') / 10.); |
| 1126 |
} |
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
|
| 1138 |
|
| 1139 |
|
| 1140 |
|
| 1141 |
|
| 1142 |
|
| 1143 |
|
| 1144 |
|
| 1145 |
|
| 1146 |
|
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
int |
| 1152 |
cm_alidisplay_Print(FILE *fp, CM_ALIDISPLAY *ad, int min_aliwidth, int linewidth, int show_accessions) |
| 1153 |
{ |
| 1154 |
char *buf = NULL; |
| 1155 |
char *show_cmname = NULL; |
| 1156 |
char *show_seqname = NULL; |
| 1157 |
int namewidth, coordwidth, aliwidth, cur_aliwidth; |
| 1158 |
int pos; |
| 1159 |
int status; |
| 1160 |
int ni, nk; |
| 1161 |
int z, zp; |
| 1162 |
long i1,i2; |
| 1163 |
int k1,k2; |
| 1164 |
int ni_toadd, nk_toadd; |
| 1165 |
int trunc_at_start; |
| 1166 |
|
| 1167 |
|
| 1168 |
show_cmname = (show_accessions && ad->cmacc[0] != '\0') ? ad->cmacc : ad->cmname; |
| 1169 |
show_seqname = (show_accessions && ad->sqacc[0] != '\0') ? ad->sqacc : ad->sqname; |
| 1170 |
|
| 1171 |
|
| 1172 |
namewidth = ESL_MAX(strlen(show_cmname), strlen(show_seqname)); |
| 1173 |
coordwidth = ESL_MAX(ESL_MAX(integer_textwidth(ad->cfrom_span), |
| 1174 |
integer_textwidth(ad->cto_span)), |
| 1175 |
ESL_MAX(integer_textwidth(ad->sqfrom), |
| 1176 |
integer_textwidth(ad->sqto))); |
| 1177 |
aliwidth = (linewidth > 0) ? linewidth - namewidth - 2*coordwidth - 5 : ad->N; |
| 1178 |
if (aliwidth < ad->N && aliwidth < min_aliwidth) aliwidth = min_aliwidth; |
| 1179 |
ESL_ALLOC(buf, sizeof(char) * (aliwidth+1)); |
| 1180 |
buf[aliwidth] = '\0'; |
| 1181 |
|
| 1182 |
|
| 1183 |
i1 = ad->sqfrom; |
| 1184 |
k1 = ad->cfrom_emit; |
| 1185 |
cur_aliwidth = aliwidth; |
| 1186 |
|
| 1187 |
for (pos = 0; pos < ad->N; pos += cur_aliwidth) |
| 1188 |
{ |
| 1189 |
if (pos > 0) fprintf(fp, "\n"); |
| 1190 |
|
| 1191 |
ni = nk = 0; |
| 1192 |
cur_aliwidth = aliwidth; |
| 1193 |
|
| 1194 |
for (z = pos; z < pos + cur_aliwidth && z < ad->N; z++) { |
| 1195 |
if ((ad->aseq[z] == '*' && ad->model[z] == '*') || |
| 1196 |
(ad->aseq[z] == '<' && ad->model[z] == '<')) { |
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
|
| 1201 |
|
| 1202 |
|
| 1203 |
trunc_at_start = (ad->aseq[z] == '<' && ad->model[z] == '<') ? TRUE : FALSE; |
| 1204 |
nk_toadd = ni_toadd = 0; |
| 1205 |
if(ad->aseq[z+1] != '[' || ad->model[z+1] != '[') { status = eslEINVAL; goto ERROR; } |
| 1206 |
|
| 1207 |
zp = z+2; |
| 1208 |
while(ad->model[zp] == ' ') { zp++; } |
| 1209 |
while(ad->model[zp] != ']') { nk_toadd *= 10; nk_toadd += ad->model[zp] - '0'; zp++; } |
| 1210 |
|
| 1211 |
zp = z+2; |
| 1212 |
while(ad->aseq[zp] == ' ') { zp++; } |
| 1213 |
while(ad->aseq[zp] != ']') { ni_toadd *= 10; ni_toadd += ad->aseq[zp] - '0'; zp++; } |
| 1214 |
|
| 1215 |
if((zp+1) >= (pos + aliwidth)) { |
| 1216 |
cur_aliwidth = z - pos; |
| 1217 |
} |
| 1218 |
else { |
| 1219 |
nk += nk_toadd; |
| 1220 |
ni += ni_toadd; |
| 1221 |
if(trunc_at_start) k1 -= nk_toadd; |
| 1222 |
z = zp+1; |
| 1223 |
|
| 1224 |
} |
| 1225 |
} |
| 1226 |
else { |
| 1227 |
if (ad->model[z] != '.') nk++; |
| 1228 |
if (ad->aseq[z] != '-') ni++; |
| 1229 |
} |
| 1230 |
} |
| 1231 |
|
| 1232 |
if(aliwidth != cur_aliwidth) buf[cur_aliwidth] = '\0'; |
| 1233 |
|
| 1234 |
k2 = k1+nk-1; |
| 1235 |
if (ad->sqfrom < ad->sqto) { i2 = i1+ni-1; } |
| 1236 |
else { i2 = i1-ni+1; } |
| 1237 |
|
| 1238 |
if (ad->ncline != NULL) { strncpy(buf, ad->ncline+pos, cur_aliwidth); fprintf(fp, " %*s %s %*sNC\n", namewidth+coordwidth+1, "", buf, aliwidth-cur_aliwidth, ""); } |
| 1239 |
strncpy(buf, ad->csline+pos, cur_aliwidth); fprintf(fp, " %*s %s %*sCS\n", namewidth+coordwidth+1, "", buf, aliwidth-cur_aliwidth, ""); |
| 1240 |
strncpy(buf, ad->model+pos, cur_aliwidth); fprintf(fp, " %*s %*d %s %*s%-*d\n", namewidth, show_cmname, coordwidth, k1, buf, aliwidth-cur_aliwidth, "", coordwidth, k2); |
| 1241 |
strncpy(buf, ad->mline+pos, cur_aliwidth); fprintf(fp, " %*s %s\n", namewidth+coordwidth+1, " ", buf); |
| 1242 |
if (ni > 0) { strncpy(buf, ad->aseq+pos, cur_aliwidth); fprintf(fp, " %*s %*ld %s %*s%-*ld\n", namewidth, show_seqname, coordwidth, i1, buf, aliwidth-cur_aliwidth, "", coordwidth, i2); } |
| 1243 |
else { strncpy(buf, ad->aseq+pos, cur_aliwidth); fprintf(fp, " %*s %*s %s %*s%*s\n", namewidth, show_seqname, coordwidth, "-", buf, aliwidth-cur_aliwidth, "", coordwidth, "-"); } |
| 1244 |
if (ad->ppline != NULL) { strncpy(buf, ad->ppline+pos, cur_aliwidth); fprintf(fp, " %*s %s %*sPP\n", namewidth+coordwidth+1, "", buf, aliwidth-cur_aliwidth, ""); } |
| 1245 |
if (ad->rfline != NULL) { strncpy(buf, ad->rfline+pos, cur_aliwidth); fprintf(fp, " %*s %s %*sRF\n", namewidth+coordwidth+1, "", buf, aliwidth-cur_aliwidth, ""); } |
| 1246 |
|
| 1247 |
k1 += nk; |
| 1248 |
if (ad->sqfrom < ad->sqto) { i1 += ni; } |
| 1249 |
else { i1 -= ni; } |
| 1250 |
} |
| 1251 |
fflush(fp); |
| 1252 |
free(buf); |
| 1253 |
return eslOK; |
| 1254 |
|
| 1255 |
ERROR: |
| 1256 |
if (buf != NULL) free(buf); |
| 1257 |
return status; |
| 1258 |
} |
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
int |
| 1280 |
cm_alidisplay_Is5PTrunc(const CM_ALIDISPLAY *ad) |
| 1281 |
{ |
| 1282 |
return (ad->cfrom_emit != ad->cfrom_span) ? TRUE : FALSE; |
| 1283 |
} |
| 1284 |
|
| 1285 |
int |
| 1286 |
cm_alidisplay_Is3PTrunc(const CM_ALIDISPLAY *ad) |
| 1287 |
{ |
| 1288 |
return (ad->cto_emit != ad->cto_span) ? TRUE : FALSE; |
| 1289 |
} |
| 1290 |
|
| 1291 |
int |
| 1292 |
cm_alidisplay_Is5PAnd3PTrunc(const CM_ALIDISPLAY *ad) |
| 1293 |
{ |
| 1294 |
return (ad->cfrom_emit != ad->cfrom_span && ad->cto_emit != ad->cto_span) ? TRUE : FALSE; |
| 1295 |
} |
| 1296 |
|
| 1297 |
int |
| 1298 |
cm_alidisplay_Is5PTruncOnly(const CM_ALIDISPLAY *ad) |
| 1299 |
{ |
| 1300 |
return (ad->cfrom_emit != ad->cfrom_span && ad->cto_emit == ad->cto_span) ? TRUE : FALSE; |
| 1301 |
} |
| 1302 |
|
| 1303 |
int |
| 1304 |
cm_alidisplay_Is3PTruncOnly(const CM_ALIDISPLAY *ad) |
| 1305 |
{ |
| 1306 |
return (ad->cfrom_emit == ad->cfrom_span && ad->cto_emit != ad->cto_span) ? TRUE : FALSE; |
| 1307 |
} |
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
char * |
| 1318 |
cm_alidisplay_TruncString(const CM_ALIDISPLAY *ad) |
| 1319 |
{ |
| 1320 |
if (ad->hmmonly) return "-"; |
| 1321 |
else if(cm_alidisplay_Is5PAnd3PTrunc(ad)) return "5'&3'"; |
| 1322 |
else if(cm_alidisplay_Is5PTruncOnly(ad)) return "5'"; |
| 1323 |
else if(cm_alidisplay_Is3PTruncOnly(ad)) return "3'"; |
| 1324 |
else return "no"; |
| 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 |
int |
| 1356 |
cm_alidisplay_Backconvert(CM_t *cm, const CM_ALIDISPLAY *ad, char *errbuf, ESL_SQ **ret_sq, Parsetree_t **ret_tr, char **ret_pp) |
| 1357 |
{ |
| 1358 |
int status; |
| 1359 |
ESL_SQ *sq = NULL; |
| 1360 |
Parsetree_t *tr = NULL; |
| 1361 |
char *pp = NULL; |
| 1362 |
Parsetree_t *mtr = NULL; |
| 1363 |
ESL_MSA *msa = NULL; |
| 1364 |
char *aseq = NULL; |
| 1365 |
int apos, upos; |
| 1366 |
int *a2u_map = NULL; |
| 1367 |
int *used_el = NULL; |
| 1368 |
int x, ulen; |
| 1369 |
|
| 1370 |
if(cm->cmcons == NULL) ESL_FAIL(eslEINVAL, errbuf, "cm_alidisplay_Backconvert(): cm->cmcons is NULL"); |
| 1371 |
|
| 1372 |
msa = esl_msa_Create(1, ad->N_el); |
| 1373 |
memcpy(msa->aseq[0], ad->aseq_el, ad->N_el); |
| 1374 |
if((status = esl_strdup(ad->rfline_el, msa->alen, &(msa->rf))) != eslOK) ESL_XFAIL(status, errbuf, "cm_alidisplay_BackConvert() out of memory"); |
| 1375 |
|
| 1376 |
if(ad->ppline_el) { |
| 1377 |
ESL_ALLOC(msa->pp, sizeof(char *) * 1); |
| 1378 |
if((status = esl_strdup(ad->ppline_el, msa->alen, &(msa->pp[0]))) != eslOK) ESL_XFAIL(status, errbuf, "cm_alidisplay_Backconvert() out of memory"); |
| 1379 |
} |
| 1380 |
ESL_ALLOC(msa->ss_cons, sizeof(char) * (msa->alen+1)); |
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
upos = 0; |
| 1385 |
for(apos = 0; apos < msa->alen; apos++) { |
| 1386 |
msa->ss_cons[apos] = (isupper(msa->aseq[0][apos]) || msa->aseq[0][apos] == '-') ? cm->cmcons->cstr[upos++] : '.'; |
| 1387 |
} |
| 1388 |
msa->ss_cons[msa->alen] = '\0'; |
| 1389 |
if(upos != cm->clen) ESL_XFAIL(eslERANGE, errbuf, "cm_alidisplay_Backconvert() failed to create temporary msa"); |
| 1390 |
|
| 1391 |
esl_msa_FormatSeqName(msa, 0, "%s/%ld-%ld", ad->sqname, ad->sqfrom, ad->sqto); |
| 1392 |
|
| 1393 |
if(ad->sqacc) esl_msa_SetSeqAccession (msa, 0, ad->sqacc, -1); |
| 1394 |
if(ad->sqdesc) esl_msa_SetSeqDescription(msa, 0, ad->sqdesc, -1); |
| 1395 |
|
| 1396 |
if((status = esl_msa_Digitize(cm->abc, msa, errbuf)) != eslOK) goto ERROR; |
| 1397 |
|
| 1398 |
|
| 1399 |
if((status = cm_Guidetree(cm, errbuf, msa, &mtr)) != eslOK) goto ERROR; |
| 1400 |
|
| 1401 |
ESL_ALLOC(used_el, (msa->alen+1) * sizeof(int)); |
| 1402 |
|
| 1403 |
used_el[0] = FALSE; |
| 1404 |
for(apos = 0; apos < msa->alen; apos++) { |
| 1405 |
used_el[apos+1] = (msa->rf[apos] == '~') ? TRUE : FALSE; |
| 1406 |
} |
| 1407 |
|
| 1408 |
|
| 1409 |
if(cm_alidisplay_Is5PTrunc(ad)) { |
| 1410 |
for (apos = 1; apos <= msa->alen; apos++) { |
| 1411 |
if (esl_abc_XIsResidue(cm->abc, msa->ax[0][apos])) break; |
| 1412 |
msa->ax[0][apos] = esl_abc_XGetMissing(cm->abc); |
| 1413 |
} |
| 1414 |
} |
| 1415 |
if(cm_alidisplay_Is3PTrunc(ad)) { |
| 1416 |
for (apos = msa->alen; apos >= 1; apos--) { |
| 1417 |
if (esl_abc_XIsResidue(cm->abc, msa->ax[0][apos])) break; |
| 1418 |
msa->ax[0][apos] = esl_abc_XGetMissing(cm->abc); |
| 1419 |
} |
| 1420 |
} |
| 1421 |
|
| 1422 |
if((status = Transmogrify(cm, errbuf, mtr, msa->ax[0], used_el, msa->alen, &tr)) != eslOK) goto ERROR; |
| 1423 |
|
| 1424 |
|
| 1425 |
|
| 1426 |
|
| 1427 |
ESL_ALLOC(a2u_map, sizeof(int) * (msa->alen+1)); |
| 1428 |
a2u_map[0] = -1; |
| 1429 |
upos = 1; |
| 1430 |
for(apos = 1; apos <= msa->alen; apos++) { |
| 1431 |
a2u_map[apos] = ((esl_abc_XIsGap(msa->abc, msa->ax[0][apos])) || |
| 1432 |
(esl_abc_XIsMissing(msa->abc, msa->ax[0][apos]))) |
| 1433 |
? -1 : upos++; |
| 1434 |
} |
| 1435 |
ulen = upos; |
| 1436 |
for(x = 0; x < tr->n; x++) { |
| 1437 |
if(tr->emitl[x] != -1) tr->emitl[x] = a2u_map[tr->emitl[x]]; |
| 1438 |
if(tr->emitr[x] != -1) tr->emitr[x] = a2u_map[tr->emitr[x]]; |
| 1439 |
} |
| 1440 |
if((status = esl_sq_FetchFromMSA(msa, 0, &sq)) != eslOK) ESL_XFAIL(status, errbuf, "cm_alidisplay_Backconvert() unable to fetch seq from msa"); |
| 1441 |
if(msa->pp) { |
| 1442 |
ESL_ALLOC(pp, sizeof(char) * (ulen+1)); |
| 1443 |
upos = 0; |
| 1444 |
for(apos = 0; apos < msa->alen; apos++) { |
| 1445 |
if(a2u_map[apos+1] != -1) pp[upos++] = msa->pp[0][apos]; |
| 1446 |
} |
| 1447 |
if(upos+1 != ulen) ESL_XFAIL(eslERANGE, errbuf, "cm_alidisplay_Backconvert() failed to create temporary msa"); |
| 1448 |
} |
| 1449 |
|
| 1450 |
esl_msa_Destroy(msa); |
| 1451 |
free(used_el); |
| 1452 |
free(a2u_map); |
| 1453 |
FreeParsetree(mtr); |
| 1454 |
free(aseq); |
| 1455 |
|
| 1456 |
*ret_sq = sq; |
| 1457 |
*ret_tr = tr; |
| 1458 |
*ret_pp = pp; |
| 1459 |
return eslOK; |
| 1460 |
|
| 1461 |
ERROR: |
| 1462 |
if (msa != NULL) esl_msa_Destroy(msa); |
| 1463 |
if (mtr != NULL) FreeParsetree(mtr); |
| 1464 |
if (aseq != NULL) free(aseq); |
| 1465 |
if (a2u_map != NULL) free(a2u_map); |
| 1466 |
if (sq != NULL) esl_sq_Destroy(sq); |
| 1467 |
if (tr != NULL) FreeParsetree(tr); |
| 1468 |
if (pp != NULL) free(pp); |
| 1469 |
*ret_sq = NULL; |
| 1470 |
*ret_tr = NULL; |
| 1471 |
return status; |
| 1472 |
} |
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
|
| 1488 |
|
| 1489 |
|
| 1490 |
|
| 1491 |
|
| 1492 |
int |
| 1493 |
cm_alidisplay_Dump(FILE *fp, const CM_ALIDISPLAY *ad) |
| 1494 |
{ |
| 1495 |
fprintf(fp, "CM_ALIDISPLAY dump\n"); |
| 1496 |
fprintf(fp, "------------------\n"); |
| 1497 |
|
| 1498 |
fprintf(fp, "rfline = %s\n", ad->rfline ? ad->rfline : "[none]"); |
| 1499 |
fprintf(fp, "ncline = %s\n", ad->ncline ? ad->ncline : "[none]"); |
| 1500 |
fprintf(fp, "csline = %s\n", ad->csline ? ad->csline : "[none]"); |
| 1501 |
fprintf(fp, "model = %s\n", ad->model); |
| 1502 |
fprintf(fp, "mline = %s\n", ad->mline); |
| 1503 |
fprintf(fp, "ppline = %s\n", ad->ppline ? ad->ppline : "[none]"); |
| 1504 |
fprintf(fp, "aseq = %s\n", ad->aseq); |
| 1505 |
fprintf(fp, "N = %d\n", ad->N); |
| 1506 |
fprintf(fp, "\n"); |
| 1507 |
|
| 1508 |
fprintf(fp, "aseq_el = %s\n", ad->aseq_el); |
| 1509 |
fprintf(fp, "ppline_el = %s\n", ad->ppline_el ? ad->ppline_el : "[none]"); |
| 1510 |
fprintf(fp, "N_el = %d\n", ad->N_el); |
| 1511 |
fprintf(fp, "\n"); |
| 1512 |
|
| 1513 |
fprintf(fp, "cmname = %s\n", ad->cmname); |
| 1514 |
fprintf(fp, "cmacc = %s\n", ad->cmacc[0] == '\0' ? "[none]" : ad->cmacc); |
| 1515 |
fprintf(fp, "cmdesc = %s\n", ad->cmdesc[0] == '\0' ? "[none]" : ad->cmdesc); |
| 1516 |
fprintf(fp, "cfrom_span = %d\n", ad->cfrom_span); |
| 1517 |
fprintf(fp, "cfrom_emit = %d\n", ad->cfrom_emit); |
| 1518 |
fprintf(fp, "cto_emit = %d\n", ad->cto_emit); |
| 1519 |
fprintf(fp, "cto_span = %d\n", ad->cto_span); |
| 1520 |
fprintf(fp, "clen = %d\n", ad->clen); |
| 1521 |
fprintf(fp, "\n"); |
| 1522 |
|
| 1523 |
fprintf(fp, "sqname = %s\n", ad->sqname); |
| 1524 |
fprintf(fp, "sqacc = %s\n", ad->sqacc[0] == '\0' ? "[none]" : ad->sqacc); |
| 1525 |
fprintf(fp, "sqdesc = %s\n", ad->sqdesc[0] == '\0' ? "[none]" : ad->sqdesc); |
| 1526 |
fprintf(fp, "sqfrom = %ld\n", ad->sqfrom); |
| 1527 |
fprintf(fp, "sqto = %ld\n", ad->sqto); |
| 1528 |
fprintf(fp, "\n"); |
| 1529 |
|
| 1530 |
fprintf(fp, "sc = %.2f\n",ad->sc); |
| 1531 |
fprintf(fp, "avgpp = %.2f\n",ad->avgpp); |
| 1532 |
fprintf(fp, "gc = %.2f\n",ad->gc); |
| 1533 |
fprintf(fp, "tau = %g\n", ad->tau); |
| 1534 |
fprintf(fp, "mx Mb = %.6f\n",ad->matrix_Mb); |
| 1535 |
fprintf(fp, "seconds = %.6f\n",ad->elapsed_secs); |
| 1536 |
fprintf(fp, "hmmonly = %s\n", ad->hmmonly ? "TRUE" : "FALSE"); |
| 1537 |
|
| 1538 |
fprintf(fp, "\n"); |
| 1539 |
|
| 1540 |
fprintf(fp, "size = %d bytes\n", (int) cm_alidisplay_Sizeof(ad)); |
| 1541 |
fprintf(fp, "%s\n", ad->mem ? "serialized" : "not serialized"); |
| 1542 |
return eslOK; |
| 1543 |
} |
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
|
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
|
| 1556 |
int |
| 1557 |
cm_alidisplay_Compare(const CM_ALIDISPLAY *ad1, const CM_ALIDISPLAY *ad2) |
| 1558 |
{ |
| 1559 |
if (ad1->mem && ad2->mem) |
| 1560 |
{ |
| 1561 |
if (ad1->memsize != ad2->memsize) return eslFAIL; |
| 1562 |
if (memcmp(ad1->mem, ad2->mem, ad1->memsize) != 0) return eslFAIL; |
| 1563 |
} |
| 1564 |
|
| 1565 |
if (esl_strcmp(ad1->rfline, ad2->rfline) != eslOK) return eslFAIL; |
| 1566 |
if (esl_strcmp(ad1->csline, ad2->csline) != eslOK) return eslFAIL; |
| 1567 |
if (esl_strcmp(ad1->model, ad2->model) != eslOK) return eslFAIL; |
| 1568 |
if (esl_strcmp(ad1->mline, ad2->mline) != eslOK) return eslFAIL; |
| 1569 |
if (esl_strcmp(ad1->aseq, ad2->aseq) != eslOK) return eslFAIL; |
| 1570 |
if (esl_strcmp(ad1->ppline, ad2->ppline) != eslOK) return eslFAIL; |
| 1571 |
if (ad1->N != ad2->N) return eslFAIL; |
| 1572 |
|
| 1573 |
if (esl_strcmp(ad1->cmname, ad2->cmname) != eslOK) return eslFAIL; |
| 1574 |
if (esl_strcmp(ad1->cmacc, ad2->cmacc) != eslOK) return eslFAIL; |
| 1575 |
if (esl_strcmp(ad1->cmdesc, ad2->cmdesc) != eslOK) return eslFAIL; |
| 1576 |
if (ad1->cfrom_emit != ad2->cfrom_emit) return eslFAIL; |
| 1577 |
if (ad1->cto_emit != ad2->cto_emit) return eslFAIL; |
| 1578 |
if (ad1->cfrom_span != ad2->cfrom_span) return eslFAIL; |
| 1579 |
if (ad1->cto_span != ad2->cto_span) return eslFAIL; |
| 1580 |
|
| 1581 |
if (esl_strcmp(ad1->sqname, ad2->sqname) != eslOK) return eslFAIL; |
| 1582 |
if (esl_strcmp(ad1->sqacc, ad2->sqacc) != eslOK) return eslFAIL; |
| 1583 |
if (esl_strcmp(ad1->sqdesc, ad2->sqdesc) != eslOK) return eslFAIL; |
| 1584 |
if (ad1->sqfrom != ad2->sqfrom) return eslFAIL; |
| 1585 |
if (ad1->sqto != ad2->sqto) return eslFAIL; |
| 1586 |
if (ad1->clen != ad2->clen) return eslFAIL; |
| 1587 |
|
| 1588 |
return eslOK; |
| 1589 |
} |
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|