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 | GB_ERROR error = NULp; |
---|
90 | |
---|
91 | if (changed_awar_name) { |
---|
92 | int changed_pair_idx = -1; |
---|
93 | for (int i = 0; i<PAIR_TYPES; ++i) { |
---|
94 | if (strcmp(changed_awar_name, pairdef[i].awar_pairs) == 0) { |
---|
95 | changed_pair_idx = i; |
---|
96 | break; |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | sec_assert(changed_pair_idx != -1); |
---|
101 | |
---|
102 | if (changed_pair_idx != -1) { |
---|
103 | char *content = aw_root->awar(changed_awar_name)->read_string(); |
---|
104 | |
---|
105 | for (int i = 0; i<PAIR_TYPES; ++i) { |
---|
106 | if (i != changed_pair_idx) { // correct other pair strings |
---|
107 | clear(); |
---|
108 | AW_awar *awar = aw_root->awar(pairdef[i].awar_pairs); |
---|
109 | |
---|
110 | char *oldP = awar->read_string(); |
---|
111 | |
---|
112 | insert(oldP, '#'); |
---|
113 | insert(content, ' '); |
---|
114 | |
---|
115 | char *newP = get_pair_string('#'); |
---|
116 | |
---|
117 | if (strcmp(oldP, newP) != 0) awar->write_string(newP); |
---|
118 | |
---|
119 | free(newP); |
---|
120 | free(oldP); |
---|
121 | } |
---|
122 | } |
---|
123 | free(content); |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | clear(); |
---|
128 | for (int i = 0; !error && i<PAIR_TYPES; ++i) { |
---|
129 | char *pairs = aw_root->awar(pairdef[i].awar_pairs)->read_string(); |
---|
130 | char *pairchar = aw_root->awar(pairdef[i].awar_pairchar)->read_string(); |
---|
131 | |
---|
132 | error = insert(pairs, pairchar[0]); |
---|
133 | |
---|
134 | free(pairchar); |
---|
135 | free(pairs); |
---|
136 | } |
---|
137 | |
---|
138 | return error; |
---|
139 | } |
---|
140 | |
---|
141 | static void pair_def_changed_cb(AW_root *aw_root, SEC_db_interface *db, const char *awar_name) { |
---|
142 | AWT_auto_refresh allowed_on(db->canvas()); |
---|
143 | GB_ERROR err = db->bonds()->update(aw_root, awar_name); |
---|
144 | if (err) aw_message(err); |
---|
145 | db->canvas()->request_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 *)NULp)); |
---|
155 | } |
---|
156 | |
---|
157 | pair_def_changed_cb(aw_root, db, NULp); |
---|
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 | AWT_auto_refresh allowed_on(scr); |
---|
190 | |
---|
191 | char *species_name = aw_root->awar(AWAR_SPECIES_NAME)->read_string(); |
---|
192 | bool had_sequence = sequence; |
---|
193 | GBDATA *gb_species = GBT_find_species(gb_main, species_name); |
---|
194 | |
---|
195 | delete sequence; |
---|
196 | sequence = gb_species ? new SEC_seq_data(gb_species, aliname, cb) : NULp; |
---|
197 | Host.announce_current_species(species_name); |
---|
198 | |
---|
199 | if (bool(sequence) != had_sequence) scr->request_zoom_reset(); |
---|
200 | if (sequence) gfx->request_update(SEC_UPDATE_SHOWN_POSITIONS); |
---|
201 | |
---|
202 | scr->request_refresh(); |
---|
203 | |
---|
204 | free(species_name); |
---|
205 | } |
---|
206 | |
---|
207 | void SEC_db_interface::reload_ecoli(const SEC_dbcb *cb) { |
---|
208 | GB_transaction ta(gb_main); |
---|
209 | AWT_auto_refresh allowed_on(scr); |
---|
210 | |
---|
211 | delete ecoli_seq; |
---|
212 | delete Ecoli; |
---|
213 | |
---|
214 | GBDATA *gb_ecoli = GBT_find_SAI(gb_main, "ECOLI"); |
---|
215 | if (gb_ecoli) { |
---|
216 | ecoli_seq = new SEC_seq_data(gb_ecoli, aliname, cb); |
---|
217 | Ecoli = new BI_ecoli_ref; |
---|
218 | |
---|
219 | Ecoli->init(ecoli_seq->sequence(), ecoli_seq->length()); |
---|
220 | } |
---|
221 | else { |
---|
222 | ecoli_seq = NULp; |
---|
223 | Ecoli = NULp; |
---|
224 | } |
---|
225 | |
---|
226 | gfx->request_update(SEC_UPDATE_SHOWN_POSITIONS); |
---|
227 | scr->request_refresh(); |
---|
228 | } |
---|
229 | |
---|
230 | void SEC_db_interface::reload_helix(const SEC_dbcb *cb) { |
---|
231 | GB_transaction ta(gb_main); |
---|
232 | AWT_auto_refresh allowed_on(scr); |
---|
233 | |
---|
234 | delete helix_nr; helix_nr = NULp; |
---|
235 | delete helix_pos; helix_pos = NULp; |
---|
236 | delete Helix; Helix = NULp; |
---|
237 | |
---|
238 | char *helix_pos_name = GBT_get_default_helix(gb_main); |
---|
239 | GBDATA *gb_helix_pos = GBT_find_SAI(gb_main, helix_pos_name); |
---|
240 | if (gb_helix_pos) { |
---|
241 | char *helix_nr_name = GBT_get_default_helix_nr(gb_main); |
---|
242 | GBDATA *gb_helix_nr = GBT_find_SAI(gb_main, helix_nr_name); |
---|
243 | |
---|
244 | if (gb_helix_nr) { |
---|
245 | helix_pos = new SEC_seq_data(gb_helix_pos, aliname, cb); |
---|
246 | helix_nr = new SEC_seq_data(gb_helix_nr, aliname, cb); |
---|
247 | Helix = new BI_helix; |
---|
248 | |
---|
249 | GB_ERROR error = Helix->initFromData(helix_nr->sequence(), helix_pos->sequence(), helix_pos->length()); |
---|
250 | if (error) { |
---|
251 | error = ta.close(error); |
---|
252 | aw_message(error); |
---|
253 | } |
---|
254 | } |
---|
255 | |
---|
256 | free(helix_nr_name); |
---|
257 | } |
---|
258 | free(helix_pos_name); |
---|
259 | |
---|
260 | gfx->request_update(static_cast<SEC_update_request>(SEC_UPDATE_SHOWN_POSITIONS|SEC_UPDATE_RELOAD)); |
---|
261 | scr->request_refresh(); |
---|
262 | } |
---|
263 | |
---|
264 | void SEC_db_interface::update_positions(const SEC_dbcb *) { |
---|
265 | AWT_auto_refresh allowed_on(scr); |
---|
266 | displayBindingHelixPositions = aw_root->awar(AWAR_SECEDIT_DISPPOS_BINDING)->read_int(); |
---|
267 | displayEcoliPositions = aw_root->awar(AWAR_SECEDIT_DISPPOS_ECOLI)->read_int(); |
---|
268 | |
---|
269 | gfx->sec_root->nail_cursor(); |
---|
270 | gfx->request_update(SEC_UPDATE_SHOWN_POSITIONS); |
---|
271 | scr->request_refresh(); |
---|
272 | } |
---|
273 | |
---|
274 | void SEC_db_interface::relayout(const SEC_dbcb *) { |
---|
275 | SEC_root *root = secroot(); |
---|
276 | AWT_auto_refresh allowed_on(scr); |
---|
277 | root->reread_display_params(awroot(), Host); |
---|
278 | root->nail_cursor(); |
---|
279 | gfx->request_update(SEC_UPDATE_RECOUNT); |
---|
280 | scr->request_refresh(); |
---|
281 | } |
---|
282 | |
---|
283 | void SEC_db_interface::refresh(const SEC_dbcb *) { |
---|
284 | SEC_root *root = secroot(); |
---|
285 | AWT_auto_refresh allowed_on(scr); |
---|
286 | root->reread_display_params(awroot(), Host); |
---|
287 | scr->request_refresh(); |
---|
288 | } |
---|
289 | |
---|
290 | void SEC_root::set_cursor(int abspos) { |
---|
291 | |
---|
292 | nail_cursor(); |
---|
293 | int nailedPos = nailedAbsPos; |
---|
294 | |
---|
295 | cursorAbsPos = abspos; |
---|
296 | |
---|
297 | { |
---|
298 | AWT_auto_refresh allowed_on(db->canvas()); // @@@ try up-scope! |
---|
299 | db->canvas()->request_refresh(); |
---|
300 | } |
---|
301 | |
---|
302 | nailedAbsPos = nailedPos; |
---|
303 | position_cursor(false, false); |
---|
304 | } |
---|
305 | |
---|
306 | void SEC_db_interface::cursor_changed(const SEC_dbcb *) { |
---|
307 | SEC_root *root = secroot(); |
---|
308 | int seq_pos = bio2info(aw_root->awar_int(AWAR_CURSOR_POSITION)->read_int()); |
---|
309 | |
---|
310 | root->set_cursor(seq_pos); |
---|
311 | } |
---|
312 | |
---|
313 | void SEC_db_interface::alilen_changed(const SEC_dbcb *) { |
---|
314 | AWT_auto_refresh allowed_on(scr); |
---|
315 | |
---|
316 | // @@@ reread alilen. test changing ali length! |
---|
317 | |
---|
318 | gfx->request_update(SEC_UPDATE_RELOAD); |
---|
319 | scr->request_refresh(); |
---|
320 | } |
---|
321 | |
---|
322 | // -------------------------------------------------------------------------------- |
---|
323 | |
---|
324 | static const char *update_pos_awars[] = { |
---|
325 | AWAR_SECEDIT_DISPPOS_BINDING, |
---|
326 | AWAR_SECEDIT_DISPPOS_ECOLI, |
---|
327 | NULp |
---|
328 | }; |
---|
329 | |
---|
330 | static const char *relayout_awars[] = { |
---|
331 | AWAR_SECEDIT_DIST_BETW_STRANDS, |
---|
332 | NULp |
---|
333 | }; |
---|
334 | |
---|
335 | static const char *refresh_awars[] = { |
---|
336 | AWAR_SECEDIT_SHOW_HELIX_NRS, |
---|
337 | AWAR_SECEDIT_SHOW_BONDS, |
---|
338 | AWAR_SECEDIT_SHOW_CURPOS, |
---|
339 | AWAR_SECEDIT_HIDE_BASES, |
---|
340 | AWAR_SECEDIT_SHOW_ECOLI_POS, |
---|
341 | AWAR_SECEDIT_DISPLAY_SEARCH, |
---|
342 | AWAR_SECEDIT_DISPLAY_SAI, |
---|
343 | AWAR_SECEDIT_SHOW_STR_SKELETON, |
---|
344 | AWAR_SECEDIT_SKELETON_THICKNESS, |
---|
345 | AWAR_SECEDIT_BOND_THICKNESS, |
---|
346 | AWAR_EDIT_RIGHTWARD, |
---|
347 | ED4_AWAR_SEARCH_RESULT_CHANGED, |
---|
348 | #if defined(DEBUG) |
---|
349 | AWAR_SECEDIT_SHOW_DEBUG, |
---|
350 | #endif // DEBUG |
---|
351 | NULp |
---|
352 | }; |
---|
353 | |
---|
354 | void SEC_db_interface::bind_awars(const char **awars, SEC_dbcb *cb) { |
---|
355 | RootCallback awarcb = makeRootCallback(sec_dbcb, cb); |
---|
356 | for (int i = 0; awars[i]; ++i) { |
---|
357 | aw_root->awar(awars[i])->add_callback(awarcb); |
---|
358 | } |
---|
359 | } |
---|
360 | |
---|
361 | // -------------------------------------------------------------------------------- |
---|
362 | |
---|
363 | static void create_awars(AW_root *aw_root, AW_default def) { |
---|
364 | aw_root->awar_int(AWAR_SECEDIT_BASELINEWIDTH, 0, def)->set_minmax(0, 10); |
---|
365 | aw_root->awar_string(AWAR_FOOTER); |
---|
366 | |
---|
367 | { |
---|
368 | char *dir = ARB_strdup(GB_path_in_arbprop("secondary_structure")); |
---|
369 | AW_create_fileselection_awars(aw_root, AWAR_SECEDIT_SAVEDIR, dir, ".ass", "noname.ass"); |
---|
370 | free(dir); |
---|
371 | } |
---|
372 | |
---|
373 | aw_root->awar_float(AWAR_SECEDIT_DIST_BETW_STRANDS, 1, def)->set_minmax(0.01, 40); |
---|
374 | aw_root->awar_int (AWAR_SECEDIT_SKELETON_THICKNESS, 1, def)->set_minmax(1, 10); |
---|
375 | aw_root->awar_int (AWAR_SECEDIT_BOND_THICKNESS, 1, def)->set_minmax(1, 10); |
---|
376 | |
---|
377 | #if defined(DEBUG) |
---|
378 | aw_root->awar_int(AWAR_SECEDIT_SHOW_DEBUG, 0, def); |
---|
379 | #endif // DEBUG |
---|
380 | aw_root->awar_int(AWAR_SECEDIT_SHOW_HELIX_NRS, 0, def); |
---|
381 | aw_root->awar_int(AWAR_SECEDIT_SHOW_ECOLI_POS, 0, def); |
---|
382 | aw_root->awar_int(AWAR_SECEDIT_SHOW_STR_SKELETON, 0, def); |
---|
383 | aw_root->awar_int(AWAR_SECEDIT_HIDE_BASES, 0, def); |
---|
384 | aw_root->awar_int(AWAR_SECEDIT_SHOW_BONDS, SHOW_HELIX_BONDS, def); |
---|
385 | aw_root->awar_int(AWAR_SECEDIT_SHOW_CURPOS, SHOW_ABS_CURPOS, def); |
---|
386 | aw_root->awar_int(AWAR_SECEDIT_DISPLAY_SAI, 0, def); |
---|
387 | aw_root->awar_int(AWAR_SECEDIT_DISPLAY_SEARCH, 0, def); |
---|
388 | aw_root->awar_int(AWAR_SECEDIT_DISPPOS_BINDING, 0, def); |
---|
389 | aw_root->awar_int(AWAR_SECEDIT_DISPPOS_ECOLI, 1, def); |
---|
390 | |
---|
391 | for (int i = 0; i<PAIR_TYPES; ++i) { |
---|
392 | PairDefinition& pd = pairdef[i]; |
---|
393 | aw_root->awar_string(pd.awar_pairs, pd.default_pairs); |
---|
394 | aw_root->awar_string(pd.awar_pairchar, pd.default_pairchar); |
---|
395 | } |
---|
396 | } |
---|
397 | |
---|
398 | // -------------------------------------------------------------------------------- |
---|
399 | |
---|
400 | SEC_db_interface::SEC_db_interface(SEC_graphic *Gfx, AWT_canvas *Scr, ED4_plugin_host& host_) : |
---|
401 | sequence(NULp), |
---|
402 | Host(host_), |
---|
403 | displayEcoliPositions(false), |
---|
404 | ecoli_seq(NULp), |
---|
405 | Ecoli(NULp), |
---|
406 | displayBindingHelixPositions(true), |
---|
407 | helix_nr(NULp), |
---|
408 | helix_pos(NULp), |
---|
409 | Helix(NULp), |
---|
410 | gfx(Gfx), |
---|
411 | scr(Scr), |
---|
412 | gb_main(gfx->gb_main), |
---|
413 | aw_root(gfx->aw_root) |
---|
414 | { |
---|
415 | AWT_auto_refresh allowed_on(Scr); |
---|
416 | GB_transaction ta(gb_main); |
---|
417 | |
---|
418 | create_awars(aw_root, AW_ROOT_DEFAULT); |
---|
419 | |
---|
420 | aliname = GBT_get_default_alignment(gb_main); |
---|
421 | sec_assert(aliname); |
---|
422 | ali_length = GBT_get_alignment_len(gb_main, aliname); |
---|
423 | displayPos = new bool[ali_length]; |
---|
424 | bonddef = new SEC_bond_def(GBT_get_alignment_type(gb_main, aliname)); |
---|
425 | |
---|
426 | // awar and DB callbacks: |
---|
427 | |
---|
428 | sequence_cb = new SEC_dbcb(this, &SEC_db_interface::reload_sequence); |
---|
429 | ecoli_cb = new SEC_dbcb(this, &SEC_db_interface::reload_ecoli); |
---|
430 | helix_cb = new SEC_dbcb(this, &SEC_db_interface::reload_helix); |
---|
431 | updatepos_cb = new SEC_dbcb(this, &SEC_db_interface::update_positions); |
---|
432 | relayout_cb = new SEC_dbcb(this, &SEC_db_interface::relayout); |
---|
433 | refresh_cb = new SEC_dbcb(this, &SEC_db_interface::refresh); |
---|
434 | cursorpos_cb = new SEC_dbcb(this, &SEC_db_interface::cursor_changed); |
---|
435 | alilen_changed_cb = new SEC_dbcb(this, &SEC_db_interface::alilen_changed); |
---|
436 | |
---|
437 | aw_root->awar_string(AWAR_SPECIES_NAME, "", gb_main)->add_callback(makeRootCallback(sec_dbcb, sequence_cb)); |
---|
438 | aw_root->awar_string(AWAR_CURSOR_POSITION, "", gb_main)->add_callback(makeRootCallback(sec_dbcb, cursorpos_cb)); |
---|
439 | |
---|
440 | bind_awars(update_pos_awars, updatepos_cb); |
---|
441 | bind_awars(relayout_awars, relayout_cb); |
---|
442 | bind_awars(refresh_awars, refresh_cb); |
---|
443 | |
---|
444 | bind_bonddef_awars(this); |
---|
445 | |
---|
446 | { |
---|
447 | GBDATA *gb_alignment = GBT_get_alignment(gb_main, aliname); |
---|
448 | GBDATA *gb_alignment_len = GB_search(gb_alignment, "alignment_len", GB_FIND); |
---|
449 | sec_assert(gb_alignment_len); |
---|
450 | GB_add_callback(gb_alignment_len, GB_CB_CHANGED, makeDatabaseCallback(sec_dbcb, alilen_changed_cb)); |
---|
451 | } |
---|
452 | |
---|
453 | sequence_cb->call(); |
---|
454 | ecoli_cb->call(); |
---|
455 | helix_cb->call(); |
---|
456 | updatepos_cb->call(); |
---|
457 | relayout_cb->call(); |
---|
458 | refresh_cb->call(); |
---|
459 | |
---|
460 | toggler = NULp; |
---|
461 | } |
---|
462 | |
---|
463 | SEC_db_interface::~SEC_db_interface() { |
---|
464 | free(aliname); |
---|
465 | |
---|
466 | delete [] displayPos; |
---|
467 | |
---|
468 | delete sequence; sequence = NULp; |
---|
469 | |
---|
470 | delete ecoli_seq; ecoli_seq = NULp; |
---|
471 | delete Ecoli; Ecoli = NULp; |
---|
472 | |
---|
473 | delete helix_nr; helix_nr = NULp; |
---|
474 | delete helix_pos; helix_pos = NULp; |
---|
475 | delete Helix; Helix = NULp; |
---|
476 | |
---|
477 | delete sequence_cb; sequence_cb = NULp; |
---|
478 | delete ecoli_cb; ecoli_cb = NULp; |
---|
479 | delete helix_cb; helix_cb = NULp; |
---|
480 | delete updatepos_cb; updatepos_cb = NULp; |
---|
481 | delete relayout_cb; relayout_cb = NULp; |
---|
482 | delete refresh_cb; refresh_cb = NULp; |
---|
483 | delete cursorpos_cb; cursorpos_cb = NULp; |
---|
484 | delete alilen_changed_cb; alilen_changed_cb = NULp; |
---|
485 | |
---|
486 | delete toggler; toggler = NULp; |
---|
487 | |
---|
488 | delete bonddef; bonddef = NULp; |
---|
489 | } |
---|
490 | |
---|
491 | SEC_root *SEC_db_interface::secroot() const { return gfx->sec_root; } |
---|
492 | |
---|
493 | // -------------------------------------------------------------------------------- |
---|
494 | |
---|
495 | void SEC_db_interface::update_shown_positions() { |
---|
496 | shown = 0; |
---|
497 | |
---|
498 | sec_assert(sequence && Helix); |
---|
499 | |
---|
500 | for (size_t pos = 0; pos<ali_length; ++pos) { |
---|
501 | bool isPaired = Helix->pairtype(pos) != HELIX_NONE; |
---|
502 | char base = baseAt(pos); |
---|
503 | |
---|
504 | if (isPaired) { |
---|
505 | if (displayBindingHelixPositions) { |
---|
506 | displayPos[pos] = true; |
---|
507 | } |
---|
508 | else { |
---|
509 | char oppoBase = baseAt(Helix->opposite_position(pos)); |
---|
510 | displayPos[pos] = !(SEC_is_gap(base) && SEC_is_gap(oppoBase)); // display if one side of helix has base |
---|
511 | } |
---|
512 | } |
---|
513 | else { |
---|
514 | displayPos[pos] = !SEC_is_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] && !SEC_is_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 | |
---|