| 1 | #include <stdio.h> |
|---|
| 2 | #include <stdlib.h> |
|---|
| 3 | #include <string.h> |
|---|
| 4 | #include <memory.h> |
|---|
| 5 | #include <malloc.h> |
|---|
| 6 | |
|---|
| 7 | #include <arbdb.h> |
|---|
| 8 | #include <arbdbt.h> |
|---|
| 9 | |
|---|
| 10 | #include <aw_root.hxx> |
|---|
| 11 | #include <aw_device.hxx> |
|---|
| 12 | #include <aw_window.hxx> |
|---|
| 13 | #include <aw_preset.hxx> |
|---|
| 14 | #include <aw_awars.hxx> |
|---|
| 15 | #include <awt_seq_colors.hxx> |
|---|
| 16 | #include <awt_map_key.hxx> |
|---|
| 17 | #include <awt.hxx> |
|---|
| 18 | #define _USE_AW_WINDOW |
|---|
| 19 | #include <BI_helix.hxx> |
|---|
| 20 | #include <st_window.hxx> |
|---|
| 21 | #include <gde.hxx> |
|---|
| 22 | |
|---|
| 23 | #include "ed4_class.hxx" |
|---|
| 24 | #include "ed4_awars.hxx" |
|---|
| 25 | #include "ed4_defs.hxx" |
|---|
| 26 | #include "ed4_edit_string.hxx" |
|---|
| 27 | #include "ed4_nds.hxx" |
|---|
| 28 | |
|---|
| 29 | #include "edit_naligner.hxx" |
|---|
| 30 | |
|---|
| 31 | AW_HEADER_MAIN |
|---|
| 32 | |
|---|
| 33 | ED4_root *ED4_ROOT; |
|---|
| 34 | GBDATA *gb_main = NULL; |
|---|
| 35 | ED4_database *main_db; |
|---|
| 36 | long global_width = 100; |
|---|
| 37 | |
|---|
| 38 | int TERMINALHEIGHT; // this variable replaces the define |
|---|
| 39 | int MAXLETTERDESCENT; // Important for drawing text on the screen |
|---|
| 40 | int MAXSEQUENCECHARACTERLENGTH; // greatest # of characters in a sequence string terminal |
|---|
| 41 | int MAXSPECIESWIDTH; |
|---|
| 42 | int MAXINFOWIDTH; // # of characters used to display sequence info ("CONS", "4data", etc.) |
|---|
| 43 | int MAXCHARWIDTH; |
|---|
| 44 | int MARGIN; // sets margin for cursor moves in characters |
|---|
| 45 | long ED4_counter = 0; |
|---|
| 46 | long all_found; // nr of species which haven't been found |
|---|
| 47 | long species_read; // nr of species read; important during loading |
|---|
| 48 | void *not_found_message; |
|---|
| 49 | long max_seq_terminal_length; // global maximum of sequence terminal length |
|---|
| 50 | ED4_EDITMODI awar_edit_modus; |
|---|
| 51 | long awar_edit_direction; |
|---|
| 52 | bool move_cursor; // only needed for editing in consensus |
|---|
| 53 | bool DRAW; |
|---|
| 54 | bool last_window_reached; // needed for refreshing all windows (if TRUE refresh/...-flags will be cleared) |
|---|
| 55 | |
|---|
| 56 | double status_add_count; // only needed for loading configuration |
|---|
| 57 | double status_total_count; |
|---|
| 58 | bool loading; |
|---|
| 59 | //long last_used_timestamp; |
|---|
| 60 | |
|---|
| 61 | int ED4_font_info::max_width = 0; |
|---|
| 62 | int ED4_font_info::max_height = 0; |
|---|
| 63 | int ED4_font_info::max_ascent = 0; |
|---|
| 64 | int ED4_font_info::max_descent = 0; |
|---|
| 65 | |
|---|
| 66 | void ED4_config_change_cb(AW_root *) |
|---|
| 67 | { |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | inline void replaceChars(char *s, char o, char n) |
|---|
| 71 | { |
|---|
| 72 | while (1) { |
|---|
| 73 | char c = *s++; |
|---|
| 74 | if (!c) { |
|---|
| 75 | break; |
|---|
| 76 | } |
|---|
| 77 | if (c==o) { |
|---|
| 78 | s[-1] = n; |
|---|
| 79 | } |
|---|
| 80 | } |
|---|
| 81 | } |
|---|
| 82 | |
|---|
| 83 | inline void set_and_realloc_gde_array(uchar **&the_names, uchar **&the_sequences, long &allocated, long &numberspecies, long &maxalign, |
|---|
| 84 | const char *name, int name_len, const char *seq, int seq_len) |
|---|
| 85 | { |
|---|
| 86 | if (allocated==numberspecies) |
|---|
| 87 | { |
|---|
| 88 | long new_allocated = (allocated*3)/2; |
|---|
| 89 | |
|---|
| 90 | the_names = (uchar**)GB_recalloc(the_names, allocated, new_allocated, sizeof(*the_names)); |
|---|
| 91 | the_sequences = (uchar**)GB_recalloc(the_sequences, allocated, new_allocated, sizeof(*the_sequences)); |
|---|
| 92 | allocated = new_allocated; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | the_names[numberspecies] = (uchar*)GB_calloc(name_len+1, sizeof(char)); |
|---|
| 96 | memcpy(the_names[numberspecies], name, name_len); |
|---|
| 97 | the_names[numberspecies][name_len] = 0; |
|---|
| 98 | replaceChars((char*)the_names[numberspecies], ' ', '_'); |
|---|
| 99 | |
|---|
| 100 | the_sequences[numberspecies] = (uchar*)GB_calloc(seq_len+1, sizeof(char)); |
|---|
| 101 | memcpy(the_sequences[numberspecies], seq, seq_len); |
|---|
| 102 | the_sequences[numberspecies][seq_len] = 0; |
|---|
| 103 | |
|---|
| 104 | if (seq_len>maxalign) { |
|---|
| 105 | maxalign = seq_len; |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | numberspecies++; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | #ifndef NDEBUG |
|---|
| 112 | |
|---|
| 113 | inline const char *id(ED4_base *base) |
|---|
| 114 | { |
|---|
| 115 | return base->id ? base->id : "???"; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | static void childs(ED4_manager *manager) |
|---|
| 119 | { |
|---|
| 120 | int i; |
|---|
| 121 | int anz = manager->children->members(); |
|---|
| 122 | |
|---|
| 123 | if (anz) { |
|---|
| 124 | printf("("); |
|---|
| 125 | for (i=0; i<anz; i++) { |
|---|
| 126 | if (i) printf(", "); |
|---|
| 127 | printf("%s", id(manager->children->member(i))); |
|---|
| 128 | } |
|---|
| 129 | printf(")"); |
|---|
| 130 | } |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | void baum(ED4_base *base) |
|---|
| 134 | { |
|---|
| 135 | static int level; |
|---|
| 136 | |
|---|
| 137 | level++; |
|---|
| 138 | |
|---|
| 139 | if (base->parent) { |
|---|
| 140 | baum(base->parent); |
|---|
| 141 | } |
|---|
| 142 | |
|---|
| 143 | printf("[%2i] %-30s", level, id(base)); |
|---|
| 144 | if (base->is_manager()) { |
|---|
| 145 | childs(base->to_manager()); |
|---|
| 146 | } |
|---|
| 147 | printf("\n"); |
|---|
| 148 | |
|---|
| 149 | level--; |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | void baum(const char *id) |
|---|
| 153 | { |
|---|
| 154 | baum(ED4_ROOT->root_group_man->search_ID(id)); |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | #endif |
|---|
| 158 | |
|---|
| 159 | static char *add_area_for_gde(ED4_area_manager *area_man, uchar **&the_names, uchar **&the_sequences, |
|---|
| 160 | long &allocated, long &numberspecies, long &maxalign, |
|---|
| 161 | int show_sequence, int show_SAI, int show_helix, int show_consensus, int show_remark) |
|---|
| 162 | { |
|---|
| 163 | ED4_terminal *terminal = area_man->get_first_terminal(), |
|---|
| 164 | *last = area_man->get_last_terminal(); |
|---|
| 165 | // ED4_multi_species_manager *last_multi = 0; |
|---|
| 166 | |
|---|
| 167 | for (;terminal;) { |
|---|
| 168 | if (terminal->is_species_name_terminal()) { |
|---|
| 169 | ED4_species_manager *species_manager = terminal->get_parent(ED4_L_SPECIES)->to_species_manager(); |
|---|
| 170 | ED4_species_name_terminal *species_name = species_manager->search_spec_child_rek(ED4_L_SPECIES_NAME)->to_species_name_terminal(); |
|---|
| 171 | int name_len; |
|---|
| 172 | char *name = species_name->resolve_pointer_to_string(&name_len); |
|---|
| 173 | ED4_sequence_terminal *sequence_terminal; |
|---|
| 174 | |
|---|
| 175 | { |
|---|
| 176 | ED4_base *sequence_term = species_manager->search_spec_child_rek(ED4_L_SEQUENCE_STRING); |
|---|
| 177 | if (!sequence_term) goto end_of_loop; |
|---|
| 178 | sequence_terminal = sequence_term->to_sequence_terminal(); |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | int show = -1; |
|---|
| 182 | int is_consensus = 0; |
|---|
| 183 | int is_SAI = 0; |
|---|
| 184 | |
|---|
| 185 | if (sequence_terminal->parent) { |
|---|
| 186 | ED4_manager *cons_man = sequence_terminal->parent->parent; |
|---|
| 187 | if (cons_man && cons_man->flag.is_consensus) { // consensus |
|---|
| 188 | show = show_consensus; |
|---|
| 189 | is_consensus = 1; |
|---|
| 190 | } |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | if (show==-1) { |
|---|
| 194 | if (species_manager->flag.is_SAI) { |
|---|
| 195 | show = show_SAI; |
|---|
| 196 | is_SAI = 1; |
|---|
| 197 | } |
|---|
| 198 | else { |
|---|
| 199 | show = show_sequence; |
|---|
| 200 | } |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | e4_assert(show!=-1); |
|---|
| 204 | |
|---|
| 205 | if (show) { |
|---|
| 206 | int seq_len; |
|---|
| 207 | char *seq = 0; |
|---|
| 208 | |
|---|
| 209 | if (is_consensus) { |
|---|
| 210 | ED4_group_manager *group_manager = sequence_terminal->get_parent(ED4_L_GROUP)->to_group_manager(); |
|---|
| 211 | int size = group_manager->table().size(); |
|---|
| 212 | |
|---|
| 213 | seq = GB_give_buffer(size+1); |
|---|
| 214 | seq[size] = 0; |
|---|
| 215 | seq = group_manager->table().build_consensus_string(0, size-1, seq); |
|---|
| 216 | seq_len = size; |
|---|
| 217 | e4_assert(strlen(seq)==size_t(seq_len)); |
|---|
| 218 | |
|---|
| 219 | ED4_group_manager *folded_group_man = sequence_terminal->is_in_folded_group(); |
|---|
| 220 | |
|---|
| 221 | if (folded_group_man) { // we are in a folded group |
|---|
| 222 | if (folded_group_man==group_manager) { // we are the consensus of the folded group |
|---|
| 223 | if (folded_group_man->is_in_folded_group()) { // a folded group inside a folded group -> do not show |
|---|
| 224 | seq = 0; |
|---|
| 225 | } |
|---|
| 226 | else { // group folded but consensus shown -> add '-' before name |
|---|
| 227 | char *new_name = GB_give_buffer2(name_len+2); |
|---|
| 228 | #ifndef NDEBUG |
|---|
| 229 | memset(new_name, 0, name_len+2); // avoids (rui) |
|---|
| 230 | #endif |
|---|
| 231 | sprintf(new_name, "-%s", name); |
|---|
| 232 | name = new_name; |
|---|
| 233 | name_len++; |
|---|
| 234 | } |
|---|
| 235 | } |
|---|
| 236 | else { // we are really inside a folded group -> don't show |
|---|
| 237 | seq = 0; |
|---|
| 238 | } |
|---|
| 239 | } |
|---|
| 240 | } |
|---|
| 241 | else { // sequence |
|---|
| 242 | if (!sequence_terminal->is_in_folded_group()) { |
|---|
| 243 | seq = sequence_terminal->resolve_pointer_to_string(&seq_len); |
|---|
| 244 | } |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | if (seq) { |
|---|
| 248 | set_and_realloc_gde_array(the_names, the_sequences, allocated, numberspecies, maxalign, name, name_len, seq, seq_len); |
|---|
| 249 | if (show_helix && !is_SAI && ED4_ROOT->helix->size) { |
|---|
| 250 | char *helix = ED4_ROOT->helix->seq_2_helix(seq, '.'); |
|---|
| 251 | set_and_realloc_gde_array(the_names, the_sequences, allocated, numberspecies, maxalign, name, name_len, helix, seq_len); |
|---|
| 252 | } |
|---|
| 253 | if (show_remark && !is_consensus) { |
|---|
| 254 | ED4_multi_sequence_manager *ms_man = sequence_terminal->get_parent(ED4_L_MULTI_SEQUENCE)->to_multi_sequence_manager(); |
|---|
| 255 | ED4_base *remark_name_term = ms_man->search_ID("remark"); |
|---|
| 256 | if (remark_name_term) { |
|---|
| 257 | ED4_base *remark_term = remark_name_term->get_next_terminal(); |
|---|
| 258 | e4_assert(remark_term); |
|---|
| 259 | |
|---|
| 260 | int remark_len; |
|---|
| 261 | char *remark = remark_term->resolve_pointer_to_string(&remark_len); |
|---|
| 262 | |
|---|
| 263 | replaceChars(remark, ' ', '_'); |
|---|
| 264 | set_and_realloc_gde_array(the_names, the_sequences, allocated, numberspecies, maxalign, name, name_len, remark, remark_len); |
|---|
| 265 | } |
|---|
| 266 | } |
|---|
| 267 | } |
|---|
| 268 | } |
|---|
| 269 | } |
|---|
| 270 | end_of_loop: |
|---|
| 271 | if (terminal==last) break; |
|---|
| 272 | terminal = terminal->get_next_terminal(); |
|---|
| 273 | } |
|---|
| 274 | |
|---|
| 275 | return 0; |
|---|
| 276 | } |
|---|
| 277 | |
|---|
| 278 | char *ED4_create_sequences_for_gde(void*, GBDATA **&the_species, uchar **&the_names, uchar **&the_sequences, long &numberspecies, long &maxalign) |
|---|
| 279 | { |
|---|
| 280 | int top = ED4_ROOT->aw_root->awar("gde/top_area")->read_int(); |
|---|
| 281 | int tops = ED4_ROOT->aw_root->awar("gde/top_area_sai")->read_int(); |
|---|
| 282 | int toph = ED4_ROOT->aw_root->awar("gde/top_area_helix")->read_int(); |
|---|
| 283 | int topk = ED4_ROOT->aw_root->awar("gde/top_area_kons")->read_int(); |
|---|
| 284 | int topr = ED4_ROOT->aw_root->awar("gde/top_area_remark")->read_int(); |
|---|
| 285 | int middle = ED4_ROOT->aw_root->awar("gde/middle_area")->read_int(); |
|---|
| 286 | int middles = ED4_ROOT->aw_root->awar("gde/middle_area_sai")->read_int(); |
|---|
| 287 | int middleh = ED4_ROOT->aw_root->awar("gde/middle_area_helix")->read_int(); |
|---|
| 288 | int middlek = ED4_ROOT->aw_root->awar("gde/middle_area_kons")->read_int(); |
|---|
| 289 | int middler = ED4_ROOT->aw_root->awar("gde/middle_area_remark")->read_int(); |
|---|
| 290 | |
|---|
| 291 | numberspecies = 0; |
|---|
| 292 | maxalign = 0; |
|---|
| 293 | |
|---|
| 294 | long allocated = 100; |
|---|
| 295 | the_species = 0; |
|---|
| 296 | the_names = (uchar**)GB_calloc(allocated, sizeof(*the_names)); |
|---|
| 297 | the_sequences = (uchar**)GB_calloc(allocated, sizeof(*the_sequences)); |
|---|
| 298 | |
|---|
| 299 | char *err = add_area_for_gde(ED4_ROOT->top_area_man, the_names, the_sequences, allocated, numberspecies, maxalign, top, tops, toph, topk, topr); |
|---|
| 300 | if (!err) { |
|---|
| 301 | err = add_area_for_gde(ED4_ROOT->middle_area_man, the_names, the_sequences, allocated, numberspecies, maxalign, middle, middles, middleh, middlek, middler); |
|---|
| 302 | } |
|---|
| 303 | |
|---|
| 304 | if (allocated!=(numberspecies+1)) { |
|---|
| 305 | the_names = (uchar**)GB_recalloc(the_names, allocated, numberspecies+1, sizeof(*the_names)); |
|---|
| 306 | the_sequences = (uchar**)GB_recalloc(the_sequences, allocated, numberspecies+1, sizeof(*the_sequences)); |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | return err; |
|---|
| 310 | } |
|---|
| 311 | |
|---|
| 312 | static void ED4_gap_chars_changed(AW_root *root) { |
|---|
| 313 | char *gap_chars = root->awar_string(ED4_AWAR_GAP_CHARS)->read_string(); |
|---|
| 314 | |
|---|
| 315 | ED4_init_is_align_character(gap_chars); |
|---|
| 316 | } |
|---|
| 317 | |
|---|
| 318 | void ED4_create_global_awars(AW_root *root) { |
|---|
| 319 | root->awar_string(AWAR_ITARGET_STRING, "", gb_main); |
|---|
| 320 | ED4_create_search_awars(root); |
|---|
| 321 | } |
|---|
| 322 | |
|---|
| 323 | void ED4_create_awars(AW_root *root, const char *config_name) { // cursor awars are created in window constructor |
|---|
| 324 | |
|---|
| 325 | ED4_create_global_awars(root); |
|---|
| 326 | create_naligner_variables(root, AW_ROOT_DEFAULT); |
|---|
| 327 | |
|---|
| 328 | root->awar_int(ED4_AWAR_SPECIES_NAME_WIDTH,20) ->add_target_var(&global_width) ->set_minmax(10,50) ->add_callback(ED4_config_change_cb); |
|---|
| 329 | awar_edit_modus = AD_ALIGN; |
|---|
| 330 | |
|---|
| 331 | int def_sec_level = 0; |
|---|
| 332 | #ifdef DEBUG |
|---|
| 333 | def_sec_level = 6; // don't nag developers |
|---|
| 334 | #endif |
|---|
| 335 | root->awar_int( AWAR_EDIT_SECURITY_LEVEL, def_sec_level,AW_ROOT_DEFAULT); |
|---|
| 336 | |
|---|
| 337 | root->awar_int( AWAR_EDIT_SECURITY_LEVEL_ALIGN, def_sec_level,AW_ROOT_DEFAULT)->add_callback(ed4_changesecurity,(AW_CL) def_sec_level); |
|---|
| 338 | root->awar_int( AWAR_EDIT_SECURITY_LEVEL_CHANGE, def_sec_level,AW_ROOT_DEFAULT)->add_callback(ed4_changesecurity,(AW_CL) def_sec_level); |
|---|
| 339 | |
|---|
| 340 | // root->awar_int( AWAR_EDIT_MODE, (long) awar_edit_modus )->add_target_var((long *) &awar_edit_modus)->add_callback(ed4_changesecurity,(AW_CL) 0); |
|---|
| 341 | |
|---|
| 342 | root->awar_int( AWAR_EDIT_MODE, 0)->add_callback(ed4_change_edit_mode, (AW_CL)0); |
|---|
| 343 | root->awar_int( AWAR_INSERT_MODE, 1)->add_callback(ed4_change_edit_mode, (AW_CL)0); |
|---|
| 344 | |
|---|
| 345 | root->awar_int( AWAR_EDIT_DIRECTION, 1)->add_target_var(&awar_edit_direction); |
|---|
| 346 | root->awar_int( AWAR_EDIT_HELIX_SPACING, 6)->add_target_var(&ED4_ROOT->helix_spacing); |
|---|
| 347 | root->awar_int( AWAR_EDIT_TITLE_MODE, 0); |
|---|
| 348 | |
|---|
| 349 | root->awar_int(AWAR_CURSOR_POSITION, 1, gb_main); |
|---|
| 350 | root->awar_int(AWAR_SET_CURSOR_POSITION, 1, gb_main)->add_callback(ED4_remote_set_cursor_cb, 0, 0); |
|---|
| 351 | |
|---|
| 352 | root->awar_string(AWAR_FIELD_CHOSEN, "", gb_main); |
|---|
| 353 | |
|---|
| 354 | root->awar_string(AWAR_SPECIES_NAME, "", gb_main)->add_callback(ED4_selected_species_changed_cb); |
|---|
| 355 | root->awar_string(AWAR_EDIT_CONFIGURATION,config_name,gb_main); |
|---|
| 356 | ed4_changesecurity(root,0); |
|---|
| 357 | |
|---|
| 358 | root->awar_int(ED4_AWAR_COMPRESS_SEQUENCE_GAPS,0)->add_callback(ED4_compression_toggle_changed_cb, AW_CL(0), 0); |
|---|
| 359 | root->awar_int(ED4_AWAR_COMPRESS_SEQUENCE_HIDE,0)->add_callback(ED4_compression_toggle_changed_cb, AW_CL(1), 0); |
|---|
| 360 | root->awar_int(ED4_AWAR_COMPRESS_SEQUENCE_TYPE,0)->add_callback(ED4_compression_changed_cb); |
|---|
| 361 | root->awar_int(ED4_AWAR_COMPRESS_SEQUENCE_PERCENT,1)->add_callback(ED4_compression_changed_cb)->set_minmax(1,99); |
|---|
| 362 | root->awar_int(ED4_AWAR_COMPRESS_LEFT_COLUMN,0); |
|---|
| 363 | |
|---|
| 364 | root->awar_int(ED4_AWAR_DIGITS_AS_REPEAT, 0); |
|---|
| 365 | root->awar_int(ED4_AWAR_FAST_CURSOR_JUMP, 0); |
|---|
| 366 | root->awar_int(ED4_AWAR_CURSOR_TYPE, (int)ED4_RIGHT_ORIENTED_CURSOR); |
|---|
| 367 | |
|---|
| 368 | ED4_create_consensus_awars(root); |
|---|
| 369 | ED4_create_NDS_awars(root); |
|---|
| 370 | |
|---|
| 371 | root->awar_string(ED4_AWAR_REP_SEARCH_PATTERN, "."); |
|---|
| 372 | root->awar_string(ED4_AWAR_REP_REPLACE_PATTERN, "-"); |
|---|
| 373 | |
|---|
| 374 | root->awar_int( ED4_AWAR_SCROLL_SPEED_X, 40); |
|---|
| 375 | root->awar_int( ED4_AWAR_SCROLL_SPEED_Y, 20); |
|---|
| 376 | |
|---|
| 377 | root->awar_string(ED4_AWAR_SPECIES_TO_CREATE, ""); |
|---|
| 378 | |
|---|
| 379 | root->awar_string(ED4_AWAR_GAP_CHARS, ".-~?")->add_callback(ED4_gap_chars_changed); |
|---|
| 380 | ED4_gap_chars_changed(root); |
|---|
| 381 | |
|---|
| 382 | create_gde_var(ED4_ROOT->aw_root, ED4_ROOT->db, ED4_create_sequences_for_gde, CGSS_WT_EDIT4, 0); |
|---|
| 383 | |
|---|
| 384 | root->awar_string(ED4_AWAR_CREATE_FROM_CONS_REPL_EQUAL, "-"); |
|---|
| 385 | root->awar_string(ED4_AWAR_CREATE_FROM_CONS_REPL_POINT, "?"); |
|---|
| 386 | root->awar_int(ED4_AWAR_CREATE_FROM_CONS_CREATE_POINTS, 1); |
|---|
| 387 | root->awar_int(ED4_AWAR_CREATE_FROM_CONS_ALL_UPPER, 1); |
|---|
| 388 | root->awar_int(ED4_AWAR_CREATE_FROM_CONS_DATA_SOURCE, 0); |
|---|
| 389 | } |
|---|
| 390 | |
|---|
| 391 | int main(int argc,char **argv) |
|---|
| 392 | { |
|---|
| 393 | const char *data_path = ":"; |
|---|
| 394 | const char *err = NULL; |
|---|
| 395 | char *config_name = NULL; |
|---|
| 396 | |
|---|
| 397 | if (argc > 1 && strcmp(argv[1],"-c") == 0) { |
|---|
| 398 | config_name = new char[strlen(argv[2])+1]; |
|---|
| 399 | strcpy(config_name,argv[2]); |
|---|
| 400 | argc -= 2; argv += 2; |
|---|
| 401 | } |
|---|
| 402 | else { // load 'default_configuration' if no command line is given |
|---|
| 403 | config_name = strdup("default_configuration"); |
|---|
| 404 | err = "Using 'default_configuration'"; |
|---|
| 405 | #ifndef NDEBUG |
|---|
| 406 | err = 0; |
|---|
| 407 | #endif |
|---|
| 408 | } |
|---|
| 409 | |
|---|
| 410 | if (argc>1) |
|---|
| 411 | { |
|---|
| 412 | data_path = argv[1]; |
|---|
| 413 | argc--; argv++; |
|---|
| 414 | } |
|---|
| 415 | |
|---|
| 416 | gb_main = GB_open(data_path, "rwt"); |
|---|
| 417 | if (!gb_main) |
|---|
| 418 | { |
|---|
| 419 | GB_print_error(); |
|---|
| 420 | exit (-1); |
|---|
| 421 | } |
|---|
| 422 | |
|---|
| 423 | ED4_ROOT = new ED4_root(); |
|---|
| 424 | |
|---|
| 425 | ED4_ROOT->db = ED4_ROOT->aw_root->open_default( ".arb_prop/edit4.arb" ); // open default-database |
|---|
| 426 | ED4_ROOT->aw_root->init_variables( ED4_ROOT->db); // pass defaults |
|---|
| 427 | ED4_ROOT->aw_root->init( "ARB_EDIT4" ); // initialize window-system |
|---|
| 428 | |
|---|
| 429 | ED4_ROOT->database = new EDB_root_bact; |
|---|
| 430 | ED4_ROOT->init_alignment(); |
|---|
| 431 | ED4_create_awars(ED4_ROOT->aw_root, config_name); |
|---|
| 432 | |
|---|
| 433 | ED4_ROOT->st_ml = new_ST_ML(gb_main); |
|---|
| 434 | ED4_ROOT->sequence_colors = new AWT_seq_colors((GBDATA *)ED4_ROOT->aw_root->application_database,(int)ED4_G_SEQUENCES, ED4_refresh_window, 0,0); |
|---|
| 435 | |
|---|
| 436 | ED4_ROOT->edk = new ed_key; |
|---|
| 437 | ED4_ROOT->edk->create_awars(ED4_ROOT->aw_root); |
|---|
| 438 | |
|---|
| 439 | ED4_ROOT->sequence_colors->aww = ED4_ROOT->create_new_window();// create first editor window |
|---|
| 440 | |
|---|
| 441 | ED4_ROOT->helix = new BI_helix(ED4_ROOT->aw_root); |
|---|
| 442 | |
|---|
| 443 | if (err){ |
|---|
| 444 | aw_message(err); |
|---|
| 445 | err = 0; |
|---|
| 446 | } |
|---|
| 447 | |
|---|
| 448 | err = ED4_ROOT->helix->init(gb_main); |
|---|
| 449 | if (err) aw_message(err); |
|---|
| 450 | |
|---|
| 451 | { |
|---|
| 452 | int found_config = 0; |
|---|
| 453 | |
|---|
| 454 | if (config_name) |
|---|
| 455 | { |
|---|
| 456 | GB_begin_transaction(gb_main); |
|---|
| 457 | GBDATA *gb_configuration = GBT_find_configuration(gb_main, config_name); |
|---|
| 458 | |
|---|
| 459 | if (gb_configuration) { |
|---|
| 460 | GBDATA *gb_middle_area = GB_search(gb_configuration, "middle_area", GB_FIND); |
|---|
| 461 | GBDATA *gb_top_area = GB_search(gb_configuration, "top_area", GB_FIND); |
|---|
| 462 | char *config_data_middle = GB_read_as_string(gb_middle_area); |
|---|
| 463 | char *config_data_top = GB_read_as_string(gb_top_area); |
|---|
| 464 | |
|---|
| 465 | ED4_ROOT->create_hierarchy(config_data_middle, config_data_top); // create internal hierarchy |
|---|
| 466 | delete config_data_middle; |
|---|
| 467 | delete config_data_top; |
|---|
| 468 | |
|---|
| 469 | found_config = 1; |
|---|
| 470 | } |
|---|
| 471 | else { |
|---|
| 472 | aw_message(GBS_global_string("Could not find configuration '%s'", config_name)); |
|---|
| 473 | } |
|---|
| 474 | |
|---|
| 475 | GB_commit_transaction(gb_main); |
|---|
| 476 | } |
|---|
| 477 | |
|---|
| 478 | if (!found_config) { |
|---|
| 479 | // create internal hierarchy |
|---|
| 480 | |
|---|
| 481 | char *as_mid = ED4_ROOT->database->make_string(); |
|---|
| 482 | char *as_top = ED4_ROOT->database->make_top_bot_string(); |
|---|
| 483 | |
|---|
| 484 | ED4_ROOT->create_hierarchy(as_mid, as_top); |
|---|
| 485 | |
|---|
| 486 | delete as_mid; |
|---|
| 487 | delete as_top; |
|---|
| 488 | } |
|---|
| 489 | } |
|---|
| 490 | |
|---|
| 491 | { |
|---|
| 492 | GB_transaction dummy(gb_main); |
|---|
| 493 | GBDATA *species_container = GB_search(gb_main, "species_data", GB_FIND); |
|---|
| 494 | GB_add_callback(species_container, (GB_CB_TYPE)GB_CB_CHANGED, (GB_CB)ED4_species_container_changed_cb, 0); // callback if species_data changes |
|---|
| 495 | |
|---|
| 496 | ED4_elements_in_species_container = GB_rescan_number_of_subentries(species_container); // store # of species |
|---|
| 497 | #if defined(DEBUG) && 0 |
|---|
| 498 | printf("Species container contains %i species (at startup)\n", ED4_elements_in_species_container); |
|---|
| 499 | #endif |
|---|
| 500 | } |
|---|
| 501 | |
|---|
| 502 | ED4_ROOT->aw_root->main_loop(); // enter main-loop |
|---|
| 503 | } |
|---|
| 504 | |
|---|
| 505 | void AD_map_viewer(GBDATA *,AD_MAP_VIEWER_TYPE) |
|---|
| 506 | { |
|---|
| 507 | } |
|---|
| 508 | |
|---|
| 509 | // -------------------------------------------------------------------------------- |
|---|
| 510 | // Debug-Routine dump() -- displays ED4_base-Tree (use 'p base->dump()' in debugger) |
|---|
| 511 | // -------------------------------------------------------------------------------- |
|---|
| 512 | |
|---|
| 513 | #ifdef IMPLEMENT_DUMP |
|---|
| 514 | |
|---|
| 515 | static inline void spaces(int anz) { |
|---|
| 516 | while (anz--) { |
|---|
| 517 | fputc('|', stdout); |
|---|
| 518 | fputc(' ', stdout); |
|---|
| 519 | } |
|---|
| 520 | } |
|---|
| 521 | |
|---|
| 522 | void ED4_base::dump(int depth) const { |
|---|
| 523 | if (is_terminal()) { |
|---|
| 524 | to_terminal()->dump(depth); |
|---|
| 525 | } |
|---|
| 526 | else { |
|---|
| 527 | to_manager()->dump(depth); |
|---|
| 528 | } |
|---|
| 529 | } |
|---|
| 530 | |
|---|
| 531 | static void printLevel(ED4_level level) { |
|---|
| 532 | #define plev(tag) if (level&ED4_L_##tag) printf(#tag"|") |
|---|
| 533 | |
|---|
| 534 | plev(ROOT); |
|---|
| 535 | plev(DEVICE); |
|---|
| 536 | plev(AREA); |
|---|
| 537 | plev(MULTI_SPECIES); |
|---|
| 538 | plev(SPECIES); |
|---|
| 539 | plev(MULTI_SEQUENCE); |
|---|
| 540 | plev(SEQUENCE); |
|---|
| 541 | plev(TREE); |
|---|
| 542 | plev(SPECIES_NAME); |
|---|
| 543 | plev(SEQUENCE_INFO); |
|---|
| 544 | plev(SEQUENCE_STRING); |
|---|
| 545 | plev(SPACER); |
|---|
| 546 | plev(LINE); |
|---|
| 547 | plev(MULTI_NAME); |
|---|
| 548 | plev(NAME_MANAGER); |
|---|
| 549 | plev(GROUP); |
|---|
| 550 | plev(BRACKET); |
|---|
| 551 | plev(PURE_TEXT); |
|---|
| 552 | plev(COL_STAT); |
|---|
| 553 | |
|---|
| 554 | #undef plev |
|---|
| 555 | } |
|---|
| 556 | |
|---|
| 557 | void ED4_terminal::dump(int depth) const { |
|---|
| 558 | spaces(depth); |
|---|
| 559 | printf("terminal "); |
|---|
| 560 | printLevel(spec->level); |
|---|
| 561 | printf(" id='%s' ((ED4_terminal*)0x%p)\n", id ? id : "(nil)", this); |
|---|
| 562 | } |
|---|
| 563 | void ED4_manager::dump(int depth) const { |
|---|
| 564 | spaces(depth); |
|---|
| 565 | printf("manager "); |
|---|
| 566 | printLevel(spec->level); |
|---|
| 567 | printf(" id='%s' ((ED4_terminal*)0x%p)\n", id ? id : "(nil)", this); |
|---|
| 568 | |
|---|
| 569 | children->dump(depth+1); |
|---|
| 570 | } |
|---|
| 571 | void ED4_members::dump(int depth) const { |
|---|
| 572 | ED4_index i; |
|---|
| 573 | |
|---|
| 574 | for (i=0; i<members(); i++) { |
|---|
| 575 | member(i)->dump(depth); |
|---|
| 576 | } |
|---|
| 577 | } |
|---|
| 578 | |
|---|
| 579 | #endif |
|---|