source: tags/ms_r18q1/AWTI/awti_imp_local.hxx

Last change on this file was 16763, checked in by westram, 6 years ago
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.3 KB
Line 
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// more awars defined at awti_import.hxx@AWAR_IMPORT
31#define AWAR_IMPORT_FILEBASE AWAR_IMPORT_TMP_PREFIX "pattern"
32#define AWAR_IMPORT_FILENAME AWAR_IMPORT_FILEBASE "/file_name"
33
34#define AWAR_IMPORT_FORMATBASE   AWAR_IMPORT_TMP_PREFIX "form"
35#define AWAR_IMPORT_FORMATNAME   AWAR_IMPORT_FORMATBASE "/file_name"
36#define AWAR_IMPORT_FORMATFILTER AWAR_IMPORT_FORMATBASE "/filter"
37#define AWAR_IMPORT_FORMATDIR    AWAR_IMPORT_FORMATBASE "/directory"
38
39#define AWAR_IMPORT_FORMAT_DESC    AWAR_IMPORT_TMP_PREFIX "description"
40#define AWAR_IMPORT_ALI            AWAR_IMPORT_TMP_PREFIX "alignment"
41#define AWAR_IMPORT_ALI_TYPE       AWAR_IMPORT_TMP_PREFIX "alignment_type"
42#define AWAR_IMPORT_ALI_PROTECTION AWAR_IMPORT_TMP_PREFIX "alignment_protection"
43
44#define AWTI_IMPORT_CHECK_BUFFER_SIZE 10000
45
46
47struct import_match : virtual Noncopyable {
48    // one for each "MATCH" section of the import format
49
50    char *match;
51
52    // variables get expanded when one of the following variables is used:
53    // (search for 'expandSetVariables')
54    char *aci;
55    char *srt;
56    char *mtag;
57    char *append;
58    char *write;
59    // --------------------
60
61    char     *setvar;
62    GB_TYPES  type;
63    char     *defined_at; // where was match defined
64
65    import_match *next;
66
67    import_match *reverse(import_match *to_append) {
68        import_match *rest = next;
69        next = to_append;
70        return rest ? rest->reverse(this) : this;
71    }
72
73    import_match();
74    ~import_match();
75};
76
77#define IFS_VARIABLES 26                            // 'a'-'z'
78
79class SetVariables {
80    typedef SmartPtr<std::string> StringPtr;
81    StringPtr value[IFS_VARIABLES];
82
83public:
84    SetVariables() {}
85
86    void set(char c, const char *s) {
87        awti_assert(c >= 'a' && c <= 'z');
88        value[c-'a'] = new std::string(s);
89    }
90    const std::string *get(char c) const {
91        awti_assert(c >= 'a' && c <= 'z');
92        StringPtr v = value[c-'a'];
93        return v.isNull() ? NULp : &*v;
94    }
95};
96
97
98struct import_format : virtual Noncopyable {
99    char   *autodetect;
100    char   *system;
101    char   *new_format;
102    size_t  new_format_lineno;
103    size_t  tab;
104
105    char *description; // (multiline) description of filter
106
107    char *begin;
108
109    char   *sequencestart;
110    int     read_this_sequence_line_too;
111    char   *sequenceend;
112    char   *sequencesrt;
113    char   *sequenceaci;
114    char   *filetag;
115    char   *autotag;
116    size_t  sequencecolumn;
117    int     autocreateacc;
118    int     noautonames;
119
120    char *end;
121
122    SetVariables global_variables;                 // values of global variables
123    SetVariables variable_errors;                  // user-defined errors (used when var not set)
124
125    char *b1;
126    char *b2;
127
128    import_match *match;
129
130    import_format();
131    ~import_format();
132};
133
134class ArbImporter : virtual Noncopyable {
135    import_format *ifo;  // main input format
136    import_format *ifo2; // symlink to input format
137
138    GBDATA *gb_import_main; // import database
139
140    RootCallback after_import_cb;
141
142    StrArray filenames;
143    int      current_file_idx;
144
145    FILE *in;
146
147    GBDATA *gb_main_4_nameserver; // main DB (needed to auto-select correct nameserver-settings)
148
149public:
150    explicit ArbImporter(const RootCallback& after_import_cb_)
151        : ifo(NULp),
152          ifo2(NULp),
153          gb_import_main(NULp),
154          after_import_cb(after_import_cb_),
155          current_file_idx(0),
156          in(NULp),
157          gb_main_4_nameserver(NULp)
158    {
159        gb_import_main = GB_open("noname.arb", "wc");
160        awti_assert(gb_import_main);
161    }
162
163    ~ArbImporter() {
164        if (gb_import_main) GB_close(gb_import_main);
165        delete ifo;
166        delete ifo2;
167
168        awti_assert(!in);
169    }
170
171    GB_ERROR read_format(const char *file);
172    void     detect_format(AW_root *root);
173    const import_format *peek_format() const { return ifo; }
174
175    int       next_file();
176    char     *read_line(int tab, char *sequencestart, char *sequenceend);
177    GB_ERROR  read_data(char *ali_name, int security_write);
178
179    void set_db_4_nameserver(GBDATA *gb_main) { gb_main_4_nameserver = gb_main; }
180
181    GB_ERROR import_data(AW_root *awr, const char *mask, bool keep_found_IDs);
182    void     import_and_continueOnSuccess(AW_window *aww);
183
184    GBDATA *peekImportDB() {
185        return gb_import_main;
186    }
187    GBDATA *takeImportDB() {
188        GBDATA *gbm    = gb_import_main;
189        gb_import_main = NULp;
190        return gbm;
191    }
192};
193
194
195#else
196#error awti_imp_local.hxx included twice
197#endif // AWTI_IMP_LOCAL_HXX
Note: See TracBrowser for help on using the repository browser.