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