ARB
AWTC_submission.cxx
Go to the documentation of this file.
1 // ================================================================ //
2 // //
3 // File : AWTC_submission.cxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // ================================================================ //
10 
11 #include <aw_window.hxx>
12 #include <aw_awars.hxx>
13 #include <aw_edit.hxx>
14 #include <aw_root.hxx>
15 #include <aw_msg.hxx>
16 
17 #include <arbdbt.h>
18 #include <arb_strbuf.h>
19 #include <arb_strarray.h>
20 #include <gb_aci.h>
21 
22 #define awtc_assert(bed) arb_assert(bed)
23 
24 #define AWAR_SUBMIT_PARSER "tmp/submission/parser"
25 #define AWAR_SUBMIT_PARSED "tmp/submission/parsed"
26 
27 #define AWAR_SUBMIT_SOURCE "submission/source"
28 #define AWAR_SUBMIT_FILE "submission/file"
29 #define AWAR_SUBMIT_PRIVAT "submission/privat"
30 
32  root->awar_string(AWAR_SUBMIT_SOURCE, "", db1);
33  root->awar_string(AWAR_SUBMIT_PARSER, "press READ INFO", db1);
34  root->awar_string(AWAR_SUBMIT_PARSED, "", db1);
35  root->awar_string(AWAR_SUBMIT_FILE, "", db1);
36  root->awar_string(AWAR_SUBMIT_PRIVAT, "$(ADDRESS)=TUM Munich:\n", db1);
37 }
38 
39 static void ed_calltexe_event(AW_window *aww, const char *varname) {
40  AW_edit(aww->get_root()->awar(varname)->read_char_pntr());
41 }
42 
43 static AW_window *create_calltexe_window(AW_root *root, const char *varname) {
44  AW_window_simple *aws = new AW_window_simple;
45  {
46  char *var_id = GBS_string_2_key(varname);
47  char *window_id = GBS_global_string_copy("SUBM_TEXTEDIT_%s", var_id);
48  aws->init(root, window_id, "START TEXT EDITOR");
49  free(window_id);
50  free(var_id);
51  }
52 
53  aws->load_xfig("calltexe.fig");
54  aws->label_length(18);
55  aws->button_length(8);
56 
57  aws->at("close");
58  aws->callback(AW_POPDOWN);
59  aws->create_button("CLOSE", "CLOSE", "O");
60 
61  aws->at("file");
62  aws->create_input_field(varname, 34);
63 
64  aws->at("edit");
65  aws->callback(makeWindowCallback(ed_calltexe_event, varname));
66  aws->create_button("EDIT", "EDIT", "E");
67 
68  return aws;
69 }
70 
71 static void ed_submit_info_event_rm(char *string) {
72  char *p = string;
73  int c;
74  while ((c=*p) != 0) {
75  if (c==':') *p = ';';
76  if (c=='=') *p = '-';
77  p++;
78  }
79 }
80 
82  AW_root *aw_root = aww->get_root();
83 
84  GB_transaction ta(gb_main);
85  char *species_name = aw_root->awar(AWAR_SPECIES_NAME)->read_string();
86  GBDATA *gb_species = GBT_find_species(gb_main, species_name);
87  GBS_strstruct strstruct(1000);
88 
89  if (gb_species) {
90  for (GBDATA *gb_entry = GB_child(gb_species); gb_entry; gb_entry = GB_nextChild(gb_entry)) {
91  int type = GB_read_type(gb_entry);
92  switch (type) {
93  case GB_STRING:
94  case GB_INT:
95  case GB_BITS:
96  case GB_FLOAT: {
97  char *key = GB_read_key(gb_entry);
98 
99  strstruct.cat("$(");
100  strstruct.cat(key);
101  strstruct.cat(")=");
102  free(key);
103 
104  key = GB_read_as_string(gb_entry);
106  strstruct.cat(key);
107  free(key);
108 
109  strstruct.cat(":\n");
110  break;
111  }
112  default:
113  break;
114  }
115  }
116 
117  const char *srt_submit =
118  "*="
119  "$(SEQ_LEN)\\=*(|sequence|len(.-))\\:\n"
120  "$(SEQ_A)\\=*(|sequence|count(aA))\\:\n"
121  "$(SEQ_C)\\=*(|sequence|count(cC))\\:\n"
122  "$(SEQ_G)\\=*(|sequence|count(gG))\\:\n"
123  "$(SEQ_T)\\=*(|sequence|count(tT))\\:\n"
124  "$(SEQ_U)\\=*(|sequence|count(uU))\\:\n"
125  "$(SEQUENCE)\\=*(|sequence|remove(.-)|format_sequence(firsttab\\=12;tab\\=12;width\\=60;numleft;gap\\=10))\\:\n";
126 
127  GBL_env env(gb_main, NULp);
128  GBL_call_env callEnv(gb_species, env);
129  char *seq_info = GBS_string_eval_in_env(" ", srt_submit, callEnv);
130  if (seq_info) {
131  strstruct.cat(seq_info);
132  free(seq_info);
133  }
134  else {
136  }
137  }
138  else {
139  strstruct.cat("Species not found");
140  }
141 
142  char *parser = strstruct.release();
143  aw_root->awar(AWAR_SUBMIT_PARSER)->write_string(parser);
144 
145  free(parser);
146  free(species_name);
147 }
148 
149 static void ed_save_var_to_file(AW_window *aww, const char *data_var, const char *file_var) {
150  AW_root *aw_root = aww->get_root();
151  char *data = aw_root->awar(data_var)->read_string();
152  char *file_name = aw_root->awar(file_var)->read_string();
153  FILE *out = fopen(file_name, "w");
154 
155  if (out) {
156  fprintf(out, "%s", data);
157  fclose(out);
158  }
159  else {
160  aw_message(GB_IO_error("saving info", file_name));
161  }
162  free(file_name);
163  free(data);
164 }
165 static void ed_submit_parse_event(AW_window *aww) {
166  AW_root *aw_root = aww->get_root();
167  char *parser = aw_root->awar(AWAR_SUBMIT_PARSER)->read_string();
168  char *dest;
169  char *dest2;
170  char *privat;
171  char *p, *d;
172  int c;
173 
174  for (d = p = parser; *p; p++) {
175  if ((c=*p)==':') {
176  if (p[1] == '\n') p++; // skip newline
177  }
178  *(d++) = c;
179  }
180  *d = 0;
181  char *sub_file = aw_root->awar(AWAR_SUBMIT_SOURCE)->read_string();
182  char *source = GB_read_file(sub_file);
183  if (source) {
184  dest = GBS_string_eval(source, parser);
185  if (!dest) dest = ARB_strdup(GB_await_error());
186  }
187  else {
188  dest = GBS_global_string_copy("submission form not found\n(Reason: %s)", GB_await_error());
189  }
190 
191  awtc_assert(dest); // should contain partly filled form or error message
192 
193  privat = aw_root->awar(AWAR_SUBMIT_PRIVAT)->read_string();
194  for (d = p = privat; *p; p++) {
195  if ((c=*p)==':') {
196  if (p[1] == '\n') p++; // skip newline
197  }
198  *(d++) = c;
199  }
200  *d = 0;
201 
202  dest2 = GBS_string_eval(dest, privat);
203  if (!dest2) dest2 = ARB_strdup(GB_await_error());
204 
205  aw_root->awar(AWAR_SUBMIT_PARSED)->write_string(dest2);
206 
207  free(dest);
208  free(dest2);
209  free(privat);
210  free(source);
211  free (sub_file);
212  free(parser);
213 }
214 
215 static void ed_submit_gen_event(AW_window *aww) {
216  AW_root *aw_root = aww->get_root();
217  char buffer[256];
218  char *name = aw_root->awar(AWAR_SPECIES_NAME)->read_string();
219  sprintf(buffer, "%s.submit", name);
220  free(name);
221  aw_root->awar(AWAR_SUBMIT_FILE)->write_string(buffer);
222 }
223 
224 
226  AW_window_simple *aws = new AW_window_simple;
227  aws->init(root, "SUBMISSION", "SUBMISSION");
228 
229  aws->load_xfig("submiss.fig");
230  aws->label_length(18);
231  aws->button_length(8);
232 
233  aws->at("close");
234  aws->callback(AW_POPDOWN);
235  aws->create_button("CLOSE", "CLOSE", "O");
236 
237  aws->callback(makeHelpCallback("submission.hlp"));
238  aws->at("help");
239  aws->create_button("HELP", "HELP", "H");
240 
241  aws->button_length(15);
242 
243  aws->at("privat");
244  aws->create_text_field(AWAR_SUBMIT_PRIVAT, 80, 5);
245 
246  aws->at("parsed_info");
247  aws->create_text_field(AWAR_SUBMIT_PARSER, 80, 6);
248 
249  aws->at("parsed");
250  aws->create_text_field(AWAR_SUBMIT_PARSED, 80, 13);
251 
252  aws->at("species");
253  aws->label("Species Name:");
254  aws->create_input_field(AWAR_SPECIES_NAME, 12);
255 
256  aws->at("submission");
257  {
258  StrArray submits;
259  GBS_read_dir(submits, GB_path_in_ARBLIB("submit"), NULp);
260 
261  if (!submits.empty()) {
262  aws->label("Select a Form");
263  aws->create_option_menu(AWAR_SUBMIT_SOURCE);
264  for (int i = 0; submits[i]; ++i) {
265  aws->insert_option(submits[i], "", submits[i]);
266  }
267  aws->insert_default_option("default", "d", "default");
268  aws->update_option_menu();
269  }
270  }
271 
272  aws->at("gen");
273  aws->label("Gen File Name");
274  aws->callback(ed_submit_gen_event);
275  aws->create_button("GEN_FILE_NAME", "CREATE NAME", "C");
276 
277  aws->at("file");
278  aws->label("or enter");
279  aws->create_input_field(AWAR_SUBMIT_FILE, 30);
280 
281  aws->at("info");
282  aws->callback(makeWindowCallback(ed_submit_info_event, gb_main));
283  aws->create_button("READ_INFO", "READ INFO", "R");
284 
285  aws->at("parse");
286  aws->callback(ed_submit_parse_event);
287  aws->create_button("FILL_OUT_FORM", "FILL THE FORM", "F");
288 
289  aws->at("write");
290  aws->callback(makeWindowCallback(ed_save_var_to_file, AWAR_SUBMIT_PARSED, AWAR_SUBMIT_FILE));
291  aws->create_button("SAVE", "SAVE TO FILE", "S");
292 
293  aws->button_length(20);
294  aws->at("edit");
295  aws->callback(makeCreateWindowCallback(create_calltexe_window, AWAR_SUBMIT_SOURCE));
296  aws->create_button("EDIT_FORM", "EDIT FORM", "R");
297 
298  aws->at("editresult");
299  aws->callback(makeCreateWindowCallback(create_calltexe_window, AWAR_SUBMIT_FILE));
300  aws->create_button("EDIT_SAVED", "EDIT SAVED", "S");
301 
302  aws->at("privatlabel");
303  aws->create_button(NULp, "Your private data");
304 
305  return aws;
306 }
static void ed_submit_info_event(AW_window *aww, GBDATA *gb_main)
static void ed_submit_parse_event(AW_window *aww)
GB_TYPES type
#define AWAR_SUBMIT_PARSED
char * GB_read_key(GBDATA *gbd)
Definition: arbdb.cxx:1652
GBDATA * GB_child(GBDATA *father)
Definition: adquery.cxx:322
return string(buffer, length)
Definition: arbdb.h:69
void AWTC_create_submission_variables(AW_root *root, AW_default db1)
char * GBS_string_eval_in_env(const char *insource, const char *icommand, const GBL_call_env &callEnv)
Definition: admatch.cxx:493
void load_xfig(const char *file, bool resize=true)
Definition: AW_window.cxx:720
void AW_edit(const char *path)
Definition: AW_edit.cxx:16
AW_window * AWTC_create_submission_window(AW_root *root, GBDATA *gb_main)
static AW_window * create_calltexe_window(AW_root *root, const char *varname)
#define AWAR_SUBMIT_SOURCE
GB_ERROR GB_IO_error(const char *action, const char *filename)
Definition: arb_msg.cxx:285
char * ARB_strdup(const char *str)
Definition: arb_string.h:27
char * GB_read_as_string(GBDATA *gbd)
Definition: arbdb.cxx:1060
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:129
char * GBS_string_2_key(const char *str)
Definition: adstring.cxx:52
void cat(const char *from)
Definition: arb_strbuf.h:199
char buffer[MESSAGE_BUFFERSIZE]
Definition: seq_search.cxx:34
#define awtc_assert(bed)
#define AWAR_SUBMIT_FILE
const char * read_char_pntr() const
Definition: AW_awar.cxx:168
GB_ERROR GB_await_error()
Definition: arb_msg.cxx:342
WindowCallback makeHelpCallback(const char *helpfile)
Definition: aw_window.hxx:106
Definition: arbdb.h:67
GB_TYPES GB_read_type(GBDATA *gbd)
Definition: arbdb.cxx:1643
AW_root * root
Definition: aw_window.hxx:272
static void ed_submit_gen_event(AW_window *aww)
static void ed_submit_info_event_rm(char *string)
#define AWAR_SPECIES_NAME
char * read_string() const
Definition: AW_awar.cxx:198
GB_CSTR GB_path_in_ARBLIB(const char *relative_path)
Definition: adsocket.cxx:1156
AW_awar * awar(const char *awar)
Definition: AW_root.cxx:554
void GBS_read_dir(StrArray &names, const char *dir, const char *mask)
Definition: adfile.cxx:213
#define AWAR_SUBMIT_PARSER
#define AWAR_SUBMIT_PRIVAT
static void ed_calltexe_event(AW_window *aww, const char *varname)
void aw_message(const char *msg)
Definition: AW_status.cxx:1142
AW_root * get_root()
Definition: aw_window.hxx:359
#define NULp
Definition: cxxforward.h:116
GBDATA * GBT_find_species(GBDATA *gb_main, const char *name)
Definition: aditem.cxx:139
GB_ERROR write_string(const char *aw_string)
GBDATA * GB_nextChild(GBDATA *child)
Definition: adquery.cxx:326
GB_transaction ta(gb_var)
GBDATA * gb_main
Definition: adname.cxx:32
AW_awar * awar_string(const char *var_name, const char *default_value="", AW_default default_file=AW_ROOT_DEFAULT)
Definition: AW_root.cxx:570
static void ed_save_var_to_file(AW_window *aww, const char *data_var, const char *file_var)
char * GBS_global_string_copy(const char *templat,...)
Definition: arb_msg.cxx:194
Definition: arbdb.h:66
char * GB_read_file(const char *path)
Definition: adsocket.cxx:287