ARB
AW_helix.cxx
Go to the documentation of this file.
1 // ==================================================================== //
2 // //
3 // File : AW_helix.cxx //
4 // Purpose : Wrapper for BI_helix + AW-specific functions //
5 // //
6 // //
7 // Coded by Ralf Westram (coder@reallysoft.de) in December 2004 //
8 // Copyright Department of Microbiology (Technical University Munich) //
9 // //
10 // Visit our web site at: http://www.arb-home.de/ //
11 // //
12 // ==================================================================== //
13 
14 #include "AW_helix.hxx"
15 #include <aw_root.hxx>
16 #include <aw_window.hxx>
17 #include <aw_awar.hxx>
18 #include <aw_device.hxx>
19 #include <arbdbt.h>
20 #include <cctype>
21 #include <awt_config_manager.hxx>
22 
23 #define HELIX_AWAR_ENABLE "Helix/enable"
24 #define HELIX_AWAR_SYMBOL_TEMPLATE "Helix/symbols/%s"
25 #define HELIX_AWAR_PAIR_TEMPLATE "Helix/pairs/%s"
26 
28  const char *awar;
30 };
31 
33  { "Strong_Pair", HELIX_STRONG_PAIR },
34  { "Normal_Pair", HELIX_PAIR },
35  { "Weak_Pair", HELIX_WEAK_PAIR },
36  { "No_Pair", HELIX_NO_PAIR },
37  { "User_Pair", HELIX_USER0 },
38  { "User_Pair2", HELIX_USER1 },
39  { "User_Pair3", HELIX_USER2 },
40  { "User_Pair4", HELIX_USER3 },
41  { "Default", HELIX_DEFAULT },
42  { "Non_Standard_aA", HELIX_NON_STANDARD0 },
43  { "Non_Standard1", HELIX_NON_STANDARD1 },
44  { "Non_Standard2", HELIX_NON_STANDARD2 },
45  { "Non_Standard3", HELIX_NON_STANDARD3 },
46  { "Non_Standard4", HELIX_NON_STANDARD4 },
47  { "Non_Standard5", HELIX_NON_STANDARD5 },
48  { "Non_Standard6", HELIX_NON_STANDARD6 },
49  { "Non_Standard7", HELIX_NON_STANDARD7 },
50  { "Non_Standard8", HELIX_NON_STANDARD8 },
51  { "Non_Standard9", HELIX_NON_STANDARD9 },
52  { "Not_Non_Standard", HELIX_NO_MATCH },
53  { NULp, HELIX_NONE },
54 };
55 
56 inline const char *helix_symbol_awar(int idx) { return GBS_global_string(HELIX_AWAR_SYMBOL_TEMPLATE, helix_awars[idx].awar); }
57 inline const char *helix_pair_awar (int idx) { return GBS_global_string(HELIX_AWAR_PAIR_TEMPLATE, helix_awars[idx].awar); }
58 
60  : enabled(0)
61 {
62  for (int j=0; helix_awars[j].awar; j++) {
63  int i = helix_awars[j].pair_type;
64  aw_root->awar_string(helix_pair_awar(j), pairs[i]) ->add_target_var(&pairs[i]);
66  }
67  aw_root->awar_int(HELIX_AWAR_ENABLE, 1)->add_target_var(&enabled);
68 }
69 
70 char AW_helix::get_symbol(char left, char right, BI_PAIR_TYPE pair_type) {
71  left = toupper(left);
72  right = toupper(right);
73 
74  int erg;
75  if (pair_type < HELIX_NON_STANDARD0) {
76  erg = *char_bind[HELIX_DEFAULT];
77  for (int i = HELIX_STRONG_PAIR; i< HELIX_NON_STANDARD0; i++) {
78  if (is_pairtype(left, right, (BI_PAIR_TYPE)i)) {
79  erg = *char_bind[i];
80  break;
81  }
82  }
83  }
84  else {
85  erg = *char_bind[HELIX_NO_MATCH];
86  if (is_pairtype(left, right, pair_type)) erg = *char_bind[pair_type];
87  }
88  if (!erg) erg = ' ';
89  return erg;
90 }
91 
92 char *AW_helix::seq_2_helix(char *sequence, char undefsymbol) {
93  size_t size2 = strlen(sequence);
94  bi_assert(size2<=size()); // if this fails there is a sequence longer than the alignment
95  char *helix = ARB_calloc<char>(size()+1);
96  size_t i, j;
97  for (i=0; i<size2; i++) {
98  BI_PAIR_TYPE pairType = pairtype(i);
99 
100  if (pairType == HELIX_NONE) {
101  helix[i] = undefsymbol;
102  }
103  else {
104  j = opposite_position(i);
105  char sym = get_symbol(sequence[i], sequence[j], pairType);
106  helix[i] = sym == ' ' ? undefsymbol : sym;
107  }
108  }
109  return helix;
110 }
111 
112 static void helix_pairs_changed_cb(AW_window *aww, int changed_idx, const WindowCallback *refreshCallback) {
113  static bool recursion = false;
114 
115  if (!recursion) {
116  AW_root *aw_root = aww->get_root();
117  AW_awar *awar_pair = aw_root->awar(helix_pair_awar(changed_idx));
118  char *pairdef = awar_pair->read_string();
119 
120  {
121  LocallyModify<bool> flag(recursion, true);
122  for (int i = 0; ; i += 3) {
123  char left = toupper(pairdef[i]); if (!left) break;
124  char right = toupper(pairdef[i+1]); if (!right) break;
125 
126  pairdef[i] = left;
127  pairdef[i+1] = right;
128 
129  for (int j = 0; helix_awars[j].awar; j++) {
130  if (j != changed_idx) {
131  AW_awar *awar_pair2 = aw_root->awar(helix_pair_awar(j));
132  char *pd2 = awar_pair2->read_string();
133  int dst = 0;
134  bool modified = false;
135 
136  for (int k = 0; ; k += 3) {
137  char l = toupper(pd2[k]); if (!l) break;
138  char r = toupper(pd2[k+1]); if (!r) break;
139 
140  if ((left == l && right == r) || (left == r && right == l)) {
141  // remove duplicated pair
142  modified = true;
143  }
144  else {
145  pd2[dst] = l;
146  pd2[dst+1] = r;
147 
148  dst += 3;
149  }
150  if (!pd2[k+2]) break;
151  }
152 
153  if (modified) {
154  pd2[dst-1] = 0;
155  awar_pair2->write_string(pd2);
156  }
157 
158  free(pd2);
159  }
160  }
161 
162  if (!pairdef[i+2]) break;
163  }
164  awar_pair->write_string(pairdef); // write back uppercase version
165  }
166  (*refreshCallback)(aww);
167 
168  free(pairdef);
169  }
170 }
171 
173  cdef.add(HELIX_AWAR_ENABLE, "enable");
174 
175  for (int j=0; helix_awars[j].awar; j++) {
176  int i = helix_awars[j].pair_type;
177 
178  const char *name = helix_awars[j].awar;
179  if (i != HELIX_DEFAULT && i != HELIX_NO_MATCH) {
180  cdef.add(helix_pair_awar(j), name);
181  }
182  cdef.add(helix_symbol_awar(j), GBS_global_string("%s_symbol", name));
183  }
184 }
185 
186 AW_window *create_helix_props_window(AW_root *awr, const WindowCallback *refreshCallback) {
187  static AW_window_simple *aws = NULp;
188  if (!aws) {
189  aws = new AW_window_simple;
190  aws->init(awr, "HELIX_PROPS", "HELIX_PROPERTIES");
191 
192  aws->at(10, 10);
193  aws->auto_space(3, 3);
194 
195  aws->callback(AW_POPDOWN);
196  aws->create_button("CLOSE", "CLOSE", "C");
197 
198  aws->callback(makeHelpCallback("helixsym.hlp"));
199  aws->create_button("HELP", "HELP", "H");
200 
201  AWT_insert_config_manager(aws, AW_ROOT_DEFAULT, "helix", makeConfigSetupCallback(setup_helix_config));
202 
203  aws->at_newline();
204 
205  const size_t max_awar_len = 18;
206  aws->label_length(max_awar_len);
207 
208  aws->label("Show helix?");
209  aws->callback(*refreshCallback); // @@@ used as TOGGLE_CLICK_CB (see #559)
210  aws->create_toggle(HELIX_AWAR_ENABLE);
211 
212  aws->at_newline();
213 
214  int ex = 0;
215  for (int j = 0; helix_awars[j].awar; j++) {
216  int i = helix_awars[j].pair_type;
217 
218  aw_assert(strlen(helix_awars[j].awar) <= max_awar_len);
219 
220  if (i != HELIX_DEFAULT && i != HELIX_NO_MATCH) {
221  aws->label(helix_awars[j].awar);
222  aws->callback(makeWindowCallback(helix_pairs_changed_cb, j, refreshCallback)); // @@@ used as INPUTFIELD_CB (see #559)
223  aws->create_input_field(helix_pair_awar(j), 20);
224 
225  if (j == 0) ex = aws->get_at_xposition();
226  }
227  else {
228  aw_assert(j != 0);
229  aws->create_autosize_button(NULp, helix_awars[j].awar);
230  aws->at_x(ex);
231  }
232 
233  aws->callback(*refreshCallback); // @@@ used as INPUTFIELD_CB (see #559)
234  aws->create_input_field(helix_symbol_awar(j), 3);
235  aws->at_newline();
236  }
237  aws->window_fit();
238  }
239  return aws;
240 }
241 
242 
#define HELIX_AWAR_SYMBOL_TEMPLATE
Definition: AW_helix.cxx:24
const char * awar
Definition: AW_helix.cxx:28
void add(const char *awar_name, const char *config_name)
AW_helix(AW_root *awroot)
Definition: AW_helix.cxx:59
#define HELIX_AWAR_ENABLE
Definition: AW_helix.cxx:23
BI_PAIR_TYPE
Definition: BI_helix.hxx:18
void AWT_insert_config_manager(AW_window *aww, AW_default default_file_, const char *id, const StoreConfigCallback &store_cb, const RestoreConfigCallback &load_or_reset_cb, const char *macro_id, const AWT_predefined_config *predef)
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:204
size_t opposite_position(size_t pos) const
Definition: BI_helix.hxx:96
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
char * char_bind[HELIX_MAX]
Definition: BI_helix.hxx:68
char * pairs[HELIX_MAX]
Definition: BI_helix.hxx:67
char get_symbol(char left, char right, BI_PAIR_TYPE pair_type)
Definition: AW_helix.cxx:70
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
const char * helix_symbol_awar(int idx)
Definition: AW_helix.cxx:56
bool is_pairtype(char left, char right, BI_PAIR_TYPE pair_type)
Definition: BI_helix.cxx:309
#define aw_assert(bed)
Definition: aw_position.hxx:29
#define bi_assert(bed)
Definition: BI_basepos.hxx:25
size_t size() const
Definition: BI_helix.hxx:88
#define HELIX_AWAR_PAIR_TEMPLATE
Definition: AW_helix.cxx:25
static helix_pair_def helix_awars[]
Definition: AW_helix.cxx:32
char * read_string() const
Definition: AW_awar.cxx:201
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
long int flag
Definition: f2c.h:39
char * seq_2_helix(char *sequence, char undefsymbol= ' ')
Definition: AW_helix.cxx:92
static PairDefinition pairdef[PAIR_TYPES]
Definition: SEC_db.cxx:80
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:580
BI_PAIR_TYPE pair_type
Definition: AW_helix.cxx:29
BI_PAIR_TYPE pairtype(size_t pos) const
Definition: BI_helix.hxx:101
AW_awar * add_target_var(char **ppchr)
Definition: AW_awar.cxx:239
static void setup_helix_config(AWT_config_definition &cdef)
Definition: AW_helix.cxx:172
AW_root * get_root()
Definition: aw_window.hxx:348
AW_window * create_helix_props_window(AW_root *awr, const WindowCallback *refreshCallback)
Definition: AW_helix.cxx:186
#define NULp
Definition: cxxforward.h:97
GB_ERROR write_string(const char *aw_string)
static void helix_pairs_changed_cb(AW_window *aww, int changed_idx, const WindowCallback *refreshCallback)
Definition: AW_helix.cxx:112
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:570
const char * helix_pair_awar(int idx)
Definition: AW_helix.cxx:57
#define AW_ROOT_DEFAULT
Definition: aw_base.hxx:106