| 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; |
|---|
| 70 | GB_TYPES type; |
|---|
| 71 | char *defined_at; // where was match defined |
|---|
| 72 | |
|---|
| 73 | import_match *next; |
|---|
| 74 | |
|---|
| 75 | import_match *reverse(import_match *to_append) { |
|---|
| 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 { |
|---|
| 88 | typedef SmartPtr<std::string> StringPtr; |
|---|
| 89 | StringPtr value[IFS_VARIABLES]; |
|---|
| 90 | |
|---|
| 91 | public: |
|---|
| 92 | SetVariables() {} |
|---|
| 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; |
|---|
| 109 | size_t new_format_lineno; |
|---|
| 110 | size_t tab; |
|---|
| 111 | |
|---|
| 112 | char *description; // (multiline) description of filter |
|---|
| 113 | |
|---|
| 114 | char *begin; |
|---|
| 115 | |
|---|
| 116 | char *sequencestart; |
|---|
| 117 | int read_this_sequence_line_too; |
|---|
| 118 | char *sequenceend; |
|---|
| 119 | char *sequencesrt; |
|---|
| 120 | char *sequenceaci; |
|---|
| 121 | char *filetag; |
|---|
| 122 | char *autotag; |
|---|
| 123 | size_t sequencecolumn; |
|---|
| 124 | int autocreateacc; |
|---|
| 125 | int noautonames; |
|---|
| 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 | |
|---|
| 135 | import_match *match; |
|---|
| 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 | |
|---|
| 176 | ~ArbImporter() { |
|---|
| 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); |
|---|
| 193 | void import_and_continueOnSuccess(AW_window *aww); |
|---|
| 194 | |
|---|
| 195 | GBDATA *peekImportDB() { |
|---|
| 196 | return gb_import_main; |
|---|
| 197 | } |
|---|
| 198 | GBDATA *takeImportDB() { |
|---|
| 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 | |
|---|