source: tags/svn.1.5.4/PROBE/probe.h

Last change on this file was 8309, checked in by westram, 14 years ago
  • moved much code into static scope

(partly reverted by [8310])

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
Line 
1#ifndef PROBE_H
2#define PROBE_H
3
4#ifndef __LIST__
5#include <list>
6#endif
7#ifndef __SET__
8#include <set>
9#endif
10
11#ifndef ARBDB_H
12#include <arbdb.h>
13#endif
14#ifndef PT_COM_H
15#include <PT_com.h>
16#endif
17#ifndef AISC_GEN_SERVER_INCLUDED
18#include <PT_server.h>
19#endif
20
21#define PT_SERVER_MAGIC   0x32108765                // pt server identifier
22#define PT_SERVER_VERSION 2                         // version of pt server database (no versioning till 2009/05/13)
23
24#define pt_assert(bed) arb_assert(bed)
25
26#if defined(DEBUG)
27// #define PTM_DEBUG
28#endif // DEBUG
29
30typedef unsigned long ULONG;
31typedef unsigned int  UINT;
32typedef unsigned char uchar;
33
34#define PT_CORE *(int *)0 = 0;
35
36#define PT_POS_TREE_HEIGHT 20
37#define PT_POS_SECURITY    10
38#define MIN_PROBE_LENGTH   6
39
40enum PT_MATCH_TYPE {
41    PT_MATCH_TYPE_INTEGER           = 0,
42    PT_MATCH_TYPE_WEIGHTED_PLUS_POS = 1,
43    PT_MATCH_TYPE_WEIGHTED          = -1
44};
45
46
47
48#define MATCHANSWER  50                             // private msg type: match result answer
49#define CREATEANSWER 51                             // private msg type: create result answer
50#define FINDANSWER   52                             // private msg type: find result answer
51
52extern int gene_flag;           // if 'gene_flag' == 1 -> we are a gene pt server
53extern ULONG physical_memory;
54struct Hs_struct;
55
56enum type_types {
57    t_int    = 1,
58    t_string = 0,
59    t_float  = 2
60};
61
62enum PT_BASES {
63    PT_QU = 0,
64    PT_N  = 1,
65    PT_A,
66    PT_C,
67    PT_G,
68    PT_T,
69    PT_B_MAX,
70    PT_B_UNDEF,
71};
72
73// -----------------
74//      POS TREE
75
76enum PT_NODE_TYPE {
77    PT_NT_LEAF        = 0,
78    PT_NT_CHAIN       = 1,
79    PT_NT_NODE        = 2,
80    PT_NT_SINGLE_NODE = 3,                          // stage 3
81    PT_NT_SAVED       = 3,                          // stage 1+2
82    PT_NT_UNDEF       = 4
83};
84
85struct POS_TREE {
86    uchar flags;
87    char  data;
88};
89
90struct PTM2 {
91    char *data_start;                               // points to start of data
92    int   stage1;
93    int   stage2;
94    int   stage3;
95    int   mode;
96};
97
98
99
100// ---------------------
101//      Probe search
102
103class probe_input_data : virtual Noncopyable {      // every taxa's own data
104
105    char *data;       // sequence
106    long  checksum;   // checksum of sequence
107    int   size; // @@@ misleading (contains 1 if no bases in sequence)
108
109    char   *name;
110    char   *fullname;
111    GBDATA *gbd;
112
113    bool group;           // probe_design: whether species is in group
114
115    // obsolete methods below @@@ remove them
116    GBDATA *get_gbdata() const { return gbd; }
117    void set_data(char *assign, int size_) { pt_assert(!data); data = assign; size = size_; }
118    void set_checksum(long cs) { checksum = cs; }
119   
120public:
121
122    probe_input_data()
123        : data(0),
124          checksum(0), 
125          size(0), 
126          name(0), 
127          fullname(0), 
128          gbd(0), 
129          group(false) 
130    {}
131    ~probe_input_data() {
132        free(data);
133        free(name);
134        free(fullname);
135    }
136
137    GB_ERROR init(GBDATA *gbd_);
138
139    const char *get_data() const { return data; }
140    char *read_alignment(int *psize) const;
141
142    const char *get_name() const { return name; }
143    const char *get_fullname() const { return fullname; }
144    long get_checksum() const { return checksum; }
145    int get_size() const { return size; }
146
147    bool inside_group() const { return group; }
148    bool outside_group() const { return !group; }
149
150    void set_group_state(bool isGroupMember) { group = isGroupMember; }
151
152    long get_abspos() const {
153        pt_assert(gene_flag); // only legal in gene-ptserver
154        GBDATA *gb_pos = GB_entry(get_gbdata(), "abspos");
155        if (gb_pos) return GB_read_int(gb_pos);
156        return -1;
157    }
158
159private:
160};
161
162struct probe_statistic_struct {
163#ifdef ARB_64
164    int  cut_offs;                                  // statistic of chains
165    int  single_node;
166    int  short_node;
167    int  int_node;
168    int  long_node;
169    int  longs;
170    int  ints;
171    int  ints2;
172    int  shorts;
173    int  shorts2;
174    int  chars;
175    long maxdiff;
176#else
177    int  cut_offs;                                  // statistic of chains
178    int  single_node;
179    int  short_node;
180    int  long_node;
181    int  longs;
182    int  shorts;
183    int  shorts2;
184    int  chars;
185#endif
186
187};
188
189class BI_ecoli_ref;
190
191class MostUsedPos : virtual Noncopyable {
192    int pos;
193    int used;
194
195    MostUsedPos *next;
196
197    void swapWith(MostUsedPos *other) {
198        std::swap(pos, other->pos);
199        std::swap(used, other->used);
200    }
201
202public:
203    MostUsedPos() : pos(0), used(0), next(NULL) { }
204    MostUsedPos(int p) : pos(p), used(1), next(NULL) { }
205    ~MostUsedPos() { delete next; }
206
207    void clear() {
208        pos  = 0;
209        used = 0;
210        delete next;
211        next = NULL;
212    }
213
214    void announce(int p) {
215        if (p == pos) used++;
216        else {
217            if (next) next->announce(p);
218            else next = new MostUsedPos(p);
219            if (next->used>used) swapWith(next);
220        }
221    }
222
223
224    int get_most_used() const { return pos; }
225};
226
227extern struct probe_struct_global {
228    GB_shell *gb_shell;
229    GBDATA   *gb_main;                              // ARBDB interface
230    GBDATA   *gb_species_data;
231    GBDATA   *gb_sai_data;
232    char     *alignment_name;
233    GB_HASH  *namehash;                             // name to int
234
235    int                      data_count;
236    struct probe_input_data *data;                  // the internal database
237
238    char         *ecoli;                            // the ecoli sequenz
239    BI_ecoli_ref *bi_ecoli;
240
241    int  max_size;                                  // maximum sequence len
242    long char_count;                                // number of all 'acgtuACGTU'
243
244    int    mismatches;                              // chain handle in match
245    double wmismatches;
246    int    N_mismatches;
247    int    w_N_mismatches[PT_POS_TREE_HEIGHT+PT_POS_SECURITY+1];
248
249    int reversed;                                   // tell the matcher whether probe is reversed
250
251    double *pos_to_weight;                          // position to weight
252    char    complement[256];                        // complement
253
254    int deep;                                       // for probe matching
255    int height;
256    int length;
257   
258    MostUsedPos abs_pos;
259
260    int sort_by;
261
262    char *probe;                                    // probe design + chains
263    char *main_probe;
264
265    char      *server_name;                         // name of this server
266    aisc_com  *link;
267    T_PT_MAIN  main;
268    Hs_struct *com_so;                              // the communication socket
269    POS_TREE  *pt;
270    PTM2      *ptmain;
271
272    probe_statistic_struct stat;
273
274} psg;
275
276class gene_struct {
277    char       *gene_name;
278    const char *arb_species_name; // pointers into 'gene_name'
279    const char *arb_gene_name;
280
281    void init(const char *gene_name_, const char *arb_species_name_, const char *arb_gene_name_) {
282        int gene_name_len        = strlen(gene_name_);
283        int arb_species_name_len = strlen(arb_species_name_);
284        int arb_gene_name_len    = strlen(arb_gene_name_);
285
286        int fulllen      = gene_name_len+1+arb_species_name_len+1+arb_gene_name_len+1;
287        gene_name        = new char[fulllen];
288        strcpy(gene_name, gene_name_);
289        arb_species_name = gene_name+(gene_name_len+1);
290        strcpy((char*)arb_species_name, arb_species_name_);
291        arb_gene_name    = arb_species_name+(arb_species_name_len+1);
292        strcpy((char*)arb_gene_name, arb_gene_name_);
293    }
294
295public:
296    gene_struct(const char *gene_name_, const char *arb_species_name_, const char *arb_gene_name_) {
297        init(gene_name_, arb_species_name_, arb_gene_name_);
298    }
299    gene_struct(const gene_struct& other) {
300        if (&other != this) {
301            init(other.get_internal_gene_name(), other.get_arb_species_name(), other.get_arb_gene_name());
302        }
303    }
304    gene_struct& operator = (const gene_struct& other) {
305        if (&other != this) {
306            delete [] gene_name;
307            init(other.get_internal_gene_name(), other.get_arb_species_name(), other.get_arb_gene_name());
308        }
309        return *this;
310    }
311
312    ~gene_struct() {
313        delete [] gene_name;
314    }
315
316    const char *get_internal_gene_name() const { return gene_name; }
317    const char *get_arb_species_name() const { return arb_species_name; }
318    const char *get_arb_gene_name() const { return arb_gene_name; }
319};
320
321struct ltByArbName {
322    bool operator()(const gene_struct *gs1, const gene_struct *gs2) const {
323        int cmp           = strcmp(gs1->get_arb_species_name(), gs2->get_arb_species_name());
324        if (cmp == 0) { cmp = strcmp(gs1->get_arb_gene_name(), gs2->get_arb_gene_name()); }
325        return cmp<0;
326    }
327};
328struct ltByInternalName {
329    bool operator()(const gene_struct *gs1, const gene_struct *gs2) const {
330        int cmp = strcmp(gs1->get_internal_gene_name(), gs2->get_internal_gene_name());
331        return cmp<0;
332    }
333};
334
335typedef std::list<gene_struct>                          gene_struct_list;
336typedef std::set<const gene_struct *, ltByInternalName> gene_struct_index_internal;
337typedef std::set<const gene_struct *, ltByArbName>      gene_struct_index_arb;
338
339extern gene_struct_index_arb      gene_struct_arb2internal; // sorted by arb species+gene name
340extern gene_struct_index_internal gene_struct_internal2arb; // sorted by internal name
341
342#define PT_base_string_counter_eof(str) (*(unsigned char *)(str) == 255)
343
344#else
345#error probe.h included twice
346#endif
347
348
Note: See TracBrowser for help on using the repository browser.