1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 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 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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 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 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 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 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 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 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 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
|
#include <string.h>
#include <ctype.h>
#include "seq_reg.h"
#include "sequence_pair_display.h"
#include "seq_raster.h"
#include "text_output.h"
#include "tcl_utils.h"
#include "seq_results.h"
#include "xalloc.h"
#include "spin_globals.h"
/*yy*/
#include "sequence_formats.h"
#include "readpam.h"
#include "sip_results.h"
extern int **score_matrix;
/*yy*/
void seq_disp_callback(int seq_num, void *obj, seq_reg_data *jdata);
void seq_disp_move_cursor(Tcl_Interp *interp,
char *seq_disp_win,
int result_id,
int pos,
int direction)
{
char cmd[1024];
sprintf(cmd, "seq_disp_show_cursor %s %d %d %d\n", seq_disp_win, result_id,
pos, direction);
if (TCL_OK != Tcl_Eval(interp, cmd)) {
printf("seq_disp_move_cursor: %s\n",Tcl_GetStringResult(interp));
}
}
void seq_disp_shutdown(Tcl_Interp *interp,
seq_pair_disp_result *result,
int seq_num)
{
int seq_num_h;
int seq_num_v;
char *tmp;
/* need to set prev_pos */
#ifdef REMOVE
result->cursor[HORIZONTAL]->prev_pos = result->cursor[HORIZONTAL]->abspos;
result->cursor[VERTICAL]->prev_pos = result->cursor[VERTICAL]->abspos;
#endif
result->prev_pos[HORIZONTAL] = result->cursor[HORIZONTAL]->abspos;
result->prev_pos[VERTICAL] = result->cursor[VERTICAL]->abspos;
seq_num_h = GetSeqNum(result->seq_id[HORIZONTAL]);
seq_num_v = GetSeqNum(result->seq_id[VERTICAL]);
seq_deregister(seq_num_h, seq_disp_callback, (seq_pair_disp_result *)result);
seq_deregister(seq_num_v, seq_disp_callback, (seq_pair_disp_result *)result);
delete_cursor(seq_num_h, result->cursor[HORIZONTAL]->id, 1);
delete_cursor(seq_num_v, result->cursor[VERTICAL]->id, 1);
tmp = get_default_string(result->interp, tk_utils_defs, w("RASTER.RESULTS.WIN"));
if (TCL_OK != Tcl_VarEval(result->interp, "seq_result_list_update ",
tmp, NULL)){
verror(ERR_WARN, "seq disp shutdown", "%s \n", Tcl_GetStringResult(result->interp));
}
xfree(result);
}
void seq_disp_callback(int seq_num, void *obj, seq_reg_data *jdata)
{
seq_pair_disp_result *result = (seq_pair_disp_result *) obj;
char *seq_disp_win = result->seq_disp_win;
switch(jdata->job) {
case SEQ_QUERY_NAME:
{
sprintf(jdata->name.line, "sequence display");
return;
}
case SEQ_QUIT:
case SEQ_DELETE:
{
seq_disp_shutdown(result->interp, result, seq_num);
return;
}
case SEQ_GET_OPS:
{
jdata->get_ops.ops = "Remove\0";
break;
}
case SEQ_INVOKE_OP:
switch (jdata->invoke_op.op) {
case 0:
seq_disp_shutdown(result->interp, result, seq_num);
return;
}
break;
case SEQ_CURSOR_NOTIFY:
{
cursor_t *cursor = (cursor_t *)jdata->cursor_notify.cursor;
#ifdef DEBUG
printf("SEQ_CURSOR_NOTIFY seqed pos %d id %d result id %d\n",
cursor->abspos, cursor->id, result->cursor[HORIZONTAL]->id);
#endif
if (result->cursor[HORIZONTAL]->id == cursor->id) {
seq_disp_move_cursor(result->interp, result->seq_disp_win,
result->result_id, cursor->abspos,
HORIZONTAL);
}
if (result->cursor[VERTICAL]->id == cursor->id) {
seq_disp_move_cursor(result->interp, result->seq_disp_win,
result->result_id, cursor->abspos,
VERTICAL);
}
break;
}
case SEQ_RESULT_INFO:
switch (jdata->info.op) {
case WINDOW:
jdata->info.result = (void *)seq_disp_win;
break;
case RESULT:
jdata->info.result = (void *)result;
break;
}
break;
}
}
/*
* register sequence display widget
*/
int seq_disp_reg(Tcl_Interp *interp,
char *seq_disp_win,
int seq_id_h,
int seq_id_v,
int cursor_id_h,
int cursor_id_v,
int result_id,
int wx,
int wy)
{
int id;
seq_pair_disp_result *seq_disp_result;
seq_cursor_notify cn;
cursor_t *cursor;
int seq_num;
int line_width;
if (NULL == (seq_disp_result = (seq_pair_disp_result *)xmalloc(sizeof(seq_pair_disp_result))))
return -1;
seq_disp_result->op_func = seq_disp_callback;
seq_disp_result->seq_id[HORIZONTAL] = seq_id_h;
seq_disp_result->seq_id[VERTICAL] = seq_id_v;
seq_disp_result->result_id = result_id;
strcpy(seq_disp_result->seq_disp_win, seq_disp_win);
seq_disp_result->interp = interp;
id = get_reg_id();
seq_disp_result->index = id;
line_width = get_default_int(interp, spin_defs, w("SEQ.CURSOR.LINE_WIDTH"));
if (cursor_id_h < 0) {
/* no horizontal cursor */
seq_disp_result->cursor[HORIZONTAL] = create_cursor(GetSeqNum(seq_id_h), 1, NULL, line_width, 1, HORIZONTAL);
seq_disp_result->cursor_visible[HORIZONTAL] = 0;
} else {
seq_num = GetSeqNum(seq_id_h);
cursor = find_cursor(&seq_num, cursor_id_h, -1);
#ifdef DEBUG
printf("USING EXISTING CURSOR private %d\n", cursor->private);
#endif
cursor->private = 1;
seq_disp_result->cursor[HORIZONTAL] = cursor;
}
if (cursor_id_v < 0) {
/* no vertical cursor */
seq_disp_result->cursor[VERTICAL] = create_cursor(GetSeqNum(seq_id_v), 1, NULL, line_width, 1, VERTICAL);
seq_disp_result->cursor_visible[VERTICAL] = 0;
} else {
seq_num = GetSeqNum(seq_id_v);
cursor = find_cursor(&seq_num, cursor_id_v, -1);
#ifdef DEBUG
printf("USING EXISTING CURSOR private %d\n", cursor->private);
#endif
cursor->private = 1;
seq_disp_result->cursor[VERTICAL] = cursor;
}
#ifdef REMOVE
seq_disp_result->cursor[HORIZONTAL]->prev_pos = seq_disp_result->cursor[HORIZONTAL]->abspos;
seq_disp_result->cursor[VERTICAL]->prev_pos = seq_disp_result->cursor[VERTICAL]->abspos;
#endif
seq_disp_result->prev_pos[HORIZONTAL] = seq_disp_result->cursor[HORIZONTAL]->abspos;
seq_disp_result->prev_pos[VERTICAL] = seq_disp_result->cursor[VERTICAL]->abspos;
seq_disp_result->cursor[HORIZONTAL]->abspos = wx;
seq_disp_result->cursor[VERTICAL]->abspos = wy;
seq_register(GetSeqNum(seq_id_h), seq_disp_callback,
(void *)seq_disp_result, SEQ_SEQED, id);
seq_register(GetSeqNum(seq_id_v), seq_disp_callback,
(void *)seq_disp_result, SEQ_SEQED, id);
cn.job = SEQ_CURSOR_NOTIFY;
cn.cursor = seq_disp_result->cursor[HORIZONTAL];
cn.cursor->job = CURSOR_MOVE;
seq_notify(GetSeqNum(seq_id_h), (seq_reg_data *)&cn);
cn.cursor = seq_disp_result->cursor[VERTICAL];
cn.cursor->job = CURSOR_MOVE;
seq_notify(GetSeqNum(seq_id_v), (seq_reg_data *)&cn);
return id;
}
/*
* scrolling procedure in sequence display widget
*/
int update_seqs(Tcl_Interp *interp,
char *window1,
char *window2,
char *win_diff,
char *seq1,
char *seq2,
int seq1_len,
int seq2_len,
int seq1_left,
int seq2_left,
int width,
int type)
{
/* yypp */
int row;
int col;
int row_pam;
int col_pam;
char chap_pam[] = {'A','B','C','D','E','F','G','H','I','K','L','M','N','P','Q','R','S','T','V','W','Y','Z','X','*','-'};
int chap_pam_size = sizeof(chap_pam);
/* yypp */
char tmp[10];
int start;
int end;
int i;
static int cur_width = 0;
static char *tmp2 = NULL;
static char *tmp_str = NULL;
int s1_left_tmp, s2_left_tmp;
int **score_display;
score_display = get_matrix_file(PROTEIN);
/*
* check if current sequence window width is the same as new width ie
* if the same amount of sequence is to be displayed
*/
if (cur_width != width) {
/* printf("%d %d \n", cur_width, width); */
if (tmp2)
xfree(tmp2);
if (tmp_str)
xfree(tmp_str);
if (NULL == (tmp2 = (char *)xmalloc((width+21) * sizeof(char))))
return TCL_OK;
if (NULL == (tmp_str = (char *)xmalloc((width+2) * sizeof(char))))
return TCL_OK;
}
/* insert padding in line 1 and line 2 */
if (seq1_left < 0) {
s1_left_tmp = seq1_left < -width ? width : -seq1_left;
memset(tmp_str, ' ', s1_left_tmp);
tmp_str[s1_left_tmp] = '\0';
Tcl_VarEval(interp, window1, " insert 1.end ", "\"", tmp_str, "\"", NULL);
Tcl_VarEval(interp, window1, " insert 2.end ", "\"", tmp_str, "\"", NULL);
}
if (seq2_left < 0) {
s2_left_tmp = seq2_left < -width ? width : -seq2_left;
memset(tmp_str, ' ', s2_left_tmp);
tmp_str[s2_left_tmp] = '\0';
Tcl_VarEval(interp, window2, " insert 1.end ", "\"", tmp_str, "\"", NULL);
Tcl_VarEval(interp, window2, " insert 2.end ", "\"", tmp_str, "\"", NULL);
}
/* insert numbers in line 1 of win1 and line 2 of win2 */
tmp[0] = '\0';
tmp2[0] = '\0';
if (seq1_left < 0)
start = 1;
else
start = seq1_left / 10;
/*
if ((seq1_left + width) > seq1_len)
end = seq1_len/ 10;
else
*/
end = (width + seq1_left) / 10;
for (i = start; i <= end; i++) {
sprintf(tmp, "%10d", i*10);
strcat(tmp2, tmp);
}
tmp_str[0] = '\0';
if (seq1_left < 0)
strncpy(tmp_str, &tmp2[0], width);
else
strncpy(tmp_str, &tmp2[seq1_left%10+10], width);
tmp_str[width] = '\0';
Tcl_VarEval(interp, window1, " insert 1.end ", "\"", tmp_str, "\"", NULL);
/* sequence 2 numbers */
tmp2[0] = '\0';
tmp_str[0] = '\0';
if (seq2_left <= 0)
start = 1;
else
start = seq2_left / 10;
/*
if ((seq2_left + width) > seq2_len)
end = seq2_len/ 10;
else
*/
end = (width + seq2_left) / 10;
for (i = start; i <= end; i++) {
sprintf(tmp, "%10d", i*10);
strcat(tmp2, tmp);
}
if (seq2_left < 0)
strncpy(tmp_str, &tmp2[0], width);
else
strncpy(tmp_str, &tmp2[seq2_left%10+10], width);
tmp_str[width] = '\0';
Tcl_VarEval(interp, window2, " insert 2.end ", "\"", tmp_str, "\"", NULL);
/* insert seq in line 2 of win1 and line 1 of win2 */
tmp_str[0] = '\0';
memset(tmp_str, ' ', width);
if (seq1_left < 0) {
if (seq1_left > -width) {
strncpy(tmp_str, &seq1[0], width + seq1_left);
tmp_str[width + seq1_left] = '\0';
} else {
tmp_str[width] = '\0';
}
} else {
if (seq1_left + width <= seq1_len) {
strncpy(tmp_str, &seq1[seq1_left], width);
} else {
if (seq1_left < seq1_len) {
strcpy(tmp_str, &seq1[seq1_left]);
tmp_str[strlen(tmp_str)] = ' ';
}
}
tmp_str[width] = '\0';
}
Tcl_VarEval(interp, window1, " insert 2.end {", tmp_str, "}", NULL);
/* printf("%s\n", tmp_str); */
/* sequence 2 */
tmp_str[0] = '\0';
memset(tmp_str, ' ', width);
if (seq2_left < 0) {
if (seq2_left > -width) {
strncpy(tmp_str, &seq2[0], width + seq2_left);
tmp_str[width + seq2_left] = '\0';
} else {
tmp_str[width] = '\0';
}
} else {
if (seq2_left + width <= seq2_len) {
strncpy(tmp_str, &seq2[seq2_left], width);
} else {
if (seq2_left < seq2_len) {
strcpy(tmp_str, &seq2[seq2_left]);
tmp_str[strlen(tmp_str)] = ' ';
}
}
tmp_str[width] = '\0';
}
Tcl_VarEval(interp, window2, " insert 1.end {", tmp_str, "}", NULL);
/* diffs line */
tmp_str[0] = '\0';
for (i = 0; i < width; i++, seq1_left++, seq2_left++) {
if ((seq1_left < 0) || (seq2_left < 0) || (seq1_left > (seq1_len-1))
|| (seq2_left > (seq2_len-1))){
tmp_str[i] = '!';
} else {
/*yypp */
if ( type ==PROTEIN ){
if (toupper(seq1[seq1_left]) == toupper(seq2[seq2_left])) {
tmp_str[i] = symbol_align0[0];
} else { row_pam = -1; col_pam = -1;
for( row=0; row < chap_pam_size; row++){
if(toupper(seq1[seq1_left]) == toupper(chap_pam[row])){
row_pam = row;
break;
}
}
if(row_pam < 0){
verror(ERR_WARN, "Update Seqs",
"Sequence contains a character that is not mentioned in score matrix\n");
return -1;
}
for( col=0; col < chap_pam_size; col++){
if(toupper(seq2[seq2_left]) == toupper(chap_pam[col])){
col_pam = col;
break;
}
}
if(col_pam < 0){
verror(ERR_WARN, "Update Seqs",
"Sequence contains a character that is not mentioned in score matrix\n");
return -1;
}
if(score_display[row_pam][col_pam] > cutoff_align3 &&
score_display[row_pam][col_pam] <= cutoff_align2 )
tmp_str[i] = symbol_align3[0];
else if (score_display[row_pam][col_pam] > cutoff_align2 &&
score_display[row_pam][col_pam] <= cutoff_align1 )
tmp_str[i] = symbol_align2[0];
else if (score_display[row_pam][col_pam] > cutoff_align1 )
tmp_str[i] = symbol_align1[0];
else
tmp_str[i] = ' ';
}
}
if(type == DNA){
if (toupper(seq1[seq1_left]) == toupper(seq2[seq2_left]))
tmp_str[i] = '|';
else
tmp_str[i] = ' ';
}
}
}
tmp_str[width] = '\0';
Tcl_VarEval(interp, win_diff, " insert end ", "\"", tmp_str, "\"", NULL);
cur_width = width;
return TCL_OK;
}
/*
* create the sequence display widget
*/
void SequencePairDisplay(Tcl_Interp *interp,
char *raster_win,
int result_index,
int seq_id_h,
int seq_id_v)
{
char cmd[1024];
int raster_id;
int height;
Tcl_VarEval(interp, "GetRasterId ", raster_win, NULL);
raster_id = atoi(Tcl_GetStringResult(interp));
Tcl_VarEval(interp, "winfo height ", raster_win, NULL);
height = atoi(Tcl_GetStringResult(interp));
sprintf(cmd, "SequencePairDisplay 1 1 %d %d -1 -1 %d\n",
seq_id_h, seq_id_v, result_index);
/* dmalloc_verify(NULL); */
if (TCL_OK != Tcl_GlobalEval(interp, cmd)) {
printf("DisplaySequences: %s\n", Tcl_GetStringResult(interp));
}
}
/*
* destroy the sequence display widget
*/
void DestroySequencePairDisplay(Tcl_Interp *interp,
int result_index)
{
char cmd[1024];
char *seq_disp_win;
seq_disp_win = get_default_string(interp, spin_defs,
"SEQ_DISP.WIN");
sprintf(cmd, "SeqDispStartShutdown %s%d", seq_disp_win, result_index);
if (TCL_ERROR == (Tcl_Eval(interp, cmd))) {
printf("DestroyDisplaySequences %s\n", Tcl_GetStringResult(interp));
}
}
/********/
int spin_list_alignment ( char *seq1, char *seq2, char *name1, char *name2,
int pos1, int pos2, char *title, int type )
{
char *match_syms ;
int i,j,k,seq_len,p1,p2,line_length=60;
int l, spads1,spads2, p11,p22;
int row,col;
int row_pam,col_pam;
char chap_pam[] = {'A','B','C','D','E','F','G','H','I','K','L','M','N',
'P','Q','R','S','T','V','W','Y','Z','X','*','-','.', ' '};
int chap_pam_size = sizeof(chap_pam);
p11=pos1;
p22=pos2;
seq_len = strlen(seq1);
if ( ! (match_syms = (char *) xmalloc ( sizeof(char) * (seq_len) + 1))) {
return -1;
}
for (i=0; i<seq_len; i++){
if (type == PROTEIN){
if (toupper(seq1[i]) == toupper(seq2[i])) {
match_syms[i] = symbol_align0[0];
}else
if(seq1[i]=='.'||seq2[i]=='.'){
match_syms[i] = ' ';
} else { row_pam = -1; col_pam = -1;
for( row=0; row < chap_pam_size; row++){
if(toupper(seq1[i]) == toupper(chap_pam[row])){
row_pam = row;
break;
}
}
if(row_pam < 0){
verror(ERR_WARN, "Update Seqs",
"Sequence contains a character that is not mentioned in score matrix\n");
return -1;
}
for( col=0; col < chap_pam_size; col++){
if(toupper(seq2[i]) == toupper(chap_pam[col])){
col_pam = col;
break;
}
}
if(col_pam < 0){
verror(ERR_WARN, "Update Seqs",
"Sequence contains a character that is not mentioned in score matrix\n");
return -1;
}
if(score_matrix[row_pam][col_pam] > cutoff_align3 &&
score_matrix[row_pam][col_pam] <= cutoff_align2 )
match_syms[i] = symbol_align3[0];
else if (score_matrix[row_pam][col_pam] > cutoff_align2 &&
score_matrix[row_pam][col_pam] <= cutoff_align1 )
match_syms[i] = symbol_align2[0];
else if (score_matrix[row_pam][col_pam] > cutoff_align1 )
match_syms[i] = symbol_align1[0];
else
match_syms[i] = ' ';
}
}else
if (type == DNA){
if (toupper(seq1[i]) == toupper(seq2[i])) {
match_syms[i] = '|';
}else
match_syms[i] = ' ';
}
}
for ( i=0,p1=pos1,p2=pos2;i<seq_len;i+=line_length) {
vmessage(" ");
vmessage("%4s"," ");
for (j=0;j<6 && p1<pos1+seq_len;j++,p1+=10) {
spads1=0;
for(l=0; l<10 && j*10+l+i < seq_len; l++){
if (seq1[j*10+l+i]=='.')
spads1++;
}
if ( seq1[p1-pos1]=='.'){
vmessage("%10c", '-');
p11=p11-spads1+10;
}
else{
vmessage("%10d",p11);
p11=p11-spads1+10;
}
}
vmessage("\n%20.16s %.*s\n ",
name1,
i+line_length < seq_len ? 60 : seq_len - i,
&seq1[i]);
vmessage("%4s", " ");
for (k=i;k<seq_len && k<i+line_length;k++) {
vmessage("%c",match_syms[k]);
}
vmessage("\n%20.16s %.*s\n ",
name2,
i+line_length < seq_len ? 60 : seq_len - i,
&seq2[i]);
vmessage("%4s"," ");
for (j=0;j<6 && p2<pos2+seq_len;j++,p2+=10) {
spads2=0;
for(l=0; l<10 && j*10+l+i < seq_len; l++){
if(seq2[j*10+l+i]=='.')
spads2++;
}
if (seq2[p2-pos2]=='.'){
vmessage("%10c", '-');
p22=p22-spads2+10;
}
else{
vmessage("%10d",p22);
p22=p22-spads2+10;
}
}
vmessage("\n\n");
}
free ( match_syms );
return 0;
}
|