1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <string.h> |
---|
4 | #include <memory.h> |
---|
5 | #include <iostream> |
---|
6 | // #include <malloc.h> |
---|
7 | |
---|
8 | #include <arbdb.h> |
---|
9 | #include <arbdbt.h> |
---|
10 | |
---|
11 | #include <aw_root.hxx> |
---|
12 | #include <aw_device.hxx> |
---|
13 | #include <aw_keysym.hxx> |
---|
14 | #include <aw_window.hxx> |
---|
15 | #include <aw_preset.hxx> |
---|
16 | #include <aw_awars.hxx> |
---|
17 | |
---|
18 | #include <AW_helix.hxx> |
---|
19 | |
---|
20 | #include <awt_seq_colors.hxx> |
---|
21 | #include <awt_attributes.hxx> |
---|
22 | #include <st_window.hxx> |
---|
23 | |
---|
24 | #include <ed4_extern.hxx> |
---|
25 | |
---|
26 | #include "ed4_class.hxx" |
---|
27 | #include "ed4_awars.hxx" |
---|
28 | #include "ed4_edit_string.hxx" |
---|
29 | #include "ed4_block.hxx" |
---|
30 | #include "ed4_nds.hxx" |
---|
31 | #include "ed4_visualizeSAI.hxx" |
---|
32 | #include "ed4_ProteinViewer.hxx" |
---|
33 | #include "ed4_protein_2nd_structure.hxx" |
---|
34 | |
---|
35 | int ED4_consensus_sequence_terminal::get_length() const { |
---|
36 | return get_char_table().size(); |
---|
37 | } |
---|
38 | |
---|
39 | ED4_returncode ED4_consensus_sequence_terminal::draw( int /*only_text*/ ) |
---|
40 | { |
---|
41 | AW_pos x, y; |
---|
42 | AW_pos text_x, text_y; |
---|
43 | long left_index = 0, right_index = 0; |
---|
44 | |
---|
45 | static char *buffer = 0; |
---|
46 | static size_t buffer_size = 0; |
---|
47 | |
---|
48 | calc_world_coords(&x, &y); |
---|
49 | ED4_ROOT->world_to_win_coords(ED4_ROOT->get_aww(), &x, &y); |
---|
50 | calc_update_intervall(&left_index, &right_index ); |
---|
51 | |
---|
52 | text_x = x + CHARACTEROFFSET; // don't change |
---|
53 | text_y = y + SEQ_TERM_TEXT_YOFFSET; |
---|
54 | |
---|
55 | #if defined(DEBUG) && 0 |
---|
56 | int paint_back = 1; |
---|
57 | if (paint_back) { |
---|
58 | paint_back = 3-paint_back; |
---|
59 | ED4_ROOT->get_device()->box(ED4_G_FIRST_COLOR_GROUP+paint_back-1, x, y, extension.size[WIDTH], extension.size[HEIGHT], -1, 0, 0); |
---|
60 | } |
---|
61 | #endif // DEBUG |
---|
62 | |
---|
63 | const ED4_remap *rm = ED4_ROOT->root_group_man->remap(); |
---|
64 | rm->clip_screen_range(&left_index, &right_index); |
---|
65 | |
---|
66 | if (right_index<0 || left_index<0) { |
---|
67 | e4_assert(left_index == -1 && right_index <= 0); // no update intervall |
---|
68 | |
---|
69 | const char *no_data = "No consensus data"; |
---|
70 | size_t len = strlen(no_data); |
---|
71 | if (buffer_size <= len) { |
---|
72 | delete buffer; |
---|
73 | buffer_size = len+10; |
---|
74 | buffer = new char[buffer_size]; |
---|
75 | memset(buffer, ' ' , buffer_size); // previously buffer was filled with zero's |
---|
76 | } |
---|
77 | memcpy(buffer, no_data, len); |
---|
78 | right_index = buffer_size-1; |
---|
79 | } |
---|
80 | else { |
---|
81 | int seq_start = rm->screen_to_sequence(left_index); |
---|
82 | int seq_end = rm->screen_to_sequence(right_index); |
---|
83 | |
---|
84 | while (seq_end >= MAXSEQUENCECHARACTERLENGTH && right_index>0) { // behind end of sequence |
---|
85 | right_index--; |
---|
86 | seq_end = rm->screen_to_sequence(right_index); |
---|
87 | } |
---|
88 | |
---|
89 | char *cons = GB_give_buffer(seq_end+1); |
---|
90 | cons = get_char_table().build_consensus_string(seq_start, seq_end, cons); |
---|
91 | |
---|
92 | if ( size_t(right_index) >= buffer_size){ |
---|
93 | delete [] buffer; |
---|
94 | buffer_size = right_index + 10; |
---|
95 | e4_assert(buffer_size>0); |
---|
96 | buffer = new char[buffer_size+1]; |
---|
97 | |
---|
98 | memset(buffer, ' ' , buffer_size); // previously buffer was filled with zero's |
---|
99 | buffer[buffer_size] = 0; |
---|
100 | } |
---|
101 | |
---|
102 | |
---|
103 | { |
---|
104 | int pos; |
---|
105 | for (pos = left_index; pos <= right_index; pos++){ |
---|
106 | int seq_pos = rm->screen_to_sequence(pos); |
---|
107 | if (seq_pos<0){ |
---|
108 | buffer[pos] = ' '; |
---|
109 | }else{ |
---|
110 | buffer[pos] = cons[seq_pos]; |
---|
111 | e4_assert(buffer[pos]); |
---|
112 | } |
---|
113 | } |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | if (buffer_size) { |
---|
119 | ED4_ROOT->get_device()->top_font_overlap = 1; |
---|
120 | ED4_ROOT->get_device()->bottom_font_overlap = 1; |
---|
121 | |
---|
122 | ED4_ROOT->get_device()->text( ED4_G_SEQUENCES, buffer, text_x, text_y, 0, 1, 0, 0, (long) right_index+1); |
---|
123 | |
---|
124 | ED4_ROOT->get_device()->top_font_overlap = 0; |
---|
125 | ED4_ROOT->get_device()->bottom_font_overlap = 0; |
---|
126 | } |
---|
127 | |
---|
128 | return ( ED4_R_OK ); |
---|
129 | } |
---|
130 | |
---|
131 | static int ED4_show_helix_on_device(AW_device *device, int gc, const char *opt_string, size_t opt_string_size, size_t start, size_t size, |
---|
132 | AW_pos x,AW_pos y, AW_pos opt_ascent,AW_pos opt_descent, |
---|
133 | AW_CL cduser, AW_CL real_sequence_length, AW_CL cd2) |
---|
134 | { |
---|
135 | AWUSE(opt_ascent);AWUSE(opt_descent);AWUSE(opt_string_size); |
---|
136 | AW_helix *helix = (AW_helix *)cduser; |
---|
137 | const ED4_remap *rm = ED4_ROOT->root_group_man->remap(); |
---|
138 | char *buffer = GB_give_buffer(size+1); |
---|
139 | long i,j,k; |
---|
140 | |
---|
141 | for (k=0; size_t(k)<size; k++) { |
---|
142 | i = rm->screen_to_sequence(k+start); |
---|
143 | |
---|
144 | BI_PAIR_TYPE pairType = helix->pairtype(i); |
---|
145 | if (pairType == HELIX_NONE) { |
---|
146 | buffer[k] = ' '; |
---|
147 | } |
---|
148 | else { |
---|
149 | j = helix->opposite_position(i); |
---|
150 | char pairchar = j<real_sequence_length ? opt_string[j] : '.'; |
---|
151 | buffer[k] = helix->get_symbol(opt_string[i], pairchar, pairType); |
---|
152 | } |
---|
153 | } |
---|
154 | buffer[size] = 0; |
---|
155 | return device->text(gc,buffer,x,y,0.0,(AW_bitset)-1,0,cd2); |
---|
156 | } |
---|
157 | |
---|
158 | /** \brief Calls ED4_pfold_calculate_secstruct_match() for the visible area in the |
---|
159 | * editor to compute the protein secondary structure match and outputs the |
---|
160 | * result to the device. |
---|
161 | * \param[in] protstruct The protein structure (primary or secondary) that should be compared to \a global_protstruct |
---|
162 | * \param[in] global_protstruct The reference protein secondary structure SAI |
---|
163 | */ |
---|
164 | static int ED4_show_protein_match_on_device(AW_device *device, int gc, const char *protstruct, size_t /*protstruct_len*/, size_t start, size_t size, |
---|
165 | AW_pos x, AW_pos y, AW_pos /*opt_ascent*/, AW_pos /*opt_descent*/, |
---|
166 | AW_CL cl_protstruct, AW_CL /*real_sequence_length*/, AW_CL cd2) |
---|
167 | { |
---|
168 | GB_ERROR error = 0; |
---|
169 | //TODO: proper use of ED4_remap? |
---|
170 | const ED4_remap *rm = ED4_ROOT->root_group_man->remap(); |
---|
171 | char *buffer = GB_give_buffer(size+1); |
---|
172 | if (!buffer) { |
---|
173 | error = GB_export_error("Out of memory."); |
---|
174 | } |
---|
175 | else { |
---|
176 | error = ED4_pfold_calculate_secstruct_match((const unsigned char *)cl_protstruct, |
---|
177 | (const unsigned char *)protstruct, |
---|
178 | rm->screen_to_sequence(start), |
---|
179 | rm->screen_to_sequence(start + size), |
---|
180 | buffer, |
---|
181 | (PFOLD_MATCH_METHOD)ED4_ROOT->aw_root->awar(PFOLD_AWAR_MATCH_METHOD)->read_int()); |
---|
182 | } |
---|
183 | if (error) aw_message(error); |
---|
184 | buffer[size] = 0; |
---|
185 | return device->text(gc,buffer,x,y,0.0,(AW_bitset)-1,0,cd2); |
---|
186 | } |
---|
187 | |
---|
188 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
189 | // ProteinViewer: Drawing AminoAcid sequence parallel to the DNA sequence |
---|
190 | //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
191 | #define is_upper(c) ('A'<=(c) && (c)<='Z') |
---|
192 | |
---|
193 | ED4_returncode ED4_AA_sequence_terminal::draw( int /*only_text*/ ) |
---|
194 | { |
---|
195 | AW_pos text_x, text_y; |
---|
196 | int max_seq_len = 0; |
---|
197 | static int color_is_used[ED4_G_DRAG]; |
---|
198 | static char **colored_strings = 0; |
---|
199 | static int len_of_colored_strings = 0; |
---|
200 | AW_device *device = ED4_ROOT->get_device(); |
---|
201 | |
---|
202 | max_seq_len = strlen(this->aaSequence); |
---|
203 | |
---|
204 | AW_pos world_x, world_y; |
---|
205 | |
---|
206 | calc_world_coords(&world_x, &world_y); |
---|
207 | ED4_ROOT->world_to_win_coords(ED4_ROOT->get_aww(), &world_x, &world_y); |
---|
208 | |
---|
209 | text_x = world_x + CHARACTEROFFSET; // don't change |
---|
210 | text_y = world_y + SEQ_TERM_TEXT_YOFFSET; |
---|
211 | |
---|
212 | const ED4_remap *rm = ED4_ROOT->root_group_man->remap(); |
---|
213 | |
---|
214 | long left,right; |
---|
215 | calc_update_intervall(&left, &right ); |
---|
216 | rm->clip_screen_range(&left, &right); |
---|
217 | |
---|
218 | { |
---|
219 | int max_seq_pos = rm->sequence_to_screen_clipped(max_seq_len-1); |
---|
220 | |
---|
221 | if (right>max_seq_len) right = max_seq_pos; |
---|
222 | if (left>right) { |
---|
223 | const char *no_data = "No sequence data"; |
---|
224 | size_t len = strlen(no_data); |
---|
225 | |
---|
226 | device->text(ED4_G_STANDARD, no_data, text_x, text_y, 0, 1, 0, 0, len); |
---|
227 | return ED4_R_OK; |
---|
228 | } |
---|
229 | } |
---|
230 | |
---|
231 | if (right >= len_of_colored_strings){ |
---|
232 | len_of_colored_strings = right + 256; |
---|
233 | if (!colored_strings) { |
---|
234 | colored_strings = (char **)GB_calloc(sizeof(char *),ED4_G_DRAG); |
---|
235 | } |
---|
236 | int i; |
---|
237 | for (i=0;i<ED4_G_DRAG;i++){ |
---|
238 | freeset(colored_strings[i], (char *)malloc(sizeof(char) * (len_of_colored_strings+1))); |
---|
239 | memset(colored_strings[i],' ',len_of_colored_strings); |
---|
240 | colored_strings[i][len_of_colored_strings] = 0; |
---|
241 | } |
---|
242 | } |
---|
243 | |
---|
244 | // int seq_start = rm->screen_to_sequence(left); // real start of sequence |
---|
245 | int seq_end = rm->screen_to_sequence(right); |
---|
246 | |
---|
247 | // mark all strings as unused |
---|
248 | memset(color_is_used,0,sizeof(color_is_used)); |
---|
249 | |
---|
250 | // int iDisplayAminoAcids = ED4_ROOT->aw_root->awar(AWAR_PROTVIEW_DISPLAY_AA)->read_int(); |
---|
251 | int iDisplayMode = ED4_ROOT->aw_root->awar(AWAR_PROTVIEW_DISPLAY_OPTIONS)->read_int(); |
---|
252 | { |
---|
253 | unsigned char *aaSequence_copy = (unsigned char *) strdup(aaSequence); |
---|
254 | |
---|
255 | { // transform strings, compress if needed |
---|
256 | AWT_reference *ref = ED4_ROOT->reference; |
---|
257 | ref->expand_to_length(seq_end); |
---|
258 | |
---|
259 | char *char_2_char = ED4_ROOT->sequence_colors->char_2_char_aa; |
---|
260 | char *char_2_gc = ED4_ROOT->sequence_colors->char_2_gc_aa; |
---|
261 | int scr_pos; |
---|
262 | |
---|
263 | for (scr_pos=left; scr_pos <= right; scr_pos++) { |
---|
264 | int seq_pos = rm->screen_to_sequence(scr_pos); |
---|
265 | int c = aaSequence_copy[seq_pos]; |
---|
266 | int gc = char_2_gc[c]; |
---|
267 | |
---|
268 | color_is_used[gc] = scr_pos+1; |
---|
269 | colored_strings[gc][scr_pos] = char_2_char[aaSequence_copy[seq_pos]]; |
---|
270 | } |
---|
271 | } |
---|
272 | |
---|
273 | // painting background |
---|
274 | if((iDisplayMode == PV_AA_CODE) || (iDisplayMode == PV_AA_BOX)) { |
---|
275 | { |
---|
276 | AW_pos width = ED4_ROOT->font_group.get_width(ED4_G_HELIX); |
---|
277 | int real_left = left; |
---|
278 | int real_right = right; |
---|
279 | AW_pos x2 = text_x + width*real_left; |
---|
280 | AW_pos x1 = x2; |
---|
281 | AW_pos y1 = world_y; |
---|
282 | AW_pos y2 = text_y+1; |
---|
283 | AW_pos height = y2-y1+1; |
---|
284 | int color = ED4_G_STANDARD; |
---|
285 | char *char_2_gc_aa = ED4_ROOT->sequence_colors->char_2_gc_aa; |
---|
286 | |
---|
287 | int i; |
---|
288 | for ( i = real_left; i <= real_right; i++,x2 += width) { |
---|
289 | int new_pos = rm->screen_to_sequence(i); //getting the real position of the base in the sequence |
---|
290 | int c = aaSequence_copy[new_pos]; |
---|
291 | char base = aaSequence_copy[new_pos]; |
---|
292 | |
---|
293 | if (is_upper(base) || (base=='*')) { |
---|
294 | x1 = x2-width; // store current x pos to x1 |
---|
295 | x2 += width*2; // add 2 char width to x2 |
---|
296 | i += 2; //jump two pos |
---|
297 | |
---|
298 | int gcChar = char_2_gc_aa[c]; |
---|
299 | if ((gcChar>=0) && (gcChar<ED4_G_DRAG)) { |
---|
300 | color = gcChar; |
---|
301 | if (iDisplayMode == PV_AA_BOX) { |
---|
302 | device->box(color, true, x1, y1, width*3, height, -1, 0,0); |
---|
303 | } |
---|
304 | else { |
---|
305 | device->arc(ED4_G_STANDARD, false, x1+(width*3)/2, y1, (width*3)/2, height/2, 0, -180, -1, 0, 0); |
---|
306 | } |
---|
307 | } |
---|
308 | } |
---|
309 | } |
---|
310 | } |
---|
311 | } |
---|
312 | free(aaSequence_copy); |
---|
313 | } |
---|
314 | |
---|
315 | device->top_font_overlap = 1; |
---|
316 | device->bottom_font_overlap = 1; |
---|
317 | |
---|
318 | // output strings -- when display aminoacid sequence selected |
---|
319 | if((iDisplayMode == PV_AA_NAME) || (iDisplayMode == PV_AA_CODE)) { |
---|
320 | // if (!iDisplayAsColoredBox || iDisplayAminoAcids) { |
---|
321 | int gc; |
---|
322 | for (gc = 0; gc < ED4_G_DRAG; gc++){ |
---|
323 | if (!color_is_used[gc]) continue; |
---|
324 | if ((int)strlen(colored_strings[gc])>=color_is_used[gc]) { |
---|
325 | device->text( gc, colored_strings[gc], text_x, text_y, 0, 1, 0, 0, color_is_used [gc]); |
---|
326 | memset(colored_strings[gc] + left,' ', right-left+1); // clear string |
---|
327 | } |
---|
328 | } |
---|
329 | } |
---|
330 | device->top_font_overlap = 0; |
---|
331 | device->bottom_font_overlap = 0; |
---|
332 | |
---|
333 | return ( ED4_R_OK ); |
---|
334 | } |
---|
335 | |
---|
336 | ED4_returncode ED4_sequence_terminal::draw( int /*only_text*/ ) |
---|
337 | { |
---|
338 | AW_pos text_x, text_y; |
---|
339 | int max_seq_len = 0; |
---|
340 | static int color_is_used[ED4_G_DRAG]; |
---|
341 | static char **colored_strings = 0; |
---|
342 | static int len_of_colored_strings = 0; |
---|
343 | AW_device *device = ED4_ROOT->get_device(); |
---|
344 | |
---|
345 | resolve_pointer_to_char_pntr(&max_seq_len); |
---|
346 | e4_assert(max_seq_len>0); |
---|
347 | |
---|
348 | #if defined(DEBUG) && 0 |
---|
349 | int paint_back = 0; |
---|
350 | if (strcmp(species_name, "ARTGLOB3") == 0) { paint_back = 1; } |
---|
351 | else if (strcmp(species_name, "ARTGLOB4") == 0) { paint_back = 2; } |
---|
352 | else if (strcmp(species_name, "ARTLUTE2") == 0) { paint_back = 3; } |
---|
353 | #endif // DEBUG |
---|
354 | |
---|
355 | AW_pos world_x, world_y; |
---|
356 | |
---|
357 | calc_world_coords(&world_x, &world_y); |
---|
358 | ED4_ROOT->world_to_win_coords(ED4_ROOT->get_aww(), &world_x, &world_y); |
---|
359 | |
---|
360 | #if defined(DEBUG) && 0 |
---|
361 | int paint_back = 1; |
---|
362 | if (paint_back) { |
---|
363 | paint_back = 3-paint_back; |
---|
364 | device->box(ED4_G_FIRST_COLOR_GROUP+paint_back-1, world_x, world_y, extension.size[WIDTH], extension.size[HEIGHT], -1, 0, 0); |
---|
365 | } |
---|
366 | #endif // DEBUG |
---|
367 | |
---|
368 | text_x = world_x + CHARACTEROFFSET; // don't change |
---|
369 | text_y = world_y + SEQ_TERM_TEXT_YOFFSET; |
---|
370 | |
---|
371 | const ED4_remap *rm = ED4_ROOT->root_group_man->remap(); |
---|
372 | |
---|
373 | long left,right; |
---|
374 | calc_update_intervall(&left, &right ); |
---|
375 | rm->clip_screen_range(&left, &right); |
---|
376 | |
---|
377 | { |
---|
378 | int max_seq_pos = rm->sequence_to_screen_clipped(max_seq_len-1); |
---|
379 | |
---|
380 | if (right>max_seq_len) right = max_seq_pos; |
---|
381 | if (left>right) { |
---|
382 | const char *no_data = "No sequence data"; |
---|
383 | size_t len = strlen(no_data); |
---|
384 | |
---|
385 | device->text(ED4_G_STANDARD, no_data, text_x, text_y, 0, 1, 0, 0, len); |
---|
386 | return ED4_R_OK; |
---|
387 | } |
---|
388 | } |
---|
389 | |
---|
390 | if (right >= len_of_colored_strings){ |
---|
391 | len_of_colored_strings = right + 256; |
---|
392 | if (!colored_strings) { |
---|
393 | colored_strings = (char **)GB_calloc(sizeof(char *),ED4_G_DRAG); |
---|
394 | } |
---|
395 | int i; |
---|
396 | for (i=0;i<ED4_G_DRAG;i++){ |
---|
397 | freeset(colored_strings[i], (char *)malloc(sizeof(char) * (len_of_colored_strings+1))); |
---|
398 | memset(colored_strings[i],' ',len_of_colored_strings); |
---|
399 | colored_strings[i][len_of_colored_strings] = 0; |
---|
400 | } |
---|
401 | } |
---|
402 | |
---|
403 | int seq_start = rm->screen_to_sequence(left); // real start of sequence |
---|
404 | int seq_end = rm->screen_to_sequence(right); |
---|
405 | |
---|
406 | // mark all strings as unused |
---|
407 | memset(color_is_used,0,sizeof(color_is_used)); |
---|
408 | |
---|
409 | // transform strings, compress if needed |
---|
410 | { |
---|
411 | AWT_reference *ref = ED4_ROOT->reference; |
---|
412 | unsigned char *db_pointer = (unsigned char *)resolve_pointer_to_string_copy(); |
---|
413 | |
---|
414 | ref->expand_to_length(seq_end); |
---|
415 | |
---|
416 | GB_alignment_type aliType = GetAliType(); |
---|
417 | char *char_2_char = (aliType && (aliType==GB_AT_AA))? ED4_ROOT->sequence_colors->char_2_char_aa:ED4_ROOT->sequence_colors->char_2_char; |
---|
418 | char *char_2_gc = (aliType && (aliType==GB_AT_AA))? ED4_ROOT->sequence_colors->char_2_gc_aa:ED4_ROOT->sequence_colors->char_2_gc; |
---|
419 | |
---|
420 | int scr_pos; |
---|
421 | int is_ref = ref->reference_species_is(species_name); |
---|
422 | |
---|
423 | for (scr_pos=left; scr_pos <= right; scr_pos++) { |
---|
424 | int seq_pos = rm->screen_to_sequence(scr_pos); |
---|
425 | int c = db_pointer[seq_pos]; |
---|
426 | int gc = char_2_gc[c]; |
---|
427 | |
---|
428 | color_is_used[gc] = scr_pos+1; |
---|
429 | colored_strings[gc][scr_pos] = char_2_char[is_ref ? c : ref->convert(c, seq_pos)]; |
---|
430 | } |
---|
431 | |
---|
432 | free(db_pointer); |
---|
433 | } |
---|
434 | |
---|
435 | // Set background |
---|
436 | |
---|
437 | { |
---|
438 | GB_transaction dummy(GLOBAL_gb_main); |
---|
439 | ST_ML_Color *colors = 0; |
---|
440 | char *searchColors = results().buildColorString(this, seq_start, seq_end); // defined in ED4_SearchResults class : ED4_search.cxx |
---|
441 | ED4_species_manager *spec_man = get_parent(ED4_L_SPECIES)->to_species_manager(); |
---|
442 | int is_marked = GB_read_flag(spec_man->get_species_pointer()); |
---|
443 | int selection_col1, selection_col2; |
---|
444 | int is_selected = ED4_get_selected_range(this, &selection_col1, &selection_col2); |
---|
445 | int color_group = AWT_species_get_dominant_color(spec_man->get_species_pointer()); |
---|
446 | // int color_group = AW_find_color_group(spec_man->get_species_pointer()); |
---|
447 | |
---|
448 | if (species_name && |
---|
449 | ED4_ROOT->column_stat_activated && |
---|
450 | (st_ml_node || (st_ml_node = st_ml_convert_species_name_to_node(ED4_ROOT->st_ml,this->species_name)))) |
---|
451 | { |
---|
452 | colors = st_ml_get_color_string(ED4_ROOT->st_ml, 0, st_ml_node, seq_start, seq_end); |
---|
453 | } |
---|
454 | |
---|
455 | const char *saiColors = 0; |
---|
456 | |
---|
457 | if (species_name && |
---|
458 | ED4_ROOT->visualizeSAI && |
---|
459 | !spec_man->flag.is_SAI && |
---|
460 | (is_marked || ED4_ROOT->visualizeSAI_allSpecies)) |
---|
461 | { |
---|
462 | saiColors = ED4_getSaiColorString(ED4_ROOT->aw_root, seq_start, seq_end); |
---|
463 | } |
---|
464 | |
---|
465 | if (colors || searchColors || is_marked || is_selected || color_group || saiColors) { |
---|
466 | int i; |
---|
467 | AW_pos width = ED4_ROOT->font_group.get_width(ED4_G_HELIX); |
---|
468 | int real_left = left; |
---|
469 | int real_right = right; |
---|
470 | AW_pos x2 = text_x + width*real_left; |
---|
471 | AW_pos old_x = x2; |
---|
472 | AW_pos y1 = world_y; |
---|
473 | AW_pos y2 = text_y+1; |
---|
474 | AW_pos height = y2-y1+1; |
---|
475 | int old_color = ED4_G_STANDARD; |
---|
476 | int color = ED4_G_STANDARD; |
---|
477 | |
---|
478 | if (is_selected && selection_col2<0) { |
---|
479 | selection_col2 = rm->screen_to_sequence(real_right); |
---|
480 | } |
---|
481 | |
---|
482 | for ( i = real_left; i <= real_right; i++,x2 += width) { |
---|
483 | int new_pos = rm->screen_to_sequence(i); //getting the real position of the base in the sequence |
---|
484 | |
---|
485 | if (searchColors && searchColors[new_pos]) { |
---|
486 | color = searchColors[new_pos]; |
---|
487 | } |
---|
488 | else if (is_selected && new_pos>=selection_col1 && new_pos<=selection_col2) { |
---|
489 | color = ED4_G_SELECTED; |
---|
490 | } |
---|
491 | else if (colors) { |
---|
492 | color = colors[new_pos] + ED4_G_CBACK_0; |
---|
493 | if (color > ED4_G_CBACK_9) color = ED4_G_CBACK_9; |
---|
494 | } |
---|
495 | else if (saiColors) { |
---|
496 | color = saiColors[new_pos]; |
---|
497 | if (color < ED4_G_CBACK_0 || color > ED4_G_CBACK_9) color = ED4_G_STANDARD; |
---|
498 | } |
---|
499 | else if (is_marked) { |
---|
500 | color = ED4_G_MARKED; |
---|
501 | } |
---|
502 | else if (color_group) { |
---|
503 | color = ED4_G_FIRST_COLOR_GROUP+color_group-1; |
---|
504 | } |
---|
505 | else { |
---|
506 | color = ED4_G_STANDARD; |
---|
507 | } |
---|
508 | |
---|
509 | if (color != old_color) { // draw till oldcolor |
---|
510 | if (x2>old_x){ |
---|
511 | if (old_color!=ED4_G_STANDARD) { |
---|
512 | device->box(old_color, true, old_x, y1, x2-old_x, height, -1, 0,0); // paints the search pattern background |
---|
513 | } |
---|
514 | } |
---|
515 | old_x = x2; |
---|
516 | old_color = color; |
---|
517 | } |
---|
518 | } |
---|
519 | |
---|
520 | if (x2>old_x){ |
---|
521 | if (color!=ED4_G_STANDARD) { |
---|
522 | device->box(color, true, old_x, y1, x2-old_x, height, -1, 0,0); |
---|
523 | } |
---|
524 | } |
---|
525 | } |
---|
526 | } |
---|
527 | |
---|
528 | device->top_font_overlap = 1; |
---|
529 | device->bottom_font_overlap = 1; |
---|
530 | |
---|
531 | // output helix |
---|
532 | if (ED4_ROOT->helix->is_enabled()) { // should do a remap |
---|
533 | int screen_length = rm->clipped_sequence_to_screen(ED4_ROOT->helix->size()); |
---|
534 | if ((right+1) < screen_length) { |
---|
535 | screen_length = right+1; |
---|
536 | } |
---|
537 | if (screen_length) { |
---|
538 | char *db_pointer = resolve_pointer_to_string_copy(); |
---|
539 | device->text_overlay( ED4_G_HELIX, |
---|
540 | (char *)db_pointer, screen_length, |
---|
541 | text_x , text_y + ED4_ROOT->helix_spacing , 0.0 , -1, |
---|
542 | (AW_CL)ED4_ROOT->helix, (AW_CL)max_seq_len, 0, |
---|
543 | 1.0,1.0, ED4_show_helix_on_device); |
---|
544 | free(db_pointer); |
---|
545 | } |
---|
546 | } |
---|
547 | |
---|
548 | // output protein structure match |
---|
549 | ED4_species_manager *spec_man = get_parent(ED4_L_SPECIES)->to_species_manager(); |
---|
550 | if ( ED4_ROOT->protstruct && !spec_man->flag.is_SAI && |
---|
551 | ED4_ROOT->aw_root->awar(PFOLD_AWAR_ENABLE)->read_int() ) { // should do a remap |
---|
552 | int screen_length = rm->clipped_sequence_to_screen(ED4_ROOT->protstruct_len); |
---|
553 | if ((right+1) < screen_length) { |
---|
554 | screen_length = right+1; |
---|
555 | } |
---|
556 | if (screen_length) { |
---|
557 | // get protein structure (primary or secondary) from the species |
---|
558 | char *protstruct = resolve_pointer_to_string_copy(); |
---|
559 | if (protstruct) { |
---|
560 | device->text_overlay( ED4_G_HELIX, |
---|
561 | protstruct, screen_length, |
---|
562 | text_x , text_y + ED4_ROOT->helix_spacing , 0.0 , -1, |
---|
563 | (AW_CL)ED4_ROOT->protstruct, (AW_CL)max_seq_len, 0, |
---|
564 | 1.0,1.0, ED4_show_protein_match_on_device); |
---|
565 | free(protstruct); |
---|
566 | } |
---|
567 | } |
---|
568 | } |
---|
569 | |
---|
570 | // output strings |
---|
571 | { |
---|
572 | int gc; |
---|
573 | for (gc = 0; gc < ED4_G_DRAG; gc++){ |
---|
574 | if (!color_is_used[gc]) continue; |
---|
575 | device->text( gc, colored_strings[gc], text_x, text_y, 0, 1, 0, 0, color_is_used [gc]); |
---|
576 | memset(colored_strings[gc] + left,' ', right-left+1); // clear string |
---|
577 | } |
---|
578 | } |
---|
579 | |
---|
580 | device->top_font_overlap = 0; |
---|
581 | device->bottom_font_overlap = 0; |
---|
582 | |
---|
583 | return ( ED4_R_OK ); |
---|
584 | } |
---|
585 | |
---|
586 | |
---|
587 | ED4_returncode ED4_sequence_info_terminal::draw( int /*only_text*/ ) |
---|
588 | { |
---|
589 | AW_pos x, y; |
---|
590 | |
---|
591 | calc_world_coords(&x, &y); |
---|
592 | ED4_ROOT->world_to_win_coords(ED4_ROOT->get_aww(), &x, &y); |
---|
593 | |
---|
594 | AW_pos text_x = x + CHARACTEROFFSET; // don't change |
---|
595 | AW_pos text_y = y+INFO_TERM_TEXT_YOFFSET; |
---|
596 | |
---|
597 | char buffer[10]; |
---|
598 | GBDATA *gbdata = data(); |
---|
599 | |
---|
600 | if (gbdata){ |
---|
601 | GB_push_transaction(gbdata); |
---|
602 | buffer[0] = '0' + GB_read_security_write(gbdata); |
---|
603 | GB_pop_transaction(gbdata); |
---|
604 | } |
---|
605 | else { |
---|
606 | buffer[0] = ' '; |
---|
607 | } |
---|
608 | strncpy(&buffer[1],this->id,8); |
---|
609 | buffer[9] = 0; |
---|
610 | |
---|
611 | ED4_species_name_terminal *name_term = corresponding_species_name_terminal(); |
---|
612 | if (name_term->flag.selected) { |
---|
613 | ED4_ROOT->get_device()->box(ED4_G_SELECTED, true, x, y, extension.size[WIDTH], text_y-y+1, (AW_bitset)-1, 0, 0); |
---|
614 | } |
---|
615 | |
---|
616 | ED4_ROOT->get_device()->top_font_overlap = 1; |
---|
617 | ED4_ROOT->get_device()->bottom_font_overlap = 1; |
---|
618 | |
---|
619 | ED4_ROOT->get_device()->text( ED4_G_STANDARD, buffer, text_x, text_y, 0, 1, 0, 0, 0); |
---|
620 | |
---|
621 | ED4_ROOT->get_device()->top_font_overlap = 0; |
---|
622 | ED4_ROOT->get_device()->bottom_font_overlap = 0; |
---|
623 | |
---|
624 | return ( ED4_R_OK ); |
---|
625 | |
---|
626 | } |
---|
627 | |
---|
628 | // -------------------------------------------------------------------------------- |
---|
629 | // ED4_text_terminal |
---|
630 | // -------------------------------------------------------------------------------- |
---|
631 | |
---|
632 | ED4_returncode ED4_text_terminal::Show(int IF_DEBUG(refresh_all), int is_cleared) |
---|
633 | { |
---|
634 | e4_assert(update_info.refresh || refresh_all); |
---|
635 | ED4_ROOT->get_device()->push_clip_scale(); |
---|
636 | if (adjust_clipping_rectangle()) { |
---|
637 | if (update_info.clear_at_refresh && !is_cleared) { |
---|
638 | clear_background(); |
---|
639 | } |
---|
640 | draw(); |
---|
641 | } |
---|
642 | ED4_ROOT->get_device()->pop_clip_scale(); |
---|
643 | |
---|
644 | ED4_cursor *cursor = &ED4_ROOT->get_ed4w()->cursor; |
---|
645 | if (this == cursor->owner_of_cursor){ |
---|
646 | ED4_ROOT->get_device()->push_clip_scale(); |
---|
647 | cursor->ShowCursor(0, ED4_C_NONE, 0); |
---|
648 | ED4_ROOT->get_device()->pop_clip_scale(); |
---|
649 | } |
---|
650 | |
---|
651 | return ED4_R_OK; |
---|
652 | } |
---|
653 | |
---|
654 | ED4_returncode ED4_text_terminal::draw( int /*only_text*/ ) |
---|
655 | { |
---|
656 | AW_pos x, y; |
---|
657 | AW_pos text_x, text_y; |
---|
658 | |
---|
659 | calc_world_coords(&x, &y); |
---|
660 | ED4_ROOT->world_to_win_coords(ED4_ROOT->get_aww(), &x, &y); |
---|
661 | |
---|
662 | text_x = x + CHARACTEROFFSET; // don't change |
---|
663 | text_y = y + INFO_TERM_TEXT_YOFFSET; |
---|
664 | |
---|
665 | ED4_ROOT->get_device()->top_font_overlap = 1; |
---|
666 | ED4_ROOT->get_device()->bottom_font_overlap = 1; |
---|
667 | |
---|
668 | if (is_species_name_terminal()) { |
---|
669 | GB_CSTR real_name = to_species_name_terminal()->get_displayed_text(); |
---|
670 | int is_marked = 0; |
---|
671 | int width_of_char; |
---|
672 | int height_of_char = -1; |
---|
673 | int paint_box = !parent->flag.is_consensus && !parent->parent->parent->flag.is_SAI; // do not paint marked-boxes for consensi and SAIs |
---|
674 | |
---|
675 | if (paint_box) { |
---|
676 | ED4_species_manager *species_man = get_parent(ED4_L_SPECIES)->to_species_manager(); |
---|
677 | GBDATA *gbd = species_man->get_species_pointer(); |
---|
678 | |
---|
679 | if (gbd) { |
---|
680 | is_marked = GB_read_flag(gbd); |
---|
681 | } |
---|
682 | |
---|
683 | width_of_char = ED4_ROOT->font_group.get_width(ED4_G_STANDARD); |
---|
684 | height_of_char = ED4_ROOT->font_group.get_height(ED4_G_STANDARD); |
---|
685 | #define MIN_MARK_BOX_SIZE 8 |
---|
686 | if (width_of_char<MIN_MARK_BOX_SIZE) width_of_char = MIN_MARK_BOX_SIZE; |
---|
687 | if (height_of_char<MIN_MARK_BOX_SIZE) height_of_char = MIN_MARK_BOX_SIZE; |
---|
688 | #undef MIN_MARK_BOX_SIZE |
---|
689 | } |
---|
690 | else { |
---|
691 | width_of_char = 0; |
---|
692 | } |
---|
693 | |
---|
694 | if (flag.selected) { |
---|
695 | ED4_ROOT->get_device()->box(ED4_G_SELECTED, true, x, y, extension.size[WIDTH], text_y-y+1, (AW_bitset)-1, 0, 0); |
---|
696 | } |
---|
697 | ED4_ROOT->get_device()->text( ED4_G_STANDARD, real_name, text_x+width_of_char, text_y, 0, 1, 0, 0, 0); |
---|
698 | |
---|
699 | if (paint_box) { |
---|
700 | int xsize = (width_of_char*6)/10; |
---|
701 | int ysize = (height_of_char*6)/10; |
---|
702 | int xoff = xsize>>1; |
---|
703 | int yoff = 0; |
---|
704 | int bx = int(text_x+xoff); |
---|
705 | int by = int(text_y-(yoff+ysize)); |
---|
706 | |
---|
707 | ED4_ROOT->get_device()->box(ED4_G_STANDARD, true, bx, by, xsize, ysize, (AW_bitset)-1, 0, 0); |
---|
708 | if (!is_marked && xsize>2 && ysize>2) { |
---|
709 | ED4_ROOT->get_device()->clear_part(bx+1, by+1, xsize-2, ysize-2, (AW_bitset)-1); |
---|
710 | } |
---|
711 | } |
---|
712 | } |
---|
713 | else { |
---|
714 | char *db_pointer = resolve_pointer_to_string_copy(); |
---|
715 | |
---|
716 | if (is_sequence_info_terminal()) { |
---|
717 | ED4_ROOT->get_device()->text( ED4_G_STANDARD, db_pointer, text_x, text_y, 0, 1, 0, 0, 4); |
---|
718 | } |
---|
719 | else if (is_pure_text_terminal()) { // normal text (i.e. remark) |
---|
720 | text_y += (SEQ_TERM_TEXT_YOFFSET-INFO_TERM_TEXT_YOFFSET); |
---|
721 | ED4_ROOT->get_device()->text( ED4_G_SEQUENCES, db_pointer, text_x, text_y, 0, 1, 0, 0, 0); |
---|
722 | } |
---|
723 | else{ |
---|
724 | e4_assert(0); // unknown terminal type |
---|
725 | } |
---|
726 | |
---|
727 | free(db_pointer); |
---|
728 | } |
---|
729 | ED4_ROOT->get_device()->top_font_overlap = 0; |
---|
730 | ED4_ROOT->get_device()->bottom_font_overlap = 0; |
---|
731 | |
---|
732 | return ( ED4_R_OK ); |
---|
733 | } |
---|
734 | |
---|
735 | ED4_text_terminal::ED4_text_terminal(GB_CSTR temp_id, AW_pos x, AW_pos y, AW_pos width, AW_pos height, ED4_manager *temp_parent) : |
---|
736 | ED4_terminal( temp_id, x, y, width, height, temp_parent ) |
---|
737 | { |
---|
738 | } |
---|
739 | |
---|
740 | |
---|
741 | ED4_text_terminal::~ED4_text_terminal() |
---|
742 | { |
---|
743 | } |
---|
744 | |
---|
745 | |
---|
746 | |
---|