ARB
probe_design.cxx
Go to the documentation of this file.
1 // =============================================================== //
2 // //
3 // File : probe_design.cxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // =============================================================== //
10 
12 #include "probe_match_parser.hxx"
13 
14 #include <PT_com.h>
15 #include <PT_server.h> // needed for DOMAIN_MIN_LENGTH
16 #include <client.h>
17 #include <servercntrl.h>
18 #include <probe_gui.hxx>
19 #include <probe_local.hxx>
20 
21 #include <GEN.hxx>
22 #include <TreeCallbacks.hxx>
23 
24 #include <iupac.h>
25 #include <awt_config_manager.hxx>
26 #include <awt_sel_boxes.hxx>
27 #include <awt_misc.hxx>
28 
29 #include <aw_awars.hxx>
30 #include <aw_preset.hxx>
31 #include <aw_select.hxx>
32 #include <aw_msg.hxx>
33 #include <aw_root.hxx>
34 #include <aw_question.hxx>
35 #include <aw_edit.hxx>
36 #include <rootAsWin.h>
37 
38 #include <adGene.h>
39 
40 #include <arb_progress.h>
41 #include <arb_strbuf.h>
42 #include <arb_file.h>
43 #include <arb_misc.h>
44 
45 #include "probe_collection.hxx"
46 
47 // general awars
48 
49 #define AWAR_PROBE_CREATE_GENE_SERVER "tmp/probe_admin/gene_server" // whether to create a gene pt server
50 
51 #define AWAR_ITARGET_STRING "nt/itarget_string"
52 
53 // probe match awars
54 
55 // #define AWAR_PD_MATCH_ITEM AWAR_SPECIES_NAME
56 #define AWAR_PD_SELECTED_MATCH "tmp/probe_design/match"
57 #define AWAR_PD_MATCH_RESOLVE "tmp/probe_design/match_resolve" // for IUPAC resolution
58 
59 #define AWAR_PD_MATCH_SORTBY "probe_match/sort_by" // weighted mismatches
60 #define AWAR_PD_MATCH_ALSO_REVCOMP "probe_match/complement" // check reverse complement too
61 #define AWAR_PD_MATCH_MARKHITS "probe_match/mark_hits" // mark hitten species in database
62 #define AWAR_PD_MATCH_WRITE2TMP "probe_match/write_2_tmp" // write result to field tmp
63 #define AWAR_PD_MATCH_AUTOMATCH "probe_match/auto_match" // auto match probes when target string changes
64 
65 #define AWAR_PD_MATCH_NHITS "tmp/probe_match/nhits" // display the 'number of hits'
66 
67 // probe design awars
68 
69 #define AWAR_PD_DESIGN_CLIPRESULT "probe_design/CLIPRESULT" // 'length of output' (how many probes will get designed)
70 #define AWAR_PD_DESIGN_MISHIT "probe_design/MISHIT" // 'non group hits'
71 #define AWAR_PD_DESIGN_MAXBOND "probe_design/MAXBOND" // max hairpinbonds ?
72 #define AWAR_PD_DESIGN_MINTARGETS "probe_design/MINTARGETS" // 'min. group hits (%)'
73 
74 #define AWAR_PD_DESIGN_MIN_LENGTH "probe_design/PROBELENGTH" // min. length of probe
75 #define AWAR_PD_DESIGN_MAX_LENGTH "probe_design/PROBEMAXLENGTH" // max. length of probe (or empty)
76 
77 #define AWAR_PD_DESIGN_MIN_TEMP "probe_design/MINTEMP" // temperature (min)
78 #define AWAR_PD_DESIGN_MAX_TEMP "probe_design/MAXTEMP" // temperature (max)
79 #define AWAR_PD_DESIGN_MIN_GC "probe_design/MINGC" // GC content (min)
80 #define AWAR_PD_DESIGN_MAX_GC "probe_design/MAXGC" // GC content (max)
81 #define AWAR_PD_DESIGN_MIN_ECOLIPOS "probe_design/MINECOLI" // ecolipos (min)
82 #define AWAR_PD_DESIGN_MAX_ECOLIPOS "probe_design/MAXECOLI" // ecolipos (max)
83 
84 #define AWAR_PD_DESIGN_GENE "probe_design/gene" // generate probes for genes ?
85 
86 // probe design/match (expert window)
87 #define AWAR_PD_COMMON_EXP_BONDS_FORMAT "probe_design/bonds/pos%i" // format to generate bond awar names
88 #define AWAR_PD_COMMON_EXP_SPLIT "probe_design/SPLIT"
89 
90 #define AWAR_PD_DESIGN_EXP_DTEDGE "probe_design/DTEDGE"
91 #define AWAR_PD_DESIGN_EXP_DT "probe_design/DT"
92 
93 #define AWAR_PD_MATCH_NMATCHES "probe_match/nmatches"
94 #define AWAR_PD_MATCH_LIM_NMATCH "probe_match/lim_nmatch"
95 #define AWAR_PD_MATCH_MAX_RES "probe_match/maxres"
96 
97 // --------------------------------
98 // probe collection awars
99 
100 // probe collection window
101 #define AWAR_PC_TARGET_STRING "probe_collection/target_string"
102 #define AWAR_PC_TARGET_NAME "probe_collection/target_name"
103 #define AWAR_PC_MATCH_WEIGHTS "probe_collection/match_weights/pos"
104 #define AWAR_PC_MATCH_WIDTH "probe_collection/match_weights/width"
105 #define AWAR_PC_MATCH_BIAS "probe_collection/match_weights/bias"
106 #define AWAR_PC_AUTO_MATCH "probe_collection/auto"
107 #define AWAR_PC_CURRENT_COLLECTION "probe_collection/current"
108 
109 #define AWAR_PC_SELECTED_PROBE "tmp/probe_collection/probe"
110 #define AWAR_PC_MATCH_NHITS "tmp/probe_collection/nhits"
111 
112 // probe collection matching control parameters
113 #define AWAR_PC_MISMATCH_THRESHOLD "probe_collection/mismatch_threshold"
114 
115 #define REPLACE_TARGET_CONTROL_CHARS ":#=_:\\:=_"
116 
117 // ----------------------------------------
118 
120 
121 static struct {
123  T_PT_LOCS locs;
124  T_PT_MAIN com;
125  AW_window_simple *win;
126  AW_selection_list *resultList; // @@@ replace by TypedSelectionList?
127 } PD;
128 
132  int *counter; // may be NULp (if specified -> afterwards contains number of hits)
133 
134  // results set by probe_match_event:
135  std::string hits_summary; // shown in probe match window
137 
138  void init_results() {
139  refresh_sai_display = false;
140  }
141 
142  ProbeMatchEventParam(GBDATA *gb_main_, int *counter_) : gb_main(gb_main_), selection_id(NULp), counter(counter_) { init_results(); }
143  ProbeMatchEventParam(GBDATA *gb_main_, AW_selection_list *id) : gb_main(gb_main_), selection_id(id), counter(NULp) { init_results(); }
144 };
145 
148  bool disable;
149 
150  AutoMatchSettings(ProbeMatchEventParam *event_param_, bool disable_)
151  : event_param(event_param_), disable(disable_)
152  {}
154  event_param(NULp),
155  disable(true)
156  {}
157 
158  bool initialized() const { return event_param; }
159 };
160 
162 
163 // prototypes:
164 static void probe_match_event_using_awars(AW_root *root, ProbeMatchEventParam *event_param);
165 
166 static void auto_match_cb(AW_root *root) {
167  if (!auto_match_cb_settings.disable) {
168  char *ts = root->awar(AWAR_TARGET_STRING)->read_string();
169  if (strlen(ts) > 0) {
170  probe_match_event_using_awars(root, auto_match_cb_settings.event_param);
171  }
172  free(ts);
173  }
174 }
175 
176 static const char *auto_match_sensitive_awars[] = {
182  NULp
183 };
184 
185 static void auto_match_changed(AW_root *root) {
186  static bool callback_active = false;
187  int autoMatch = root->awar(AWAR_PD_MATCH_AUTOMATCH)->read_int();
188 
189  if (autoMatch) {
190  if (!callback_active) {
191  for (int i = 0; auto_match_sensitive_awars[i]; ++i) {
192  root->awar(auto_match_sensitive_awars[i])->add_callback(auto_match_cb);
193  }
194  }
195  }
196  else {
197  if (callback_active) {
198  for (int i = 0; auto_match_sensitive_awars[i]; ++i) {
199  root->awar(auto_match_sensitive_awars[i])->remove_callback(auto_match_cb);
200  }
201  }
202  }
203  callback_active = bool(autoMatch);
204 }
205 
206 static void enable_auto_match_cb(AW_root *root, ProbeMatchEventParam *event_param) {
207  if (!event_param && auto_match_cb_settings.initialized()) {
208  // "partially" enable (w/o ProbeMatchEventParam) is only done
209  // if not already "fully enabled"
210  return;
211  }
212 
213  auto_match_cb_settings = AutoMatchSettings(event_param, false);
214  auto_match_changed(root);
215 }
216 
217 static void popup_match_window_cb(AW_window *aww, GBDATA *gb_main) { // @@@ shall be called by auto_match_cb (if never opened b4)
218  AW_root *root = aww->get_root();
219  AW_window *match_window = create_probe_match_window(root, gb_main);
220  match_window->activate();
221  root->awar(AWAR_TARGET_STRING)->touch(); // force re-match
222 }
223 
224 // --------------------------------------------------------------------------------
225 
227  if (!PD.win) {
228  AW_root *root = aww->get_root();
229 
230  PD.win = new AW_window_simple;
231  PD.win->init(root, "PD_RESULT", "PD RESULT");
232  PD.win->load_xfig("pd_reslt.fig");
233 
234  PD.win->button_length(6);
235  PD.win->auto_space(10, 10);
236 
237  PD.win->at("help");
238  PD.win->callback(makeHelpCallback("probedesignresult.hlp"));
239  PD.win->create_button("HELP", "HELP", "H");
240 
241  PD.win->at("result");
242  PD.resultList = PD.win->create_selection_list(AWAR_TARGET_STRING, 40, 5);
243  const StorableSelectionList *storable_result_list = new StorableSelectionList(TypedSelectionList("prb", PD.resultList, "designed probes", "designed")); // @@@ make member of PD ?
244 
245  PD.resultList->clear();
246  PD.resultList->insert_default("No probes designed yet", "");
247 
248  PD.win->at("buttons");
249 
250  PD.win->callback(AW_POPDOWN);
251  PD.win->create_button("CLOSE", "CLOSE", "C");
252 
253  PD.win->callback(makeWindowCallback(awt_clear_selection_list_cb, PD.resultList));
254  PD.win->create_button("CLEAR", "CLEAR", "R");
255 
256  PD.win->callback(makeCreateWindowCallback(create_load_box_for_selection_lists, storable_result_list));
257  PD.win->create_button("LOAD", "LOAD", "L");
258 
259  PD.win->callback(makeCreateWindowCallback(create_save_box_for_selection_lists, storable_result_list));
260  PD.win->create_button("SAVE", "SAVE", "S");
261 
262  PD.win->callback(makeWindowCallback(create_print_box_for_selection_lists, &storable_result_list->get_typedsellist()));
263  PD.win->create_button("PRINT", "PRINT", "P");
264 
265  PD.win->callback(makeWindowCallback(popup_match_window_cb, gb_main));
266  PD.win->create_button("MATCH", "MATCH", "M");
267 
268  PD.win->label("Auto match");
269  PD.win->create_toggle(AWAR_PD_MATCH_AUTOMATCH);
270 
271  enable_auto_match_cb(root, NULp);
272  }
273  PD.win->activate();
274 }
275 
276 static int init_local_com_struct() {
277  const char *user = GB_getenvUSER();
278 
279  if (aisc_create(PD.link, PT_MAIN, PD.com,
280  MAIN_LOCS, PT_LOCS, PD.locs,
281  LOCS_USER, user,
282  NULp)) {
283  return 1;
284  }
285  return 0;
286 }
287 
288 static const char *PD_probe_pt_look_for_server(int serverNumber, GB_ERROR& error) {
289  // return PT server info string (see GBS_read_arb_tcp for details)
290  // or NULp (in this case 'error' is set)
291 
292  // DRY vs ../TOOLS/arb_probe.cxx@AP_probe_pt_look_for_server
293  // DRY vs ../MULTI_PROBE/MP_noclass.cxx@MP_probe_pt_look_for_server
294 
295  const char *result = NULp;
296  const char *server_tag = GBS_ptserver_tag(serverNumber);
297 
298  error = arb_look_and_start_server(AISC_MAGIC_NUMBER, server_tag);
299  if (!error) {
300  result = GBS_read_arb_tcp(server_tag);
301  if (!result) error = GB_await_error();
302  }
303  pd_assert(contradicted(result, error));
304  return result;
305 }
306 
307 static GB_ERROR species_requires(GBDATA *gb_species, const char *whats_required) {
308  return GBS_global_string("Species '%s' needs %s", GBT_get_name_or_description(gb_species), whats_required);
309 }
310 
311 static GB_ERROR gene_requires(GBDATA *gb_gene, const char *whats_required) {
312  GBDATA *gb_species = GB_get_grandfather(gb_gene);
313  pd_assert(gb_species);
314  return GBS_global_string("Gene '%s' of organism '%s' needs %s", GBT_get_name_or_description(gb_gene), GBT_get_name_or_description(gb_species), whats_required);
315 }
316 
319  GBS_strstruct *checksums = GBS_stropen(1024);
320 
322  if (!error) {
323  char *use = GBT_get_default_alignment(gb_main);
324  if (!use) {
325  error = GB_await_error();
326  }
327  else {
328  for (GBDATA *gb_species = GBT_first_marked_species(gb_main); gb_species; gb_species = GBT_next_marked_species(gb_species)) {
329  GBDATA *gb_name = GB_entry(gb_species, "name");
330  if (!gb_name) { error = species_requires(gb_species, "name"); break; }
331 
332  GBDATA *gb_data = GBT_find_sequence(gb_species, use);
333  if (!gb_data) { error = species_requires(gb_species, GBS_global_string("data in '%s'", use)); break; }
334 
335  GBS_intcat(checksums, GBS_checksum(GB_read_char_pntr(gb_data), 1, ".-"));
336  GBS_strcat(names, GB_read_char_pntr(gb_name));
337  GBS_chrcat(checksums, '#');
338  GBS_chrcat(names, '#');
339  }
340 
341  if (!error) {
342  GBS_str_cut_tail(names, 1); // remove trailing '#'
343  GBS_str_cut_tail(checksums, 1); // remove trailing '#'
344  }
345  free(use);
346  }
347  }
348 
349  bs.size = GBS_memoffset(names)+1;
350  bs.data = GBS_strclose(names);
351 
352  checksum.size = GBS_memoffset(checksums)+1;
353  checksum.data = GBS_strclose(checksums);
354 
355  error = GB_end_transaction(gb_main, error);
356 
357  return error;
358 }
359 
362  GBS_strstruct *checksums = GBS_stropen(1024);
363  GB_ERROR error = NULp;
364 
365  GB_begin_transaction(gb_main);
366  const char *use = GENOM_ALIGNMENT; // gene pt server is always build on 'ali_genom'
367 
368  for (GBDATA *gb_species = GEN_first_organism(gb_main); gb_species && !error; gb_species = GEN_next_organism(gb_species)) {
369  const char *species_name = NULp;
370  {
371  GBDATA *gb_data = GBT_find_sequence(gb_species, use);
372  if (!gb_data) { error = species_requires(gb_species, GBS_global_string("data in '%s'", use)); break; }
373 
374  GBDATA *gb_name = GB_search(gb_species, "name", GB_FIND);
375  if (!gb_name) { error = species_requires(gb_species, "name"); break; }
376  species_name = GB_read_char_pntr(gb_name);
377  }
378 
379  for (GBDATA *gb_gene = GEN_first_marked_gene(gb_species); gb_gene && !error; gb_gene = GEN_next_marked_gene(gb_gene)) {
380  const char *gene_name = NULp;
381  {
382  GBDATA *gb_gene_name = GB_entry(gb_gene, "name");
383  if (!gb_gene_name) { error = gene_requires(gb_gene, "name"); break; }
384  gene_name = GB_read_char_pntr(gb_gene_name);
385  }
386 
387  {
388  char *gene_seq = GBT_read_gene_sequence(gb_gene, false, 0);
389  if (!gene_seq) error = GB_await_error();
390  else {
391  long CheckSum = GBS_checksum(gene_seq, 1, ".-");
392  const char *id = GBS_global_string("%s/%s", species_name, gene_name);
393 
394  GBS_intcat(checksums, CheckSum);
395  GBS_strcat(names, id);
396  GBS_chrcat(checksums, '#');
397  GBS_chrcat(names, '#');
398 
399  free(gene_seq);
400  }
401  }
402  }
403  }
404 
405  GBS_str_cut_tail(names, 1); // remove trailing '#'
406  GBS_str_cut_tail(checksums, 1); // remove trailing '#'
407 
408  if (error) {
409  GBS_strforget(names);
410  GBS_strforget(checksums);
411  }
412  else {
413  bs.size = GBS_memoffset(names)+1;
414  bs.data = GBS_strclose(names);
415 
416  checksum.size = GBS_memoffset(checksums)+1;
417  checksum.data = GBS_strclose(checksums);
418  }
419  error = GB_end_transaction(gb_main, error);
420  return error;
421 }
422 
423 inline const char *bond_awar_name(int i) {
425 }
426 
428  float split;
429  float bonds[16];
430 
431  explicit ProbeCommonSettings(AW_root *root)
432  : split(root->awar(AWAR_PD_COMMON_EXP_SPLIT)->read_float())
433  {
434  for (int i=0; i<16; i++) {
435  bonds[i] = root->awar(bond_awar_name(i))->read_float();
436  }
437  }
438 };
439 
440 static int probe_common_send_data(const ProbeCommonSettings& commonSettings) {
441  // send data common to probe-design AND -match
442  if (aisc_put(PD.link, PT_LOCS, PD.locs,
443  LOCS_SPLIT, (double)commonSettings.split,
444  NULp))
445  return 1;
446 
447  for (int i=0; i<16; i++) {
448  if (aisc_put(PD.link, PT_LOCS, PD.locs,
449  PT_INDEX, (long)i,
450  LOCS_BONDVAL, (double)commonSettings.bonds[i],
451  NULp))
452  return 1;
453  }
454  return 0;
455 }
456 static int probe_design_send_data(AW_root *root, const T_PT_PDC& pdc) {
457  if (aisc_put(PD.link, PT_PDC, pdc,
458  PDC_DTEDGE, (double)root->awar(AWAR_PD_DESIGN_EXP_DTEDGE)->read_float()*100.0,
459  PDC_DT, (double)root->awar(AWAR_PD_DESIGN_EXP_DT)->read_float()*100.0,
460  PDC_CLIPRESULT, (long)root->awar(AWAR_PD_DESIGN_CLIPRESULT)->read_int(),
461  NULp))
462  return 1;
463 
465 }
466 
469  int nmatches;
470  int nlimit;
471  int maxhits;
473  int sortBy;
475  int markHits;
477 
479 
480  explicit ProbeMatchSettings(AW_root *root)
481  : ProbeCommonSettings(root),
482  serverNumber(root->awar(AWAR_PT_SERVER)->read_int()),
483  nmatches(root->awar(AWAR_PD_MATCH_NMATCHES)->read_int()),
484  nlimit(root->awar(AWAR_PD_MATCH_LIM_NMATCH)->read_int()),
485  maxhits(root->awar(AWAR_PD_MATCH_MAX_RES)->read_int()),
486  alsoRevcompl(root->awar(AWAR_PD_MATCH_ALSO_REVCOMP)->read_int()),
487  sortBy(root->awar(AWAR_PD_MATCH_SORTBY)->read_int()),
488  maxMismatches(root->awar(AWAR_MAX_MISMATCHES)->read_int()),
489  markHits(root->awar(AWAR_PD_MATCH_MARKHITS)->read_int()),
490  write2tmp(root->awar(AWAR_PD_MATCH_WRITE2TMP)->read_int()),
491  targetString(root->awar(AWAR_TARGET_STRING)->read_char_pntr())
492  {}
493 };
494 
495 static int probe_match_send_data(const ProbeMatchSettings& matchSettings) {
496  if (aisc_put(PD.link, PT_LOCS, PD.locs,
497  LOCS_MATCH_N_ACCEPT, (long)matchSettings.nmatches,
498  LOCS_MATCH_N_LIMIT, (long)matchSettings.nlimit,
499  LOCS_MATCH_MAX_HITS, (long)matchSettings.maxhits,
500  NULp))
501  return 1;
502 
503  return probe_common_send_data(matchSettings);
504 }
505 
506 static int ecolipos2int(const char *awar_val) {
507  int i = atoi(awar_val);
508  return i>0 ? i : -1;
509 }
510 
511 static char *readableUnknownNames(const ConstStrArray& unames) {
512  GBS_strstruct readable(100);
513 
514  int ulast = unames.size()-1;
515  int umax = ulast <= 10 ? ulast : 10;
516  for (int u = 0; u <= umax; ++u) {
517  if (u) readable.cat(u == ulast ? " and " : ", ");
518  readable.cat(unames[u]);
519  }
520 
521  if (umax<ulast) readable.nprintf(30, " (and %i other)", ulast-umax);
522 
523  return readable.release();
524 }
525 
527  AW_root *root = aww->get_root();
528  T_PT_PDC pdc;
529  T_PT_TPROBE tprobe;
530  bytestring bs;
531  bytestring check;
532  GB_ERROR error = NULp;
533 
534  arb_progress progress("Probe design");
535  progress.subtitle("Connecting PT-server");
536 
537  {
538  const char *servername = PD_probe_pt_look_for_server(root->awar(AWAR_PT_SERVER)->read_int(), error);
539  if (servername) {
540  PD.link = aisc_open(servername, PD.com, AISC_MAGIC_NUMBER, &error);
541  if (!PD.link) error = "can't contact PT server";
542  PD.locs.clear();
543  }
544  }
545 
546  if (!error && init_local_com_struct()) {
547  error = "Cannot contact to probe server: Connection Refused";
548  }
549 
550  bool design_gene_probes = root->awar(AWAR_PD_DESIGN_GENE)->read_int();
551  if (design_gene_probes) {
552  GB_transaction ta(gb_main);
553  if (!GEN_is_genome_db(gb_main, -1)) design_gene_probes = false;
554  }
555 
556  if (!error) {
557  if (design_gene_probes) { // design probes for genes
558  error = pd_get_the_gene_names(gb_main, bs, check);
559  }
560  else {
561  error = pd_get_the_names(gb_main, bs, check);
562  }
563  }
564 
565  if (error) {
566  aw_message(error);
567  return;
568  }
569 
570  progress.subtitle("probe design running");
571 
572  if (aisc_create(PD.link, PT_LOCS, PD.locs,
573  LOCS_PROBE_DESIGN_CONFIG, PT_PDC, pdc,
574  PDC_MIN_PROBELEN, (long)root->awar(AWAR_PD_DESIGN_MIN_LENGTH)->read_int(),
575  PDC_MAX_PROBELEN, (long)root->awar(AWAR_PD_DESIGN_MAX_LENGTH)->read_int(),
576  PDC_MINTEMP, (double)root->awar(AWAR_PD_DESIGN_MIN_TEMP)->read_float(),
577  PDC_MAXTEMP, (double)root->awar(AWAR_PD_DESIGN_MAX_TEMP)->read_float(),
578  PDC_MINGC, (double)root->awar(AWAR_PD_DESIGN_MIN_GC)->read_float()/100.0,
579  PDC_MAXGC, (double)root->awar(AWAR_PD_DESIGN_MAX_GC)->read_float()/100.0,
580  PDC_MAXBOND, (double)root->awar(AWAR_PD_DESIGN_MAXBOND)->read_int(),
581  PDC_MIN_ECOLIPOS, (long)ecolipos2int(root->awar(AWAR_PD_DESIGN_MIN_ECOLIPOS)->read_char_pntr()),
582  PDC_MAX_ECOLIPOS, (long)ecolipos2int(root->awar(AWAR_PD_DESIGN_MAX_ECOLIPOS)->read_char_pntr()),
583  PDC_MISHIT, (long)root->awar(AWAR_PD_DESIGN_MISHIT)->read_int(),
584  PDC_MINTARGETS, (double)root->awar(AWAR_PD_DESIGN_MINTARGETS)->read_float()/100.0,
585  NULp))
586  {
587  aw_message("Connection to PT_SERVER lost (1)");
588  return;
589  }
590 
591  if (probe_design_send_data(root, pdc)) {
592  aw_message("Connection to PT_SERVER lost (1)");
593  return;
594  }
595 
596  aisc_put(PD.link, PT_PDC, pdc,
597  PDC_NAMES, &bs,
598  PDC_CHECKSUMS, &check,
599  NULp);
600 
601 
602  // Get the unknown names
603  bytestring unknown_names;
604  if (aisc_get(PD.link, PT_PDC, pdc,
605  PDC_UNKNOWN_NAMES, &unknown_names,
606  NULp))
607  {
608  aw_message("Connection to PT_SERVER lost (1)");
609  return;
610  }
611 
612  bool abort = false;
613 
614  if (unknown_names.size>1) {
615  ConstStrArray unames_array;
616  GBT_split_string(unames_array, unknown_names.data, "#", true);
617 
618  char *readable_unames = readableUnknownNames(unames_array);
619 
620  if (design_gene_probes) { // updating sequences of missing genes is not possible with gene PT server
621  aw_message(GBS_global_string("Your PT server is not up to date or wrongly chosen!\n"
622  "It knows nothing about the following genes:\n"
623  "\n"
624  " %s\n"
625  "\n"
626  "You have to rebuild the PT server.",
627  readable_unames));
628  abort = true;
629  }
630  else if (aw_question("ptserver_add_unknown",
631  GBS_global_string("Your PT server is not up to date or wrongly chosen!\n"
632  "It knows nothing about the following species:\n"
633  "\n"
634  " %s\n"
635  "\n"
636  "You may now temporarily add these sequences for probe design.\n",
637  readable_unames),
638  "Add and continue,Abort"))
639  {
640  abort = true;
641  }
642  else {
643  GB_transaction ta(gb_main);
644 
645  char *ali_name = GBT_get_default_alignment(gb_main);
646  if (!ali_name) {
648  abort = true;
649  }
650 
651  for (size_t u = 0; !abort && u<unames_array.size(); ++u) {
652  const char *uname = unames_array[u];
653  GBDATA *gb_species = GBT_find_species(gb_main, uname);
654  if (!gb_species) {
655  aw_message(GBS_global_string("Species '%s' not found", uname));
656  abort = true;
657  }
658  else {
659  GBDATA *data = GBT_find_sequence(gb_species, ali_name);
660  if (!data) {
661  aw_message(GB_export_errorf("Species '%s' has no sequence belonging to alignment '%s'", uname, ali_name));
662  abort = true;
663  }
664  else {
665  T_PT_SEQUENCE pts;
666 
667  bytestring bs_seq;
668  bs_seq.data = (char*)GB_read_char_pntr(data);
669  bs_seq.size = GB_read_string_count(data)+1;
670 
671  aisc_create(PD.link, PT_PDC, pdc,
672  PDC_SEQUENCE, PT_SEQUENCE, pts,
673  SEQUENCE_SEQUENCE, &bs_seq,
674  NULp);
675  }
676  }
677  }
678  free(ali_name);
679  }
680  free(readable_unames);
681  free(unknown_names.data);
682  }
683 
684  if (!abort) {
685  aisc_put(PD.link, PT_PDC, pdc,
686  PDC_GO, (long)0,
687  NULp);
688 
689  progress.subtitle("Reading results from server");
690  {
691  char *locs_error = NULp;
692  if (aisc_get(PD.link, PT_LOCS, PD.locs,
693  LOCS_ERROR, &locs_error,
694  NULp))
695  {
696  aw_message("Connection to PT_SERVER lost (1)");
697  abort = true;
698  }
699  else if (*locs_error) {
700  aw_message(locs_error);
701  abort = true;
702  }
703  else {
704  free(locs_error);
705  }
706  }
707  }
708 
709  if (!abort) {
710  aisc_get(PD.link, PT_PDC, pdc,
711  PDC_TPROBE, tprobe.as_result_param(),
712  NULp);
713 
714  popup_probe_design_result_window(aww, gb_main);
715  PD.resultList->clear();
716 
717  {
718  char *match_info = NULp;
719  aisc_get(PD.link, PT_PDC, pdc,
720  PDC_INFO_HEADER, &match_info,
721  NULp);
722 
723  char *s = strtok(match_info, "\n");
724  while (s) {
725  PD.resultList->insert(s, "");
726  s = strtok(NULp, "\n");
727  }
728  free(match_info);
729  }
730 
731  while (tprobe.exists()) {
732  T_PT_TPROBE tprobe_next;
733  char *match_info = NULp;
734 
735  if (aisc_get(PD.link, PT_TPROBE, tprobe,
736  TPROBE_NEXT, tprobe_next.as_result_param(),
737  TPROBE_INFO, &match_info,
738  NULp)) break;
739 
740  tprobe.assign(tprobe_next);
741 
742  char *probe, *space;
743  probe = strpbrk(match_info, "acgtuACGTU");
744  if (probe) space = strchr(probe, ' ');
745  if (probe && space) {
746  *space = 0; probe = ARB_strdup(probe); *space=' ';
747  }
748  else {
749  probe = ARB_strdup("");
750  }
751  PD.resultList->insert(match_info, probe);
752  free(probe);
753  free(match_info);
754  }
755  PD.resultList->insert_default("", "");
756  PD.resultList->update();
757  }
758 
759  aisc_close(PD.link, PD.com); PD.link = NULp;
760  return;
761 }
762 
763 static bool allow_probe_match_event = true;
764 
766  GB_ERROR error = NULp;
768 #if defined(ASSERTION_USED)
769  // runtime check against awar usage when NOT called from probe match window!
770  typedef SmartPtr< LocallyModify<bool> > Maybe;
771 
772  Maybe dontReadAwars;
773  Maybe dontWriteAwars;
774 
775  if (!event_param || !event_param->selection_id) {
776  dontReadAwars = new LocallyModify<bool>(AW_awar::deny_read, true);
777  dontWriteAwars = new LocallyModify<bool>(AW_awar::deny_write, true);
778  }
779 #endif
780 
781  AW_selection_list *selection_id = event_param ? event_param->selection_id : NULp;
782  int *counter = event_param ? event_param->counter : NULp;
783  GBDATA *gb_main = event_param ? event_param->gb_main : NULp;
784  int show_status = 0;
785  int extras = 1; // mark species and write to temp fields
786 
787  if (!gb_main) { error = "Please open probe match window once to enable auto-match"; }
788 
789  SmartPtr<arb_progress> progress;
790 
791  if (!error) {
792  const char *servername = PD_probe_pt_look_for_server(matchSettings.serverNumber, error);
793 
794  if (!error) {
795  if (selection_id) {
796  selection_id->clear();
797  pd_assert(!counter);
798  show_status = 1;
799  }
800  else if (counter) {
801  extras = 0;
802  }
803 
804  if (show_status) {
805  progress = new arb_progress("Probe match");
806  progress->subtitle("Connecting PT-server");
807  }
808 
809  PD.link = aisc_open(servername, PD.com, AISC_MAGIC_NUMBER, &error);
810  if (!error && !PD.link) error = "Cannot contact PT-server";
811  PD.locs.clear();
812  }
813  }
814 
815  if (!error && init_local_com_struct()) error = "Cannot contact PT-server (2)";
816  if (!error && probe_match_send_data(matchSettings)) error = "Connection to PT_SERVER lost (2)";
817 
818  const char *probe = matchSettings.targetString.c_str();
819  if (!error) {
820  if (show_status) progress->subtitle("Probe match running");
821 
822  if (aisc_nput(PD.link, PT_LOCS, PD.locs,
823  LOCS_MATCH_ALSO_REVCOMP, (long)matchSettings.alsoRevcompl,
824  LOCS_COMPLEMENT_FIRST, (long)0, // (use sequence passed below as is. do not complement it.)
825  LOCS_MATCH_SORT_BY, (long)matchSettings.sortBy,
826  LOCS_MATCH_MAX_MISMATCHES, (long)matchSettings.maxMismatches,
827  LOCS_SEARCHMATCH, probe,
828  NULp))
829  {
830  error = "Connection to PT_SERVER lost (2)";
831  }
832  else {
833  delete(g_spd); // delete previous probe data
834  g_spd = new saiProbeData;
835  transferProbeData(g_spd);
836 
837  g_spd->setProbeTarget(probe);
838  }
839  }
840 
841  bytestring bs;
842  bs.data = NULp;
843 
844  long matches_truncated = 0;
845  if (!error) {
846  if (show_status) progress->subtitle("Reading results");
847 
848  T_PT_MATCHLIST match_list;
849  long match_list_cnt = 0;
850  char *locs_error = NULp;
851 
852  if (aisc_get(PD.link, PT_LOCS, PD.locs,
853  LOCS_MATCH_LIST, match_list.as_result_param(),
854  LOCS_MATCH_LIST_CNT, &match_list_cnt,
855  LOCS_MATCH_STRING, &bs,
856  LOCS_MATCHES_TRUNCATED, &matches_truncated,
857  LOCS_ERROR, &locs_error,
858  NULp))
859  {
860  error = "Connection to PT_SERVER lost (3)";
861  }
862  else {
863  if (locs_error) {
864  if (*locs_error) error = GBS_static_string(locs_error);
865  free(locs_error);
866  }
867  else {
868  error = "Missing status from server (connection aborted?)";
869  }
870  }
871 
872  event_param->hits_summary = GBS_global_string(matches_truncated ? "[more than %li]" : "%li", match_list_cnt);
873  if (matches_truncated) {
874  aw_message("Too many matches, displaying a random digest.\n" // @@@ should better be handled by caller
875  "Increase the limit in the expert window.");
876  }
877  }
878 
879  long mcount = 0;
880  long unknown_species_count = 0;
881  long unknown_gene_count = 0;
882 
883  if (!error) {
884  char toksep[2] = { 1, 0 };
885  char *strtok_ptr = NULp; // stores strtok position
886  const char *hinfo = strtok_r(bs.data, toksep, &strtok_ptr);
887 
888  bool gene_flag = false;
889  ProbeMatchParser *parser = NULp;
890  char *result = ARB_alloc<char>(1024);
891 
892 
893  if (hinfo) {
894  g_spd->setHeadline(hinfo);
895  parser = new ProbeMatchParser(probe, hinfo);
896  error = parser->get_error();
897  if (!error) gene_flag = parser->is_gene_result();
898  }
899 
900  if (selection_id) {
901  int width = 0;
902  if (parser && !error) width = parser->get_probe_region_offset()+2+10; // 2 cause headline is shorter and 10 for match prefix region
903 
904  const char *searched = GBS_global_string("%-*s%s", width, "Searched for ", probe);
905  selection_id->insert(searched, probe);
906  if (hinfo) selection_id->insert(hinfo, "");
907  }
908 
909 
910  // clear all marks and delete all 'tmp' entries
911 
912  int mark = extras && matchSettings.markHits;
913  int write_2_tmp = extras && matchSettings.write2tmp;
914 
915  GB_push_transaction(gb_main);
916 
918  if (mark && !error) {
919  if (show_status) progress->subtitle(gene_flag ? "Unmarking all species and genes" : "Unmarking all species");
920  for (GBDATA *gb_species = GBT_first_marked_species_rel_species_data(gb_species_data);
921  gb_species;
922  gb_species = GBT_next_marked_species(gb_species))
923  {
924  GB_write_flag(gb_species, 0);
925  }
926 
927  if (gene_flag) {
928  // unmark genes of ALL species
929  for (GBDATA *gb_species = GBT_first_species_rel_species_data(gb_species_data);
930  gb_species;
931  gb_species = GBT_next_species(gb_species))
932  {
933  GBDATA *genData = GEN_find_gene_data(gb_species);
934  if (genData) {
935  for (GBDATA *gb_gene = GEN_first_marked_gene(gb_species);
936  gb_gene;
937  gb_gene = GEN_next_marked_gene(gb_gene))
938  {
939  GB_write_flag(gb_gene, 0);
940  }
941  }
942  }
943  }
944  }
945  if (write_2_tmp && !error) {
946  if (show_status) progress->subtitle("Deleting old 'tmp' fields");
947  for (GBDATA *gb_species = GBT_first_species_rel_species_data(gb_species_data);
948  gb_species;
949  gb_species = GBT_next_species(gb_species))
950  {
951  GBDATA *gb_tmp = GB_entry(gb_species, "tmp");
952  if (gb_tmp) GB_delete(gb_tmp);
953  if (gene_flag) {
954  for (GBDATA *gb_gene = GEN_first_gene(gb_species);
955  gb_gene;
956  gb_gene = GEN_next_gene(gb_species))
957  {
958  gb_tmp = GB_entry(gb_gene, "tmp");
959  if (gb_tmp) GB_delete(gb_tmp);
960  }
961  }
962  }
963  }
964 
965  // read results from pt-server :
966 
967  if (!error) {
968  if (show_status) progress->subtitle("Parsing results");
969 
970  g_spd->probeSpecies.clear();
971  g_spd->probeSeq.clear();
972 
973  if (gene_flag) {
974  if (!GEN_is_genome_db(gb_main, -1)) {
975  error = "Wrong PT-Server chosen (selected one is built for genes)";
976  }
977  }
978  }
979 
980  const char *match_name = NULp;
981  while (hinfo && !error && (match_name = strtok_r(NULp, toksep, &strtok_ptr))) {
982  const char *match_info = strtok_r(NULp, toksep, &strtok_ptr);
983  if (!match_info) break;
984 
985  pd_assert(parser);
986  ParsedProbeMatch ppm(match_info, *parser);
987  char *gene_str = NULp;
988 
989  if (gene_flag) {
990  gene_str = ppm.get_column_content("genename", true);
991  }
992 
993  if (!error) {
994  char flags[] = "xx";
995  GBDATA *gb_species = GBT_find_species_rel_species_data(gb_species_data, match_name);
996 
997  if (gb_species) {
998  GBDATA *gb_gene = NULp;
999  if (gene_flag && strncmp(gene_str, "intergene_", 10) != 0) { // real gene
1000  gb_gene = GEN_find_gene(gb_species, gene_str);
1001  if (!gb_gene) {
1002  aw_message(GBS_global_string("Gene '%s' not found in organism '%s'", gene_str, match_name));
1003  }
1004  }
1005 
1006  if (mark) {
1007  GB_write_flag(gb_species, 1);
1008  flags[0] = '*';
1009  if (gb_gene) {
1010  GB_write_flag(gb_gene, 1);
1011  flags[1] = '*';
1012  }
1013  else {
1014  flags[1] = '?'; // no gene
1015  }
1016  }
1017  else {
1018  flags[0] = " *"[GB_read_flag(gb_species)];
1019  flags[1] = " *?"[gb_gene ? GB_read_flag(gb_gene) : 2];
1020  }
1021 
1022  if (write_2_tmp) {
1023  // write or append to field 'tmp'
1024 
1025  GBDATA *gb_tmp = NULp;
1026  GB_ERROR error2 = NULp;
1027  bool append = true;
1028  {
1029  GBDATA *gb_parent = gene_flag ? gb_gene : gb_species;
1030  gb_tmp = GB_search(gb_parent, "tmp", GB_FIND);
1031  if (!gb_tmp) {
1032  append = false;
1033  gb_tmp = GB_search(gb_parent, "tmp", GB_STRING);
1034  if (!gb_tmp) error2 = GB_await_error();
1035  }
1036  }
1037 
1038  if (!error2) {
1039  pd_assert(gb_tmp);
1040  if (append) {
1041  char *prevContent = GB_read_string(gb_tmp);
1042  if (!prevContent) {
1043  error2 = GB_await_error();
1044  }
1045  else {
1046  char *concatenatedContent = ARB_alloc<char>(strlen(prevContent)+1+strlen(match_info)+1);
1047  sprintf(concatenatedContent, "%s\n%s", prevContent, match_info);
1048  error2 = GB_write_string(gb_tmp, concatenatedContent);
1049  free(concatenatedContent);
1050  free(prevContent);
1051  }
1052  }
1053  else {
1054  error2 = GB_write_string(gb_tmp, match_info);
1055  }
1056  }
1057 
1058  if (error2) aw_message(error2);
1059  }
1060  }
1061  else {
1062  flags[0] = flags[1] = '?'; // species does not exist
1063  unknown_species_count++;
1064  }
1065 
1066 
1067  if (gene_flag) {
1068  sprintf(result, "%s %s", flags, match_info+1); // both flags (skip 1 space from match info to keep alignment)
1069  char *gene_match_name = new char[strlen(match_name) + strlen(gene_str)+2];
1070  sprintf(gene_match_name, "%s/%s", match_name, gene_str);
1071  if (selection_id) selection_id->insert(result, gene_match_name); // @@@ wert fuer awar eintragen
1072  }
1073  else {
1074  sprintf(result, "%c %s", flags[0], match_info); // only first flag ( = species related)
1075  if (selection_id) selection_id->insert(result, match_name); // @@@ wert fuer awar eintragen
1076 
1077  // storing probe data into linked lists
1078  g_spd->probeSeq.push_back(std::string(match_info));
1079  g_spd->probeSpecies.push_back(std::string(match_name));
1080  }
1081  mcount++;
1082  }
1083 
1084  free(gene_str);
1085  }
1086 
1087  if (error) error = GBS_static_string(error); // make static copy (error may be freed by delete parser)
1088  delete parser;
1089  free(result);
1090 
1091  GB_pop_transaction(gb_main);
1092  }
1093 
1094  if (error) {
1095  if (event_param) event_param->hits_summary = "[none]"; // clear hits
1096  }
1097  else {
1098  if (unknown_species_count>0) {
1099  error = GBS_global_string("%li matches hit unknown species -- PT-server is out-of-date or build upon a different database", unknown_species_count);
1100  }
1101  if (unknown_gene_count>0 && !error) {
1102  error = GBS_global_string("%li matches hit unknown genes -- PT-server is out-of-date or build upon a different database", unknown_gene_count);
1103  }
1104 
1105  if (selection_id) { // if !selection_id then probe match window is not opened
1106  pd_assert(g_spd);
1107  event_param->refresh_sai_display = true; // want refresh of SAI/Probe window
1108  }
1109  }
1110 
1111  if (counter) *counter = mcount;
1112 
1113  aisc_close(PD.link, PD.com);
1114  PD.link = NULp;
1115 
1116  if (selection_id) {
1117  const char *last_line = NULp;
1118  if (error) last_line = GBS_global_string("****** Error: %s *******", error);
1119  else if (matches_truncated) last_line = "****** List is truncated *******";
1120  else last_line = "****** End of List *******";
1121 
1122  selection_id->insert_default(last_line, "");
1123  selection_id->update();
1124  }
1125 
1126  free(bs.data);
1127  }
1128  return error;
1129 }
1130 
1133  GB_ERROR error = probe_match_event(ProbeMatchSettings(root), event_param);
1134  aw_message_if(error);
1135 
1137 
1138  if (event_param) {
1139  if (event_param->refresh_sai_display) {
1140  root->awar(AWAR_SPV_DB_FIELD_NAME)->touch(); // force refresh of SAI/Probe window
1141  }
1142  if (event_param->selection_id) {
1143  root->awar(AWAR_PD_MATCH_NHITS)->write_string(event_param->hits_summary.c_str()); // update hits in probe match window
1144  }
1145  }
1146  root->awar(AWAR_TREE_REFRESH)->touch(); // refresh tree
1147  }
1148 }
1149 
1150 static void probe_match_all_event(AW_window *aww, AW_selection_list *iselection_id, GBDATA *gb_main) {
1151  AW_selection_list_iterator selentry(iselection_id);
1152  arb_progress progress("Matching all resolved strings", iselection_id->size());
1153  ProbeMatchSettings matchSettings(aww->get_root());
1154  const bool got_result = selentry;
1155 
1156  while (selentry) {
1157  const char *entry = selentry.get_value()->get_string(); // @@@ rename -> probe
1158  matchSettings.targetString = entry;
1159 
1160  int counter = -1;
1161  ProbeMatchEventParam match_event(gb_main, &counter);
1162  GB_ERROR error = probe_match_event(matchSettings, &match_event);
1163 
1164  // write # of hits to list entries:
1165  {
1166 #define DISP_FORMAT "%7i %s"
1167  const char *displayed;
1168  if (error) {
1169  displayed = GBS_global_string(DISP_FORMAT " (Error: %s)", 0, entry, error);
1170  }
1171  else {
1172  displayed = GBS_global_string(DISP_FORMAT, counter, entry);
1173  }
1174  selentry.set_displayed(displayed);
1175 #undef DISP_FORMAT
1176  }
1177 
1178  ++selentry;
1179  progress.inc();
1180  }
1181 
1182  if (got_result) {
1183  iselection_id->sort(true, true);
1184  iselection_id->update();
1185  }
1186 }
1187 
1188 static void resolved_probe_chosen(AW_root *root) {
1189  char *string = root->awar(AWAR_PD_MATCH_RESOLVE)->read_string();
1190  root->awar(AWAR_TARGET_STRING)->write_string(string);
1191 }
1192 
1194  // this gets called when ever the selected probe match changes
1195  char *temp;
1196  char *selected_match = root->awar(AWAR_PD_SELECTED_MATCH)->read_string();
1197 
1198  if (strchr(selected_match, '/')) { // "organism/gene"
1199  temp = strtok(selected_match, "/");
1200  root->awar(AWAR_SPECIES_NAME)->write_string(temp);
1201  temp = strtok(NULp, " /\n");
1202  root->awar(AWAR_GENE_NAME)->write_string(temp);
1203  }
1204  else {
1205  root->awar(AWAR_SPECIES_NAME)->write_string(selected_match);
1206  }
1207 
1208  {
1209  LocallyModify<bool> flag(allow_probe_match_event, false); // avoid recursion
1210  root->awar(AWAR_TARGET_STRING)->touch(); // forces editor to jump to probe match in gene
1211  }
1212 
1213  free(selected_match);
1214 }
1215 
1216 static void probelength_changed_cb(AW_root *root, bool maxChanged) {
1217  static bool avoid_recursion = false;
1218  if (!avoid_recursion) {
1219  AW_awar *awar_minl = root->awar(AWAR_PD_DESIGN_MIN_LENGTH);
1220  AW_awar *awar_maxl = root->awar(AWAR_PD_DESIGN_MAX_LENGTH);
1221 
1222  int minl = awar_minl->read_int();
1223  int maxl = awar_maxl->read_int();
1224 
1225  if (minl>maxl) {
1226  if (maxChanged) awar_minl->write_int(maxl);
1227  else awar_maxl->write_int(minl);
1228  }
1229  }
1230 }
1231 
1232 static void minmax_awar_pair_changed_cb(AW_root *root, bool maxChanged, const char *minAwarName, const char *maxAwarName) {
1233  static bool avoid_recursion = false;
1234  if (!avoid_recursion) {
1235  LocallyModify<bool> flag(avoid_recursion, true);
1236 
1237  AW_awar *awar_min = root->awar(minAwarName);
1238  AW_awar *awar_max = root->awar(maxAwarName);
1239 
1240  float currMin = awar_min->read_float();
1241  float currMax = awar_max->read_float();
1242 
1243  if (currMin>currMax) { // invalid -> correct
1244  if (maxChanged) awar_min->write_float(currMax);
1245  else awar_max->write_float(currMin);
1246  }
1247  }
1248 }
1249 static void gc_minmax_changed_cb(AW_root *root, bool maxChanged) {
1251 }
1252 static void temp_minmax_changed_cb(AW_root *root, bool maxChanged) {
1254 }
1255 
1257  PD.win = NULp; // design result window not created
1258 
1259  root->awar_string(AWAR_SPECIES_NAME, "", props);
1261  root->awar_float (AWAR_PD_DESIGN_EXP_DTEDGE, .5, props);
1262  root->awar_float (AWAR_PD_DESIGN_EXP_DT, .5, props);
1263 
1264  double default_bonds[16] = {
1265  0.0, 0.0, 0.5, 1.1,
1266  0.0, 0.0, 1.5, 0.0,
1267  0.5, 1.5, 0.4, 0.9,
1268  1.1, 0.0, 0.9, 0.0
1269  };
1270 
1271  for (int i=0; i<16; i++) {
1272  root->awar_float(bond_awar_name(i), default_bonds[i], props)->set_minmax(0, 3.0);
1273  }
1274  root->awar_float(AWAR_PD_COMMON_EXP_SPLIT, .5, props);
1275  root->awar_float(AWAR_PD_DESIGN_EXP_DTEDGE, .5, props);
1276  root->awar_float(AWAR_PD_DESIGN_EXP_DT, .5, props);
1277 
1278  root->awar_int (AWAR_PD_DESIGN_CLIPRESULT, 50, props)->set_minmax(0, 1000);
1279  root->awar_int (AWAR_PD_DESIGN_MISHIT, 0, props)->set_minmax(0, 100000);
1280  root->awar_int (AWAR_PD_DESIGN_MAXBOND, 4, props)->set_minmax(0, 20);
1281  root->awar_float(AWAR_PD_DESIGN_MINTARGETS, 50.0, props)->set_minmax(0, 100);
1282 
1283  AW_awar *awar_min_len = root->awar_int(AWAR_PD_DESIGN_MIN_LENGTH, 18, props);
1284  awar_min_len->set_minmax(DOMAIN_MIN_LENGTH, 100)->add_callback(makeRootCallback(probelength_changed_cb, false));
1285  root->awar_int(AWAR_PD_DESIGN_MAX_LENGTH, awar_min_len->read_int(), props)->set_minmax(DOMAIN_MIN_LENGTH, 100)->add_callback(makeRootCallback(probelength_changed_cb, true));
1286 
1287  root->awar_float(AWAR_PD_DESIGN_MIN_TEMP, 30.0, props)->set_minmax(0, 1000)->add_callback(makeRootCallback(temp_minmax_changed_cb, false));
1288  root->awar_float(AWAR_PD_DESIGN_MAX_TEMP, 100.0, props)->set_minmax(0, 1000)->add_callback(makeRootCallback(temp_minmax_changed_cb, true));
1289 
1290  root->awar_float(AWAR_PD_DESIGN_MIN_GC, 50.0, props)->add_callback(makeRootCallback(gc_minmax_changed_cb, false));
1291  root->awar_float(AWAR_PD_DESIGN_MAX_GC, 100.0, props)->add_callback(makeRootCallback(gc_minmax_changed_cb, true));
1292 
1293  gc_minmax_changed_cb(root, false);
1294  gc_minmax_changed_cb(root, true);
1295 
1296  root->awar_string(AWAR_PD_DESIGN_MIN_ECOLIPOS, "", props);
1297  root->awar_string(AWAR_PD_DESIGN_MAX_ECOLIPOS, "", props);
1298 
1299  root->awar_int(AWAR_PT_SERVER, 0, props);
1300  root->awar_int(AWAR_PD_DESIGN_GENE, 0, props);
1301 
1302  root->awar_int(AWAR_PD_MATCH_MARKHITS, 1, props);
1303  root->awar_int(AWAR_PD_MATCH_SORTBY, 0, props);
1304  root->awar_int(AWAR_PD_MATCH_WRITE2TMP, 0, props);
1305  root->awar_int(AWAR_PD_MATCH_ALSO_REVCOMP, 0, props);
1306 
1307  root->awar_int (AWAR_MAX_MISMATCHES, 0, db)->set_minmax(0, 200);
1308  root->awar_string(AWAR_TARGET_STRING, NULp, db);
1309 
1310  root->awar_string(AWAR_PD_MATCH_NHITS, "[none]", props);
1311  root->awar_int (AWAR_PD_MATCH_NMATCHES, 1, props);
1312  root->awar_int (AWAR_PD_MATCH_LIM_NMATCH, 4, props);
1313  root->awar_int (AWAR_PD_MATCH_MAX_RES, 1000000, props);
1314 
1316 
1318  root->awar_string(AWAR_ITARGET_STRING, "", db);
1319 
1320  root->awar_int(AWAR_PROBE_ADMIN_PT_SERVER, 0, db);
1322 
1323  root->awar_string(AWAR_SPV_SAI_2_PROBE, "", db); // name of SAI selected in list
1324  root->awar_string(AWAR_SPV_DB_FIELD_NAME, "name", db); // name of displayed species field
1325  root->awar_int (AWAR_SPV_DB_FIELD_WIDTH, 10, db); // width of displayed species field
1326  root->awar_string(AWAR_SPV_ACI_COMMAND, "", db); // User defined or pre-defined ACI command to display
1327 
1328  root->awar_int(AWAR_PC_MATCH_NHITS, 0, db);
1329  root->awar_int(AWAR_PC_AUTO_MATCH, 0, props);
1330 
1333  root->awar_string(AWAR_PC_SELECTED_PROBE, "", db);
1334 
1335  root->awar_float(AWAR_PC_MATCH_WIDTH, 1.0, db)->set_minmax(0.01, 100.0);
1336  root->awar_float(AWAR_PC_MATCH_BIAS, 0.0, db)->set_minmax(-1.0, 1.0);
1337 
1338  root->awar_float(AWAR_PC_MISMATCH_THRESHOLD, 0.0, db)->set_minmax(0, 100); // Note: limits will be modified by probe_match_with_specificity_event
1339 
1340  float default_weights[16] = {0.0};
1341  float default_width = 1.0;
1342  float default_bias = 0.0;
1343 
1344  ArbProbeCollection& g_probe_collection = get_probe_collection();
1345  g_probe_collection.getParameters(default_weights, default_width, default_bias);
1346  g_probe_collection.clear();
1347 
1348  char buffer[256] = {0};
1349 
1350  for (int i = 0; i < 16 ; i++) {
1351  sprintf(buffer, AWAR_PC_MATCH_WEIGHTS"%i", i);
1352  AW_awar *awar = root->awar_float(buffer, 0.0, db);
1353 
1354  awar->set_minmax(0, 10);
1355  default_weights[i] = awar->read_float();
1356  }
1357 
1358  g_probe_collection.setParameters(default_weights, default_width, default_bias);
1359 
1360  // read probes from DB and add them to collection
1361  {
1362  AW_awar *awar_current = root->awar_string(AWAR_PC_CURRENT_COLLECTION, "", db);
1363  char *current = awar_current->read_string();
1364 
1365  if (current && current[0]) {
1366  // Note: target sequences/names do not contain '#'/':' (see REPLACE_TARGET_CONTROL_CHARS)
1367  ConstStrArray probes;
1368  GBT_splitNdestroy_string(probes, current, "#", true);
1369 
1370  for (size_t i = 0; i<probes.size(); ++i) {
1371  const char *probe = probes[i];
1372  const char *colon = strchr(probe, ':');
1373 
1374  if (colon) {
1375  char *name = ARB_strpartdup(probe, colon-1);
1376  const char *seq = colon+1;
1377  g_probe_collection.add(name, seq);
1378  free(name);
1379  }
1380  else {
1381  aw_message(GBS_global_string("Saved probe ignored: has wrong format ('%s', expected 'name:seq')", probe));
1382  }
1383  }
1384  }
1385  free(current);
1386  }
1387  root->awar_string(AWAR_SPV_SELECTED_PROBE, "", db); // For highlighting the selected PROBE
1388 }
1389 
1390 static AW_window *create_probe_expert_window(AW_root *root, bool for_design) {
1391  AW_window_simple *aws = new AW_window_simple;
1392  if (for_design) {
1393  aws->init(root, "PD_exp", "Probe Design (Expert)");
1394  aws->load_xfig("pd_spec.fig");
1395  }
1396  else {
1397  aws->init(root, "PM_exp", "Probe Match (Expert)");
1398  aws->load_xfig("pm_spec.fig");
1399  }
1400 
1401  aws->label_length(30);
1402  aws->button_length(10);
1403 
1404  aws->at("close");
1405  aws->callback(AW_POPDOWN);
1406  aws->create_button("CLOSE", "CLOSE", "C");
1407 
1408  aws->callback(makeHelpCallback(for_design ? "pd_spec_param.hlp" : "pm_spec_param.hlp")); // uses_hlp_res("pm_spec_param.hlp", "pd_spec_param.hlp"); see ../SOURCE_TOOLS/check_resources.pl@uses_hlp_res
1409  aws->at("help");
1410  aws->create_button("HELP", "HELP", "C");
1411 
1412  for (int i=0; i<16; i++) { // bond matrix
1413  char bondAt[20];
1414  sprintf(bondAt, "%i", i);
1415  aws->at(bondAt);
1416 
1417  aws->create_input_field(bond_awar_name(i), 4);
1418  }
1419 
1420  aws->sens_mask(AWM_EXP);
1421  aws->at("split"); aws->create_input_field(AWAR_PD_COMMON_EXP_SPLIT, 6);
1422 
1423  if (for_design) {
1424  aws->at("dt_edge"); aws->create_input_field(AWAR_PD_DESIGN_EXP_DTEDGE, 6);
1425  aws->at("dt"); aws->create_input_field(AWAR_PD_DESIGN_EXP_DT, 6);
1426  aws->sens_mask(AWM_ALL);
1427  }
1428  else {
1429  aws->at("nmatches"); aws->create_input_field(AWAR_PD_MATCH_NMATCHES, 3);
1430  aws->at("lim_nmatch"); aws->create_input_field(AWAR_PD_MATCH_LIM_NMATCH, 3);
1431  aws->sens_mask(AWM_ALL);
1432  aws->at("max_res"); aws->create_input_field(AWAR_PD_MATCH_MAX_RES, 14);
1433  }
1434 
1435  return aws;
1436 }
1437 
1439  // main window:
1440  { AWAR_PD_DESIGN_CLIPRESULT, "clip" },
1441  { AWAR_PD_DESIGN_MISHIT, "mishit" },
1442  { AWAR_PD_DESIGN_MAXBOND, "maxbond" },
1443  { AWAR_PD_DESIGN_MINTARGETS, "mintarget" },
1444  { AWAR_PD_DESIGN_MIN_LENGTH, "probelen" },
1445  { AWAR_PD_DESIGN_MAX_LENGTH, "probemaxlen" },
1446  { AWAR_PD_DESIGN_MIN_TEMP, "mintemp" },
1447  { AWAR_PD_DESIGN_MAX_TEMP, "maxtemp" },
1448  { AWAR_PD_DESIGN_MIN_GC, "mingc" },
1449  { AWAR_PD_DESIGN_MAX_GC, "maxgc" },
1450  { AWAR_PD_DESIGN_MIN_ECOLIPOS, "minecoli" },
1451  { AWAR_PD_DESIGN_MAX_ECOLIPOS, "maxecoli" },
1452  { AWAR_PD_DESIGN_GENE, "gene" },
1453 
1454  // expert window:
1455  { AWAR_PD_DESIGN_EXP_DTEDGE, "dtedge" },
1456  { AWAR_PD_DESIGN_EXP_DT, "dt" },
1457 
1458  { NULp, NULp }
1459 };
1460 
1462  cdef.add(mapping);
1463 
1464  // entries common for both expert windows (design + match)
1465  cdef.add(AWAR_PD_COMMON_EXP_SPLIT, "split");
1466  for (int i = 0; i<16; ++i) {
1467  cdef.add(bond_awar_name(i), "bond", i);
1468  }
1469 }
1470 
1472  bool is_genom_db;
1473  {
1474  GB_transaction ta(gb_main);
1475  is_genom_db = GEN_is_genome_db(gb_main, -1);
1476  }
1477 
1478  AW_window_simple *aws = new AW_window_simple;
1479  aws->init(root, "PROBE_DESIGN", "PROBE DESIGN");
1480 
1481  aws->load_xfig("pd_main.fig");
1482 
1483  aws->at("close");
1484  aws->callback(AW_POPDOWN);
1485  aws->create_button("CLOSE", "CLOSE", "C");
1486 
1487  aws->at("help");
1488  aws->callback(makeHelpCallback("probedesign.hlp"));
1489  aws->create_button("HELP", "HELP", "H");
1490 
1491  aws->callback(makeWindowCallback(probe_design_event, gb_main));
1492  aws->at("design");
1493  aws->highlight();
1494  aws->create_button("GO", "GO", "G");
1495 
1496  aws->callback(makeWindowCallback(popup_probe_design_result_window, gb_main));
1497  aws->at("result");
1498  aws->create_button("RESULT", "RESULT", "S");
1499 
1500  aws->callback(makeCreateWindowCallback(create_probe_expert_window, true));
1501  aws->at("expert");
1502  aws->create_button("EXPERT", "EXPERT", "S");
1503 
1504  aws->at("pt_server");
1505  aws->label("PT-Server:");
1507 
1508  aws->at("lenout"); aws->create_input_field(AWAR_PD_DESIGN_CLIPRESULT, 6);
1509  aws->at("mishit"); aws->create_input_field(AWAR_PD_DESIGN_MISHIT, 6);
1510  aws->sens_mask(AWM_EXP);
1511  aws->at("maxbonds"); aws->create_input_field(AWAR_PD_DESIGN_MAXBOND, 6);
1512  aws->sens_mask(AWM_ALL);
1513  aws->at("minhits"); aws->create_input_field(AWAR_PD_DESIGN_MINTARGETS, 6);
1514 
1515  aws->at("minlen"); aws->create_input_field(AWAR_PD_DESIGN_MIN_LENGTH, 5);
1516  aws->at("maxlen"); aws->create_input_field(AWAR_PD_DESIGN_MAX_LENGTH, 5);
1517  aws->at("mint"); aws->create_input_field(AWAR_PD_DESIGN_MIN_TEMP, 5);
1518  aws->at("maxt"); aws->create_input_field(AWAR_PD_DESIGN_MAX_TEMP, 5);
1519  aws->at("mingc"); aws->create_input_field(AWAR_PD_DESIGN_MIN_GC, 5);
1520  aws->at("maxgc"); aws->create_input_field(AWAR_PD_DESIGN_MAX_GC, 5);
1521  aws->at("minpos"); aws->create_input_field(AWAR_PD_DESIGN_MIN_ECOLIPOS, 5);
1522  aws->at("maxpos"); aws->create_input_field(AWAR_PD_DESIGN_MAX_ECOLIPOS, 5);
1523 
1524  if (is_genom_db) {
1525  aws->at("gene");
1526  aws->label("Gene probes?");
1527  aws->create_toggle(AWAR_PD_DESIGN_GENE);
1528  }
1529 
1530  aws->at("save");
1531  AWT_insert_config_manager(aws, AW_ROOT_DEFAULT, "probe_design", makeConfigSetupCallback(setup_probe_config, probe_design_mapping_def));
1532 
1533  return aws;
1534 }
1535 
1536 // -------------------------------------------------------------------
1537 
1538 inline void my_strupr(char *s) {
1539  pd_assert(s);
1540  for (int i=0; s[i]; i++) {
1541  s[i] = toupper(s[i]);
1542  }
1543 }
1544 
1546  selection_id->clear();
1547 
1548  GB_ERROR error = NULp;
1549  char *ali_name = GBT_get_default_alignment(gb_main);
1550  if (!ali_name) {
1551  error = GB_await_error();
1552  }
1553  else {
1554  GB_alignment_type ali_type = GBT_get_alignment_type(gb_main, ali_name);
1555  if (ali_type != GB_AT_RNA && ali_type!=GB_AT_DNA) {
1556  error = GB_append_exportedError("Wrong alignment type");
1557  }
1558  else {
1559  int index = ali_type==GB_AT_RNA ? 1 : 0;
1560  char *istring = root->awar(AWAR_ITARGET_STRING)->read_string();
1561 
1562  if (istring && istring[0]) { // contains sth?
1563  my_strupr(istring);
1564 
1565  int bases_to_resolve = 0;
1566  char *istr = istring;
1567  int istring_length = strlen(istring);
1568 
1569  for (;;) {
1570  char i = *istr++;
1571  if (!i) break;
1572  if (i=='?') continue; // ignore '?'
1573 
1574  int idx = i-'A';
1575  if (idx<0 || idx>=26 || !iupac::nuc_group[idx][index].members) {
1576  error = GBS_global_string("Illegal character '%c' in IUPAC-String", i);
1577  break;
1578  }
1579 
1580  if (iupac::nuc_group[idx][index].count>1) {
1581  bases_to_resolve++;
1582  }
1583  }
1584 
1585  if (!error) {
1586  int *offsets_to_resolve = new int[bases_to_resolve];
1587  int resolutions = 1;
1588  {
1589  istr = istring;
1590  int offset = 0;
1591  int offset_count = 0;
1592  for (;;) {
1593  char i = *istr++;
1594  if (!i) break;
1595 
1596  if (i!='?') {
1597  int idx = iupac::to_index(i);
1598  pd_assert(iupac::nuc_group[idx][index].members);
1599 
1600  if (iupac::nuc_group[idx][index].count>1) {
1601  offsets_to_resolve[offset_count++] = offset; // store string offsets of non-unique base-codes
1602  resolutions *= iupac::nuc_group[idx][index].count; // calc # of resolutions
1603  }
1604  }
1605  offset++;
1606  }
1607  }
1608 
1609  {
1610  int *resolution_idx = new int[bases_to_resolve];
1611  int *resolution_max_idx = new int[bases_to_resolve];
1612  {
1613  int i;
1614  for (i=0; i<bases_to_resolve; i++) {
1615  resolution_idx[i] = 0;
1616  int idx = iupac::to_index(istring[offsets_to_resolve[i]]);
1617  resolution_max_idx[i] = iupac::nuc_group[idx][index].count-1;
1618  }
1619  }
1620 
1621  char *buffer = new char[istring_length+1];
1622  int not_last = resolutions-1;
1623 
1624  for (;;) {
1625  // create string according to resolution_idx[]:
1626  int i;
1627 
1628  memcpy(buffer, istring, istring_length+1);
1629  for (i=0; i<bases_to_resolve; i++) {
1630  int off = offsets_to_resolve[i];
1631  int idx = iupac::to_index(istring[off]);
1632 
1633  pd_assert(iupac::nuc_group[idx][index].members);
1634  buffer[off] = iupac::nuc_group[idx][index].members[resolution_idx[i]];
1635  }
1636 
1637  selection_id->insert(buffer, buffer);
1638  not_last--;
1639 
1640  // permute indices:
1641  int nidx = bases_to_resolve-1;
1642  int done = 0;
1643  while (!done && nidx>=0) {
1644  if (resolution_idx[nidx]<resolution_max_idx[nidx]) {
1645  resolution_idx[nidx]++;
1646  done = 1;
1647  break;
1648  }
1649  nidx--;
1650  }
1651  if (!done) break; // we did all permutations!
1652 
1653  nidx++; // do not touch latest incremented index
1654  while (nidx<bases_to_resolve) resolution_idx[nidx++] = 0; // zero all other indices
1655  }
1656 
1657  delete [] buffer;
1658  delete [] resolution_max_idx;
1659  delete [] resolution_idx;
1660 
1661  pd_assert(!error);
1662  selection_id->insert_default("", "");
1663  }
1664 
1665  delete [] offsets_to_resolve;
1666  }
1667  }
1668  else { // empty input
1669  selection_id->insert_default("", "");
1670  }
1671  }
1672  free(ali_name);
1673  }
1674  if (error) selection_id->insert_default(error, "");
1675  selection_id->update();
1676 }
1677 
1679 
1680 static void modify_target_string(AW_window *aww, GBDATA *gb_main, ModMode mod_mode) {
1681  AW_root *root = aww->get_root();
1682  char *target_string = root->awar(AWAR_TARGET_STRING)->read_string();
1683  GB_ERROR error = NULp;
1684 
1685  if (mod_mode == TS_MOD_CLEAR) target_string[0] = 0;
1686  else {
1687  GB_transaction ta(gb_main);
1688 
1689  if (ta.ok()) {
1690  char *ali_name = GBT_get_default_alignment(gb_main);
1691  if (!ali_name) {
1692  error = GB_await_error();
1693  }
1694  else {
1695  GB_alignment_type ali_type = GBT_get_alignment_type(gb_main, ali_name);
1696  pd_assert(ali_type != GB_AT_UNKNOWN);
1697 
1698  if (mod_mode == TS_MOD_REV_COMPL) {
1699  char T_or_U;
1700  error = GBT_determine_T_or_U(ali_type, &T_or_U, "reverse-complement");
1701  if (!error) GBT_reverseComplementNucSequence(target_string, strlen(target_string), T_or_U);
1702  }
1703  else if (mod_mode == TS_MOD_COMPL) {
1704  char T_or_U;
1705  error = GBT_determine_T_or_U(ali_type, &T_or_U, "complement");
1706  if (!error) freeset(target_string, GBT_complementNucSequence(target_string, strlen(target_string), T_or_U));
1707  }
1708  free(ali_name);
1709  }
1710  }
1711  }
1712 
1713  if (error) aw_message(error);
1714  else root->awar(AWAR_TARGET_STRING)->write_string(target_string);
1715  free(target_string);
1716 }
1717 
1718 static void clear_itarget(AW_window *aww) {
1720 }
1721 
1723  AW_window_simple *aws = new AW_window_simple;
1724 
1725  aws->init(root, "PROBE_MATCH_RESOLVE_IUPAC", "Resolve IUPAC for Probe Match");
1726  aws->load_xfig("pd_match_iupac.fig");
1727 
1728  aws->button_length(11);
1729 
1730  aws->at("close");
1731  aws->callback(AW_POPDOWN);
1732  aws->create_button("CLOSE", "CLOSE", "C");
1733 
1734  aws->at("help");
1735  aws->callback(makeHelpCallback("pd_match_iupac.hlp"));
1736  aws->create_button("HELP", "HELP", "H");
1737 
1738  aws->at("istring");
1739  aws->create_input_field(AWAR_ITARGET_STRING, 32);
1740 
1741  aws->at("iresult");
1742  AW_selection_list *iselection_id;
1743  iselection_id = aws->create_selection_list(AWAR_PD_MATCH_RESOLVE, 32, 15);
1744  iselection_id->insert_default("---empty---", "");
1745 
1746  // add callback for automatic decomposition of AWAR_ITARGET_STRING:
1747  RootCallback upd_cb = makeRootCallback(resolve_IUPAC_target_string, iselection_id, gb_main);
1748  AW_awar *awar_itarget = root->awar(AWAR_ITARGET_STRING);
1749  awar_itarget->add_callback(upd_cb);
1750  root->awar(AWAR_DEFAULT_ALIGNMENT)->add_callback(upd_cb);
1751 
1752  aws->at("match_all");
1753  aws->callback(makeWindowCallback(probe_match_all_event, iselection_id, gb_main));
1754  aws->create_button("MATCH_ALL", "Match all", "M");
1755 
1756  aws->at("clear");
1757  aws->callback(clear_itarget);
1758  aws->create_button("CLEAR", "Clear", "r");
1759 
1760  aws->at("iupac_info");
1761  aws->callback(AWT_create_IUPAC_info_window);
1762  aws->create_button("IUPAC_INFO", "IUPAC info", "I");
1763 
1764  awar_itarget->touch(); // force initial refresh for saved value
1765 
1766  return aws;
1767 }
1768 
1770  static AW_window *aw_saiProbeMatch = NULp;
1771 
1772  if (!aw_saiProbeMatch) aw_saiProbeMatch = createSaiProbeMatchWindow(aw->get_root(), gb_main);
1773  if (g_spd) transferProbeData(g_spd); // transferring probe data to saiProbeMatch function
1774 
1775  aw_saiProbeMatch->activate();
1776 }
1777 
1779  // main window:
1780  { AWAR_TARGET_STRING, "target" },
1781  { AWAR_PD_MATCH_ALSO_REVCOMP, "complement" },
1782  { AWAR_PD_MATCH_MARKHITS, "markhits" },
1783  { AWAR_PD_MATCH_WRITE2TMP, "writetmp" },
1784  { AWAR_PD_MATCH_AUTOMATCH, "automatch" },
1785 
1786  // expert window:
1787  { AWAR_PD_MATCH_NMATCHES, "nmatches" },
1788  { AWAR_PD_MATCH_LIM_NMATCH, "limitnmatch" },
1789  { AWAR_PD_MATCH_MAX_RES, "maxresults" },
1790 
1791  { NULp, NULp }
1792 };
1793 
1794 
1796  static AW_window_simple *aws = NULp; // the one and only probe match window
1797  if (!aws) {
1798  aws = new AW_window_simple;
1799 
1800  aws->init(root, "PROBE_MATCH", "PROBE MATCH");
1801  aws->load_xfig("pd_match.fig");
1802 
1803  aws->auto_space(5, 5);
1804 
1805  aws->at("close");
1806  aws->callback(AW_POPDOWN);
1807  aws->create_button("CLOSE", "CLOSE", "C");
1808 
1809  aws->callback(makeHelpCallback("probematch.hlp"));
1810  aws->at("help");
1811  aws->create_button("HELP", "HELP", "H");
1812 
1813  aws->at("string");
1814  aws->create_input_field(AWAR_TARGET_STRING, 32);
1815 
1816  AW_selection_list *selection_id;
1817  aws->at("result");
1818  selection_id = aws->create_selection_list(AWAR_PD_SELECTED_MATCH, 110, 15);
1819  selection_id->insert_default("****** No results yet *******", ""); // if list is empty -> crashed if new species was selected in ARB_EDIT4
1820 
1821  static SmartPtr<TypedSelectionList> typed_selection = new TypedSelectionList("match", selection_id, "probe match", "probe_match");
1822  aws->at("print");
1823  aws->callback(makeWindowCallback(create_print_box_for_selection_lists, &*typed_selection));
1824  aws->create_button("PRINT", "PRINT", "P");
1825 
1826  aws->at("matchSai");
1827  aws->help_text("saiProbe.hlp");
1828  aws->callback(makeWindowCallback(popupSaiProbeMatchWindow, gb_main));
1829  aws->create_button("MATCH_SAI", "Match SAI", "S");
1830 
1831  aws->callback(makeCreateWindowCallback(create_probe_expert_window, false));
1832  aws->at("expert");
1833  aws->create_button("EXPERT", "EXPERT", "X");
1834 
1835  aws->at("pt_server");
1837 
1838  aws->at("complement");
1839  aws->create_toggle(AWAR_PD_MATCH_ALSO_REVCOMP);
1840 
1841  aws->at("mark");
1842  aws->create_toggle(AWAR_PD_MATCH_MARKHITS);
1843 
1844  aws->at("weighted");
1845  aws->create_toggle(AWAR_PD_MATCH_SORTBY);
1846 
1847  aws->at("mismatches");
1848  aws->create_input_field_with_scaler(AWAR_MAX_MISMATCHES, 5, 200, AW_SCALER_EXP_LOWER);
1849 
1850  aws->at("tmp");
1851  aws->create_toggle(AWAR_PD_MATCH_WRITE2TMP);
1852 
1853  aws->at("nhits");
1854  aws->create_button(NULp, AWAR_PD_MATCH_NHITS);
1855 
1856  aws->button_length(9);
1857 
1858  ProbeMatchEventParam *event_param = new ProbeMatchEventParam(gb_main, selection_id);
1859  aws->callback(RootAsWindowCallback::simple(probe_match_event_using_awars, event_param));
1860  aws->at("match");
1861  aws->create_button("MATCH", "MATCH", "D");
1862 
1863  aws->at("auto");
1864  aws->label("Auto");
1865  aws->create_toggle(AWAR_PD_MATCH_AUTOMATCH);
1866  enable_auto_match_cb(root, event_param);
1867 
1868  aws->callback(makeWindowCallback(modify_target_string, gb_main, TS_MOD_CLEAR));
1869  aws->at("clear");
1870  aws->create_button("CLEAR", "Clear", "0");
1871 
1872  aws->callback(makeWindowCallback(modify_target_string, gb_main, TS_MOD_REV_COMPL));
1873  aws->at("revcompl");
1874  aws->create_button("REVCOMPL", "RevCompl", "R");
1875 
1876  aws->callback(makeWindowCallback(modify_target_string, gb_main, TS_MOD_COMPL));
1877  aws->at("compl");
1878  aws->create_button("COMPL", "Compl", "C");
1879 
1880  aws->callback(makeCreateWindowCallback(create_IUPAC_resolve_window, gb_main));
1881  aws->at("iupac");
1882  aws->create_button("IUPAC", "IUPAC", "I");
1883 
1884  aws->at("config");
1885  AWT_insert_config_manager(aws, AW_ROOT_DEFAULT, "probe_match", makeConfigSetupCallback(setup_probe_config, probe_match_mapping_def));
1886  }
1887  return aws;
1888 }
1889 
1890 static void pd_start_pt_server(AW_window *aww) {
1891  const char *server_tag = GBS_ptserver_tag(aww->get_root()->awar(AWAR_PROBE_ADMIN_PT_SERVER)->read_int());
1892  arb_progress progress("Connecting PT-server");
1894  if (error) aw_message(error);
1895 }
1896 
1897 static void pd_kill_pt_server(AW_window *aww, bool kill_all) {
1898  if (aw_ask_sure("kill_ptserver",
1899  GBS_global_string("Are you sure to stop %s", kill_all ? "all servers" : "that server")))
1900  {
1901  long min = 0;
1902  long max = 0;
1903 
1904  if (kill_all) {
1905  const char * const *pt_servers = GBS_get_arb_tcp_entries("ARB_PT_SERVER*");
1906  while (pt_servers[max]) max++;
1907  }
1908  else {
1909  min = max = aww->get_root()->awar(AWAR_PROBE_ADMIN_PT_SERVER)->read_int(); // selected server
1910  }
1911 
1912  arb_progress progress("Stopping PT-servers..", max-min+1);
1913  GB_ERROR error = NULp;
1914 
1915  for (int i = min; i <= max && !error; i++) {
1916  char *choice = GBS_ptserver_id_to_choice(i, 0);
1917  if (!choice) {
1918  error = GB_await_error();
1919  }
1920  else {
1921  progress.subtitle(GBS_global_string("Trying to stop '%s'", choice));
1922 
1923  const char *server_tag = GBS_ptserver_tag(i);
1924  GB_ERROR kill_error = arb_look_and_kill_server(AISC_MAGIC_NUMBER, server_tag);
1925 
1926  if (kill_error) aw_message(GBS_global_string("Could not stop '%s' (Reason: %s)", choice, kill_error));
1927  else aw_message(GBS_global_string("Stopped '%s'", choice));
1928 
1929  free(choice);
1930  }
1931  progress.inc_and_check_user_abort(error);
1932  }
1933  progress.done();
1934  aw_message_if(error);
1935  }
1936 }
1937 
1938 static const char *ptserver_directory_info_command(const char *dirname, const char *directory) {
1939  return GBS_global_string("echo 'Contents of directory %s:'; echo; (cd \"%s\"; ls -hl); echo; "
1940  "echo 'Available disk space in %s:'; echo; df -h \"%s\"; echo; ",
1941  dirname, directory,
1942  dirname, directory);
1943 
1944 }
1945 
1946 static void pd_query_pt_server(AW_window *aww) {
1947  const char *server_tag = GBS_ptserver_tag(aww->get_root()->awar(AWAR_PROBE_ADMIN_PT_SERVER)->read_int());
1948 
1949  GBS_strstruct query_cmd(1024);
1950  query_cmd.cat(ptserver_directory_info_command("ARBHOME/lib/pts", "$ARBHOME/lib/pts"));
1951 
1952  const char *ARB_LOCAL_PTS = ARB_getenv_ignore_empty("ARB_LOCAL_PTS");
1953  if (ARB_LOCAL_PTS) query_cmd.cat(ptserver_directory_info_command("ARB_LOCAL_PTS", "$ARB_LOCAL_PTS")); // only defined if called via 'arb'-script
1954  else query_cmd.cat(ptserver_directory_info_command("HOME/.arb_pts", "${HOME}/.arb_pts"));
1955 
1956  query_cmd.cat("echo 'Running ARB programs:'; echo; ");
1957 
1958  GB_ERROR error = NULp;
1959  {
1960  const char *socketid = GBS_read_arb_tcp(server_tag);
1961  if (!socketid) {
1962  error = GB_await_error();
1963  }
1964  else {
1965  char *arb_who = createCallOnSocketHost(socketid, "$ARBHOME/bin/", "arb_who", WAIT_FOR_TERMINATION, NULp);
1966  query_cmd.cat(arb_who);
1967  free(arb_who);
1968  }
1969  }
1970 
1971  if (!error) error = GB_xcmd(query_cmd.get_data(), XCMD_ASYNC_WAITKEY);
1972  aw_message_if(error);
1973 }
1974 
1976  AW_root *awr = aww->get_root();
1977  GB_ERROR error = NULp;
1978 
1979  bool create_gene_server = awr->awar(AWAR_PROBE_CREATE_GENE_SERVER)->read_int();
1980  {
1981  GB_transaction ta(gb_main);
1982  if (create_gene_server && !GEN_is_genome_db(gb_main, -1)) create_gene_server = false;
1983 
1984  // check alignment first
1985  if (create_gene_server) {
1986  GBDATA *gb_ali = GBT_get_alignment(gb_main, GENOM_ALIGNMENT);
1987  if (!gb_ali) error = GB_await_error();
1988  }
1989  else { // normal pt server
1990  char *use = GBT_get_default_alignment(gb_main);
1991  if (!use) {
1992  error = GB_await_error();
1993  }
1994  else {
1995  GB_alignment_type alitype = GBT_get_alignment_type(gb_main, use);
1996  pd_assert(alitype != GB_AT_UNKNOWN);
1997  if (alitype == GB_AT_AA) error = "The PT-server does only support RNA/DNA sequence data";
1998  free(use);
1999  }
2000  }
2001  }
2002 
2003  long server_num = awr->awar(AWAR_PROBE_ADMIN_PT_SERVER)->read_int();
2004  const char *server_tag = GBS_ptserver_tag(server_num);
2005 
2006  if (!error &&
2007  aw_question("update_ptserver",
2008  "This function will send your loaded database to the pt_server,\n"
2009  "which will need a long time (up to several hours) to analyse the data.\n"
2010  "Until the new server has analyzed all data, no server functions are available.\n\n"
2011  "Note 1: You must have the write permissions to do that ($ARBHOME/lib/pts/xxx))\n"
2012  "Note 2: The server will do the job in background,\n"
2013  " quitting this program won't affect the server",
2014  "Cancel,Do it"))
2015  {
2016  arb_progress progress("Updating PT-server");
2017  progress.subtitle("Stopping PT-server");
2019 
2020  const char *ipPort = GBS_read_arb_tcp(server_tag);
2021  const char *file = NULp;
2022  if (!ipPort) error = GB_await_error();
2023  else {
2024  file = GBS_scan_arb_tcp_param(ipPort, "-d");
2025  GBS_add_ptserver_logentry(GBS_global_string("Started build of '%s'", file));
2026 
2027  char *db_name = awr->awar(AWAR_DB_PATH)->read_string();
2028  GBS_add_ptserver_logentry(GBS_global_string("Exporting DB '%s'", db_name));
2029  free(db_name);
2030  }
2031 
2032  if (!error) {
2033  progress.subtitle("Exporting the database");
2034  {
2035  const char *mode = GB_supports_mapfile() ? "mbf" : "bf"; // save PT-server database with Fastload file (if supported)
2036  if (create_gene_server) {
2037  char *temp_server_name = GBS_string_eval(file, "*.arb=*_temp.arb");
2038  error = GB_save_as(gb_main, temp_server_name, mode);
2039 
2040  if (!error) {
2041  // convert database (genes -> species)
2042  progress.subtitle("Preparing DB for gene PT server");
2043  GBS_add_ptserver_logentry("Preparing DB for gene PT server");
2044  char *command = GBS_global_string_copy("$ARBHOME/bin/arb_gene_probe %s %s", temp_server_name, file);
2045  error = GBK_system(command);
2046  if (error) error = GBS_global_string("Couldn't convert database for gene pt server\n(Reason: %s)", error);
2047  free(command);
2048  }
2049  free(temp_server_name);
2050  }
2051  else { // normal pt_server
2052  error = GB_save_as(gb_main, file, mode);
2053  }
2054  }
2055  }
2056 
2057  if (!error) { // set pt-server database file to same permissions as pts directory
2058  char *dir = const_cast<char*>(strrchr(file, '/'));
2059  if (dir) {
2060  *dir = 0;
2061  long modi = GB_mode_of_file(file);
2062  *dir = '/';
2063  modi &= 0666;
2064  error = GB_set_mode_of_file(file, modi);
2065  }
2066  }
2067 
2068  if (!error) {
2069  progress.subtitle("Start PT-server (builds in background)");
2070  error = arb_start_server(server_tag, 1);
2071  }
2072  }
2073  if (error) aw_message(error);
2074 }
2075 
2078 }
2080  AWT_system_in_console_cb("arb_show_log.pl server", XCMD_ASYNC_WAIT_ON_ERROR);
2081 }
2082 
2084  bool is_genom_db;
2085  {
2086  GB_transaction ta(gb_main);
2087  is_genom_db = GEN_is_genome_db(gb_main, -1);
2088  }
2089 
2090  AW_window_simple *aws = new AW_window_simple;
2091  aws->init(root, "PT_SERVER_ADMIN", "PT_SERVER ADMIN");
2092 
2093  aws->load_xfig("pd_admin.fig");
2094 
2095 
2096  aws->callback(makeHelpCallback("probeadmin.hlp"));
2097  aws->at("help");
2098  aws->create_button("HELP", "HELP", "H");
2099 
2100  aws->at("close");
2101  aws->callback(AW_POPDOWN);
2102  aws->create_button("CLOSE", "CLOSE", "C");
2103 
2104  aws->button_length(18);
2105 
2106  aws->at("pt_server");
2108 
2109  aws->at("start");
2110  aws->callback(pd_start_pt_server);
2111  aws->create_button("START_SERVER", "Start server");
2112 
2113  aws->at("kill");
2114  aws->callback(makeWindowCallback(pd_kill_pt_server, false));
2115  aws->create_button("KILL_SERVER", "Stop server");
2116 
2117  aws->at("query");
2118  aws->callback(pd_query_pt_server);
2119  aws->create_button("CHECK_SERVER", "Check server");
2120 
2121  aws->at("kill_all");
2122  aws->callback(makeWindowCallback(pd_kill_pt_server, true));
2123  aws->create_button("KILL_ALL_SERVERS", "Stop all servers");
2124 
2125  aws->at("edit");
2126  aws->callback(awt_edit_arbtcpdat_cb);
2127  aws->create_button("CREATE_TEMPLATE", "Configure");
2128 
2129  aws->at("log");
2130  aws->callback(pd_edit_ptserver_log);
2131  aws->create_button("EDIT_LOG", "Build history");
2132 
2133  aws->at("slog");
2134  aws->callback(pd_view_server_console);
2135  aws->create_button("VIEW_SERVER_LOG", "View server log");
2136 
2137  aws->at("export");
2138  aws->callback(makeWindowCallback(pd_export_pt_server, gb_main));
2139  aws->create_button("UPDATE_SERVER", "Build server");
2140 
2141  if (is_genom_db) {
2142  aws->at("gene_server");
2143  aws->label("Gene server?");
2144  aws->create_toggle(AWAR_PROBE_CREATE_GENE_SERVER);
2145  }
2146 
2147  return aws;
2148 }
2149 
2150 // ----------------------------------------------------------------------------
2151 
2153  static AW_window_simple *aws = NULp;
2154 
2155  if (!aws) {
2156  aws = new AW_window_simple;
2157 
2158  aws->init(root, "MATCH_DISPLAYCONTROL", "MATCH DISPLAY CONTROL");
2159 
2160  aws->auto_space(10, 10);
2161  aws->label_length(35);
2162 
2163  const int FIELDSIZE = 5;
2164  const int SCALERSIZE = 500;
2165 
2166  aws->label("Mismatch threshold");
2167  aws->create_input_field_with_scaler(AWAR_PC_MISMATCH_THRESHOLD, FIELDSIZE, SCALERSIZE);
2168 
2169  aws->at_newline();
2170 
2171  aws->label("Clade marked threshold");
2172  aws->create_input_field_with_scaler(AWAR_DTREE_GROUP_MARKED_THRESHOLD, FIELDSIZE, SCALERSIZE);
2173 
2174  aws->at_newline();
2175 
2176  aws->label("Clade partially marked threshold");
2177  aws->create_input_field_with_scaler(AWAR_DTREE_GROUP_PARTIALLY_MARKED_THRESHOLD, FIELDSIZE, SCALERSIZE);
2178 
2179  aws->at_newline();
2180 
2181  aws->callback(TREE_create_marker_settings_window);
2182  aws->create_autosize_button("MARKER_SETTINGS", "Marker display settings", "d");
2183 
2184  aws->at_newline();
2185  }
2186 
2187  return aws;
2188 }
2189 
2190 // ----------------------------------------------------------------------------
2191 
2195 
2197  probes_id(NULp),
2198  ntw(NULp)
2199  {}
2200 };
2201 
2203 
2204 static void probe_match_update_probe_list(ArbPM_Context *pContext);
2206 
2208  FILE *pFile;
2211 
2213  pFile(NULp),
2214  pProgress(NULp),
2215  nLastPercent(0)
2216  {}
2217 };
2218 
2219 // ----------------------------------------------------------------------------
2220 
2221 static bool probe_match_with_specificity_enum_callback(void *pVoidContext, const char *pResult, bool bIsComment, int nItem, int nItems) {
2222  ArbWriteFile_Context *pContext = (ArbWriteFile_Context*)pVoidContext;
2223  int nPercent = (int)(100.0 * nItem / nItems);
2224 
2225  if (!bIsComment) {
2226  if (pContext->nLastPercent != nPercent) {
2227  pContext->nLastPercent = nPercent;
2228  pContext->pProgress->inc();
2229  }
2230  }
2231 
2232  if (pContext->pFile) {
2233  // Update status - put after matching cause matching writes its own status messages
2234  fprintf(pContext->pFile, "%s\n", pResult);
2235  }
2236 
2237  return pContext->pProgress->aborted();
2238 }
2239 
2240 // ----------------------------------------------------------------------------
2241 
2243  AW_edit(get_results_manager().resultsFileName());
2244 }
2245 
2246 // ----------------------------------------------------------------------------
2247 
2248 class GetMatchesContext { // @@@ merge with ProbeCollDisplay?
2249  float mismatchThreshold;
2250  int nProbes;
2251 
2252  typedef ArbMatchResultPtrByStringMultiMap MatchMap;
2253  typedef ArbMatchResultPtrByStringMultiMapConstIter MatchMapIter;
2254 
2255  const MatchMap& results;
2256 public:
2257  GetMatchesContext(float misThres, int numProbes)
2258  : mismatchThreshold(misThres),
2259  nProbes(numProbes),
2260  results(get_results_manager().resultsMap())
2261  {}
2262 
2263  void detect(std::string speciesName, NodeMarkers& matches) const {
2264  std::pair<MatchMapIter,MatchMapIter> iter = results.equal_range(speciesName);
2265 
2266  for (; iter.first != iter.second ; ++iter.first) {
2267  const ArbMatchResult *pMatchResult = iter.first->second;
2268  if (pMatchResult->weight() <= mismatchThreshold) {
2269  int nProbe = pMatchResult->index();
2270  matches.incMarker(nProbe);
2271  }
2272  }
2273  matches.incNodeSize();
2274  }
2275 };
2276 
2278 
2280  ArbProbe *find_probe(int markerIdx) const {
2281  const ArbProbePtrList& rProbeList = get_probe_collection().probeList();
2282  ArbProbePtrListConstIter wanted = rProbeList.begin();
2283 
2284  if (markerIdx>=0 && markerIdx<int(rProbeList.size())) advance(wanted, markerIdx);
2285  else wanted = rProbeList.end();
2286 
2287  return wanted == rProbeList.end() ? NULp : *wanted;
2288  }
2289 
2290 public:
2291  ProbeCollDisplay(int numProbes)
2292  : MarkerDisplay(numProbes)
2293  {}
2294 
2295  // MarkerDisplay interface
2296  const char *get_marker_name(int markerIdx) const OVERRIDE {
2297  ArbProbe *probe = find_probe(markerIdx);
2298  return probe ? probe->name().c_str() : GBS_global_string("<invalid probeindex %i>", markerIdx);
2299  }
2300  void retrieve_marker_state(const char *speciesName, NodeMarkers& matches) OVERRIDE {
2301  getMatchesContext->detect(speciesName, matches);
2302  }
2303 
2305  // select probe in selection list
2306  ArbProbe *probe = find_probe(markerIdx);
2307  if (probe) AW_root::SINGLETON->awar(AWAR_PC_SELECTED_PROBE)->write_string(probe->sequence().c_str());
2308 #if defined(DEBUG)
2309  else fprintf(stderr, "ProbeCollDisplay::handle_click: no probe found for markerIdx=%i\n", markerIdx);
2310 #endif
2311  }
2312 };
2313 
2314 inline bool displays_probeColl_markers(MarkerDisplay *md) { return dynamic_cast<ProbeCollDisplay*>(md); }
2315 
2317  // setup parameters for display of probe collection matches and trigger tree refresh
2319 
2321  bool display = get_results_manager().hasResults();
2322 
2323  MarkerDisplay *markerDisplay = agt->get_marker_display();
2324  bool redraw = false;
2325  if (display) {
2326  size_t probesCount = get_probe_collection().probeList().size();
2327  getMatchesContext = new GetMatchesContext(root->awar(AWAR_PC_MISMATCH_THRESHOLD)->read_float(), probesCount);
2328 
2329  if (displays_probeColl_markers(markerDisplay) && probesCount == size_t(markerDisplay->size())) {
2330  markerDisplay->flush_cache();
2331  }
2332  else {
2333  agt->set_marker_display(new ProbeCollDisplay(get_probe_collection().probeList().size()));
2334  }
2335  redraw = true;
2336  }
2337  else {
2338  if (displays_probeColl_markers(markerDisplay)) {
2339  agt->hide_marker_display();
2340  redraw = true;
2341  }
2342  }
2343 
2344  if (redraw) root->awar(AWAR_TREE_REFRESH)->touch();
2345 }
2346 
2347 // ----------------------------------------------------------------------------
2348 
2351  GB_ERROR error = NULp;
2352 
2353  ProbeMatchSettings matchSettings(root);
2354  matchSettings.markHits = 0;
2355  matchSettings.write2tmp = 0;
2356 
2357  ArbMatchResultsManager& g_results_manager = get_results_manager();
2358  g_results_manager.reset();
2359 
2360  // Using g_probe_collection instance of ArbProbeCollection, need to loop
2361  // through all the probes in the collect and then call probe_match_event,
2362  // collating the results as we go. The results can be obtained from the
2363  // g_spd->probeSeq list.
2364  const ArbProbePtrList& rProbeList = get_probe_collection().probeList();
2365 
2366  const long nItems = rProbeList.size();
2367  long nItem = 1;
2368 
2369  int nHits = 0;
2370  int nProbeIndex = 0;
2371 
2372  // This extra scope needed to ensure the arb_progress object is released
2373  // prior to the next one being used to show progress on write results to file
2374  {
2375  arb_progress progress("Matching probe collection", nItems);
2376 
2377  ArbProbeCollection& g_probe_collection = get_probe_collection();
2378 
2379  for (ArbProbePtrListConstIter ProbeIter = rProbeList.begin() ; ProbeIter != rProbeList.end() && !error; ++ProbeIter) {
2380  const ArbProbe *pProbe = *ProbeIter;
2381 
2382  if (pProbe) {
2383  int nMatches;
2384  ArbMatchResultSet *pResultSet = g_results_manager.addResultSet(pProbe);
2385 
2386  // Update status - put after matching cause matching writes its own status messages
2387  progress.subtitle(GBS_global_string("Matching probe %li of %li", nItem, nItems));
2388 
2389  // Perform match on pProbe
2390  matchSettings.targetString = pProbe->sequence();
2391  matchSettings.maxMismatches = pProbe->allowedMismatches();
2392 
2393  int counter = -1;
2394  ProbeMatchEventParam match_event(ntw->gb_main, &counter);
2395 
2396  error = probe_match_event(matchSettings, &match_event);
2397 
2398  pResultSet->initialise(pProbe, nProbeIndex);
2399  nProbeIndex++;
2400 
2401  if (g_spd && g_spd->getHeadline() && !error) {
2402  ProbeMatchParser parser(pProbe->sequence().c_str(), g_spd->getHeadline());
2403 
2404  if (parser.get_error()) {
2405  error = parser.get_error();
2406  }
2407  else {
2408  int nStartFullName = 0;
2409  int nEndFullName = 0;
2410 
2411  parser.getColumnRange("fullname", &nStartFullName, &nEndFullName);
2412 
2413  pResultSet->headline(g_spd->getHeadline(), nEndFullName);
2414 
2415  // Collate match results
2416  nMatches = g_spd->probeSeq.size();
2417 
2418  for (int cn = 0 ; cn < nMatches && !error ; cn++) {
2419  const std::string& sResult = g_spd->probeSeq[cn];
2420 
2421  ParsedProbeMatch parsed(sResult.c_str(), parser);
2422 
2423  if (parsed.get_error()) {
2424  error = parsed.get_error();
2425  }
2426  else {
2427  char *pName = parsed.get_column_content("name", true);
2428  char *pFullName = parsed.get_column_content("fullname", true);
2429  const char *pMatchPart = parsed.get_probe_region();
2430 
2431  pResultSet->add(pName,
2432  pFullName,
2433  pMatchPart,
2434  sResult.c_str(),
2435  g_probe_collection.matchWeighting());
2436 
2437  free(pName);
2438  free(pFullName);
2439  }
2440  }
2441  }
2442  }
2443 
2444  if (error) error = GBS_global_string("while matching probe #%li: %s", nItem, error);
2445 
2446  nItem++;
2447  }
2448  progress.inc_and_check_user_abort(error);
2449  }
2450  }
2451 
2452  if (!error) {
2453  ArbWriteFile_Context Context;
2454 
2455  arb_progress progress("Writing results to file", 100L);
2456  progress.subtitle(g_results_manager.resultsFileName());
2457 
2458  Context.pFile = fopen(g_results_manager.resultsFileName(), "w");
2459  Context.pProgress = &progress;
2460  Context.nLastPercent = 0;
2461 
2462  nHits = g_results_manager.enumerate_results(probe_match_with_specificity_enum_callback, (void*)&Context);
2463 
2464  fclose(Context.pFile);
2465 
2466  if (!error) error = progress.error_if_aborted();
2467  progress.done();
2468  }
2469 
2470  root->awar(AWAR_PC_MATCH_NHITS)->write_int(nHits);
2471 
2472  if (error) {
2473  aw_message(error);
2474 
2475  // Clear the results set
2476  g_results_manager.reset();
2477  }
2478  else {
2479  // Open the Probe Match Specificity dialog to interactively show how the
2480  // matches target the phylongeny
2482 
2483  double oldMaxWeight = g_results_manager.maximumWeight();
2484  g_results_manager.updateResults();
2485  double newMaxWeight = g_results_manager.maximumWeight();
2486 
2487  if (newMaxWeight != oldMaxWeight) {
2488  // set new limits for scaler and force current value into limits
2489  newMaxWeight = std::max(newMaxWeight, 0.000001); // avoid invalid limits
2490  root->awar(AWAR_PC_MISMATCH_THRESHOLD)->set_minmax(0.0, newMaxWeight)->touch();
2491  }
2492  }
2493 
2495  }
2496 }
2497 
2498 static void auto_match_cb(AW_root *root, TREE_canvas *ntw) {
2499  if (root->awar(AWAR_PC_AUTO_MATCH)->read_int()) {
2501  }
2502 }
2503 static void trigger_auto_match(AW_root *root) {
2504  root->awar(AWAR_PC_AUTO_MATCH)->touch();
2505 }
2506 
2507 // ----------------------------------------------------------------------------
2508 
2510  AW_root *root = aww->get_root();
2511 
2513  root->awar(AWAR_PC_MATCH_NHITS)->write_int(0);
2514  refresh_matchedProbesDisplay_cb(root, pContext->ntw);
2515 }
2516 
2518  char *pSequence = root->awar(AWAR_PC_SELECTED_PROBE)->read_string();
2519  if (pSequence) {
2520  const ArbProbe *pProbe = get_probe_collection().find(pSequence);
2521  if (pProbe) {
2522  const char *seq = pProbe->sequence().c_str();
2524  root->awar(AWAR_PC_TARGET_NAME) ->write_string(pProbe->name().c_str());
2525 
2526  root->awar(AWAR_TARGET_STRING)->write_string(seq); // copy to probe match & match in edit4
2527  }
2528  }
2529  free(pSequence);
2530 }
2531 
2532 static void target_string_changed_cb(AW_root *root) {
2533  char *pSequence = root->awar(AWAR_PC_TARGET_STRING)->read_string();
2534  if (pSequence && pSequence[0]) {
2535  const ArbProbe *pProbe = get_probe_collection().find(pSequence);
2536  if (pProbe) root->awar(AWAR_PC_SELECTED_PROBE)->write_string(pSequence);
2537  }
2538  free(pSequence);
2539 }
2540 
2541 static void match_changed_cb(AW_root *root) {
2542  // automatically adapt to last probe matched
2543  // (also adapts to last selected designed probe)
2544  char *pSequence = root->awar(AWAR_TARGET_STRING)->read_string();
2545  if (pSequence && pSequence[0]) {
2546  AW_awar *awar_target = root->awar(AWAR_PC_TARGET_STRING);
2547  if (strcmp(awar_target->read_char_pntr(), pSequence) != 0) {
2548  root->awar(AWAR_PC_TARGET_NAME)->write_string(""); // clear name
2549  }
2550  awar_target->write_string(pSequence);
2551  }
2552  free(pSequence);
2553 }
2554 
2555 // ----------------------------------------------------------------------------
2556 
2558  static AW_window_simple *aws = NULp; // the one and only probeSpec window
2559 
2560  if (!aws) {
2562 
2563  aws = new AW_window_simple;
2564 
2565  aws->init(root, "PROBE_MATCH_WITH_SPECIFICITY", "PROBE MATCH WITH SPECIFICITY");
2566 
2567  aws->load_xfig("pd_match_with_specificity.fig");
2568 
2569  aws->at("close");
2570  aws->callback(AW_POPDOWN);
2571  aws->create_button("CLOSE", "CLOSE", "C");
2572 
2573  aws->callback(makeHelpCallback("probespec.hlp"));
2574  aws->at("help");
2575  aws->create_button("HELP", "HELP", "H");
2576 
2577  AW_selection_list *probes_id;
2578 
2579  aws->at("probes");
2580  probes_id = aws->create_selection_list(AWAR_PC_SELECTED_PROBE, 110, 10);
2581  probes_id->insert_default("", "");
2582 
2583  PM_Context.probes_id = probes_id;
2584  PM_Context.ntw = ntw;
2585 
2586  aws->callback(makeWindowCallback(probe_match_with_specificity_edit_event));
2587  aws->at("results");
2588  aws->create_button("RESULTS", "RESULTS", "R");
2589 
2590  aws->at("pt_server");
2592 
2593  aws->at("nhits");
2594  aws->create_button(NULp, AWAR_PC_MATCH_NHITS);
2595 
2596  aws->callback(makeCreateWindowCallback(create_probe_collection_window, &PM_Context));
2597  aws->at("edit");
2598  aws->create_button("EDIT", "EDIT", "E");
2599 
2601  aws->at("match");
2602  aws->create_button("MATCH", "MATCH", "M");
2603 
2604  aws->callback(makeWindowCallback(probe_forget_matches_event, &PM_Context));
2605  aws->at("forget");
2606  aws->create_button("FORGET", "FORGET", "F");
2607 
2608  aws->at("auto");
2609  aws->label("Auto match");
2610  aws->create_toggle(AWAR_PC_AUTO_MATCH);
2611 
2612  AW_awar *awar_automatch = root->awar(AWAR_PC_AUTO_MATCH);
2613  awar_automatch->add_callback(makeRootCallback(auto_match_cb, ntw));
2614 
2615  aws->callback(makeCreateWindowCallback(create_probe_match_specificity_control_window));
2616  aws->at("control");
2617  aws->create_autosize_button("CONTROL", "Display control", "D");
2618 
2619  probe_match_update_probe_list(&PM_Context);
2620 
2623  root->awar(AWAR_TARGET_STRING)->add_callback(makeRootCallback(match_changed_cb));
2624 
2625  awar_automatch->touch(); // automatically run match if 'auto-match' is checked at startup
2626  }
2627 
2628  return aws;
2629 }
2630 
2631 // ----------------------------------------------------------------------------
2632 
2636 
2638  selection_id(NULp),
2639  PM_Context(NULp)
2640  {}
2641 };
2642 
2644 
2645 // ----------------------------------------------------------------------------
2646 
2647 static void save_probe_list_to_DB(const ArbProbePtrList& rProbeList, AW_root *root) {
2648  std::string saved;
2649  for (ArbProbePtrListConstIter ProbeIter = rProbeList.begin() ; ProbeIter != rProbeList.end() ; ++ProbeIter) {
2650  const ArbProbe *pProbe = *ProbeIter;
2651  if (pProbe) {
2652  // Note: target sequences/names do not contain '#'/':' (see REPLACE_TARGET_CONTROL_CHARS)
2653  saved = saved + '#'+pProbe->name()+':'+pProbe->sequence();
2654  }
2655  }
2656 
2657  root->awar(AWAR_PC_CURRENT_COLLECTION)->write_string(saved.empty() ? "" : saved.c_str()+1);
2658 }
2659 
2660 static void show_probes_in_sellist(const ArbProbePtrList& rProbeList, AW_selection_list *sellist) {
2661  sellist->clear();
2662  sellist->insert_default("", "");
2663  for (ArbProbePtrListConstIter ProbeIter = rProbeList.begin() ; ProbeIter != rProbeList.end() ; ++ProbeIter) {
2664  const ArbProbe *pProbe = *ProbeIter;
2665  if (pProbe) {
2666  sellist->insert(pProbe->displayName().c_str(), pProbe->sequence().c_str());
2667  }
2668  }
2669  sellist->update();
2670 }
2671 
2672 static void load_probe_collection(AW_window *aww, ArbPC_Context *Context, const char * const *awar_filename) {
2673  char *pFileName = aww->get_root()->awar(*awar_filename)->read_string();
2674 
2675  ArbProbeCollection ProbeCollection;
2676  std::string sErrorMessage;
2677 
2678  if (ProbeCollection.openXML(pFileName, sErrorMessage)) {
2679  int cn;
2680  char buffer[256] = {0};
2681  float weights[16] = {0.0};
2682  float dWidth = 1.0;
2683  float dBias = 0.0;
2684 
2685  ArbProbeCollection& g_probe_collection = get_probe_collection();
2686  g_probe_collection = ProbeCollection;
2687 
2688  g_probe_collection.getParameters(weights, dWidth, dBias);
2689 
2690  AW_root *root = AW_root::SINGLETON;
2691  root->awar(AWAR_PC_MATCH_WIDTH)->write_float(dWidth);
2692  root->awar(AWAR_PC_MATCH_BIAS)->write_float(dBias);
2693 
2694  for (cn = 0; cn < 16 ; cn++) {
2695  sprintf(buffer, AWAR_PC_MATCH_WEIGHTS"%i", cn);
2696 
2697  root->awar(buffer)->write_float(weights[cn]);
2698  }
2699 
2700  const ArbProbePtrList& rProbeList = g_probe_collection.probeList();
2701 
2702  save_probe_list_to_DB(rProbeList, root);
2703  show_probes_in_sellist(rProbeList, Context->selection_id);
2704 
2706  aww->hide();
2707  trigger_auto_match(root);
2708  }
2709  else {
2710  // Print error message
2711  aw_message(sErrorMessage.c_str());
2712  }
2713 
2714  free(pFileName);
2715 }
2716 
2717 // ----------------------------------------------------------------------------
2718 
2720  AW_root *root = AW_root::SINGLETON;
2721 
2722  int cn;
2723  char buffer[256] = {0};
2724 
2725  float weights[16] = {0.0};
2726  float dWidth = root->awar(AWAR_PC_MATCH_WIDTH)->read_float();
2727  float dBias = root->awar(AWAR_PC_MATCH_BIAS)->read_float();
2728 
2729  for (cn = 0; cn < 16 ; cn++) {
2730  sprintf(buffer, AWAR_PC_MATCH_WEIGHTS"%i", cn);
2731 
2732  weights[cn] = root->awar(buffer)->read_float();
2733  }
2734 
2735  ArbProbeCollection& g_probe_collection = get_probe_collection();
2736  g_probe_collection.setParameters(weights, dWidth, dBias);
2737 
2738  save_probe_list_to_DB(g_probe_collection.probeList(), root);
2739 }
2740 
2741 // ----------------------------------------------------------------------------
2742 
2743 static void save_probe_collection(AW_window *aww, const char * const *awar_filename) {
2744  char *pFileName = aww->get_root()->awar(*awar_filename)->read_string();
2745 
2746  struct stat FileStatus;
2747  int nResult = ::stat(pFileName, &FileStatus);
2748  bool bWrite = true;
2749 
2750  if (nResult == 0) {
2751  bWrite = (aw_question("probe_collection_save", "File already exists. Overwrite?", "YES,NO") == 0);
2752  }
2753 
2754  if (bWrite) {
2756  get_probe_collection().saveXML(pFileName);
2757 
2758  aww->hide();
2759  }
2760 
2761  free(pFileName);
2762 }
2763 
2764 // ----------------------------------------------------------------------------
2765 
2767  AW_selection_list *selection_id = pContext->selection_id;
2768  if (selection_id) {
2769  AW_root *root = aww->get_root();
2770  char *pSequence = root->awar(AWAR_PC_TARGET_STRING)->read_string();
2771  char *pName = root->awar(AWAR_PC_TARGET_NAME)->read_string();
2772 
2773  GB_ERROR error = NULp;
2774  if (!pSequence || !pSequence[0]) {
2775  error = "Please enter a target string";
2776  }
2777  else if (get_probe_collection().find(pSequence)) {
2778  error = "Target string already in collection";
2779  }
2780 
2781  if (!error) {
2782  const ArbProbe *pProbe = NULp;
2783 
2784  if (get_probe_collection().add(pName, pSequence, &pProbe) && pProbe) {
2785  selection_id->insert(pProbe->displayName().c_str(), pSequence);
2786  selection_id->update();
2789 
2790  root->awar(AWAR_PC_SELECTED_PROBE)->write_string(pSequence);
2791  trigger_auto_match(root);
2792  }
2793  else {
2794  error = "failed to add probe";
2795  }
2796  }
2797 
2798  aw_message_if(error);
2799 
2800  free(pName);
2801  free(pSequence);
2802  }
2803 }
2804 
2805 static void modify_probe_event(AW_window *aww, ArbPC_Context *pContext) {
2806  AW_selection_list *selection_id = pContext->selection_id;
2807  if (selection_id) {
2808  AW_root *root = aww->get_root();
2809  AW_awar *awar_selected = root->awar(AWAR_PC_SELECTED_PROBE);
2810  char *oldSequence = awar_selected->read_string();
2811  char *pSequence = root->awar(AWAR_PC_TARGET_STRING)->read_string();
2812  char *pName = root->awar(AWAR_PC_TARGET_NAME)->read_string();
2813  bool sequenceChanged = false;
2814 
2815  GB_ERROR error = NULp;
2816  if (!pSequence || !pSequence[0]) {
2817  error = "Please enter a target string";
2818  }
2819  else if (!oldSequence || !oldSequence[0]) {
2820  error = "Please select probe to modify";
2821  }
2822  else {
2823  sequenceChanged = strcmp(oldSequence, pSequence) != 0;
2824  if (sequenceChanged) { // sequence changed -> test vs duplicate
2825  if (get_probe_collection().find(pSequence)) {
2826  error = "Target string already in collection";
2827  }
2828  }
2829  }
2830 
2831  if (!error) {
2832  const ArbProbe *pProbe = NULp;
2833 
2834  if (get_probe_collection().replace(oldSequence, pName, pSequence, &pProbe) && pProbe) {
2835  AW_selection_list_iterator entry(selection_id, selection_id->get_index_of_selected());
2836  entry.set_displayed(pProbe->displayName().c_str());
2837  entry.set_value(AW_scalar(pSequence));
2838  selection_id->update();
2839 
2842 
2843  awar_selected->write_string(pSequence);
2844  trigger_auto_match(root);
2845  }
2846  else {
2847  error = "failed to replace probe";
2848  }
2849  }
2850 
2851  aw_message_if(error);
2852 
2853  free(pName);
2854  free(pSequence);
2855  free(oldSequence);
2856  }
2857 }
2858 
2860  AW_selection_list *selection_id = pContext->selection_id;
2861  if (selection_id) {
2862  AW_root *root = aww->get_root();
2863  char *pSequence = root->awar(AWAR_PC_SELECTED_PROBE)->read_string();
2864  if (pSequence) {
2865  const ArbProbe *pProbe = get_probe_collection().find(pSequence);
2866  if (pProbe) {
2867  int idx = selection_id->get_index_of_selected();
2868  selection_id->delete_element_at(idx);
2869 
2870  if (selection_id->size() < 1) {
2871  selection_id->insert_default("", "");
2872  }
2873  selection_id->update();
2874  selection_id->select_element_at(idx); // select next probe for deletion
2875 
2876  get_probe_collection().remove(pSequence);
2879 
2880  trigger_auto_match(root);
2881  }
2882  free(pSequence);
2883  }
2884  }
2885 }
2886 
2887 // ----------------------------------------------------------------------------
2888 
2890  static char *awar_name = NULp; // do not free, bound to callback
2891  return awt_create_load_box(root, "Load", "probe collection",
2892  ".", "xpc", &awar_name,
2893  makeWindowCallback(load_probe_collection, pContext, (const char*const*)&awar_name));
2894 }
2896  static char *awar_name = NULp; // do not free, bound to callback
2897  return awt_create_load_box(root, "Save", "probe collection",
2898  ".", "xpc", &awar_name,
2899  makeWindowCallback(save_probe_collection, (const char*const*)&awar_name));
2900 }
2901 
2902 // ----------------------------------------------------------------------------
2903 
2905  if (pContext) {
2906  AW_selection_list *sellist = pContext->probes_id;
2907  if (sellist) show_probes_in_sellist(get_probe_collection().probeList(), sellist);
2908  }
2909 }
2911  if (get_probe_collection().clear()) {
2913  show_probes_in_sellist(get_probe_collection().probeList(), pContext->selection_id);
2914  trigger_auto_match(aww->get_root());
2915  }
2916 }
2917 
2918 // ----------------------------------------------------------------------------
2919 
2922  aww->hide();
2923 }
2924 
2925 // ----------------------------------------------------------------------------
2926 
2928  static AW_window_simple *aws = NULp; // the one and only probe match window
2929  char buffer[256];
2930 
2931  pd_assert(pContext);
2932  PC_Context.PM_Context = pContext;
2933 
2934  if (!aws) {
2935  aws = new AW_window_simple;
2936 
2937  aws->init(root, "PROBE_COLLECTION", "PROBE COLLECTION");
2938 
2939  aws->load_xfig("pd_match_probe_collection.fig");
2940 
2941  aws->callback(probe_collection_close);
2942  aws->at("close");
2943  aws->create_button("CLOSE", "CLOSE", "C");
2944 
2945  aws->callback(makeHelpCallback("probespec.hlp"));
2946  aws->at("help");
2947  aws->create_button("HELP", "HELP", "H");
2948 
2949  AW_selection_list *selection_id;
2950 
2951  aws->at("probes");
2952  selection_id = aws->create_selection_list(AWAR_PC_SELECTED_PROBE, 110, 10);
2953  selection_id->insert_default("", "");
2954 
2955  PC_Context.selection_id = selection_id;
2956 
2957  aws->at("string");
2958  aws->create_input_field(AWAR_PC_TARGET_STRING, 32);
2959 
2960  aws->at("name");
2961  aws->create_input_field(AWAR_PC_TARGET_NAME, 32);
2962 
2963  aws->callback(makeWindowCallback(add_probe_to_collection_event, &PC_Context));
2964  aws->at("add");
2965  aws->create_button("ADD", "ADD", "A");
2966 
2967  aws->callback(makeWindowCallback(modify_probe_event, &PC_Context));
2968  aws->at("modify");
2969  aws->create_button("MODIFY", "MODIFY", "M");
2970 
2971  aws->callback(makeWindowCallback(remove_probe_from_collection_event, &PC_Context));
2972  aws->at("remove");
2973  aws->create_button("REMOVE", "REMOVE", "R");
2974 
2975  aws->callback(makeCreateWindowCallback(probe_collection_load_prompt, &PC_Context));
2976  aws->at("open");
2977  aws->create_button("LOAD", "LOAD", "L");
2978 
2979  aws->callback(makeCreateWindowCallback(probe_collection_save_prompt));
2980  aws->at("save");
2981  aws->create_button("SAVE", "SAVE", "S");
2982 
2983  aws->callback(makeWindowCallback(clear_probe_collection_event, &PC_Context));
2984  aws->at("clear");
2985  aws->create_button("CLEAR", "CLEAR", "L");
2986 
2987  for (int i = 0 ; i < 16 ; i++) {
2988  sprintf(buffer, "%i", i);
2989  aws->at(buffer);
2990  sprintf(buffer, AWAR_PC_MATCH_WEIGHTS"%i", i);
2991  aws->create_input_field(buffer, 4);
2992  root->awar(buffer)->add_callback(trigger_auto_match);
2993  }
2994 
2995  aws->at("width");
2996  aws->create_input_field(AWAR_PC_MATCH_WIDTH, 5);
2998 
2999  aws->at("bias");
3000  aws->create_input_field(AWAR_PC_MATCH_BIAS, 5);
3002 
3003  show_probes_in_sellist(get_probe_collection().probeList(), selection_id);
3004  }
3005  return aws;
3006 }
AutoMatchSettings(ProbeMatchEventParam *event_param_, bool disable_)
const char * GBS_ptserver_logname(void)
Definition: adtcp.cxx:425
GB_ERROR GB_begin_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2528
std::string hits_summary
ArbMatchResultSet * addResultSet(const ArbProbe *pProbe)
GB_ERROR GBK_system(const char *system_command)
Definition: arb_msg.cxx:512
const char * GB_ERROR
Definition: arb_core.h:25
void set_marker_display(MarkerDisplay *display)
#define AWAR_PC_MISMATCH_THRESHOLD
static void selected_probe_changed_cb(AW_root *root)
string result
void sort(bool backward, bool case_sensitive)
Definition: AW_select.cxx:502
static void target_string_changed_cb(AW_root *root)
static void trigger_auto_match(AW_root *root)
AW_awar * set_srt(const char *srt)
Definition: AW_awar.cxx:567
#define AWAR_PD_MATCH_LIM_NMATCH
AW_window * create_probe_design_window(AW_root *root, GBDATA *gb_main)
GetMatchesContext(float misThres, int numProbes)
GBDATA * GEN_next_gene(GBDATA *gb_gene)
Definition: adGene.cxx:138
void add(const char *awar_name, const char *config_name)
GBDATA * GBT_first_marked_species(GBDATA *gb_main)
Definition: aditem.cxx:113
static GB_ERROR pd_get_the_gene_names(GBDATA *gb_main, bytestring &bs, bytestring &checksum)
size_t size() const
Definition: arb_strarray.h:85
#define AWAR_PD_MATCH_ALSO_REVCOMP
GBDATA * GBT_first_marked_species_rel_species_data(GBDATA *gb_species_data)
Definition: aditem.cxx:109
static void match_changed_cb(AW_root *root)
#define AWAR_PC_MATCH_WIDTH
const char * get_error() const
static const char * PD_probe_pt_look_for_server(int serverNumber, GB_ERROR &error)
ProbeCollDisplay(int numProbes)
return string(buffer, length)
void space()
Definition: test_unit.h:403
std::vector< std::string > probeSeq
#define AWAR_PD_DESIGN_MINTARGETS
void select_element_at(int wanted_index)
Definition: AW_select.cxx:433
GB_ERROR GB_append_exportedError(GB_ERROR error)
Definition: arb_msg.cxx:386
void set_displayed(const char *disp)
Definition: aw_select.hxx:162
GB_ERROR GB_write_string(GBDATA *gbd, const char *s)
Definition: arbdb.cxx:1387
#define AWAR_PROBE_CREATE_GENE_SERVER
void load_xfig(const char *file, bool resize=true)
Definition: AW_window.cxx:720
const TypedSelectionList & get_typedsellist() const
const ArbProbePtrList & probeList() const
void insert_default(const char *displayed, const AW_scalar &value)
Definition: AW_select.cxx:385
#define AWAR_SPV_DB_FIELD_NAME
GBDATA * GEN_find_gene(GBDATA *gb_species, const char *name)
Definition: adGene.cxx:64
AW_window * createSaiProbeMatchWindow(AW_root *awr, GBDATA *gb_main)
void AW_edit(const char *path)
Definition: AW_edit.cxx:16
#define AWAR_PD_DESIGN_EXP_DT
AW_window * awt_create_load_box(AW_root *aw_root, const char *action, const char *what, const char *default_directory, const char *file_extension, char **set_file_name_awar, const WindowCallback &ok_cb, const WindowCallback &close_cb, const char *close_button_text)
char * GBT_complementNucSequence(const char *s, int len, char T_or_U)
Definition: adRevCompl.cxx:78
void create_probe_design_variables(AW_root *root, AW_default props, AW_default db)
static void modify_probe_event(AW_window *aww, ArbPC_Context *pContext)
long GB_mode_of_file(const char *path)
Definition: arb_file.cxx:60
int aisc_close(aisc_com *link, AISC_Object &object)
Definition: client.c:249
const char *const members
Definition: iupac.h:47
char * get_column_content(const char *columnName, bool chop_spaces) const
#define AWAR_PD_DESIGN_MIN_TEMP
AW_selection_list * selection_id
GB_ERROR GB_end_transaction(GBDATA *gbd, GB_ERROR error)
Definition: arbdb.cxx:2561
#define AWAR_PD_MATCH_AUTOMATCH
long
Definition: AW_awar.cxx:152
static void probe_match_event_using_awars(AW_root *root, ProbeMatchEventParam *event_param)
void awt_clear_selection_list_cb(AW_window *, AW_selection_list *sellist)
AW_selection_list * selection_id
GBDATA * GBT_get_alignment(GBDATA *gb_main, const char *aliname)
Definition: adali.cxx:808
void add(int v)
Definition: ClustalV.cxx:461
static int init_local_com_struct()
#define pd_assert(bed)
Definition: probe_local.hxx:17
double maximumWeight() const
void GBS_intcat(GBS_strstruct *strstr, long val)
Definition: arb_strbuf.cxx:127
#define AWAR_PC_MATCH_WEIGHTS
ArbProbePtrList::const_iterator ArbProbePtrListConstIter
const char * ARB_getenv_ignore_empty(const char *envvar)
Definition: arb_misc.cxx:102
bool ok() const
Definition: arbdb.h:162
static void pd_export_pt_server(AW_window *aww, GBDATA *gb_main)
char * ARB_strdup(const char *str)
Definition: arb_string.h:27
AW_selection_list * resultList
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)
#define AWAR_DEFAULT_ALIGNMENT
Definition: aw_awar_defs.hxx:8
AW_window * create_probe_match_with_specificity_window(AW_root *root, TREE_canvas *ntw)
#define AWAR_SPV_DB_FIELD_WIDTH
GB_ERROR arb_look_and_start_server(long magic_number, const char *arb_tcp_env)
long read_int() const
Definition: AW_awar.cxx:184
static void auto_match_cb(AW_root *root)
static void probe_collection_close(AW_window *aww)
static saiProbeData * g_spd
GB_ERROR arb_look_and_kill_server(int magic_number, const char *arb_tcp_env)
AW_awar * set_minmax(float min, float max)
Definition: AW_awar.cxx:530
ArbPM_Context * PM_Context
static void probelength_changed_cb(AW_root *root, bool maxChanged)
void my_strupr(char *s)
void delete_element_at(int index)
Definition: AW_select.cxx:248
const char * GBS_global_string(const char *templat,...)
Definition: arb_msg.cxx:202
int aisc_nput(aisc_com *link, int o_type, const AISC_Object &object,...)
Definition: client.c:564
#define AWAR_PD_COMMON_EXP_BONDS_FORMAT
#define AWAR_MAX_MISMATCHES
bool displays_probeColl_markers(MarkerDisplay *md)
#define AWAR_PD_DESIGN_CLIPRESULT
char * GBS_string_eval(const char *insource, const char *icommand)
Definition: admatch.cxx:699
void AW_POPDOWN(AW_window *window)
Definition: AW_window.cxx:52
char * release()
Definition: arb_strbuf.h:80
static AW_window * probe_collection_save_prompt(AW_root *root)
#define AWAR_PD_DESIGN_MISHIT
void cat(const char *from)
Definition: arb_strbuf.h:158
int get_index_of_selected()
Definition: AW_select.cxx:316
static void save_probe_collection(AW_window *aww, const char *const *awar_filename)
char * ARB_strpartdup(const char *start, const char *end)
Definition: arb_string.h:51
#define AWAR_DTREE_GROUP_MARKED_THRESHOLD
Definition: TreeDisplay.hxx:70
static void probe_collection_update_parameters()
int allowedMismatches() const
ProbeMatchEventParam(GBDATA *gb_main_, AW_selection_list *id)
static void setup_probe_config(AWT_config_definition &cdef, const AWT_config_mapping_def *mapping)
char * GBS_ptserver_id_to_choice(int i, int showBuild)
Definition: adtcp.cxx:447
GBDATA * GB_get_grandfather(GBDATA *gbd)
Definition: arbdb.cxx:1728
static bool probe_match_with_specificity_enum_callback(void *pVoidContext, const char *pResult, bool bIsComment, int nItem, int nItems)
char buffer[MESSAGE_BUFFERSIZE]
Definition: seq_search.cxx:34
GB_ERROR GB_push_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2494
void activate()
Definition: aw_window.hxx:356
FILE * seq
Definition: rns.c:46
GB_ERROR arb_start_server(const char *arb_tcp_env, int do_sleep)
void incMarker(size_t markerIdx)
#define DOWNCAST(totype, expr)
Definition: downcast.h:141
void GBT_split_string(ConstStrArray &dest, const char *namelist, const char *separator, bool dropEmptyTokens)
Definition: arb_strarray.h:232
static const char * ptserver_directory_info_command(const char *dirname, const char *directory)
static GB_ERROR pd_get_the_names(GBDATA *gb_main, bytestring &bs, bytestring &checksum)
bool openXML(const char *pFileAndPath, std::string &rErrorMessage)
GB_ERROR error_if_aborted()
Definition: arb_progress.h:323
AW_awar * add_callback(const RootCallback &cb)
Definition: AW_awar.cxx:231
GB_ERROR GB_delete(GBDATA *&source)
Definition: arbdb.cxx:1916
static void modify_target_string(AW_window *aww, GBDATA *gb_main, ModMode mod_mode)
static int probe_match_send_data(const ProbeMatchSettings &matchSettings)
void flush_cache()
GBDATA * GBT_first_species_rel_species_data(GBDATA *gb_species_data)
Definition: aditem.cxx:121
void insert(const char *displayed, const AW_scalar &value)
Definition: AW_select.cxx:380
const char * get_string() const
Definition: aw_scalar.hxx:72
void setHeadline(const char *hline)
static struct aisc_static_set_mem md
static AW_window * probe_collection_load_prompt(AW_root *root, ArbPC_Context *pContext)
static void pd_query_pt_server(AW_window *aww)
static FullNameMap names
#define AWAR_SPV_SELECTED_PROBE
const char * read_char_pntr() const
Definition: AW_awar.cxx:168
static AW_window * create_IUPAC_resolve_window(AW_root *root, GBDATA *gb_main)
#define AWAR_PD_DESIGN_MIN_LENGTH
void handle_click(int markerIdx, AW_MouseButton, AWT_graphic_exports &) OVERRIDE
GBS_strstruct * GBS_stropen(long init_size)
Definition: arb_strbuf.cxx:39
int aisc_put(aisc_com *link, int o_type, const AISC_Object &object,...)
Definition: client.c:539
uchar flags
Definition: probe_tree.h:38
size_t GB_read_string_count(GBDATA *gbd)
Definition: arbdb.cxx:916
GB_ERROR GB_await_error()
Definition: arb_msg.cxx:341
static bool deny_read
Definition: aw_awar.hxx:106
static AW_root * SINGLETON
Definition: aw_root.hxx:102
void show()
Definition: AW_window.cxx:1670
static ArbPM_Context PM_Context
#define AWAR_PC_SELECTED_PROBE
AW_window * TREE_create_marker_settings_window(AW_root *root)
static AutoMatchSettings auto_match_cb_settings
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
const char * getHeadline() const
void detect(std::string speciesName, NodeMarkers &matches) const
#define AWAR_PT_SERVER
void getParameters(float aValues[16], float &dWidth, float &dBias) const
static void pd_start_pt_server(AW_window *aww)
const char * GBS_read_arb_tcp(const char *env)
Definition: adtcp.cxx:325
static void pd_edit_ptserver_log(AW_window *)
int get_probe_region_offset() const
void awt_edit_arbtcpdat_cb(AW_window *)
NOT4PERL void GBT_reverseComplementNucSequence(char *seq, long length, char T_or_U)
Definition: adRevCompl.cxx:102
const char * GBS_scan_arb_tcp_param(const char *ipPort, const char *wantedParam)
Definition: adtcp.cxx:275
ArbProbeCollection & get_probe_collection()
AW_window * AWT_create_IUPAC_info_window(AW_root *aw_root)
Definition: AWT_misc.cxx:21
AW_awar * awar_float(const char *var_name, float default_value=0.0, AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:560
AW_MouseButton
Definition: aw_window.hxx:70
bool remove(const char *pSequence)
char * createCallOnSocketHost(const char *host, const char *remotePrefix, const char *command, SpawnMode spawnmode, const char *logfile)
Definition: servercntrl.cxx:70
GBDATA * GEN_first_marked_gene(GBDATA *gb_species)
Definition: adGene.cxx:143
GBDATA * gb_species_data
Definition: adname.cxx:34
static int probe_design_send_data(AW_root *root, const T_PT_PDC &pdc)
static void pd_view_server_console(AW_window *)
#define AWAR_DB_PATH
Definition: aw_awar_defs.hxx:5
Generic smart pointer.
Definition: smartptr.h:149
static void probe_match_with_specificity_edit_event()
bool aborted()
Definition: arb_progress.h:335
void hide_marker_display()
const char * resultsFileName() const
int enumerate_results(ArbMatchResultsEnumCallback pCallback, void *pContext)
void index(int nIndex) const
#define true
Definition: ureadseq.h:14
void transferProbeData(saiProbeData *spd)
void incNodeSize()
bool add(const char *pName, const char *pSequence, const ArbProbe **ppProbe=NULp)
T_PT_MAIN com
#define AWAR_PD_MATCH_MAX_RES
static void popup_probe_design_result_window(AW_window *aww, GBDATA *gb_main)
char * data
Definition: bytestring.h:16
MarkerDisplay * get_marker_display()
GB_ERROR GB_save_as(GBDATA *gbd, const char *path, const char *savetype)
#define AWAR_PD_MATCH_NHITS
static int weights[MAX_BASETYPES][MAX_BASETYPES]
Definition: ClustalV.cxx:71
static void load_probe_collection(AW_window *aww, ArbPC_Context *Context, const char *const *awar_filename)
AW_selection_list * probes_id
static const char * auto_match_sensitive_awars[]
long GBS_memoffset(GBS_strstruct *strstr)
Definition: arb_strbuf.cxx:91
static void probe_match_all_event(AW_window *aww, AW_selection_list *iselection_id, GBDATA *gb_main)
void touch()
Definition: AW_awar.cxx:207
void GBS_strcat(GBS_strstruct *strstr, const char *ptr)
Definition: arb_strbuf.cxx:108
static void remove_probe_from_collection_event(AW_window *aww, ArbPC_Context *pContext)
static void error(const char *msg)
Definition: mkptypes.cxx:96
#define AWAR_PD_DESIGN_MAXBOND
static void add_probe_to_collection_event(AW_window *aww, ArbPC_Context *pContext)
#define AWAR_TREE_REFRESH
static void show_probes_in_sellist(const ArbProbePtrList &rProbeList, AW_selection_list *sellist)
static AWT_config_mapping_def probe_design_mapping_def[]
static void popup_match_window_cb(AW_window *aww, GBDATA *gb_main)
#define AWAR_PD_MATCH_WRITE2TMP
ArbMatchResultsManager & get_results_manager()
static __ATTR__USERESULT GB_ERROR probe_match_event(const ProbeMatchSettings &matchSettings, ProbeMatchEventParam *event_param)
static char * readableUnknownNames(const ConstStrArray &unames)
void GBT_splitNdestroy_string(ConstStrArray &names, char *&namelist, const char *separator, bool dropEmptyTokens)
GBDATA * GBT_next_marked_species(GBDATA *gb_species)
Definition: aditem.cxx:116
const char * get_error() const
ArbMatchResultPtrByStringMultiMap::const_iterator ArbMatchResultPtrByStringMultiMapConstIter
#define AWAR_PD_DESIGN_MAX_GC
ProbeMatchEventParam(GBDATA *gb_main_, int *counter_)
void create_print_box_for_selection_lists(AW_window *aw_window, const TypedSelectionList *typedsellist)
static void clear_itarget(AW_window *aww)
const Nuc_Group nuc_group[26][2]
Definition: iupac.cxx:24
static void probe_forget_matches_event(AW_window *aww, ArbPM_Context *pContext)
GB_alignment_type GBT_get_alignment_type(GBDATA *gb_main, const char *aliname)
Definition: adali.cxx:868
#define AWAR_PD_DESIGN_MAX_LENGTH
#define AWAR_SPECIES_NAME
const std::string & displayName() const
GBDATA * GEN_find_gene_data(GBDATA *gb_species)
Definition: adGene.cxx:50
GBDATA * GEN_next_organism(GBDATA *gb_organism)
Definition: adGene.cxx:755
#define AWAR_TARGET_STRING
#define AWAR_PD_SELECTED_MATCH
void GBS_str_cut_tail(GBS_strstruct *strstr, size_t byte_count)
Definition: arb_strbuf.cxx:96
#define AWAR_PD_COMMON_EXP_SPLIT
int size() const
NOT4PERL GB_ERROR GB_xcmd(const char *cmd, XCMD_TYPE exectype) __ATTR__USERESULT_TODO
Definition: adsocket.cxx:906
int GB_read_flag(GBDATA *gbd)
Definition: arbdb.cxx:2796
GBDATA * GBT_find_species_rel_species_data(GBDATA *gb_species_data, const char *name)
Definition: aditem.cxx:133
static void resolved_probe_chosen(AW_root *root)
#define AWAR_PD_MATCH_NMATCHES
char * read_string() const
Definition: AW_awar.cxx:198
static WindowCallback simple(void(*root_cb)(AW_root *, T), T t)
Definition: rootAsWin.h:47
#define AWAR_PC_TARGET_STRING
bool initialized() const
int to_index(char c)
Definition: iupac.h:53
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
GB_ERROR GB_pop_transaction(GBDATA *gbd)
Definition: arbdb.cxx:2524
void GBS_strforget(GBS_strstruct *strstr)
Definition: arb_strbuf.cxx:76
Definition: arbdb.h:86
#define GENOM_ALIGNMENT
Definition: adGene.h:19
GBDATA * GBT_find_sequence(GBDATA *gb_species, const char *aliname)
Definition: adali.cxx:708
GB_ERROR GB_set_mode_of_file(const char *path, long mode)
Definition: arb_file.cxx:231
char * GBT_read_gene_sequence(GBDATA *gb_gene, bool use_revComplement, char partSeparator)
Definition: adali.cxx:1052
AW_awar * remove_callback(const RootCallback &cb)
Definition: AW_awar.cxx:525
void awt_create_PTSERVER_selection_list(AW_window *aws, const char *varname)
AW_window * create_load_box_for_selection_lists(AW_root *aw_root, const StorableSelectionList *storabsellist)
static void probe_design_event(AW_window *aww, GBDATA *gb_main)
arb_progress * pProgress
void awt_create_PTSERVER_selection_button(AW_window *aws, const char *varname)
#define AWAR_PD_MATCH_MARKHITS
float read_float() const
Definition: AW_awar.cxx:177
GB_alignment_type
Definition: arbdb_base.h:61
long int flag
Definition: f2c.h:39
#define AISC_MAGIC_NUMBER
Definition: client_privat.h:51
const ArbProbeMatchWeighting & matchWeighting() const
#define AWAR_PD_DESIGN_MIN_ECOLIPOS
void GBS_chrcat(GBS_strstruct *strstr, char ch)
Definition: arb_strbuf.cxx:119
bool aw_ask_sure(const char *unique_id, const char *msg)
static void minmax_awar_pair_changed_cb(AW_root *root, bool maxChanged, const char *minAwarName, const char *maxAwarName)
const char * get_marker_name(int markerIdx) const OVERRIDE
static void resolve_IUPAC_target_string(AW_root *root, AW_selection_list *selection_id, GBDATA *gb_main)
std::vector< std::string > probeSpecies
int aw_question(const char *unique_id, const char *question, const char *buttons, bool sameSizeButtons, const char *helpfile)
Definition: AW_question.cxx:26
AWT_graphic * gfx
Definition: awt_canvas.hxx:339
#define AWAR_PD_DESIGN_MAX_ECOLIPOS
const char *const * GBS_get_arb_tcp_entries(const char *matching)
Definition: adtcp.cxx:390
#define AWAR_PC_CURRENT_COLLECTION
#define AWAR_PC_MATCH_NHITS
std::list< ArbProbe * > ArbProbePtrList
GB_ERROR GB_export_errorf(const char *templat,...)
Definition: arb_msg.cxx:261
ProbeCommonSettings(AW_root *root)
AW_awar * awar_int(const char *var_name, long default_value=0, AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:580
#define DISP_FORMAT
void retrieve_marker_state(const char *speciesName, NodeMarkers &matches) OVERRIDE
static void gc_minmax_changed_cb(AW_root *root, bool maxChanged)
static void clear_probe_collection_event(AW_window *aww, ArbPC_Context *pContext)
void GB_write_flag(GBDATA *gbd, long flag)
Definition: arbdb.cxx:2773
static AW_window * create_probe_match_specificity_control_window(AW_root *root)
T_PT_LOCS locs
static int ecolipos2int(const char *awar_val)
str readable(const copy< T > &v)
Definition: test_unit.h:334
int gene_flag
Definition: PT_main.cxx:39
static GB_ERROR gene_requires(GBDATA *gb_gene, const char *whats_required)
const AW_scalar * get_value() const
Definition: aw_select.hxx:160
static ArbPC_Context PC_Context
GB_CSTR GB_getenvUSER(void)
Definition: adsocket.cxx:545
#define REPLACE_TARGET_CONTROL_CHARS
aisc_com * link
#define OVERRIDE
Definition: cxxforward.h:110
static void auto_match_changed(AW_root *root)
#define AWAR_PC_MATCH_BIAS
static void probe_match_update_probe_list(ArbPM_Context *pContext)
size_t const count
Definition: iupac.h:48
aisc_com * aisc_open(const char *path, AISC_Object &main_obj, long magic, GB_ERROR *error)
Definition: client.c:205
#define __ATTR__USERESULT
Definition: attributes.h:58
void nprintf(size_t maxlen, const char *templat,...) __ATTR__FORMAT_MEMBER(2)
Definition: arb_strbuf.cxx:29
const std::string & sequence() const
bool is_gene_result() const
static void save_probe_list_to_DB(const ArbProbePtrList &rProbeList, AW_root *root)
static void temp_minmax_changed_cb(AW_root *root, bool maxChanged)
#define AWAR_PD_DESIGN_EXP_DTEDGE
void subtitle(const char *stitle)
Definition: arb_progress.h:321
char * GB_read_string(GBDATA *gbd)
Definition: arbdb.cxx:909
std::string targetString
#define AWAR_PROBE_ADMIN_PT_SERVER
Definition: probe_gui.hxx:24
char * GBS_strclose(GBS_strstruct *strstr)
Definition: arb_strbuf.cxx:69
AW_window * create_save_box_for_selection_lists(AW_root *aw_root, const StorableSelectionList *storabsellist)
const char * GBS_static_string(const char *str)
Definition: arb_msg.cxx:211
void setProbeTarget(const char *target)
#define AWAR_PD_MATCH_RESOLVE
const char * bond_awar_name(int i)
ProbeMatchSettings(AW_root *root)
uint32_t GBS_checksum(const char *seq, int ignore_case, const char *exclude)
Definition: adstring.cxx:353
static bool deny_write
Definition: aw_awar.hxx:107
#define AWAR_GENE_NAME
Definition: GEN.hxx:33
void aw_message(const char *msg)
Definition: AW_status.cxx:1142
void hide()
Definition: AW_window.cxx:1822
ModMode
static int probe_common_send_data(const ProbeCommonSettings &commonSettings)
AW_root * get_root()
Definition: aw_window.hxx:350
ProbeMatchEventParam * event_param
GBDATA * GEN_first_gene(GBDATA *gb_species)
Definition: adGene.cxx:130
AW_window_simple * win
GBDATA * GBT_next_species(GBDATA *gb_species)
Definition: aditem.cxx:128
#define NULp
Definition: cxxforward.h:114
GBDATA * GBT_find_species(GBDATA *gb_main, const char *name)
Definition: aditem.cxx:139
void AWT_system_in_console_cb(AW_window *, const char *command, XCMD_TYPE exectype)
Definition: AWT_misc.cxx:90
int aisc_get(aisc_com *link, int o_type, const AISC_Object &object,...)
Definition: client.c:266
#define AWAR_PD_DESIGN_MAX_TEMP
static struct @25 PD
static AWT_config_mapping_def probe_match_mapping_def[]
GB_ERROR write_string(const char *aw_string)
static char * command
Definition: arb_a2ps.c:319
#define AWAR_PC_AUTO_MATCH
#define offset(field)
Definition: GLwDrawA.c:73
static void selected_match_changed_cb(AW_root *root)
char * GBT_get_default_alignment(GBDATA *gb_main)
Definition: adali.cxx:747
static SmartPtr< GetMatchesContext > getMatchesContext
#define AWAR_PD_DESIGN_MIN_GC
void setParameters(const float aValues[16], float dWidth, float dBias)
static AW_window * create_probe_collection_window(AW_root *root, ArbPM_Context *pContext)
TREE_canvas * ntw
void GBS_add_ptserver_logentry(const char *entry)
Definition: adtcp.cxx:429
GB_transaction ta(gb_var)
GB_CSTR GB_read_char_pntr(GBDATA *gbd)
Definition: arbdb.cxx:904
GBDATA * gb_main
Definition: adname.cxx:33
std::multimap< std::string, ArbMatchResult * > ArbMatchResultPtrByStringMultiMap
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:570
GB_ERROR write_float(float aw_float)
GBDATA * GEN_next_marked_gene(GBDATA *gb_gene)
Definition: adGene.cxx:146
const std::string & name() const
const char * GBS_ptserver_tag(int id)
Definition: adtcp.cxx:312
GBDATA * GB_search(GBDATA *gbd, const char *fieldpath, GB_TYPES create)
Definition: adquery.cxx:531
GBDATA * GEN_first_organism(GBDATA *gb_main)
Definition: adGene.cxx:749
static GB_ERROR species_requires(GBDATA *gb_species, const char *whats_required)
GB_CSTR GBT_get_name_or_description(GBDATA *gb_item)
Definition: aditem.cxx:460
bool GEN_is_genome_db(GBDATA *gb_main, int default_value)
Definition: adGene.cxx:20
static void pd_kill_pt_server(AW_window *aww, bool kill_all)
static void probe_match_with_specificity_event(AW_root *root, TREE_canvas *ntw)
AW_window * create_probe_match_window(AW_root *root, GBDATA *gb_main)
#define AWAR_ITARGET_STRING
bool saveXML(const char *pFileAndPath) const
#define min(a, b)
Definition: f2c.h:153
static void enable_auto_match_cb(AW_root *root, ProbeMatchEventParam *event_param)
#define AWAR_SPV_ACI_COMMAND
#define AWAR_DTREE_GROUP_PARTIALLY_MARKED_THRESHOLD
Definition: TreeDisplay.hxx:71
static void popupSaiProbeMatchWindow(AW_window *aw, GBDATA *gb_main)
#define AWAR_PD_MATCH_SORTBY
#define AW_ROOT_DEFAULT
Definition: aw_base.hxx:106
static bool allow_probe_match_event
GB_ERROR write_int(long aw_int)
#define AWAR_PD_DESIGN_GENE
double weight() const
static AW_window * create_probe_expert_window(AW_root *root, bool for_design)
AW_window * create_probe_admin_window(AW_root *root, GBDATA *gb_main)
GBDATA * GB_entry(GBDATA *father, const char *key)
Definition: adquery.cxx:334
void inc_and_check_user_abort(GB_ERROR &error)
Definition: arb_progress.h:332
int aisc_create(aisc_com *link, int father_type, const AISC_Object &father, int attribute, int object_type, AISC_Object &object,...)
Definition: client.c:593
static void refresh_matchedProbesDisplay_cb(AW_root *root, TREE_canvas *ntw)
void aw_message_if(GB_ERROR error)
Definition: aw_msg.hxx:21
bool GB_supports_mapfile(void)
Definition: admap.cxx:644
char * GBS_global_string_copy(const char *templat,...)
Definition: arb_msg.cxx:193
#define AWAR_PC_TARGET_NAME
NOT4PERL GB_ERROR GBT_determine_T_or_U(GB_alignment_type alignment_type, char *T_or_U, const char *supposed_target)
Definition: adRevCompl.cxx:90
const ArbProbe * find(const char *pSequence) const
GBDATA * gb_main
Definition: awt_canvas.hxx:336
#define AWAR_SPV_SAI_2_PROBE
GBDATA * GBT_get_species_data(GBDATA *gb_main)
Definition: aditem.cxx:105
#define max(a, b)
Definition: f2c.h:154
GB_write_int const char s
Definition: AW_awar.cxx:154