1 | // ============================================================= // |
---|
2 | // // |
---|
3 | // File : ED4_main.cxx // |
---|
4 | // Purpose : // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // ============================================================= // |
---|
10 | |
---|
11 | |
---|
12 | #include "ed4_class.hxx" |
---|
13 | #include "ed4_awars.hxx" |
---|
14 | #include "ed4_edit_string.hxx" |
---|
15 | #include "ed4_nds.hxx" |
---|
16 | #include "ed4_visualizeSAI.hxx" |
---|
17 | #include "ed4_ProteinViewer.hxx" |
---|
18 | #include "ed4_protein_2nd_structure.hxx" |
---|
19 | #include "ed4_dots.hxx" |
---|
20 | #include "ed4_naligner.hxx" |
---|
21 | #include "graph_aligner_gui.hxx" |
---|
22 | #include <ed4_extern.hxx> |
---|
23 | |
---|
24 | #include <st_window.hxx> |
---|
25 | #include <gde.hxx> |
---|
26 | #include <AW_helix.hxx> |
---|
27 | #include <AP_pro_a_nucs.hxx> |
---|
28 | #include <ad_config.h> |
---|
29 | #include <awt_seq_colors.hxx> |
---|
30 | #include <awt_map_key.hxx> |
---|
31 | #include <awt.hxx> |
---|
32 | |
---|
33 | #include <aw_preset.hxx> |
---|
34 | #include <aw_awars.hxx> |
---|
35 | #include <aw_msg.hxx> |
---|
36 | #include <aw_root.hxx> |
---|
37 | #include <aw_advice.hxx> |
---|
38 | |
---|
39 | #include <arbdbt.h> |
---|
40 | |
---|
41 | #include <arb_defs.h> |
---|
42 | |
---|
43 | AW_HEADER_MAIN |
---|
44 | |
---|
45 | ED4_root *ED4_ROOT; |
---|
46 | GBDATA *GLOBAL_gb_main = NULL; // global gb_main for arb_edit4 |
---|
47 | |
---|
48 | int TERMINALHEIGHT; // this variable replaces the define |
---|
49 | |
---|
50 | int INFO_TERM_TEXT_YOFFSET; |
---|
51 | int SEQ_TERM_TEXT_YOFFSET; |
---|
52 | |
---|
53 | int MAXSEQUENCECHARACTERLENGTH; // greatest # of characters in a sequence string terminal |
---|
54 | int MAXSPECIESWIDTH; |
---|
55 | int MAXINFOWIDTH; // # of pixels used to display sequence info ("CONS", "4data", etc.) |
---|
56 | |
---|
57 | long ED4_counter = 0; |
---|
58 | |
---|
59 | size_t not_found_counter; // nr of species which haven't been found |
---|
60 | GBS_strstruct *not_found_message; |
---|
61 | |
---|
62 | long max_seq_terminal_length; // global maximum of sequence terminal length |
---|
63 | ED4_EDITMODI awar_edit_mode; |
---|
64 | long awar_edit_direction; |
---|
65 | bool move_cursor; // only needed for editing in consensus |
---|
66 | bool DRAW; |
---|
67 | bool last_window_reached; // needed for refreshing all windows (if TRUE refresh/...-flags will be cleared) |
---|
68 | |
---|
69 | inline void replaceChars(char *s, char o, char n) { |
---|
70 | while (1) { |
---|
71 | char c = *s++; |
---|
72 | if (!c) { |
---|
73 | break; |
---|
74 | } |
---|
75 | if (c==o) { |
---|
76 | s[-1] = n; |
---|
77 | } |
---|
78 | } |
---|
79 | } |
---|
80 | |
---|
81 | inline void set_and_realloc_gde_array(uchar **&the_names, uchar **&the_sequences, long &allocated, long &numberspecies, long &maxalign, |
---|
82 | const char *name, int name_len, const char *seq, int seq_len) |
---|
83 | { |
---|
84 | if (allocated==numberspecies) |
---|
85 | { |
---|
86 | long new_allocated = (allocated*3)/2; |
---|
87 | |
---|
88 | the_names = (uchar**)GB_recalloc(the_names, allocated, new_allocated, sizeof(*the_names)); |
---|
89 | the_sequences = (uchar**)GB_recalloc(the_sequences, allocated, new_allocated, sizeof(*the_sequences)); |
---|
90 | allocated = new_allocated; |
---|
91 | } |
---|
92 | |
---|
93 | the_names[numberspecies] = (uchar*)GB_calloc(name_len+1, sizeof(char)); |
---|
94 | memcpy(the_names[numberspecies], name, name_len); |
---|
95 | the_names[numberspecies][name_len] = 0; |
---|
96 | replaceChars((char*)the_names[numberspecies], ' ', '_'); |
---|
97 | |
---|
98 | the_sequences[numberspecies] = (uchar*)GB_calloc(seq_len+1, sizeof(char)); |
---|
99 | memcpy(the_sequences[numberspecies], seq, seq_len); |
---|
100 | the_sequences[numberspecies][seq_len] = 0; |
---|
101 | |
---|
102 | if (seq_len>maxalign) { |
---|
103 | maxalign = seq_len; |
---|
104 | } |
---|
105 | |
---|
106 | numberspecies++; |
---|
107 | } |
---|
108 | |
---|
109 | #ifndef NDEBUG |
---|
110 | |
---|
111 | inline const char *id(ED4_base *base) |
---|
112 | { |
---|
113 | return base->id ? base->id : "???"; |
---|
114 | } |
---|
115 | |
---|
116 | static void children(ED4_manager *manager) |
---|
117 | { |
---|
118 | int i; |
---|
119 | int anz = manager->children->members(); |
---|
120 | |
---|
121 | if (anz) { |
---|
122 | printf("("); |
---|
123 | for (i=0; i<anz; i++) { |
---|
124 | if (i) printf(", "); |
---|
125 | printf("%s", id(manager->children->member(i))); |
---|
126 | } |
---|
127 | printf(")"); |
---|
128 | } |
---|
129 | } |
---|
130 | |
---|
131 | static void baum(ED4_base *base) |
---|
132 | { |
---|
133 | static int level; |
---|
134 | |
---|
135 | level++; |
---|
136 | |
---|
137 | if (base->parent) { |
---|
138 | baum(base->parent); |
---|
139 | } |
---|
140 | |
---|
141 | printf("[%2i] %-30s", level, id(base)); |
---|
142 | if (base->is_manager()) { |
---|
143 | children(base->to_manager()); |
---|
144 | } |
---|
145 | printf("\n"); |
---|
146 | |
---|
147 | level--; |
---|
148 | } |
---|
149 | |
---|
150 | #endif |
---|
151 | |
---|
152 | static char *add_area_for_gde(ED4_area_manager *area_man, uchar **&the_names, uchar **&the_sequences, |
---|
153 | long &allocated, long &numberspecies, long &maxalign, |
---|
154 | int show_sequence, int show_SAI, int show_helix, int show_consensus, int show_remark) |
---|
155 | { |
---|
156 | ED4_terminal *terminal = area_man->get_first_terminal(); |
---|
157 | ED4_terminal *last = area_man->get_last_terminal(); |
---|
158 | |
---|
159 | for (; terminal;) { |
---|
160 | if (terminal->is_species_name_terminal()) { |
---|
161 | ED4_species_manager *species_manager = terminal->get_parent(ED4_L_SPECIES)->to_species_manager(); |
---|
162 | ED4_species_name_terminal *species_name = species_manager->search_spec_child_rek(ED4_L_SPECIES_NAME)->to_species_name_terminal(); |
---|
163 | int name_len; |
---|
164 | char *name = species_name->resolve_pointer_to_string_copy(&name_len); |
---|
165 | ED4_sequence_terminal *sequence_terminal; |
---|
166 | |
---|
167 | { |
---|
168 | ED4_base *sequence_term = species_manager->search_spec_child_rek(ED4_L_SEQUENCE_STRING); |
---|
169 | if (!sequence_term) goto end_of_loop; |
---|
170 | sequence_terminal = sequence_term->to_sequence_terminal(); |
---|
171 | } |
---|
172 | |
---|
173 | int show = -1; |
---|
174 | int is_consensus = 0; |
---|
175 | int is_SAI = 0; |
---|
176 | |
---|
177 | if (sequence_terminal->parent) { |
---|
178 | ED4_manager *cons_man = sequence_terminal->parent->parent; |
---|
179 | if (cons_man && cons_man->flag.is_consensus) { // consensus |
---|
180 | show = show_consensus; |
---|
181 | is_consensus = 1; |
---|
182 | } |
---|
183 | } |
---|
184 | |
---|
185 | if (show==-1) { |
---|
186 | if (species_manager->flag.is_SAI) { |
---|
187 | show = show_SAI; |
---|
188 | is_SAI = 1; |
---|
189 | } |
---|
190 | else { |
---|
191 | show = show_sequence; |
---|
192 | } |
---|
193 | } |
---|
194 | |
---|
195 | e4_assert(show!=-1); |
---|
196 | |
---|
197 | if (show) { |
---|
198 | int seq_len; |
---|
199 | char *seq = 0; |
---|
200 | |
---|
201 | if (is_consensus) { |
---|
202 | ED4_group_manager *group_manager = sequence_terminal->get_parent(ED4_L_GROUP)->to_group_manager(); |
---|
203 | int size = group_manager->table().size(); |
---|
204 | |
---|
205 | seq = (char*)GB_calloc(size+1, sizeof(char)); |
---|
206 | seq[size] = 0; |
---|
207 | seq = group_manager->table().build_consensus_string(0, size-1, seq); |
---|
208 | seq_len = size; |
---|
209 | |
---|
210 | e4_assert(strlen(seq) == size_t(seq_len)); |
---|
211 | |
---|
212 | ED4_group_manager *folded_group_man = sequence_terminal->is_in_folded_group(); |
---|
213 | |
---|
214 | if (folded_group_man) { // we are in a folded group |
---|
215 | if (folded_group_man==group_manager) { // we are the consensus of the folded group |
---|
216 | if (folded_group_man->is_in_folded_group()) { // a folded group inside a folded group -> do not show |
---|
217 | freenull(seq); |
---|
218 | } |
---|
219 | else { // group folded but consensus shown -> add '-' before name |
---|
220 | char *new_name = (char*)GB_calloc(name_len+2, sizeof(char)); |
---|
221 | |
---|
222 | sprintf(new_name, "-%s", name); |
---|
223 | freeset(name, new_name); |
---|
224 | name_len++; |
---|
225 | } |
---|
226 | } |
---|
227 | else { // we are really inside a folded group -> don't show |
---|
228 | freenull(seq); |
---|
229 | } |
---|
230 | } |
---|
231 | } |
---|
232 | else { // sequence |
---|
233 | if (!sequence_terminal->is_in_folded_group()) { |
---|
234 | seq = sequence_terminal->resolve_pointer_to_string_copy(&seq_len); |
---|
235 | } |
---|
236 | } |
---|
237 | |
---|
238 | if (seq) { |
---|
239 | set_and_realloc_gde_array(the_names, the_sequences, allocated, numberspecies, maxalign, name, name_len, seq, seq_len); |
---|
240 | if (show_helix && !is_SAI && ED4_ROOT->helix->size()) { |
---|
241 | char *helix = ED4_ROOT->helix->seq_2_helix(seq, '.'); |
---|
242 | set_and_realloc_gde_array(the_names, the_sequences, allocated, numberspecies, maxalign, name, name_len, helix, seq_len); |
---|
243 | free(helix); |
---|
244 | } |
---|
245 | if (show_remark && !is_consensus) { |
---|
246 | ED4_multi_sequence_manager *ms_man = sequence_terminal->get_parent(ED4_L_MULTI_SEQUENCE)->to_multi_sequence_manager(); |
---|
247 | ED4_base *remark_name_term = ms_man->search_ID("remark"); |
---|
248 | if (remark_name_term) { |
---|
249 | ED4_base *remark_term = remark_name_term->get_next_terminal(); |
---|
250 | e4_assert(remark_term); |
---|
251 | |
---|
252 | int remark_len; |
---|
253 | char *remark = remark_term->resolve_pointer_to_string_copy(&remark_len); |
---|
254 | |
---|
255 | replaceChars(remark, ' ', '_'); |
---|
256 | set_and_realloc_gde_array(the_names, the_sequences, allocated, numberspecies, maxalign, name, name_len, remark, remark_len); |
---|
257 | free(remark); |
---|
258 | } |
---|
259 | } |
---|
260 | free(seq); |
---|
261 | } |
---|
262 | } |
---|
263 | free(name); |
---|
264 | } |
---|
265 | end_of_loop : |
---|
266 | if (terminal==last) break; |
---|
267 | terminal = terminal->get_next_terminal(); |
---|
268 | } |
---|
269 | |
---|
270 | return 0; |
---|
271 | } |
---|
272 | |
---|
273 | static char *ED4_create_sequences_for_gde(AW_CL, GBDATA **&the_species, uchar **&the_names, uchar **&the_sequences, long &numberspecies, long &maxalign) { |
---|
274 | int top = ED4_ROOT->aw_root->awar("gde/top_area")->read_int(); |
---|
275 | int tops = ED4_ROOT->aw_root->awar("gde/top_area_sai")->read_int(); |
---|
276 | int toph = ED4_ROOT->aw_root->awar("gde/top_area_helix")->read_int(); |
---|
277 | int topk = ED4_ROOT->aw_root->awar("gde/top_area_kons")->read_int(); |
---|
278 | int topr = ED4_ROOT->aw_root->awar("gde/top_area_remark")->read_int(); |
---|
279 | int middle = ED4_ROOT->aw_root->awar("gde/middle_area")->read_int(); |
---|
280 | int middles = ED4_ROOT->aw_root->awar("gde/middle_area_sai")->read_int(); |
---|
281 | int middleh = ED4_ROOT->aw_root->awar("gde/middle_area_helix")->read_int(); |
---|
282 | int middlek = ED4_ROOT->aw_root->awar("gde/middle_area_kons")->read_int(); |
---|
283 | int middler = ED4_ROOT->aw_root->awar("gde/middle_area_remark")->read_int(); |
---|
284 | |
---|
285 | numberspecies = 0; |
---|
286 | maxalign = 0; |
---|
287 | |
---|
288 | long allocated = 100; |
---|
289 | the_species = 0; |
---|
290 | the_names = (uchar**)GB_calloc(allocated, sizeof(*the_names)); |
---|
291 | the_sequences = (uchar**)GB_calloc(allocated, sizeof(*the_sequences)); |
---|
292 | |
---|
293 | char *err = add_area_for_gde(ED4_ROOT->top_area_man, the_names, the_sequences, allocated, numberspecies, maxalign, top, tops, toph, topk, topr); |
---|
294 | if (!err) { |
---|
295 | err = add_area_for_gde(ED4_ROOT->middle_area_man, the_names, the_sequences, allocated, numberspecies, maxalign, middle, middles, middleh, middlek, middler); |
---|
296 | } |
---|
297 | |
---|
298 | if (allocated!=(numberspecies+1)) { |
---|
299 | the_names = (uchar**)GB_recalloc(the_names, allocated, numberspecies+1, sizeof(*the_names)); |
---|
300 | the_sequences = (uchar**)GB_recalloc(the_sequences, allocated, numberspecies+1, sizeof(*the_sequences)); |
---|
301 | } |
---|
302 | |
---|
303 | return err; |
---|
304 | } |
---|
305 | |
---|
306 | static void ED4_gap_chars_changed(AW_root *root) { |
---|
307 | char *gap_chars = root->awar_string(ED4_AWAR_GAP_CHARS)->read_string(); |
---|
308 | |
---|
309 | ED4_init_is_align_character(gap_chars); |
---|
310 | free(gap_chars); |
---|
311 | } |
---|
312 | |
---|
313 | static void ED4_edit_direction_changed(AW_root * /* awr */) { |
---|
314 | ED4_ROOT->get_ed4w()->cursor.redraw(); |
---|
315 | } |
---|
316 | |
---|
317 | void ED4_expose_all_windows() { |
---|
318 | for (ED4_window *ew = ED4_ROOT->first_window; ew; ew = ew->next) { |
---|
319 | ED4_expose_cb(ew->aww, 0, 0); |
---|
320 | } |
---|
321 | } |
---|
322 | |
---|
323 | static void ED4_do_expose(AW_root *) { |
---|
324 | ED4_expose_all_windows(); |
---|
325 | } |
---|
326 | |
---|
327 | static void ed4_bind_mainDB_awar_callbacks(AW_root *root) { |
---|
328 | // callbacks to main DB awars are bound later |
---|
329 | // (otherwise its easy to crash the editor by clicking around in ARB_NTREE during editor startup) |
---|
330 | |
---|
331 | root->awar(AWAR_SET_CURSOR_POSITION)->add_callback(ED4_remote_set_cursor_cb, 0, 0); |
---|
332 | root->awar(AWAR_SPECIES_NAME)->add_callback(ED4_selected_species_changed_cb); |
---|
333 | root->awar(AWAR_SAI_NAME)->add_callback(ED4_selected_SAI_changed_cb); |
---|
334 | } |
---|
335 | |
---|
336 | static void ed4_create_mainDB_awars(AW_root *root, const char *config_name) { |
---|
337 | // WARNING: do not bind callbacks here -> do it in ed4_bind_mainDB_awar_callbacks() |
---|
338 | |
---|
339 | root->awar_string(AWAR_ITARGET_STRING, "", GLOBAL_gb_main); |
---|
340 | |
---|
341 | root->awar_int(AWAR_CURSOR_POSITION, info2bio(0), GLOBAL_gb_main); |
---|
342 | root->awar_int(AWAR_CURSOR_POSITION_LOCAL, 0, GLOBAL_gb_main); |
---|
343 | root->awar_int(AWAR_SET_CURSOR_POSITION, 1, GLOBAL_gb_main); |
---|
344 | |
---|
345 | root->awar_string(AWAR_FIELD_CHOSEN, "", GLOBAL_gb_main); |
---|
346 | |
---|
347 | root->awar_string(AWAR_SPECIES_NAME, "", GLOBAL_gb_main); |
---|
348 | root->awar_string(AWAR_SAI_NAME, "", GLOBAL_gb_main); |
---|
349 | root->awar_string(AWAR_SAI_GLOBAL, "", GLOBAL_gb_main); |
---|
350 | |
---|
351 | root->awar_string(AWAR_EDIT_CONFIGURATION, config_name, GLOBAL_gb_main); |
---|
352 | |
---|
353 | ED4_create_search_awars(root); |
---|
354 | } |
---|
355 | |
---|
356 | static void ed4_create_all_awars(AW_root *root, const char *config_name) { |
---|
357 | // Note: cursor awars are created in window constructor |
---|
358 | |
---|
359 | ed4_create_mainDB_awars(root, config_name); |
---|
360 | |
---|
361 | #if defined(DEBUG) |
---|
362 | AWT_create_db_browser_awars(root, AW_ROOT_DEFAULT); |
---|
363 | #endif // DEBUG |
---|
364 | |
---|
365 | create_naligner_variables(root, AW_ROOT_DEFAULT); |
---|
366 | create_sina_variables(root, AW_ROOT_DEFAULT); |
---|
367 | |
---|
368 | awar_edit_mode = AD_ALIGN; |
---|
369 | |
---|
370 | int def_sec_level = 0; |
---|
371 | #ifdef DEBUG |
---|
372 | def_sec_level = 6; // don't nag developers |
---|
373 | #endif |
---|
374 | root->awar_int(AWAR_EDIT_SECURITY_LEVEL, def_sec_level, AW_ROOT_DEFAULT); |
---|
375 | |
---|
376 | root->awar_int(AWAR_EDIT_SECURITY_LEVEL_ALIGN, def_sec_level, AW_ROOT_DEFAULT)->add_callback(ed4_changesecurity, (AW_CL) def_sec_level); |
---|
377 | root->awar_int(AWAR_EDIT_SECURITY_LEVEL_CHANGE, def_sec_level, AW_ROOT_DEFAULT)->add_callback(ed4_changesecurity, (AW_CL) def_sec_level); |
---|
378 | |
---|
379 | root->awar_int(AWAR_EDIT_MODE, 0)->add_callback(ed4_change_edit_mode, (AW_CL)0); |
---|
380 | root->awar_int(AWAR_INSERT_MODE, 1)->add_callback(ed4_change_edit_mode, (AW_CL)0); |
---|
381 | |
---|
382 | root->awar_int(AWAR_EDIT_DIRECTION, 1)->add_target_var(&awar_edit_direction)->add_callback(ED4_edit_direction_changed); |
---|
383 | root->awar_int(AWAR_EDIT_HELIX_SPACING, 0)->add_target_var(&ED4_ROOT->helix_add_spacing)->add_callback(ED4_do_expose); |
---|
384 | root->awar_int(AWAR_EDIT_TERMINAL_SPACING, 0)->add_target_var(&ED4_ROOT->terminal_add_spacing)->add_callback(ED4_do_expose); |
---|
385 | root->awar_int(AWAR_EDIT_TITLE_MODE, 0); |
---|
386 | |
---|
387 | ed4_changesecurity(root, 0); |
---|
388 | |
---|
389 | root->awar_int(ED4_AWAR_COMPRESS_SEQUENCE_GAPS, 0)->add_callback(ED4_compression_toggle_changed_cb, AW_CL(0), 0); |
---|
390 | root->awar_int(ED4_AWAR_COMPRESS_SEQUENCE_HIDE, 0)->add_callback(ED4_compression_toggle_changed_cb, AW_CL(1), 0); |
---|
391 | root->awar_int(ED4_AWAR_COMPRESS_SEQUENCE_TYPE, 0)->add_callback(ED4_compression_changed_cb); |
---|
392 | root->awar_int(ED4_AWAR_COMPRESS_SEQUENCE_PERCENT, 1)->add_callback(ED4_compression_changed_cb)->set_minmax(1, 99); |
---|
393 | |
---|
394 | root->awar_int(ED4_AWAR_DIGITS_AS_REPEAT, 0); |
---|
395 | root->awar_int(ED4_AWAR_FAST_CURSOR_JUMP, 0); |
---|
396 | root->awar_int(ED4_AWAR_CURSOR_TYPE, (int)ED4_RIGHT_ORIENTED_CURSOR); |
---|
397 | |
---|
398 | ED4_create_consensus_awars(root); |
---|
399 | ED4_create_NDS_awars(root); |
---|
400 | |
---|
401 | root->awar_string(ED4_AWAR_REP_SEARCH_PATTERN, "."); |
---|
402 | root->awar_string(ED4_AWAR_REP_REPLACE_PATTERN, "-"); |
---|
403 | |
---|
404 | root->awar_int(ED4_AWAR_SCROLL_SPEED_X, 40); |
---|
405 | root->awar_int(ED4_AWAR_SCROLL_SPEED_Y, 20); |
---|
406 | root->awar_int(ED4_AWAR_SCROLL_MARGIN, 5); |
---|
407 | |
---|
408 | root->awar_string(ED4_AWAR_SPECIES_TO_CREATE, ""); |
---|
409 | |
---|
410 | root->awar_string(ED4_AWAR_GAP_CHARS, ".-~?")->add_callback(ED4_gap_chars_changed); |
---|
411 | ED4_gap_chars_changed(root); |
---|
412 | root->awar_int(ED4_AWAR_ANNOUNCE_CHECKSUM_CHANGES, 0); |
---|
413 | |
---|
414 | GDE_create_var(ED4_ROOT->aw_root, ED4_ROOT->props_db, GLOBAL_gb_main, ED4_create_sequences_for_gde, GDE_WINDOWTYPE_EDIT4, 0); |
---|
415 | |
---|
416 | root->awar_string(ED4_AWAR_CREATE_FROM_CONS_REPL_EQUAL, "-"); |
---|
417 | root->awar_string(ED4_AWAR_CREATE_FROM_CONS_REPL_POINT, "?"); |
---|
418 | root->awar_int(ED4_AWAR_CREATE_FROM_CONS_CREATE_POINTS, 1); |
---|
419 | root->awar_int(ED4_AWAR_CREATE_FROM_CONS_ALL_UPPER, 1); |
---|
420 | root->awar_int(ED4_AWAR_CREATE_FROM_CONS_DATA_SOURCE, 0); |
---|
421 | |
---|
422 | ED4_createVisualizeSAI_Awars(root, AW_ROOT_DEFAULT); |
---|
423 | ED4_create_dot_missing_bases_awars(root, AW_ROOT_DEFAULT); |
---|
424 | |
---|
425 | // Create Awars To Be Used In Protein Viewer |
---|
426 | if (ED4_ROOT->alignment_type == GB_AT_DNA) { |
---|
427 | PV_CreateAwars(root, AW_ROOT_DEFAULT); |
---|
428 | } |
---|
429 | |
---|
430 | // create awars to be used for protein secondary structure match |
---|
431 | if (ED4_ROOT->alignment_type == GB_AT_AA) { |
---|
432 | root->awar_int(PFOLD_AWAR_ENABLE, 1); |
---|
433 | root->awar_string(PFOLD_AWAR_SELECTED_SAI, "PFOLD"); |
---|
434 | root->awar_int(PFOLD_AWAR_MATCH_METHOD, SECSTRUCT_SEQUENCE); |
---|
435 | int pt; |
---|
436 | char awar[256]; |
---|
437 | for (int i = 0; pfold_match_type_awars[i].name; i++) { |
---|
438 | e4_assert(i<PFOLD_PAIRS); |
---|
439 | pt = pfold_match_type_awars[i].value; |
---|
440 | sprintf(awar, PFOLD_AWAR_PAIR_TEMPLATE, pfold_match_type_awars[i].name); |
---|
441 | root->awar_string(awar, pfold_pairs[pt])->add_target_var(&pfold_pairs[pt]); |
---|
442 | sprintf(awar, PFOLD_AWAR_SYMBOL_TEMPLATE, pfold_match_type_awars[i].name); |
---|
443 | root->awar_string(awar, pfold_pair_chars[pt])->add_target_var(&pfold_pair_chars[pt]); |
---|
444 | } |
---|
445 | root->awar_string(PFOLD_AWAR_SYMBOL_TEMPLATE_2, PFOLD_PAIR_CHARS_2); |
---|
446 | root->awar_string(PFOLD_AWAR_SAI_FILTER, "pfold"); |
---|
447 | } |
---|
448 | |
---|
449 | GB_ERROR error = ARB_init_global_awars(root, AW_ROOT_DEFAULT, GLOBAL_gb_main); |
---|
450 | if (error) aw_message(error); |
---|
451 | } |
---|
452 | |
---|
453 | const char *ED4_propertyName(int mode) { |
---|
454 | // mode == 0 -> alignment specific (e.g. "edit4_ali_16s.arb") |
---|
455 | // mode == 1 -> alignment-type specific (e.g. "edit4_rna.arb") |
---|
456 | // mode == 2 -> unspecific (normal) (always "edit4.arb") |
---|
457 | // |
---|
458 | // Note : result is only valid until next call |
---|
459 | |
---|
460 | e4_assert(mode >= 0 && mode <= 2); |
---|
461 | |
---|
462 | const char *result; |
---|
463 | if (mode == 2) { |
---|
464 | result = "edit4.arb"; |
---|
465 | } |
---|
466 | else { |
---|
467 | static char *ali_name = 0; |
---|
468 | static char *ali_type = 0; |
---|
469 | static char *result_copy = 0; |
---|
470 | |
---|
471 | if (!ali_name) { |
---|
472 | GB_transaction dummy(GLOBAL_gb_main); |
---|
473 | ali_name = GBT_get_default_alignment(GLOBAL_gb_main); |
---|
474 | ali_type = GBT_get_alignment_type_string(GLOBAL_gb_main, ali_name); |
---|
475 | result_copy = new char[21+strlen(ali_name)]; |
---|
476 | } |
---|
477 | |
---|
478 | sprintf(result_copy, "edit4_%s.arb", mode == 0 ? ali_name : ali_type); |
---|
479 | result = result_copy; |
---|
480 | } |
---|
481 | |
---|
482 | return result; |
---|
483 | } |
---|
484 | |
---|
485 | int ARB_main(int argc, const char *argv[]) { |
---|
486 | const char *data_path = ":"; |
---|
487 | const char *err = NULL; |
---|
488 | char *config_name = NULL; |
---|
489 | |
---|
490 | if (argc > 1 && ((strcmp(argv[1], "-h") == 0) || (strcmp(argv[1], "--help") == 0))) { |
---|
491 | fprintf(stderr, |
---|
492 | "\n" |
---|
493 | "arb_edit4 commandline reference:\n" |
---|
494 | "--------------------------------\n" |
---|
495 | "\n" |
---|
496 | "Usage: arb_edit4 [options] database\n" |
---|
497 | "\n" |
---|
498 | "database name of database or ':' to connect to arb-database-server\n" |
---|
499 | "\n" |
---|
500 | "Options:\n" |
---|
501 | "-c config loads configuration 'config' (default: 'default_configuration')\n" |
---|
502 | "\n" |
---|
503 | ); |
---|
504 | } |
---|
505 | |
---|
506 | if (argc > 1 && strcmp(argv[1], "-c") == 0) { |
---|
507 | config_name = new char[strlen(argv[2])+1]; |
---|
508 | strcpy(config_name, argv[2]); |
---|
509 | argc -= 2; argv += 2; |
---|
510 | } |
---|
511 | else { // load 'default_configuration' if no command line is given |
---|
512 | config_name = strdup("default_configuration"); |
---|
513 | err = "Using 'default_configuration'"; |
---|
514 | #ifndef NDEBUG |
---|
515 | err = 0; |
---|
516 | #endif |
---|
517 | } |
---|
518 | |
---|
519 | if (argc>1) { |
---|
520 | data_path = argv[1]; |
---|
521 | argc--; argv++; |
---|
522 | } |
---|
523 | |
---|
524 | aw_initstatus(); |
---|
525 | |
---|
526 | GB_shell shell; |
---|
527 | GLOBAL_gb_main = GB_open(data_path, "rwt"); |
---|
528 | if (!GLOBAL_gb_main) |
---|
529 | { |
---|
530 | GB_print_error(); |
---|
531 | exit (-1); |
---|
532 | } |
---|
533 | |
---|
534 | #if defined(DEBUG) |
---|
535 | AWT_announce_db_to_browser(GLOBAL_gb_main, GBS_global_string("ARB database (%s)", data_path)); |
---|
536 | #endif // DEBUG |
---|
537 | |
---|
538 | ED4_ROOT = new ED4_root; |
---|
539 | |
---|
540 | init_Advisor(ED4_ROOT->aw_root); |
---|
541 | |
---|
542 | ED4_ROOT->database = new EDB_root_bact; |
---|
543 | ED4_ROOT->init_alignment(); |
---|
544 | ed4_create_all_awars(ED4_ROOT->aw_root, config_name); |
---|
545 | |
---|
546 | ED4_ROOT->st_ml = STAT_create_ST_ML(GLOBAL_gb_main); |
---|
547 | ED4_ROOT->sequence_colors = new AWT_seq_colors(AW_ROOT_DEFAULT, ED4_G_SEQUENCES, ED4_refresh_window, 0, 0); |
---|
548 | |
---|
549 | ED4_ROOT->edk = new ed_key; |
---|
550 | ED4_ROOT->edk->create_awars(ED4_ROOT->aw_root); |
---|
551 | |
---|
552 | ED4_ROOT->helix = new AW_helix(ED4_ROOT->aw_root); |
---|
553 | |
---|
554 | if (err) { |
---|
555 | aw_message(err); |
---|
556 | err = 0; |
---|
557 | } |
---|
558 | |
---|
559 | switch (ED4_ROOT->alignment_type) { |
---|
560 | case GB_AT_RNA: |
---|
561 | case GB_AT_DNA: |
---|
562 | err = ED4_ROOT->helix->init(GLOBAL_gb_main); |
---|
563 | break; |
---|
564 | |
---|
565 | case GB_AT_AA: |
---|
566 | err = ED4_pfold_set_SAI(&ED4_ROOT->protstruct, GLOBAL_gb_main, ED4_ROOT->alignment_name, &ED4_ROOT->protstruct_len); |
---|
567 | break; |
---|
568 | |
---|
569 | default: |
---|
570 | e4_assert(0); |
---|
571 | break; |
---|
572 | } |
---|
573 | |
---|
574 | if (err) aw_message(err); // write to console |
---|
575 | ED4_ROOT->sequence_colors->aww = ED4_ROOT->create_new_window(); // create first editor window |
---|
576 | if (err) aw_message(err); // write again to status window |
---|
577 | |
---|
578 | { |
---|
579 | int found_config = 0; |
---|
580 | |
---|
581 | if (config_name) |
---|
582 | { |
---|
583 | GB_begin_transaction(GLOBAL_gb_main); |
---|
584 | GBDATA *gb_configuration = GBT_find_configuration(GLOBAL_gb_main, config_name); |
---|
585 | |
---|
586 | if (gb_configuration) { |
---|
587 | GBDATA *gb_middle_area = GB_search(gb_configuration, "middle_area", GB_FIND); |
---|
588 | GBDATA *gb_top_area = GB_search(gb_configuration, "top_area", GB_FIND); |
---|
589 | char *config_data_middle = GB_read_as_string(gb_middle_area); |
---|
590 | char *config_data_top = GB_read_as_string(gb_top_area); |
---|
591 | |
---|
592 | ED4_ROOT->create_hierarchy(config_data_middle, config_data_top); // create internal hierarchy |
---|
593 | free(config_data_middle); |
---|
594 | free(config_data_top); |
---|
595 | |
---|
596 | found_config = 1; |
---|
597 | } |
---|
598 | else { |
---|
599 | aw_message(GBS_global_string("Could not find configuration '%s'", config_name)); |
---|
600 | } |
---|
601 | |
---|
602 | GB_commit_transaction(GLOBAL_gb_main); |
---|
603 | } |
---|
604 | |
---|
605 | if (!found_config) { |
---|
606 | // create internal hierarchy |
---|
607 | |
---|
608 | char *as_mid = ED4_ROOT->database->make_string(); |
---|
609 | char *as_top = ED4_ROOT->database->make_top_bot_string(); |
---|
610 | |
---|
611 | ED4_ROOT->create_hierarchy(as_mid, as_top); |
---|
612 | |
---|
613 | delete as_mid; |
---|
614 | delete as_top; |
---|
615 | } |
---|
616 | } |
---|
617 | |
---|
618 | // now bind DB depending callbacks |
---|
619 | |
---|
620 | ed4_bind_mainDB_awar_callbacks(ED4_ROOT->aw_root); |
---|
621 | { |
---|
622 | GB_transaction dummy(GLOBAL_gb_main); |
---|
623 | GBDATA *species_container = GB_search(GLOBAL_gb_main, "species_data", GB_FIND); |
---|
624 | GB_add_callback(species_container, (GB_CB_TYPE)GB_CB_CHANGED, (GB_CB)ED4_species_container_changed_cb, 0); // callback if species_data changes |
---|
625 | |
---|
626 | ED4_elements_in_species_container = GB_number_of_subentries(species_container); // store # of species |
---|
627 | #if defined(DEBUG) && 0 |
---|
628 | printf("Species container contains %i species (at startup)\n", ED4_elements_in_species_container); |
---|
629 | #endif |
---|
630 | } |
---|
631 | |
---|
632 | // Create Additional sequence (aminoacid) terminals to be used in Protein Viewer |
---|
633 | if (ED4_ROOT->alignment_type == GB_AT_DNA) { |
---|
634 | PV_CallBackFunction(ED4_ROOT->aw_root); |
---|
635 | } |
---|
636 | |
---|
637 | AWT_install_cb_guards(); |
---|
638 | ED4_ROOT->aw_root->main_loop(); // enter main-loop |
---|
639 | |
---|
640 | return EXIT_SUCCESS; |
---|
641 | } |
---|
642 | |
---|