ARB
awti_imp_local.hxx
Go to the documentation of this file.
1 // ============================================================ //
2 // //
3 // File : awti_imp_local.hxx //
4 // Purpose : local definitions for import //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // www.arb-home.de //
8 // //
9 // ============================================================ //
10 
11 #ifndef AWTI_IMP_LOCAL_HXX
12 #define AWTI_IMP_LOCAL_HXX
13 
14 #ifndef _GLIBCXX_STRING
15 #include <string>
16 #endif
17 
18 #ifndef ARBDBT_H
19 #include <arbdbt.h>
20 #endif
21 #ifndef AWTI_IMPORT_HXX
22 #include <awti_import.hxx>
23 #endif
24 #ifndef ARB_STRARRAY_H
25 #include <arb_strarray.h>
26 #endif
27 #ifndef XFERSET_H
28 #include <xferset.h>
29 #endif
30 #ifndef XFERGUI_H
31 #include <xfergui.h>
32 #endif
33 
34 #define awti_assert(cond) arb_assert(cond)
35 
36 // more awars defined at awti_import.hxx@AWAR_IMPORT
37 #define AWAR_IMPORT_FILEBASE AWAR_IMPORT_TMP_PREFIX "pattern"
38 #define AWAR_IMPORT_FILENAME AWAR_IMPORT_FILEBASE "/file_name"
39 
40 #define AWAR_IMPORT_FORMATBASE AWAR_IMPORT_TMP_PREFIX "form"
41 #define AWAR_IMPORT_FORMATNAME AWAR_IMPORT_FORMATBASE "/file_name"
42 #define AWAR_IMPORT_FORMATFILTER AWAR_IMPORT_FORMATBASE "/filter"
43 #define AWAR_IMPORT_FORMATDIR AWAR_IMPORT_FORMATBASE "/directory"
44 
45 #define AWAR_IMPORT_FORMAT_DESC AWAR_IMPORT_TMP_PREFIX "description"
46 #define AWAR_IMPORT_ALI AWAR_IMPORT_TMP_PREFIX "alignment"
47 #define AWAR_IMPORT_ALI_TYPE AWAR_IMPORT_TMP_PREFIX "alignment_type"
48 #define AWAR_IMPORT_ALI_PROTECTION AWAR_IMPORT_TMP_PREFIX "alignment_protection"
49 
50 #define AWAR_IMPORT_FTS AWAR_IMPORT_TMP_PREFIX "fts"
51 
52 #define AWTI_IMPORT_CHECK_BUFFER_SIZE 10000
53 
54 
55 struct import_match : virtual Noncopyable {
56  // one for each "MATCH" section of the import format
57 
58  char *match;
59 
60  // variables get expanded when one of the following variables is used:
61  // (search for 'expandSetVariables')
62  char *aci;
63  char *srt;
64  char *mtag;
65  char *append;
66  char *write;
67  // --------------------
68 
69  char *setvar;
71  char *defined_at; // where was match defined
72 
74 
76  import_match *rest = next;
77  next = to_append;
78  return rest ? rest->reverse(this) : this;
79  }
80 
81  import_match();
82  ~import_match();
83 };
84 
85 #define IFS_VARIABLES 26 // 'a'-'z'
86 
87 class SetVariables {
89  StringPtr value[IFS_VARIABLES];
90 
91 public:
93 
94  void set(char c, const char *s) {
95  awti_assert(c >= 'a' && c <= 'z');
96  value[c-'a'] = new std::string(s);
97  }
98  const std::string *get(char c) const {
99  awti_assert(c >= 'a' && c <= 'z');
100  return value[c-'a'].content();
101  }
102 };
103 
104 
105 struct import_format : virtual Noncopyable {
106  char *autodetect;
107  char *system;
108  char *new_format;
110  size_t tab;
111 
112  char *description; // (multiline) description of filter
113 
114  char *begin;
115 
118  char *sequenceend;
119  char *sequencesrt;
120  char *sequenceaci;
121  char *filetag;
122  char *autotag;
126 
127  char *end;
128 
129  SetVariables global_variables; // values of global variables
130  SetVariables variable_errors; // user-defined errors (used when var not set)
131 
132  char *b1;
133  char *b2;
134 
136 
137  import_format();
138  ~import_format();
139 };
140 
141 class ArbImporter : virtual Noncopyable {
142  import_format *ifo; // main input format
143  import_format *ifo2; // symlink to input format
144 
145  GBDATA *gb_import_main; // import database
146 
147  RootCallback after_import_cb;
148 
149  StrArray filenames;
150  int current_file_idx;
151 
152  FILE *in;
153 
154  GBDATA *gb_main_4_nameserver; // main DB (needed to auto-select correct nameserver-settings)
155 
156  GB_ERROR load_format(AW_root *awr);
157  void unload_format() {
158  delete ifo; ifo = NULp;
159  delete ifo2; ifo2 = NULp;
160  }
161 
162 public:
163  explicit ArbImporter(const RootCallback& after_import_cb_)
164  : ifo(NULp),
165  ifo2(NULp),
166  gb_import_main(NULp),
167  after_import_cb(after_import_cb_),
168  current_file_idx(0),
169  in(NULp),
170  gb_main_4_nameserver(NULp)
171  {
172  gb_import_main = GB_open("noname.arb", "wc");
173  awti_assert(gb_import_main);
174  }
175 
177  if (gb_import_main) GB_close(gb_import_main);
178  unload_format();
179  awti_assert(!in);
180  }
181 
182  GB_ERROR read_format(const char *file);
183  void detect_format(AW_root *root);
184  const import_format *peek_format() const { return ifo; }
185 
186  int next_file();
187  char *read_line(int tab, char *sequencestart, char *sequenceend);
188  GB_ERROR read_data(char *ali_name, int security_write, FieldTransfer::RuleSetPtr ruleset);
189 
190  void set_db_4_nameserver(GBDATA *gb_main) { gb_main_4_nameserver = gb_main; }
191 
192  GB_ERROR import_data(AW_root *awr, const char *mask, bool keep_found_IDs);
194 
196  return gb_import_main;
197  }
199  GBDATA *gbm = gb_import_main;
200  gb_import_main = NULp;
201  return gbm;
202  }
203 
204  void detectAvailableFields(StrArray& fields, FieldsToScan whatToScan);
205 };
206 
207 
208 #else
209 #error awti_imp_local.hxx included twice
210 #endif // AWTI_IMP_LOCAL_HXX
211 
void import_and_continueOnSuccess(AW_window *aww)
const char * GB_ERROR
Definition: arb_core.h:25
GBDATA * GB_open(const char *path, const char *opent)
Definition: ad_load.cxx:1363
static GB_ERROR tab(GBL_command_arguments *args, bool pretab)
Definition: adlang1.cxx:913
import_match * reverse(import_match *to_append)
return string(buffer, length)
char * read_line(int tab, char *sequencestart, char *sequenceend)
GB_ERROR import_data(AW_root *awr, const char *mask, bool keep_found_IDs)
ArbImporter(const RootCallback &after_import_cb_)
void detectAvailableFields(StrArray &fields, FieldsToScan whatToScan)
void set_db_4_nameserver(GBDATA *gb_main)
import_match * match
SetVariables global_variables
GBDATA * takeImportDB()
GBDATA * peekImportDB()
SetVariables variable_errors
#define IFS_VARIABLES
FieldsToScan
Definition: xfergui.h:21
GB_ERROR read_format(const char *file)
const import_format * peek_format() const
const T * content() const
convert SmartPtr to plain old pointer (also works if isNull())
Definition: smartptr.h:263
#define awti_assert(cond)
void set(char c, const char *s)
import_match * next
void detect_format(AW_root *root)
int read_this_sequence_line_too
#define NULp
Definition: cxxforward.h:97
GB_TYPES
Definition: arbdb.h:62
GB_ERROR read_data(char *ali_name, int security_write, FieldTransfer::RuleSetPtr ruleset)
size_t new_format_lineno
GBDATA * gb_main
Definition: adname.cxx:33
void GB_close(GBDATA *gbd)
Definition: arbdb.cxx:649
GB_write_int const char s
Definition: AW_awar.cxx:156