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 | |
---|
28 | #define awti_assert(cond) arb_assert(cond) |
---|
29 | |
---|
30 | #define AWAR_FILE_BASE "tmp/import/pattern" |
---|
31 | #define AWAR_FILE AWAR_FILE_BASE"/file_name" |
---|
32 | #define AWAR_FORM "tmp/import/form" |
---|
33 | #define AWAR_ALI "tmp/import/alignment" |
---|
34 | #define AWAR_ALI_TYPE "tmp/import/alignment_type" |
---|
35 | #define AWAR_ALI_PROTECTION "tmp/import/alignment_protection" |
---|
36 | |
---|
37 | #define AWTI_IMPORT_CHECK_BUFFER_SIZE 10000 |
---|
38 | |
---|
39 | |
---|
40 | struct import_match : virtual Noncopyable { |
---|
41 | // one for each "MATCH" section of the import format |
---|
42 | |
---|
43 | char *match; |
---|
44 | char *aci; |
---|
45 | char *srt; |
---|
46 | char *mtag; |
---|
47 | char *append; |
---|
48 | char *write; |
---|
49 | char *setvar; |
---|
50 | GB_TYPES type; |
---|
51 | char *defined_at; // where was match defined |
---|
52 | |
---|
53 | import_match *next; |
---|
54 | |
---|
55 | import_match *reverse(import_match *to_append) { |
---|
56 | import_match *rest = next; |
---|
57 | next = to_append; |
---|
58 | return rest ? rest->reverse(this) : this; |
---|
59 | } |
---|
60 | |
---|
61 | import_match(); |
---|
62 | ~import_match(); |
---|
63 | }; |
---|
64 | |
---|
65 | #define IFS_VARIABLES 26 // 'a'-'z' |
---|
66 | |
---|
67 | class SetVariables { |
---|
68 | typedef SmartPtr<std::string> StringPtr; |
---|
69 | StringPtr value[IFS_VARIABLES]; |
---|
70 | |
---|
71 | public: |
---|
72 | SetVariables() {} |
---|
73 | |
---|
74 | void set(char c, const char *s) { |
---|
75 | awti_assert(c >= 'a' && c <= 'z'); |
---|
76 | value[c-'a'] = new std::string(s); |
---|
77 | } |
---|
78 | const std::string *get(char c) const { |
---|
79 | awti_assert(c >= 'a' && c <= 'z'); |
---|
80 | StringPtr v = value[c-'a']; |
---|
81 | return v.isNull() ? NULL : &*v; |
---|
82 | } |
---|
83 | }; |
---|
84 | |
---|
85 | |
---|
86 | struct import_format : virtual Noncopyable { |
---|
87 | char *autodetect; |
---|
88 | char *system; |
---|
89 | char *new_format; |
---|
90 | size_t new_format_lineno; |
---|
91 | size_t tab; |
---|
92 | |
---|
93 | char *begin; |
---|
94 | |
---|
95 | char *sequencestart; |
---|
96 | int read_this_sequence_line_too; |
---|
97 | char *sequenceend; |
---|
98 | char *sequencesrt; |
---|
99 | char *sequenceaci; |
---|
100 | char *filetag; |
---|
101 | char *autotag; |
---|
102 | size_t sequencecolumn; |
---|
103 | int autocreateacc; |
---|
104 | int noautonames; |
---|
105 | |
---|
106 | char *end; |
---|
107 | |
---|
108 | SetVariables global_variables; // values of global variables |
---|
109 | SetVariables variable_errors; // user-defined errors (used when var not set) |
---|
110 | |
---|
111 | char *b1; |
---|
112 | char *b2; |
---|
113 | |
---|
114 | import_match *match; |
---|
115 | |
---|
116 | import_format(); |
---|
117 | ~import_format(); |
---|
118 | }; |
---|
119 | |
---|
120 | struct ArbImporter : virtual Noncopyable { |
---|
121 | import_format *ifo; // main input format |
---|
122 | import_format *ifo2; // symlink to input format |
---|
123 | |
---|
124 | GBDATA *gb_import_main; // import database |
---|
125 | |
---|
126 | RootCallback after_import_cb; |
---|
127 | |
---|
128 | StrArray filenames; |
---|
129 | int current_file_idx; |
---|
130 | |
---|
131 | FILE *in; |
---|
132 | bool doExit; // whether import window 'close' does exit // @@@ rename (meaning is: import from inside ARB or not) |
---|
133 | |
---|
134 | GBDATA *gb_main_4_nameserver; // main DB (needed to select nameserver-settings) |
---|
135 | |
---|
136 | ArbImporter(const RootCallback& after_import_cb_) |
---|
137 | : ifo(NULL), |
---|
138 | ifo2(NULL), |
---|
139 | gb_import_main(NULL), |
---|
140 | after_import_cb(after_import_cb_), |
---|
141 | current_file_idx(0), |
---|
142 | in(NULL), |
---|
143 | doExit(false), |
---|
144 | gb_main_4_nameserver(NULL) |
---|
145 | { |
---|
146 | } |
---|
147 | |
---|
148 | ~ArbImporter() { |
---|
149 | if (gb_import_main) GB_close(gb_import_main); |
---|
150 | delete ifo; |
---|
151 | delete ifo2; |
---|
152 | |
---|
153 | awti_assert(!in); |
---|
154 | } |
---|
155 | |
---|
156 | GB_ERROR read_format(const char *file); |
---|
157 | void detect_format(AW_root *root); |
---|
158 | |
---|
159 | int next_file(); |
---|
160 | char *read_line(int tab, char *sequencestart, char *sequenceend); |
---|
161 | GB_ERROR read_data(char *ali_name, int security_write); |
---|
162 | |
---|
163 | void go(AW_window *aww); |
---|
164 | |
---|
165 | GBDATA *peekImportDB() { |
---|
166 | return gb_import_main; |
---|
167 | } |
---|
168 | GBDATA *takeImportDB() { |
---|
169 | GBDATA *gbm = gb_import_main; |
---|
170 | gb_import_main = NULL; |
---|
171 | return gbm; |
---|
172 | } |
---|
173 | }; |
---|
174 | |
---|
175 | |
---|
176 | #else |
---|
177 | #error awti_imp_local.hxx included twice |
---|
178 | #endif // AWTI_IMP_LOCAL_HXX |
---|