void print_hsp(gpointer key,gpointer value,gpointer user_data) { Sequence * query; HSPset * set; btCanvas * btc; btPasteArea * btp; int i,j; char q,t; query = (Sequence *)user_data; set = (HSPset *) value; btc = new_Ascii_btCanvas(stdout,12,50,5,3); for(i=0;i<set->len;i++) { for(j=0;j<set->hsp[i]->length;) { btp = get_reserved_left_btCanvas(btc); paste_string_btPasteArea(btp,0,0,query->name,BC_RIGHT,0); paste_string_btPasteArea(btp,0,2,set->hsp[i]->target->name,BC_RIGHT,0); free_btPasteArea(btp); for(;j<set->hsp[i]->length && can_get_paste_area_btCanvas(btc,1) == TRUE;j++) { btp = get_paste_area_btCanvas(btc,1); q = query->seq[set->hsp[i]->query_start+j]; t = set->hsp[i]->target->seq[set->hsp[i]->target_start+j]; paste_char_btPasteArea(btp,0,0,q,0); paste_char_btPasteArea(btp,0,2,t,0); if( q == t ) { paste_char_btPasteArea(btp,0,1,t,0); } free_btPasteArea(btp); } advance_line_btCanvas(btc); } advance_line_btCanvas(btc); } free_btCanvas(btc); }
boolean write_alignment_separator(btCanvas * btc,int aln,int score) { char buffer[64]; btPasteArea * btp; sprintf(buffer,"Alignment %d Score %4.2f (Bits)",aln,Score2Bits(score)); btp = get_paste_area_btCanvas(btc,strlen(buffer)); paste_string_btPasteArea(btp,0,5,buffer,BC_RIGHT,0); free_btPasteArea(btp); advance_line_btCanvas(btc); return TRUE; }
boolean write_name_start_stuff(btCanvas * btc,char * protname,int protoff,char * dnaname,Sequence * dna,int name_len,AlnColumn * alc) { char buffer[64]; btPasteArea * btp; btp = get_reserved_left_btCanvas(btc); paste_string_btPasteArea(btp,0,0,protname,BC_RIGHT,0); paste_string_btPasteArea(btp,0,3,dnaname,BC_RIGHT,0); sprintf(buffer,"%d",alc->alu[0]->start+1+protoff); paste_string_btPasteArea(btp,name_len+5-strlen(buffer),0,buffer,BC_RIGHT,0); if( dna->offset < dna->end ) sprintf(buffer,"%d",alc->alu[1]->start+1+dna->offset); else sprintf(buffer,"-%d",dna->offset - (alc->alu[1]->start+1)); paste_string_btPasteArea(btp,name_len+5-strlen(buffer),3,buffer,BC_RIGHT,0); free_btPasteArea(btp); return TRUE; }
boolean protdna_btc_display(AlnBlock * alb,char * protsequence,char * protname_in,int protoff,Sequence * dna,CodonTable * ct,int name,int main,btCanvas * btc,char (*match_central_line)(char,int,char),boolean multalign) { AlnColumn * alc; AlnColumn * alc_temp,*alc_endscore; int a_phase, d_phase; int intron_number = 1; int aln_score; int aln_num = 1; btPasteArea * btp; char tempbuf[2]; char protname[60]; char dnaname[60]; char dnatemp[4]; char protc; char transc; boolean is_reversed = FALSE; boolean issplit; if( strlen(protname_in) > name ) { info("Name %s is longer than allowed name block (%d). Truncating\n",protname_in,name); strncpy(protname,protname_in,name); protname[name] = '\0'; } else { strcpy(protname,protname_in); } if( strlen(dna->name) > name ) { info("Name %s is longer than allowed name block (%d). Truncating\n",dna->name,name); strncpy(dnaname,dna->name,name); dnaname[name] = '\0'; } else { strcpy(dnaname,dna->name); } if( dna->offset > dna->end ) { is_reversed = TRUE; } for(alc=alb->start;alc != NULL;) { if ( strcmp(alc->alu[1]->text_label,"END") == 0 ) break; /* end of alignment */ for(;alc != NULL && is_random_AlnColumn_genewise(alc) == TRUE;alc = alc->next) ; if( alc == NULL) break; /* end of alignment */ if( multalign == TRUE ) { /* get the end score */ for(aln_score = 0,alc_endscore=alc;alc_endscore->next != NULL;alc_endscore = alc_endscore->next) { if( is_random_AlnColumn_genewise(alc_endscore) == TRUE) break; aln_score += alc_endscore->alu[0]->score[0]; } /*aln_score += alc_endscore->alu[0]->score[0];*/ write_alignment_separator(btc,aln_num++,aln_score); } while( alc != NULL ) { write_name_start_stuff(btc,protname,protoff,dnaname,dna,name,alc); for(; alc != NULL;alc=alc->next ) { if( is_random_AlnColumn_genewise(alc) == TRUE ) break; if( strcmp(alc->alu[1]->text_label,"INSERT") == 0 ) { if( can_get_paste_area_btCanvas(btc,1) == FALSE) break; /* back to upper for, to place names and starts */ btp = get_paste_area_btCanvas(btc,1); paste_char_btPasteArea(btp,0,0,protsequence[alc->alu[0]->start+1],0); paste_char_btPasteArea(btp,0,2,'-',0); free_btPasteArea(btp); } else if ( strcmp(alc->alu[1]->text_label,"SEQUENCE_INSERTION") == 0 || strcmp(alc->alu[1]->text_label,"SEQUENCE_DELETION") == 0 ) { if( can_get_paste_area_btCanvas(btc,1) == FALSE) break; /* back to upper for, to place names and starts */ btp = get_paste_area_btCanvas(btc,1); if( strcmp(alc->alu[0]->text_label,"INSERT_STATE")== 0 ) { paste_char_btPasteArea(btp,0,0,'-',0); } else { paste_char_btPasteArea(btp,0,0,protsequence[alc->alu[0]->end],0); } sprintf(tempbuf,"%d",alc->alu[1]->end - alc->alu[1]->start); paste_char_btPasteArea(btp,0,3,tempbuf[0],0); paste_char_btPasteArea(btp,0,2,'!',0); free_btPasteArea(btp); } else if (strcmp(alc->alu[1]->text_label,"END") == 0 && strcmp(alc->alu[0]->text_label,"END") == 0) { break; /* end of alignment */ } else if ( strcmp(alc->alu[1]->text_label,"RANDOM_SEQUENCE") == 0 ) { break; } else if( strcmp(alc->alu[1]->text_label,"CODON") == 0 ) { if( can_get_paste_area_btCanvas(btc,1) == FALSE) break; /* back to upper for, to place names and starts */ btp = get_paste_area_btCanvas(btc,1); if( strcmp(alc->alu[0]->text_label,"INSERT_STATE")== 0 ) { write_codon_match(btp,'-',' ',alc->alu[1]->start+1,aminoacid_from_seq(ct,dna->seq+alc->alu[1]->start+1),dna->seq+alc->alu[1]->start+1); } else { write_codon_match(btp,protsequence[alc->alu[0]->end],(*match_central_line)(protsequence[alc->alu[0]->end],alc->alu[0]->score[0],aminoacid_from_seq(ct,dna->seq+alc->alu[1]->start+1)),alc->alu[1]->start+1,aminoacid_from_seq(ct,dna->seq+alc->alu[1]->start+1),dna->seq+alc->alu[1]->start+1); } free_btPasteArea(btp); continue; } else if ( strstartcmp(alc->alu[1]->text_label,"5SS") == 0 ) { /* * intron stuff. Figure out the start and end, * then place the 5'SS Central and End. * * If we can't fit in the intron, loop over * in this region before returning to higher loop. * */ if( strcmp(alc->alu[1]->text_label,"5SS_PHASE_0") == 0 ) { d_phase = 0; } else if ( strcmp(alc->alu[1]->text_label,"5SS_PHASE_1") == 0 ) { d_phase = 1; } else if ( strcmp(alc->alu[1]->text_label,"5SS_PHASE_2") == 0 ) { d_phase = 2; } else { warn("No no no. You have a non 0,1,2 phase intron (god knows how!). Not displaying it %s",alc->alu[1]->text_label); advance_line_btCanvas(btc); return FALSE; } alc_temp = alc->next; if( strcmp(alc_temp->alu[1]->text_label,"CENTRAL_INTRON") != 0 ) { warn("Bad news. I have found a 5SS in your alignment, but it is not followed by a central intron node. Don't like it!"); advance_line_btCanvas(btc); return FALSE; } for(alc_temp = alc_temp->next ;alc_temp != NULL && strstartcmp(alc_temp->alu[1]->text_label,"3SS") != 0;alc_temp = alc_temp->next) ; if( alc_temp == NULL ) { warn("Got to the end of the alignment in the middle of an intron from %s. Weird!",alc->alu[1]->text_label); advance_line_btCanvas(btc); return FALSE; } if( strcmp(alc_temp->alu[1]->text_label,"3SS_PHASE_0") == 0 ) { a_phase = 0; } else if ( strcmp(alc_temp->alu[1]->text_label,"3SS_PHASE_1") == 0 ) { a_phase = 1; } else if ( strcmp(alc_temp->alu[1]->text_label,"3SS_PHASE_2") == 0 ) { a_phase = 2; } else { warn("No no no. You have a non 0,1,2 phase intron (god knows how!). Not displaying it %s",alc_temp->alu[1]->text_label); advance_line_btCanvas(btc); return FALSE; } /* * At this point we have alc on 5SS alc_temp on 3SS. * * Check to see if we can place 5SS and Central intron piece * on the line, if not advance. * */ if( can_get_paste_area_btCanvas(btc,d_phase+7+13) == FALSE) { advance_line_btCanvas(btc); write_name_start_stuff(btc,protname,protoff,dnaname,dna,name,alc); } /*** ok, if we can't get it now then we are f****d ***/ if( can_get_paste_area_btCanvas(btc,d_phase+7+13) == FALSE) { warn("You have specified a length of your main canvas too small. I need at least 23 characters long."); advance_line_btCanvas(btc); return FALSE; } btp = get_paste_area_btCanvas(btc,d_phase+7); /* ? split phase */ if( a_phase == 0 || (a_phase != d_phase ) ) { protc = ' '; transc = ' '; dnatemp[0]= '\0'; issplit = FALSE; } else { if( strcmp(alc_temp->alu[0]->text_label,"INSERT_STATE")== 0 ) { protc = '-'; } else { protc = protsequence[alc->alu[0]->start+1]; } dnatemp[0] = tolower((int)dna->seq[alc->alu[1]->start+1]); if( d_phase == 2) { dnatemp[1] = tolower((int)dna->seq[alc->alu[1]->start+2]); } else { dnatemp[1] = tolower((int)dna->seq[alc_temp->alu[1]->end-1]); } dnatemp[2] = tolower((int)dna->seq[alc_temp->alu[1]->end]); dnatemp[3] = '\0'; transc = aminoacid_from_seq(ct,dnatemp); issplit = TRUE; } write_5intron_match(btp,d_phase,7,dna->seq+alc->alu[1]->start+1); free_btPasteArea(btp); btp = get_paste_area_btCanvas(btc,13); if( is_reversed == FALSE ) write_intron_desc(btp,alc->alu[1]->start+1+d_phase+dna->offset,alc_temp->alu[1]->start+3+dna->offset,intron_number++,issplit,protc,transc,dnatemp); else write_intron_desc(btp,dna->offset - (alc->alu[1]->start+d_phase+1),dna->offset - (alc_temp->alu[1]->start+3),intron_number++,issplit,protc,transc,dnatemp); free_btPasteArea(btp); /* * written the start of the intron, now to deal with the * acceptor. We need to loop here, because we might go over the * line length. */ alc = alc->next->next; /*** move alc forward two columns ***/ while( alc != alc_temp ) { for(; alc != alc_temp;alc = alc->next) { /** alc_temp is 3SS **/ if( strcmp(alc->alu[1]->text_label,"PYRIMIDINE_TRACT") == 0 ) { if( can_get_paste_area_btCanvas(btc,1) == FALSE ) break; btp = get_paste_area_btCanvas(btc,1); paste_char_btPasteArea(btp,0,3,dna->seq[alc->alu[1]->start+1],0); paste_char_btPasteArea(btp,0,4,'+',0); free_btPasteArea(btp); } else if( strcmp(alc->alu[1]->text_label,"SPACER") == 0 ) { if( can_get_paste_area_btCanvas(btc,1) == FALSE ) break; btp = get_paste_area_btCanvas(btc,1); paste_char_btPasteArea(btp,0,3,dna->seq[alc->alu[1]->start+1],0); free_btPasteArea(btp); } else { warn("Sorry, don't know how to print %s. Skipping...",alc->alu[1]->text_label); } } /** end for for loop **/ if ( alc == alc_temp ) { break; } /*** run out of space ***/ advance_line_btCanvas(btc); write_name_start_stuff(btc,protname,protoff,dnaname,dna,name,alc); } /** end of while still in central->3SS **/ /* * Now do 3SS * */ if( can_get_paste_area_btCanvas(btc,a_phase == 0 ? 3 : 3- a_phase + 3) == FALSE ) { advance_line_btCanvas(btc); write_name_start_stuff(btc,protname,protoff,dnaname,dna,name,alc); } if( a_phase != 0 ) { btp = get_paste_area_btCanvas(btc,3 - a_phase + 3); write_3intron_match(btp,a_phase,3,dna->seq + alc->alu[1]->start+1); free_btPasteArea(btp); } else { btp = get_paste_area_btCanvas(btc,3); write_3intron_match(btp,a_phase,3,dna->seq + alc->alu[1]->start+1); free_btPasteArea(btp); } /* * Finished with intron !!! */ } else { warn("Sorry, could not print the alignment %s:%s column",alc->alu[0]->text_label,alc->alu[1]->text_label); } } /*** in this loop ***/ advance_line_btCanvas(btc); if( alc == NULL) break; if ( is_random_AlnColumn_genewise(alc) == TRUE) break; } /* end of while over alignments */ } /* end of foreach alignment */ /*** end of print ! **/ return TRUE; }
boolean write_pretty_str_align_btc(AlnBlock * alb,char * qname,char * query,char * tname,char * target,btCanvas * btc) { AlnColumn * alc; AlnUnit * q; AlnUnit * t; char buffer[14]; int number_position; btPasteArea * btp; number_position = strlen(qname); if( strlen(tname) > number_position ) { number_position = strlen(tname); } for(alc=alb->start;alc != NULL;) { /** put names in **/ btp = get_reserved_left_btCanvas(btc); paste_string_btPasteArea(btp,0,0,qname,BC_RIGHT,0); paste_string_btPasteArea(btp,0,2,tname,BC_RIGHT,0); sprintf(buffer,"%d",alc->alu[0]->start+1+1); paste_string_btPasteArea(btp,number_position+2,0,buffer,BC_RIGHT,0); sprintf(buffer,"%d",alc->alu[1]->start+1+1); paste_string_btPasteArea(btp,number_position+2,2,buffer,BC_RIGHT,0); free_btPasteArea(btp); /** now loop over this block **/ for(;alc != NULL && can_get_paste_area_btCanvas(btc,1) == TRUE;alc=alc->next) { q = alc->alu[0]; t = alc->alu[1]; /* * at the end, break */ if( strcmp(q->text_label,"END") == 0 ) { alc = NULL; break; } if( strcmp(t->text_label,"LOOP") == 0 ) { btp = get_paste_area_btCanvas(btc,1); paste_char_btPasteArea(btp,0,0,'L',0); paste_char_btPasteArea(btp,0,1,'$',0); paste_char_btPasteArea(btp,0,2,'L',0); free_btPasteArea(btp); advance_line_btCanvas(btc); for(;alc != NULL && strcmp(alc->alu[1]->text_label,"LOOP") == 0;alc = alc->next) { ; } break; } /* * Get the paste area, length 1, depth will be 3 */ btp = get_paste_area_btCanvas(btc,1); /* * Write in the query sequence * */ if( strcmp(q->text_label,"SEQUENCE") == 0 || strstr(q->text_label,"BOUND") != NULL ) { paste_char_btPasteArea(btp,0,0,((int)query[q->start+1]),0); } else if( strcmp(q->text_label,"UNMATCHED_SEQUENCE") == 0 ) { paste_char_btPasteArea(btp,0,0,tolower((int)query[q->start+1]),0); } else { /** is insert- we could check **/ if( strcmp(q->text_label,"INSERT") != 0 ) { warn("Got an uninterpretable label, %s",q->text_label); paste_char_btPasteArea(btp,0,0,'?',0); } else { paste_char_btPasteArea(btp,0,0,'-',0); } } /* * Write in the target sequence * */ if( strcmp(t->text_label,"SEQUENCE") == 0 ) { paste_char_btPasteArea(btp,0,2,toupper((int)target[t->start+1]),0); } else if( strcmp(t->text_label,"UNMATCHED_SEQUENCE") == 0 ) { paste_char_btPasteArea(btp,0,2,tolower((int)target[t->start+1]),0); } else { /** is insert- we could check **/ if( strcmp(t->text_label,"INSERT") != 0 ) { warn("Got an uninterpretable label, %s",t->text_label); paste_char_btPasteArea(btp,0,2,'?',0); } else { paste_char_btPasteArea(btp,0,2,'-',0); } } /* * Match line */ if( strcmp(q->text_label,"SEQUENCE") == 0 && strcmp(t->text_label,"SEQUENCE") == 0 ) { if( q->score[0] > 0 ) { if( query[q->start+1] == target[t->start+1] ) { paste_char_btPasteArea(btp,0,1,target[t->start+1],0); } else { paste_char_btPasteArea(btp,0,1,'+',0); } } } else paste_char_btPasteArea(btp,0,1,' ',0); free_btPasteArea(btp); } /* end of for this block */ advance_line_btCanvas(btc); } /* end of for the alignment */ return TRUE; /* we never returned false. Ooops! */ }