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