| 1 | #include "awt_filter.hxx" |
|---|
| 2 | #include "awt_sel_boxes.hxx" |
|---|
| 3 | #include "ga_local.h" |
|---|
| 4 | |
|---|
| 5 | #include <aw_awars.hxx> |
|---|
| 6 | #include <aw_root.hxx> |
|---|
| 7 | #include <aw_select.hxx> |
|---|
| 8 | #include <AP_filter.hxx> |
|---|
| 9 | #include <arbdbt.h> |
|---|
| 10 | #include <arb_strbuf.h> |
|---|
| 11 | #include <ad_cb.h> |
|---|
| 12 | #include <arb_str.h> |
|---|
| 13 | |
|---|
| 14 | //! recalc filter |
|---|
| 15 | static void awt_create_select_filter_window_aw_cb(UNFIXED, adfiltercbstruct *cbs) { |
|---|
| 16 | // update the variables |
|---|
| 17 | GB_push_transaction(cbs->gb_main); |
|---|
| 18 | |
|---|
| 19 | AW_root *aw_root = cbs->awr; |
|---|
| 20 | char *target = aw_root->awar(cbs->def_subname)->read_string(); |
|---|
| 21 | char *to_free_target = target; |
|---|
| 22 | char *use = aw_root->awar(cbs->def_alignment)->read_string(); |
|---|
| 23 | char *name = strchr(target, 1); |
|---|
| 24 | GBDATA *gbd = NULp; |
|---|
| 25 | |
|---|
| 26 | if (name) { |
|---|
| 27 | *(name++) = 0; |
|---|
| 28 | target++; |
|---|
| 29 | GBDATA *gb_species; |
|---|
| 30 | if (target[-1] == '@') { |
|---|
| 31 | gb_species = GBT_find_species(cbs->gb_main, name); |
|---|
| 32 | } |
|---|
| 33 | else { |
|---|
| 34 | gb_species = GBT_find_SAI(cbs->gb_main, name); |
|---|
| 35 | } |
|---|
| 36 | if (gb_species) { |
|---|
| 37 | GBDATA *gb_ali = GB_search(gb_species, use, GB_FIND); |
|---|
| 38 | if (gb_ali) { |
|---|
| 39 | gbd = GB_search(gb_ali, target, GB_FIND); |
|---|
| 40 | } |
|---|
| 41 | else { |
|---|
| 42 | GB_clear_error(); |
|---|
| 43 | } |
|---|
| 44 | } |
|---|
| 45 | } |
|---|
| 46 | if (!gbd) { // nothing selected |
|---|
| 47 | aw_root->awar(cbs->def_name)->write_string("none"); |
|---|
| 48 | aw_root->awar(cbs->def_source)->write_string("No Filter Sequence ->All Columns Selected"); |
|---|
| 49 | aw_root->awar(cbs->def_filter)->write_string(""); |
|---|
| 50 | aw_root->awar(cbs->def_len) ->write_int(-1); // export filter |
|---|
| 51 | } |
|---|
| 52 | else { |
|---|
| 53 | GBDATA *gb_name = GB_get_father(gbd); // ali_xxxx |
|---|
| 54 | gb_name = GB_brother(gb_name, "name"); |
|---|
| 55 | char *name2 = GB_read_string(gb_name); |
|---|
| 56 | aw_root->awar(cbs->def_name)->write_string(name2); |
|---|
| 57 | free(name2); |
|---|
| 58 | char *_2filter = aw_root->awar(cbs->def_2filter)->read_string(); |
|---|
| 59 | long _2filter_len = strlen(_2filter); |
|---|
| 60 | |
|---|
| 61 | char *s, *str; |
|---|
| 62 | long len = GBT_get_alignment_len(cbs->gb_main, use); |
|---|
| 63 | GBS_strstruct *strstruct = GBS_stropen(5000); |
|---|
| 64 | long i; for (i=0; i<len; i++) { // build position line |
|---|
| 65 | if (i%10 == 0) { |
|---|
| 66 | GBS_chrcat(strstruct, '#'); |
|---|
| 67 | } |
|---|
| 68 | else if (i%5==0) { |
|---|
| 69 | GBS_chrcat(strstruct, '|'); |
|---|
| 70 | } |
|---|
| 71 | else { |
|---|
| 72 | GBS_chrcat(strstruct, '.'); |
|---|
| 73 | } |
|---|
| 74 | } |
|---|
| 75 | GBS_chrcat(strstruct, '\n'); |
|---|
| 76 | char *data = GBS_mempntr(strstruct); |
|---|
| 77 | |
|---|
| 78 | for (i=0; i<len-10; i++) { // place markers |
|---|
| 79 | if (i%10 == 0) { |
|---|
| 80 | char buffer[256]; |
|---|
| 81 | sprintf(buffer, "%li", i+1); |
|---|
| 82 | memcpy(data+i+1, buffer, strlen(buffer)); // copy string w/o trailing 0-byte! |
|---|
| 83 | } |
|---|
| 84 | } |
|---|
| 85 | |
|---|
| 86 | if (GB_read_type(gbd) == GB_STRING) { // read the filter |
|---|
| 87 | str = GB_read_string(gbd); |
|---|
| 88 | } |
|---|
| 89 | else { |
|---|
| 90 | str = GB_read_bits(gbd, '-', '+'); |
|---|
| 91 | } |
|---|
| 92 | GBS_strcat(strstruct, str); |
|---|
| 93 | GBS_chrcat(strstruct, '\n'); |
|---|
| 94 | char *canc = aw_root->awar(cbs->def_cancel)->read_string(); |
|---|
| 95 | long min = aw_root->awar(cbs->def_min)->read_int()-1; |
|---|
| 96 | long max = aw_root->awar(cbs->def_max)->read_int()-1; |
|---|
| 97 | long flen = 0; |
|---|
| 98 | for (i=0, s=str; *s; ++s, ++i) { // transform the filter |
|---|
| 99 | if (strchr(canc, *s) || (i<min) || (max>0 && i > max)) { |
|---|
| 100 | *s = '0'; |
|---|
| 101 | } |
|---|
| 102 | else { |
|---|
| 103 | if (i > _2filter_len || _2filter[i] != '0') { |
|---|
| 104 | *s = '1'; |
|---|
| 105 | flen++; |
|---|
| 106 | } |
|---|
| 107 | else { |
|---|
| 108 | *s = '0'; |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | } |
|---|
| 112 | GBS_strcat(strstruct, str); |
|---|
| 113 | GBS_chrcat(strstruct, '\n'); |
|---|
| 114 | |
|---|
| 115 | aw_root->awar(cbs->def_len) ->write_int(flen); // export filter |
|---|
| 116 | aw_root->awar(cbs->def_filter)->write_string(str); // export filter |
|---|
| 117 | aw_root->awar(cbs->def_source)->write_string(GBS_mempntr(strstruct)); // set display |
|---|
| 118 | |
|---|
| 119 | free(_2filter); |
|---|
| 120 | free(str); |
|---|
| 121 | free(canc); |
|---|
| 122 | GBS_strforget(strstruct); |
|---|
| 123 | } |
|---|
| 124 | free(to_free_target); |
|---|
| 125 | free(use); |
|---|
| 126 | GB_pop_transaction(cbs->gb_main); |
|---|
| 127 | } |
|---|
| 128 | |
|---|
| 129 | static void awt_add_sequences_to_list(adfiltercbstruct *cbs, const char *use, GBDATA *gb_extended, const char *pre, char tpre) { |
|---|
| 130 | GBDATA *gb_ali = GB_entry(gb_extended, use); |
|---|
| 131 | |
|---|
| 132 | if (gb_ali) { |
|---|
| 133 | int count = 0; |
|---|
| 134 | GBDATA *gb_type = GB_entry(gb_ali, "_TYPE"); |
|---|
| 135 | const char *TYPE = gb_type ? GB_read_char_pntr(gb_type) : ""; |
|---|
| 136 | char *name = ARB_strdup(GBT_get_name_or_description(gb_extended)); |
|---|
| 137 | GBDATA *gb_data; |
|---|
| 138 | |
|---|
| 139 | for (gb_data = GB_child(gb_ali); gb_data; gb_data = GB_nextChild(gb_data)) { |
|---|
| 140 | if (GB_read_key_pntr(gb_data)[0] != '_') { |
|---|
| 141 | long type = GB_read_type(gb_data); |
|---|
| 142 | |
|---|
| 143 | if (type == GB_BITS || type == GB_STRING) { |
|---|
| 144 | char *str; |
|---|
| 145 | |
|---|
| 146 | if (count) str = GBS_global_string_copy("%s%-20s SEQ_%i %s", pre, name, count + 1, TYPE); |
|---|
| 147 | else str = GBS_global_string_copy("%s%-20s %s", pre, name, TYPE); |
|---|
| 148 | |
|---|
| 149 | const char *target = GBS_global_string("%c%s%c%s", tpre, GB_read_key_pntr(gb_data), 1, name); |
|---|
| 150 | |
|---|
| 151 | cbs->filterlist->insert(str, target); |
|---|
| 152 | free(str); |
|---|
| 153 | count++; |
|---|
| 154 | } |
|---|
| 155 | } |
|---|
| 156 | } |
|---|
| 157 | free(name); |
|---|
| 158 | } |
|---|
| 159 | } |
|---|
| 160 | |
|---|
| 161 | static void awt_create_select_filter_window_gb_cb(UNFIXED, adfiltercbstruct *cbs) { |
|---|
| 162 | // update list widget and variables |
|---|
| 163 | GB_push_transaction(cbs->gb_main); |
|---|
| 164 | |
|---|
| 165 | if (cbs->filterlist) { |
|---|
| 166 | char *use = cbs->awr->awar(cbs->def_alignment)->read_string(); |
|---|
| 167 | |
|---|
| 168 | cbs->filterlist->clear(); |
|---|
| 169 | cbs->filterlist->insert_default("none", ""); |
|---|
| 170 | |
|---|
| 171 | const char *name = GBT_readOrCreate_char_pntr(cbs->gb_main, AWAR_SPECIES_NAME, ""); |
|---|
| 172 | if (name[0]) { |
|---|
| 173 | GBDATA *gb_species = GBT_find_species(cbs->gb_main, name); |
|---|
| 174 | if (gb_species) { |
|---|
| 175 | awt_add_sequences_to_list(cbs, use, gb_species, "SEL. SPECIES:", '@'); |
|---|
| 176 | } |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | for (GBDATA *gb_extended = GBT_first_SAI(cbs->gb_main); |
|---|
| 180 | gb_extended; |
|---|
| 181 | gb_extended = GBT_next_SAI(gb_extended)) |
|---|
| 182 | { |
|---|
| 183 | awt_add_sequences_to_list(cbs, use, gb_extended, "", ' '); |
|---|
| 184 | } |
|---|
| 185 | |
|---|
| 186 | cbs->filterlist->update(); |
|---|
| 187 | free(use); |
|---|
| 188 | } |
|---|
| 189 | awt_create_select_filter_window_aw_cb(NULp, cbs); |
|---|
| 190 | GB_pop_transaction(cbs->gb_main); |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | void awt_create_filter_awars(AW_root *aw_root, AW_default aw_def, const char *awar_filtername, const char *awar_mapto_alignment) { |
|---|
| 194 | /*! creates awars needed for filter definition (see awt_create_select_filter()) |
|---|
| 195 | * |
|---|
| 196 | * created awars: "SOMETHING/name" (as specified in param awar_filtername; type STRING) |
|---|
| 197 | * "SOMETHING/filter" (type STRING) |
|---|
| 198 | * "SOMETHING/alignment" (type STRING) |
|---|
| 199 | * |
|---|
| 200 | * The names of the created awars are available via adfiltercbstruct (after awt_create_select_filter() was called). |
|---|
| 201 | * |
|---|
| 202 | * @param aw_root application root |
|---|
| 203 | * @param aw_def database for created awars |
|---|
| 204 | * @param awar_filtername name of filtername awar (has to be "SOMETHING/name"; |
|---|
| 205 | * awarname should start with "tmp/", saving in properties/db does not work correctly!). |
|---|
| 206 | * @param awar_mapto_alignment if given, "SOMETHING/alignment" is mapped to this awar |
|---|
| 207 | */ |
|---|
| 208 | |
|---|
| 209 | ga_assert(ARB_strBeginsWith(awar_filtername, "tmp/")); // see above |
|---|
| 210 | |
|---|
| 211 | char *awar_filter = GBS_string_eval(awar_filtername, "/name=/filter"); |
|---|
| 212 | char *awar_alignment = GBS_string_eval(awar_filtername, "/name=/alignment"); |
|---|
| 213 | |
|---|
| 214 | aw_root->awar_string(awar_filtername, "none", aw_def); |
|---|
| 215 | aw_root->awar_string(awar_filter, "", aw_def); |
|---|
| 216 | |
|---|
| 217 | AW_awar *awar_ali = aw_root->awar_string(awar_alignment, "", aw_def); |
|---|
| 218 | if (awar_mapto_alignment) awar_ali->map(awar_mapto_alignment); |
|---|
| 219 | |
|---|
| 220 | free(awar_alignment); |
|---|
| 221 | free(awar_filter); |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | adfiltercbstruct *awt_create_select_filter(AW_root *aw_root, GBDATA *gb_main, const char *def_name) { |
|---|
| 225 | /*! Create filter definition (allowing customization and programmatical use of a filter) |
|---|
| 226 | * |
|---|
| 227 | * @param aw_root application root |
|---|
| 228 | * @param gb_main DB root node |
|---|
| 229 | * @param def_name filtername awarname (name has to be "SOMETHING/name"; create using awt_create_filter_awars()) |
|---|
| 230 | * @return the filter definition |
|---|
| 231 | * @see awt_create_select_filter_win(), awt_get_filter() |
|---|
| 232 | */ |
|---|
| 233 | |
|---|
| 234 | adfiltercbstruct *acbs = new adfiltercbstruct; |
|---|
| 235 | acbs->gb_main = gb_main; |
|---|
| 236 | AW_default aw_def = AW_ROOT_DEFAULT; |
|---|
| 237 | |
|---|
| 238 | GB_push_transaction(acbs->gb_main); |
|---|
| 239 | |
|---|
| 240 | #if defined(DEBUG) |
|---|
| 241 | { |
|---|
| 242 | int len = strlen(def_name); |
|---|
| 243 | |
|---|
| 244 | ga_assert(len >= 5); |
|---|
| 245 | ga_assert(strcmp(def_name+len-5, "/name") == 0); // filter awar has to be "SOMETHING/name" |
|---|
| 246 | } |
|---|
| 247 | #endif // DEBUG |
|---|
| 248 | |
|---|
| 249 | acbs->def_name = GBS_string_eval(def_name, "/name=/name"); |
|---|
| 250 | acbs->def_filter = GBS_string_eval(def_name, "/name=/filter"); |
|---|
| 251 | acbs->def_alignment = GBS_string_eval(def_name, "/name=/alignment"); |
|---|
| 252 | |
|---|
| 253 | acbs->def_min = GBS_string_eval(def_name, "*/name=tmp/*1/min:tmp/tmp=tmp"); |
|---|
| 254 | acbs->def_max = GBS_string_eval(def_name, "*/name=tmp/*1/max:tmp/tmp=tmp"); |
|---|
| 255 | aw_root->awar_int(acbs->def_min)->add_callback(makeRootCallback(awt_create_select_filter_window_aw_cb, acbs)); |
|---|
| 256 | aw_root->awar_int(acbs->def_max)->add_callback(makeRootCallback(awt_create_select_filter_window_aw_cb, acbs)); |
|---|
| 257 | |
|---|
| 258 | acbs->def_len = GBS_string_eval(def_name, "*/name=tmp/*1/len:tmp/tmp=tmp"); |
|---|
| 259 | aw_root->awar_int(acbs->def_len); |
|---|
| 260 | |
|---|
| 261 | acbs->def_dest = GBS_string_eval(def_name, "*/name=tmp/*1/dest:tmp/tmp=tmp"); |
|---|
| 262 | aw_root->awar_string(acbs->def_dest, "", aw_def); |
|---|
| 263 | |
|---|
| 264 | acbs->def_cancel = GBS_string_eval(def_name, "*/name=*1/cancel"); |
|---|
| 265 | aw_root->awar_string(acbs->def_cancel, ".0-=", aw_def); |
|---|
| 266 | |
|---|
| 267 | acbs->def_simplify = GBS_string_eval(def_name, "*/name=*1/simplify"); |
|---|
| 268 | aw_root->awar_int(acbs->def_simplify, 0, aw_def); |
|---|
| 269 | |
|---|
| 270 | acbs->def_subname = GBS_string_eval(def_name, "*/name=tmp/*1/subname:tmp/tmp=tmp"); |
|---|
| 271 | aw_root->awar_string(acbs->def_subname); |
|---|
| 272 | |
|---|
| 273 | acbs->def_source = GBS_string_eval(def_name, "*/name=tmp/*/source:tmp/tmp=tmp"); |
|---|
| 274 | aw_root->awar_string(acbs->def_source); |
|---|
| 275 | |
|---|
| 276 | acbs->def_2name = GBS_string_eval(def_name, "*/name=tmp/*/2filter/name:tmp/tmp=tmp"); |
|---|
| 277 | acbs->def_2filter = GBS_string_eval(def_name, "*/name=tmp/*/2filter/filter:tmp/tmp=tmp"); |
|---|
| 278 | acbs->def_2alignment = GBS_string_eval(def_name, "*/name=tmp/*/2filter/alignment:tmp/tmp=tmp"); |
|---|
| 279 | |
|---|
| 280 | aw_root->awar_string(acbs->def_2name)->write_string("- none -"); |
|---|
| 281 | aw_root->awar_string(acbs->def_2filter); |
|---|
| 282 | aw_root->awar_string(acbs->def_2alignment); |
|---|
| 283 | |
|---|
| 284 | acbs->filterlist = NULp; |
|---|
| 285 | acbs->aw_filt = NULp; |
|---|
| 286 | acbs->awr = aw_root; |
|---|
| 287 | { |
|---|
| 288 | char *fname = aw_root->awar(acbs->def_name)->read_string(); |
|---|
| 289 | const char *fsname = GBS_global_string(" data%c%s", 1, fname); |
|---|
| 290 | free(fname); |
|---|
| 291 | aw_root->awar(acbs->def_subname)->write_string(fsname); // cause an callback |
|---|
| 292 | } |
|---|
| 293 | |
|---|
| 294 | aw_root->awar(acbs->def_subname)->touch(); // cause an callback |
|---|
| 295 | |
|---|
| 296 | GBDATA *gb_sai_data = GBT_get_SAI_data(acbs->gb_main); |
|---|
| 297 | GBDATA *gb_sel = GB_search(acbs->gb_main, AWAR_SPECIES_NAME, GB_STRING); |
|---|
| 298 | |
|---|
| 299 | GB_add_callback(gb_sai_data, GB_CB_CHANGED, makeDatabaseCallback(awt_create_select_filter_window_gb_cb, acbs)); |
|---|
| 300 | GB_add_callback(gb_sel, GB_CB_CHANGED, makeDatabaseCallback(awt_create_select_filter_window_gb_cb, acbs)); |
|---|
| 301 | |
|---|
| 302 | aw_root->awar(acbs->def_alignment)->add_callback(makeRootCallback(awt_create_select_filter_window_gb_cb, acbs)); |
|---|
| 303 | aw_root->awar(acbs->def_2filter) ->add_callback(makeRootCallback(awt_create_select_filter_window_aw_cb, acbs)); |
|---|
| 304 | aw_root->awar(acbs->def_subname) ->add_callback(makeRootCallback(awt_create_select_filter_window_aw_cb, acbs)); |
|---|
| 305 | |
|---|
| 306 | awt_create_select_filter_window_gb_cb(NULp, acbs); |
|---|
| 307 | |
|---|
| 308 | GB_pop_transaction(acbs->gb_main); |
|---|
| 309 | return acbs; |
|---|
| 310 | } |
|---|
| 311 | |
|---|
| 312 | |
|---|
| 313 | void awt_set_awar_to_valid_filter_good_for_tree_methods(GBDATA *gb_main, AW_root *awr, const char *awar_name) { |
|---|
| 314 | GB_transaction transaction_var(gb_main); |
|---|
| 315 | if (GBT_find_SAI(gb_main, "POS_VAR_BY_PARSIMONY")) { |
|---|
| 316 | awr->awar(awar_name)->write_string("POS_VAR_BY_PARSIMONY"); |
|---|
| 317 | return; |
|---|
| 318 | } |
|---|
| 319 | if (GBT_find_SAI(gb_main, "ECOLI")) { |
|---|
| 320 | awr->awar(awar_name)->write_string("ECOLI"); |
|---|
| 321 | return; |
|---|
| 322 | } |
|---|
| 323 | } |
|---|
| 324 | |
|---|
| 325 | static AW_window *awt_create_2_filter_window(AW_root *aw_root, adfiltercbstruct *acbs) { |
|---|
| 326 | GB_push_transaction(acbs->gb_main); |
|---|
| 327 | aw_root->awar(acbs->def_2alignment)->map(acbs->def_alignment); |
|---|
| 328 | adfiltercbstruct *s2filter = awt_create_select_filter(aw_root, acbs->gb_main, acbs->def_2name); |
|---|
| 329 | GB_pop_transaction(acbs->gb_main); |
|---|
| 330 | return awt_create_select_filter_win(aw_root, s2filter); |
|---|
| 331 | } |
|---|
| 332 | |
|---|
| 333 | char *AWT_get_combined_filter_name(AW_root *aw_root, GB_CSTR prefix) { |
|---|
| 334 | char *combined_name = aw_root->awar(GBS_global_string("%s/filter/name", prefix))->read_string(); // "gde/filter/name" |
|---|
| 335 | const char *awar_prefix = AWAR_GDE_FILTER; |
|---|
| 336 | const char *awar_repeated = "/2filter"; |
|---|
| 337 | const char *awar_postfix = "/name"; |
|---|
| 338 | int prefix_len = strlen(awar_prefix); |
|---|
| 339 | int repeated_len = strlen(awar_repeated); |
|---|
| 340 | int postfix_len = strlen(awar_postfix); |
|---|
| 341 | int count; |
|---|
| 342 | |
|---|
| 343 | for (count = 1; ; ++count) { |
|---|
| 344 | char *awar_name = new char[prefix_len + count*repeated_len + postfix_len + 1]; |
|---|
| 345 | strcpy(awar_name, awar_prefix); |
|---|
| 346 | int c; |
|---|
| 347 | for (c=0; c<count; ++c) strcat(awar_name, awar_repeated); |
|---|
| 348 | strcat(awar_name, awar_postfix); |
|---|
| 349 | |
|---|
| 350 | AW_awar *awar_found = aw_root->awar_no_error(awar_name); |
|---|
| 351 | delete [] awar_name; |
|---|
| 352 | |
|---|
| 353 | if (!awar_found) break; // no more filters defined |
|---|
| 354 | char *content = awar_found->read_string(); |
|---|
| 355 | |
|---|
| 356 | if (!strstr(content, "none")) { // don't add filters named 'none' |
|---|
| 357 | freeset(combined_name, GBS_global_string_copy("%s/%s", combined_name, content)); |
|---|
| 358 | } |
|---|
| 359 | } |
|---|
| 360 | |
|---|
| 361 | return combined_name; |
|---|
| 362 | } |
|---|
| 363 | |
|---|
| 364 | AW_window *awt_create_select_filter_win(AW_root *aw_root, adfiltercbstruct *acbs) { |
|---|
| 365 | //! Create a filter selection window |
|---|
| 366 | if (!acbs->aw_filt) { |
|---|
| 367 | GB_push_transaction(acbs->gb_main); |
|---|
| 368 | |
|---|
| 369 | AW_window_simple *aws = new AW_window_simple; |
|---|
| 370 | { |
|---|
| 371 | int checksum = GBS_checksum(acbs->def_name, true, NULp); |
|---|
| 372 | char *window_id = GBS_global_string_copy("FILTER_SELECT_%i", checksum); // make window id awar specific |
|---|
| 373 | |
|---|
| 374 | aws->init(aw_root, window_id, "Select Filter"); |
|---|
| 375 | free(window_id); |
|---|
| 376 | } |
|---|
| 377 | aws->load_xfig("awt/filter.fig"); |
|---|
| 378 | aws->button_length(10); |
|---|
| 379 | |
|---|
| 380 | aws->at("close"); |
|---|
| 381 | aws->callback(AW_POPDOWN); |
|---|
| 382 | aws->create_button("CLOSE", "CLOSE", "C"); |
|---|
| 383 | |
|---|
| 384 | aws->at("help"); aws->callback(makeHelpCallback("sel_fil.hlp")); |
|---|
| 385 | aws->create_button("HELP", "HELP", "H"); |
|---|
| 386 | |
|---|
| 387 | acbs->aw_filt = aws; // store the filter selection window in 'acbs' |
|---|
| 388 | |
|---|
| 389 | aws->at("filter"); |
|---|
| 390 | acbs->filterlist = aws->create_selection_list(acbs->def_subname, 20, 3, true); |
|---|
| 391 | |
|---|
| 392 | aws->at("2filter"); |
|---|
| 393 | aws->callback(makeCreateWindowCallback(awt_create_2_filter_window, acbs)); |
|---|
| 394 | aws->create_button(acbs->def_2name, acbs->def_2name); |
|---|
| 395 | |
|---|
| 396 | aws->at("zero"); |
|---|
| 397 | aws->callback(makeWindowCallback(awt_create_select_filter_window_aw_cb, acbs)); // @@@ used as INPUTFIELD_CB (see #559) |
|---|
| 398 | aws->create_input_field(acbs->def_cancel, 10); |
|---|
| 399 | |
|---|
| 400 | aws->at("sequence"); |
|---|
| 401 | aws->create_text_field(acbs->def_source, 1, 1); |
|---|
| 402 | |
|---|
| 403 | aws->at("min"); |
|---|
| 404 | aws->create_input_field(acbs->def_min, 4); |
|---|
| 405 | |
|---|
| 406 | aws->at("max"); |
|---|
| 407 | aws->create_input_field(acbs->def_max, 4); |
|---|
| 408 | |
|---|
| 409 | aws->at("simplify"); |
|---|
| 410 | aws->create_option_menu(acbs->def_simplify, true); |
|---|
| 411 | aws->insert_option("ORIGINAL DATA", "O", 0); |
|---|
| 412 | aws->sens_mask(AWM_EXP); |
|---|
| 413 | aws->insert_option("TRANSVERSIONS ONLY", "T", 1); |
|---|
| 414 | aws->insert_option("SIMPLIFIED AA", "A", 2); |
|---|
| 415 | aws->sens_mask(AWM_ALL); |
|---|
| 416 | aws->update_option_menu(); |
|---|
| 417 | |
|---|
| 418 | awt_create_select_filter_window_gb_cb(NULp, acbs); |
|---|
| 419 | |
|---|
| 420 | aws->button_length(7); |
|---|
| 421 | aws->at("len"); |
|---|
| 422 | aws->create_button(NULp, acbs->def_len); |
|---|
| 423 | |
|---|
| 424 | GB_pop_transaction(acbs->gb_main); |
|---|
| 425 | } |
|---|
| 426 | |
|---|
| 427 | return acbs->aw_filt; |
|---|
| 428 | } |
|---|
| 429 | |
|---|
| 430 | AP_filter *awt_get_filter(adfiltercbstruct *acbs) { |
|---|
| 431 | /*! create a filter from settings made in filter-definition window. |
|---|
| 432 | * always returns a filter, use awt_invalid_filter() to check for validity |
|---|
| 433 | */ |
|---|
| 434 | AP_filter *filter = NULp; |
|---|
| 435 | |
|---|
| 436 | if (acbs) { |
|---|
| 437 | GB_push_transaction(acbs->gb_main); |
|---|
| 438 | |
|---|
| 439 | char *filter_string = acbs->awr->awar(acbs->def_filter)->read_string(); |
|---|
| 440 | long len = 0; |
|---|
| 441 | |
|---|
| 442 | { |
|---|
| 443 | char *use = acbs->awr->awar(acbs->def_alignment)->read_string(); |
|---|
| 444 | |
|---|
| 445 | len = GBT_get_alignment_len(acbs->gb_main, use); |
|---|
| 446 | free(use); |
|---|
| 447 | } |
|---|
| 448 | |
|---|
| 449 | if (len == -1) { // no alignment -> uses dummy filter |
|---|
| 450 | GB_clear_error(); |
|---|
| 451 | } |
|---|
| 452 | else { // have alignment |
|---|
| 453 | filter = new AP_filter(filter_string, "0", len); |
|---|
| 454 | int sim = acbs->awr->awar(acbs->def_simplify)->read_int(); |
|---|
| 455 | filter->enable_simplify((AWT_FILTER_SIMPLIFY)sim); |
|---|
| 456 | free(filter_string); |
|---|
| 457 | } |
|---|
| 458 | |
|---|
| 459 | GB_pop_transaction(acbs->gb_main); |
|---|
| 460 | } |
|---|
| 461 | |
|---|
| 462 | if (!filter) filter = new AP_filter(0); // empty dummy filter |
|---|
| 463 | return filter; |
|---|
| 464 | } |
|---|
| 465 | |
|---|
| 466 | GB_ERROR awt_invalid_filter(AP_filter *filter) { |
|---|
| 467 | return filter->is_invalid(); |
|---|
| 468 | } |
|---|
| 469 | |
|---|
| 470 | void awt_destroy_filter(AP_filter *filter) { |
|---|
| 471 | delete filter; |
|---|
| 472 | } |
|---|