| 1 | // =============================================================== // |
|---|
| 2 | // // |
|---|
| 3 | // File : SEC_db.cxx // |
|---|
| 4 | // Purpose : db interface // |
|---|
| 5 | // // |
|---|
| 6 | // Coded by Ralf Westram (coder@reallysoft.de) in August 2007 // |
|---|
| 7 | // Institute of Microbiology (Technical University Munich) // |
|---|
| 8 | // http://www.arb-home.de/ // |
|---|
| 9 | // // |
|---|
| 10 | // =============================================================== // |
|---|
| 11 | |
|---|
| 12 | #include "SEC_graphic.hxx" |
|---|
| 13 | #include "SEC_root.hxx" |
|---|
| 14 | #include "SEC_bonddef.hxx" |
|---|
| 15 | #include "SEC_toggle.hxx" |
|---|
| 16 | |
|---|
| 17 | #include <aw_awars.hxx> |
|---|
| 18 | #include <aw_file.hxx> |
|---|
| 19 | #include <aw_msg.hxx> |
|---|
| 20 | #include <aw_root.hxx> |
|---|
| 21 | #include <ed4_extern.hxx> |
|---|
| 22 | #include <arbdbt.h> |
|---|
| 23 | #include <ad_cb.h> |
|---|
| 24 | |
|---|
| 25 | #include <arb_defs.h> |
|---|
| 26 | |
|---|
| 27 | using namespace std; |
|---|
| 28 | |
|---|
| 29 | // ----------------------------------- |
|---|
| 30 | // member function callbacks |
|---|
| 31 | |
|---|
| 32 | typedef void (SEC_db_interface::*interface_cb)(const SEC_dbcb *); |
|---|
| 33 | |
|---|
| 34 | struct SEC_dbcb { |
|---|
| 35 | SEC_db_interface *instance; |
|---|
| 36 | interface_cb member_fun; |
|---|
| 37 | |
|---|
| 38 | SEC_dbcb(SEC_db_interface *db, interface_cb cb) : instance(db), member_fun(cb) {} |
|---|
| 39 | void call() const { (instance->*member_fun)(this); } |
|---|
| 40 | }; |
|---|
| 41 | |
|---|
| 42 | static void sec_dbcb(UNFIXED, const SEC_dbcb *cb) { |
|---|
| 43 | cb->call(); |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | // ---------------------- |
|---|
| 47 | // SEC_seq_data |
|---|
| 48 | |
|---|
| 49 | SEC_seq_data::SEC_seq_data(GBDATA *gb_item, const char *aliname, const SEC_dbcb *cb) { |
|---|
| 50 | gb_name = GB_search(gb_item, "name", GB_FIND); |
|---|
| 51 | gb_data = GBT_find_sequence(gb_item, aliname); |
|---|
| 52 | change_cb = cb; |
|---|
| 53 | len = GB_read_string_count(gb_data); |
|---|
| 54 | Data = GB_read_string(gb_data); |
|---|
| 55 | |
|---|
| 56 | if (gb_name) GB_add_callback(gb_name, GB_CB_CHANGED_OR_DELETED, makeDatabaseCallback(sec_dbcb, change_cb)); |
|---|
| 57 | if (gb_data) GB_add_callback(gb_data, GB_CB_CHANGED_OR_DELETED, makeDatabaseCallback(sec_dbcb, change_cb)); |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | SEC_seq_data::~SEC_seq_data() { |
|---|
| 61 | if (gb_name) GB_remove_callback(gb_name, GB_CB_CHANGED_OR_DELETED, makeDatabaseCallback(sec_dbcb, change_cb)); |
|---|
| 62 | if (gb_data) GB_remove_callback(gb_data, GB_CB_CHANGED_OR_DELETED, makeDatabaseCallback(sec_dbcb, change_cb)); |
|---|
| 63 | free(Data); |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | // ------------------- |
|---|
| 67 | // pair defs |
|---|
| 68 | |
|---|
| 69 | #define AWAR_PAIRS(type) AWAR_SECEDIT_##type##_PAIRS |
|---|
| 70 | #define AWAR_PCHAR(type) AWAR_SECEDIT_##type##_PAIR_CHAR |
|---|
| 71 | |
|---|
| 72 | struct PairDefinition { |
|---|
| 73 | const char *awar_pairs; |
|---|
| 74 | const char *awar_pairchar; |
|---|
| 75 | const char *default_pairs; |
|---|
| 76 | const char *default_pairchar; |
|---|
| 77 | }; |
|---|
| 78 | |
|---|
| 79 | #define PAIR_TYPES 5 |
|---|
| 80 | static PairDefinition pairdef[PAIR_TYPES] = { |
|---|
| 81 | { AWAR_PAIRS(STRONG), AWAR_PCHAR(STRONG), "GC AU AT", "-" }, |
|---|
| 82 | { AWAR_PAIRS(NORMAL), AWAR_PCHAR(NORMAL), "GU GT", "." }, |
|---|
| 83 | { AWAR_PAIRS(WEAK), AWAR_PCHAR(WEAK), "GA", "o" }, |
|---|
| 84 | { AWAR_PAIRS(NO), AWAR_PCHAR(NO), "AA AC CC CU CT GG UU TT TU", "" }, |
|---|
| 85 | { AWAR_PAIRS(USER), AWAR_PCHAR(USER), "", "" }, |
|---|
| 86 | }; |
|---|
| 87 | |
|---|
| 88 | GB_ERROR SEC_bond_def::update(AW_root *aw_root, const char *changed_awar_name) |
|---|
| 89 | { |
|---|
| 90 | GB_ERROR error = 0; |
|---|
| 91 | |
|---|
| 92 | if (changed_awar_name) { |
|---|
| 93 | int changed_pair_idx = -1; |
|---|
| 94 | for (int i = 0; i<PAIR_TYPES; ++i) { |
|---|
| 95 | if (strcmp(changed_awar_name, pairdef[i].awar_pairs) == 0) { |
|---|
| 96 | changed_pair_idx = i; |
|---|
| 97 | break; |
|---|
| 98 | } |
|---|
| 99 | } |
|---|
| 100 | |
|---|
| 101 | sec_assert(changed_pair_idx != -1); |
|---|
| 102 | |
|---|
| 103 | if (changed_pair_idx != -1) { |
|---|
| 104 | char *content = aw_root->awar(changed_awar_name)->read_string(); |
|---|
| 105 | |
|---|
| 106 | for (int i = 0; i<PAIR_TYPES; ++i) { |
|---|
| 107 | if (i != changed_pair_idx) { // correct other pair strings |
|---|
| 108 | clear(); |
|---|
| 109 | AW_awar *awar = aw_root->awar(pairdef[i].awar_pairs); |
|---|
| 110 | |
|---|
| 111 | char *oldP = awar->read_string(); |
|---|
| 112 | |
|---|
| 113 | insert(oldP, '#'); |
|---|
| 114 | insert(content, ' '); |
|---|
| 115 | |
|---|
| 116 | char *newP = get_pair_string('#'); |
|---|
| 117 | |
|---|
| 118 | if (strcmp(oldP, newP) != 0) awar->write_string(newP); |
|---|
| 119 | |
|---|
| 120 | free(newP); |
|---|
| 121 | free(oldP); |
|---|
| 122 | } |
|---|
| 123 | } |
|---|
| 124 | free(content); |
|---|
| 125 | } |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | clear(); |
|---|
| 129 | for (int i = 0; !error && i<PAIR_TYPES; ++i) { |
|---|
| 130 | char *pairs = aw_root->awar(pairdef[i].awar_pairs)->read_string(); |
|---|
| 131 | char *pairchar = aw_root->awar(pairdef[i].awar_pairchar)->read_string(); |
|---|
| 132 | |
|---|
| 133 | error = insert(pairs, pairchar[0]); |
|---|
| 134 | |
|---|
| 135 | free(pairchar); |
|---|
| 136 | free(pairs); |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | return error; |
|---|
| 140 | } |
|---|
| 141 | |
|---|
| 142 | static void pair_def_changed_cb(AW_root *aw_root, SEC_db_interface *db, const char *awar_name) { |
|---|
| 143 | GB_ERROR err = db->bonds()->update(aw_root, awar_name); |
|---|
| 144 | if (err) aw_message(err); |
|---|
| 145 | db->canvas()->refresh(); |
|---|
| 146 | } |
|---|
| 147 | |
|---|
| 148 | static void bind_bonddef_awars(SEC_db_interface *db) { |
|---|
| 149 | AW_root *aw_root = db->awroot(); |
|---|
| 150 | |
|---|
| 151 | for (int i = 0; i<PAIR_TYPES; ++i) { |
|---|
| 152 | PairDefinition& pd = pairdef[i]; |
|---|
| 153 | aw_root->awar(pd.awar_pairs) ->add_callback(makeRootCallback(pair_def_changed_cb, db, pd.awar_pairs)); |
|---|
| 154 | aw_root->awar(pd.awar_pairchar)->add_callback(makeRootCallback(pair_def_changed_cb, db, (const char *)NULL)); |
|---|
| 155 | } |
|---|
| 156 | |
|---|
| 157 | pair_def_changed_cb(aw_root, db, NULL); |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | // -------------------------------------------------------------------------------- |
|---|
| 161 | |
|---|
| 162 | void SEC_displayParams::reread(AW_root *aw_root, const ED4_plugin_host& host) { |
|---|
| 163 | show_helixNrs = aw_root->awar(AWAR_SECEDIT_SHOW_HELIX_NRS)->read_int(); |
|---|
| 164 | distance_between_strands = aw_root->awar(AWAR_SECEDIT_DIST_BETW_STRANDS)->read_float(); |
|---|
| 165 | show_bonds = (ShowBonds)aw_root->awar(AWAR_SECEDIT_SHOW_BONDS)->read_int(); |
|---|
| 166 | show_curpos = (ShowCursorPos)aw_root->awar(AWAR_SECEDIT_SHOW_CURPOS)->read_int(); |
|---|
| 167 | |
|---|
| 168 | hide_bases = aw_root->awar(AWAR_SECEDIT_HIDE_BASES)->read_int(); |
|---|
| 169 | show_ecoli_pos = aw_root->awar(AWAR_SECEDIT_SHOW_ECOLI_POS)->read_int(); |
|---|
| 170 | display_search = aw_root->awar(AWAR_SECEDIT_DISPLAY_SEARCH)->read_int(); |
|---|
| 171 | display_sai = aw_root->awar(AWAR_SECEDIT_DISPLAY_SAI)->read_int() && host.SAIs_visualized(); |
|---|
| 172 | |
|---|
| 173 | show_strSkeleton = aw_root->awar(AWAR_SECEDIT_SHOW_STR_SKELETON)->read_int(); |
|---|
| 174 | skeleton_thickness = aw_root->awar(AWAR_SECEDIT_SKELETON_THICKNESS)->read_int(); |
|---|
| 175 | bond_thickness = aw_root->awar(AWAR_SECEDIT_BOND_THICKNESS)->read_int(); |
|---|
| 176 | |
|---|
| 177 | edit_rightward = aw_root->awar(AWAR_EDIT_RIGHTWARD)->read_int(); |
|---|
| 178 | |
|---|
| 179 | #if defined(DEBUG) |
|---|
| 180 | show_debug = aw_root->awar(AWAR_SECEDIT_SHOW_DEBUG)->read_int(); |
|---|
| 181 | #endif // DEBUG |
|---|
| 182 | } |
|---|
| 183 | |
|---|
| 184 | // -------------------------- |
|---|
| 185 | // SEC_db_interface |
|---|
| 186 | |
|---|
| 187 | void SEC_db_interface::reload_sequence(const SEC_dbcb *cb) { |
|---|
| 188 | GB_transaction ta(gb_main); |
|---|
| 189 | |
|---|
| 190 | char *species_name = aw_root->awar(AWAR_SPECIES_NAME)->read_string(); |
|---|
| 191 | bool had_sequence = sequence; |
|---|
| 192 | GBDATA *gb_species = GBT_find_species(gb_main, species_name); |
|---|
| 193 | |
|---|
| 194 | delete sequence; |
|---|
| 195 | sequence = gb_species ? new SEC_seq_data(gb_species, aliname, cb) : 0; |
|---|
| 196 | Host.announce_current_species(species_name); |
|---|
| 197 | |
|---|
| 198 | if (bool(sequence) != had_sequence) gfx->request_update(SEC_UPDATE_ZOOM_RESET); |
|---|
| 199 | if (sequence) gfx->request_update(SEC_UPDATE_SHOWN_POSITIONS); |
|---|
| 200 | |
|---|
| 201 | if (perform_refresh) scr->refresh(); |
|---|
| 202 | |
|---|
| 203 | free(species_name); |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | void SEC_db_interface::reload_ecoli(const SEC_dbcb *cb) { |
|---|
| 207 | GB_transaction ta(gb_main); |
|---|
| 208 | |
|---|
| 209 | delete ecoli_seq; |
|---|
| 210 | delete Ecoli; |
|---|
| 211 | |
|---|
| 212 | GBDATA *gb_ecoli = GBT_find_SAI(gb_main, "ECOLI"); |
|---|
| 213 | if (gb_ecoli) { |
|---|
| 214 | ecoli_seq = new SEC_seq_data(gb_ecoli, aliname, cb); |
|---|
| 215 | Ecoli = new BI_ecoli_ref; |
|---|
| 216 | |
|---|
| 217 | Ecoli->init(ecoli_seq->sequence(), ecoli_seq->length()); |
|---|
| 218 | } |
|---|
| 219 | else { |
|---|
| 220 | ecoli_seq = 0; |
|---|
| 221 | Ecoli = 0; |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | gfx->request_update(SEC_UPDATE_SHOWN_POSITIONS); |
|---|
| 225 | if (perform_refresh) scr->refresh(); |
|---|
| 226 | } |
|---|
| 227 | |
|---|
| 228 | void SEC_db_interface::reload_helix(const SEC_dbcb *cb) { |
|---|
| 229 | GB_transaction ta(gb_main); |
|---|
| 230 | |
|---|
| 231 | delete helix_nr; helix_nr = 0; |
|---|
| 232 | delete helix_pos; helix_pos = 0; |
|---|
| 233 | delete Helix; Helix = 0; |
|---|
| 234 | |
|---|
| 235 | char *helix_pos_name = GBT_get_default_helix(gb_main); |
|---|
| 236 | GBDATA *gb_helix_pos = GBT_find_SAI(gb_main, helix_pos_name); |
|---|
| 237 | if (gb_helix_pos) { |
|---|
| 238 | char *helix_nr_name = GBT_get_default_helix_nr(gb_main); |
|---|
| 239 | GBDATA *gb_helix_nr = GBT_find_SAI(gb_main, helix_nr_name); |
|---|
| 240 | |
|---|
| 241 | if (gb_helix_nr) { |
|---|
| 242 | helix_pos = new SEC_seq_data(gb_helix_pos, aliname, cb); |
|---|
| 243 | helix_nr = new SEC_seq_data(gb_helix_nr, aliname, cb); |
|---|
| 244 | Helix = new BI_helix; |
|---|
| 245 | |
|---|
| 246 | GB_ERROR error = Helix->initFromData(helix_nr->sequence(), helix_pos->sequence(), helix_pos->length()); |
|---|
| 247 | if (error) { |
|---|
| 248 | error = ta.close(error); |
|---|
| 249 | aw_message(error); |
|---|
| 250 | } |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | free(helix_nr_name); |
|---|
| 254 | } |
|---|
| 255 | free(helix_pos_name); |
|---|
| 256 | |
|---|
| 257 | gfx->request_update(static_cast<SEC_update_request>(SEC_UPDATE_SHOWN_POSITIONS|SEC_UPDATE_RELOAD)); |
|---|
| 258 | if (perform_refresh) scr->refresh(); |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | void SEC_db_interface::update_positions(const SEC_dbcb *) { |
|---|
| 262 | displayBindingHelixPositions = aw_root->awar(AWAR_SECEDIT_DISPPOS_BINDING)->read_int(); |
|---|
| 263 | displayEcoliPositions = aw_root->awar(AWAR_SECEDIT_DISPPOS_ECOLI)->read_int(); |
|---|
| 264 | |
|---|
| 265 | gfx->sec_root->nail_cursor(); |
|---|
| 266 | gfx->request_update(SEC_UPDATE_SHOWN_POSITIONS); |
|---|
| 267 | if (perform_refresh) scr->refresh(); |
|---|
| 268 | } |
|---|
| 269 | |
|---|
| 270 | void SEC_db_interface::relayout(const SEC_dbcb *) { |
|---|
| 271 | SEC_root *root = secroot(); |
|---|
| 272 | root->reread_display_params(awroot(), Host); |
|---|
| 273 | root->nail_cursor(); |
|---|
| 274 | gfx->request_update(SEC_UPDATE_RECOUNT); |
|---|
| 275 | if (perform_refresh) scr->refresh(); |
|---|
| 276 | } |
|---|
| 277 | |
|---|
| 278 | void SEC_db_interface::refresh(const SEC_dbcb *) { |
|---|
| 279 | SEC_root *root = secroot(); |
|---|
| 280 | root->reread_display_params(awroot(), Host); |
|---|
| 281 | if (perform_refresh) scr->refresh(); |
|---|
| 282 | } |
|---|
| 283 | |
|---|
| 284 | void SEC_root::set_cursor(int abspos, bool performRefresh) { |
|---|
| 285 | if (performRefresh) { |
|---|
| 286 | nail_cursor(); |
|---|
| 287 | int nailedPos = nailedAbsPos; |
|---|
| 288 | |
|---|
| 289 | cursorAbsPos = abspos; |
|---|
| 290 | |
|---|
| 291 | db->canvas()->refresh(); |
|---|
| 292 | |
|---|
| 293 | nailedAbsPos = nailedPos; |
|---|
| 294 | position_cursor(false, false); |
|---|
| 295 | } |
|---|
| 296 | else { |
|---|
| 297 | cursorAbsPos = abspos; |
|---|
| 298 | } |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | void SEC_db_interface::cursor_changed(const SEC_dbcb *) { |
|---|
| 302 | SEC_root *root = secroot(); |
|---|
| 303 | int seq_pos = bio2info(aw_root->awar_int(AWAR_CURSOR_POSITION)->read_int()); |
|---|
| 304 | |
|---|
| 305 | root->set_cursor(seq_pos, perform_refresh); |
|---|
| 306 | } |
|---|
| 307 | |
|---|
| 308 | void SEC_db_interface::alilen_changed(const SEC_dbcb *) { |
|---|
| 309 | #if defined(WARN_TODO) |
|---|
| 310 | #warning @@@reread alilen |
|---|
| 311 | #warning test changing ali length! |
|---|
| 312 | #endif |
|---|
| 313 | gfx->request_update(SEC_UPDATE_RELOAD); |
|---|
| 314 | if (perform_refresh) scr->refresh(); |
|---|
| 315 | } |
|---|
| 316 | |
|---|
| 317 | // -------------------------------------------------------------------------------- |
|---|
| 318 | |
|---|
| 319 | static const char *update_pos_awars[] = { |
|---|
| 320 | AWAR_SECEDIT_DISPPOS_BINDING, |
|---|
| 321 | AWAR_SECEDIT_DISPPOS_ECOLI, |
|---|
| 322 | NULL |
|---|
| 323 | }; |
|---|
| 324 | |
|---|
| 325 | static const char *relayout_awars[] = { |
|---|
| 326 | AWAR_SECEDIT_DIST_BETW_STRANDS, |
|---|
| 327 | NULL |
|---|
| 328 | }; |
|---|
| 329 | |
|---|
| 330 | static const char *refresh_awars[] = { |
|---|
| 331 | AWAR_SECEDIT_SHOW_HELIX_NRS, |
|---|
| 332 | AWAR_SECEDIT_SHOW_BONDS, |
|---|
| 333 | AWAR_SECEDIT_SHOW_CURPOS, |
|---|
| 334 | AWAR_SECEDIT_HIDE_BASES, |
|---|
| 335 | AWAR_SECEDIT_SHOW_ECOLI_POS, |
|---|
| 336 | AWAR_SECEDIT_DISPLAY_SEARCH, |
|---|
| 337 | AWAR_SECEDIT_DISPLAY_SAI, |
|---|
| 338 | AWAR_SECEDIT_SHOW_STR_SKELETON, |
|---|
| 339 | AWAR_SECEDIT_SKELETON_THICKNESS, |
|---|
| 340 | AWAR_SECEDIT_BOND_THICKNESS, |
|---|
| 341 | AWAR_EDIT_RIGHTWARD, |
|---|
| 342 | ED4_AWAR_SEARCH_RESULT_CHANGED, |
|---|
| 343 | #if defined(DEBUG) |
|---|
| 344 | AWAR_SECEDIT_SHOW_DEBUG, |
|---|
| 345 | #endif // DEBUG |
|---|
| 346 | NULL |
|---|
| 347 | }; |
|---|
| 348 | |
|---|
| 349 | void SEC_db_interface::bind_awars(const char **awars, SEC_dbcb *cb) { |
|---|
| 350 | RootCallback awarcb = makeRootCallback(sec_dbcb, cb); |
|---|
| 351 | for (int i = 0; awars[i]; ++i) { |
|---|
| 352 | aw_root->awar(awars[i])->add_callback(awarcb); |
|---|
| 353 | } |
|---|
| 354 | } |
|---|
| 355 | |
|---|
| 356 | // -------------------------------------------------------------------------------- |
|---|
| 357 | |
|---|
| 358 | static void create_awars(AW_root *aw_root, AW_default def) { |
|---|
| 359 | aw_root->awar_int(AWAR_SECEDIT_BASELINEWIDTH, 0, def)->set_minmax(0, 10); |
|---|
| 360 | aw_root->awar_string(AWAR_FOOTER); |
|---|
| 361 | |
|---|
| 362 | { |
|---|
| 363 | char *dir = strdup(GB_path_in_arbprop("secondary_structure")); |
|---|
| 364 | AW_create_fileselection_awars(aw_root, AWAR_SECEDIT_SAVEDIR, dir, ".ass", "noname.ass"); |
|---|
| 365 | free(dir); |
|---|
| 366 | } |
|---|
| 367 | |
|---|
| 368 | aw_root->awar_float(AWAR_SECEDIT_DIST_BETW_STRANDS, 1, def)->set_minmax(0.01, 40); |
|---|
| 369 | aw_root->awar_int (AWAR_SECEDIT_SKELETON_THICKNESS, 1, def)->set_minmax(1, 10); |
|---|
| 370 | aw_root->awar_int (AWAR_SECEDIT_BOND_THICKNESS, 1, def)->set_minmax(1, 10); |
|---|
| 371 | |
|---|
| 372 | #if defined(DEBUG) |
|---|
| 373 | aw_root->awar_int(AWAR_SECEDIT_SHOW_DEBUG, 0, def); |
|---|
| 374 | #endif // DEBUG |
|---|
| 375 | aw_root->awar_int(AWAR_SECEDIT_SHOW_HELIX_NRS, 0, def); |
|---|
| 376 | aw_root->awar_int(AWAR_SECEDIT_SHOW_ECOLI_POS, 0, def); |
|---|
| 377 | aw_root->awar_int(AWAR_SECEDIT_SHOW_STR_SKELETON, 0, def); |
|---|
| 378 | aw_root->awar_int(AWAR_SECEDIT_HIDE_BASES, 0, def); |
|---|
| 379 | aw_root->awar_int(AWAR_SECEDIT_SHOW_BONDS, SHOW_HELIX_BONDS, def); |
|---|
| 380 | aw_root->awar_int(AWAR_SECEDIT_SHOW_CURPOS, SHOW_ABS_CURPOS, def); |
|---|
| 381 | aw_root->awar_int(AWAR_SECEDIT_DISPLAY_SAI, 0, def); |
|---|
| 382 | aw_root->awar_int(AWAR_SECEDIT_DISPLAY_SEARCH, 0, def); |
|---|
| 383 | aw_root->awar_int(AWAR_SECEDIT_DISPPOS_BINDING, 0, def); |
|---|
| 384 | aw_root->awar_int(AWAR_SECEDIT_DISPPOS_ECOLI, 1, def); |
|---|
| 385 | |
|---|
| 386 | for (int i = 0; i<PAIR_TYPES; ++i) { |
|---|
| 387 | PairDefinition& pd = pairdef[i]; |
|---|
| 388 | aw_root->awar_string(pd.awar_pairs, pd.default_pairs); |
|---|
| 389 | aw_root->awar_string(pd.awar_pairchar, pd.default_pairchar); |
|---|
| 390 | } |
|---|
| 391 | } |
|---|
| 392 | |
|---|
| 393 | // -------------------------------------------------------------------------------- |
|---|
| 394 | |
|---|
| 395 | SEC_db_interface::SEC_db_interface(SEC_graphic *Gfx, AWT_canvas *Scr, ED4_plugin_host& host_) |
|---|
| 396 | : sequence(0) |
|---|
| 397 | , Host(host_) |
|---|
| 398 | , displayEcoliPositions(false) |
|---|
| 399 | , ecoli_seq(0) |
|---|
| 400 | , Ecoli(0) |
|---|
| 401 | , displayBindingHelixPositions(true) |
|---|
| 402 | , helix_nr(0) |
|---|
| 403 | , helix_pos(0) |
|---|
| 404 | , Helix(0) |
|---|
| 405 | , gfx(Gfx) |
|---|
| 406 | , scr(Scr) |
|---|
| 407 | , gb_main(gfx->gb_main) |
|---|
| 408 | , aw_root(gfx->aw_root) |
|---|
| 409 | , perform_refresh(false) |
|---|
| 410 | { |
|---|
| 411 | GB_transaction ta(gb_main); |
|---|
| 412 | |
|---|
| 413 | create_awars(aw_root, AW_ROOT_DEFAULT); |
|---|
| 414 | |
|---|
| 415 | aliname = GBT_get_default_alignment(gb_main); |
|---|
| 416 | sec_assert(aliname); |
|---|
| 417 | ali_length = GBT_get_alignment_len(gb_main, aliname); |
|---|
| 418 | displayPos = new bool[ali_length]; |
|---|
| 419 | bonddef = new SEC_bond_def(GBT_get_alignment_type(gb_main, aliname)); |
|---|
| 420 | |
|---|
| 421 | // awar and DB callbacks: |
|---|
| 422 | |
|---|
| 423 | sequence_cb = new SEC_dbcb(this, &SEC_db_interface::reload_sequence); |
|---|
| 424 | ecoli_cb = new SEC_dbcb(this, &SEC_db_interface::reload_ecoli); |
|---|
| 425 | helix_cb = new SEC_dbcb(this, &SEC_db_interface::reload_helix); |
|---|
| 426 | updatepos_cb = new SEC_dbcb(this, &SEC_db_interface::update_positions); |
|---|
| 427 | relayout_cb = new SEC_dbcb(this, &SEC_db_interface::relayout); |
|---|
| 428 | refresh_cb = new SEC_dbcb(this, &SEC_db_interface::refresh); |
|---|
| 429 | cursorpos_cb = new SEC_dbcb(this, &SEC_db_interface::cursor_changed); |
|---|
| 430 | alilen_changed_cb = new SEC_dbcb(this, &SEC_db_interface::alilen_changed); |
|---|
| 431 | |
|---|
| 432 | aw_root->awar_string(AWAR_SPECIES_NAME, "", gb_main)->add_callback(makeRootCallback(sec_dbcb, sequence_cb)); |
|---|
| 433 | aw_root->awar_string(AWAR_CURSOR_POSITION, "", gb_main)->add_callback(makeRootCallback(sec_dbcb, cursorpos_cb)); |
|---|
| 434 | |
|---|
| 435 | bind_awars(update_pos_awars, updatepos_cb); |
|---|
| 436 | bind_awars(relayout_awars, relayout_cb); |
|---|
| 437 | bind_awars(refresh_awars, refresh_cb); |
|---|
| 438 | |
|---|
| 439 | bind_bonddef_awars(this); |
|---|
| 440 | |
|---|
| 441 | { |
|---|
| 442 | GBDATA *gb_alignment = GBT_get_alignment(gb_main, aliname); |
|---|
| 443 | GBDATA *gb_alignment_len = GB_search(gb_alignment, "alignment_len", GB_FIND); |
|---|
| 444 | sec_assert(gb_alignment_len); |
|---|
| 445 | GB_add_callback(gb_alignment_len, GB_CB_CHANGED, makeDatabaseCallback(sec_dbcb, alilen_changed_cb)); |
|---|
| 446 | } |
|---|
| 447 | |
|---|
| 448 | sequence_cb->call(); |
|---|
| 449 | ecoli_cb->call(); |
|---|
| 450 | helix_cb->call(); |
|---|
| 451 | updatepos_cb->call(); |
|---|
| 452 | relayout_cb->call(); |
|---|
| 453 | refresh_cb->call(); |
|---|
| 454 | |
|---|
| 455 | toggler = 0; |
|---|
| 456 | |
|---|
| 457 | perform_refresh = true; |
|---|
| 458 | } |
|---|
| 459 | |
|---|
| 460 | SEC_db_interface::~SEC_db_interface() { |
|---|
| 461 | free(aliname); |
|---|
| 462 | |
|---|
| 463 | delete [] displayPos; |
|---|
| 464 | |
|---|
| 465 | delete sequence; sequence = 0; |
|---|
| 466 | |
|---|
| 467 | delete ecoli_seq; ecoli_seq = 0; |
|---|
| 468 | delete Ecoli; Ecoli = 0; |
|---|
| 469 | |
|---|
| 470 | delete helix_nr; helix_nr = 0; |
|---|
| 471 | delete helix_pos; helix_pos = 0; |
|---|
| 472 | delete Helix; Helix = 0; |
|---|
| 473 | |
|---|
| 474 | delete sequence_cb; sequence_cb = 0; |
|---|
| 475 | delete ecoli_cb; ecoli_cb = 0; |
|---|
| 476 | delete helix_cb; helix_cb = 0; |
|---|
| 477 | delete updatepos_cb; updatepos_cb = 0; |
|---|
| 478 | delete relayout_cb; relayout_cb = 0; |
|---|
| 479 | delete refresh_cb; refresh_cb = 0; |
|---|
| 480 | delete cursorpos_cb; cursorpos_cb = 0; |
|---|
| 481 | delete alilen_changed_cb; alilen_changed_cb = 0; |
|---|
| 482 | |
|---|
| 483 | delete toggler; toggler = 0; |
|---|
| 484 | |
|---|
| 485 | delete bonddef; bonddef = 0; |
|---|
| 486 | } |
|---|
| 487 | |
|---|
| 488 | SEC_root *SEC_db_interface::secroot() const { return gfx->sec_root; } |
|---|
| 489 | |
|---|
| 490 | // -------------------------------------------------------------------------------- |
|---|
| 491 | |
|---|
| 492 | inline bool gap(char c) { return c == '-' || c == '.'; } |
|---|
| 493 | |
|---|
| 494 | void SEC_db_interface::update_shown_positions() { |
|---|
| 495 | shown = 0; |
|---|
| 496 | |
|---|
| 497 | sec_assert(sequence && Helix); |
|---|
| 498 | |
|---|
| 499 | for (size_t pos = 0; pos<ali_length; ++pos) { |
|---|
| 500 | bool isPaired = Helix->pairtype(pos) != HELIX_NONE; |
|---|
| 501 | char base = baseAt(pos); |
|---|
| 502 | |
|---|
| 503 | if (isPaired) { |
|---|
| 504 | if (displayBindingHelixPositions) { |
|---|
| 505 | displayPos[pos] = true; |
|---|
| 506 | } |
|---|
| 507 | else { |
|---|
| 508 | char oppoBase = baseAt(Helix->opposite_position(pos)); |
|---|
| 509 | |
|---|
| 510 | displayPos[pos] = !(gap(base) && gap(oppoBase)); // display if one side of helix has base |
|---|
| 511 | } |
|---|
| 512 | } |
|---|
| 513 | else { |
|---|
| 514 | displayPos[pos] = !gap(base); |
|---|
| 515 | } |
|---|
| 516 | |
|---|
| 517 | shown += displayPos[pos]; |
|---|
| 518 | } |
|---|
| 519 | |
|---|
| 520 | // add hidden ecoli positions |
|---|
| 521 | if (displayEcoliPositions && ecoli_seq) { |
|---|
| 522 | for (size_t pos = 0; pos<ali_length; ++pos) { |
|---|
| 523 | if (!displayPos[pos] && !gap(ecoli_seq->data(pos))) { |
|---|
| 524 | displayPos[pos] = true; |
|---|
| 525 | shown++; |
|---|
| 526 | } |
|---|
| 527 | } |
|---|
| 528 | } |
|---|
| 529 | } |
|---|
| 530 | |
|---|
| 531 | void SEC_db_interface::init_toggler() const { |
|---|
| 532 | if (!toggler) toggler = new SEC_structure_toggler(gb_main, aliname, gfx); |
|---|
| 533 | } |
|---|
| 534 | |
|---|
| 535 | void SEC_root::update_shown_positions() { |
|---|
| 536 | db->update_shown_positions(); |
|---|
| 537 | } |
|---|
| 538 | |
|---|
| 539 | // -------------------------------------------------------------------------------- |
|---|
| 540 | |
|---|