source: tags/arb_5.3/PROBE/probe.h

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