source: tags/arb_5.2/SL/HELIX/BI_helix.hxx

Last change on this file was 6124, checked in by westram, 15 years ago
  • fixed macro IDs for EDIT4 clone windows
  • reuse GC window (using GC manager of 1st editor window; possible cause all GC managers use the same awars)
  • HelixSettings? window
    • reuse in EDIT4 clone windows
    • added HELP button
    • tighter layout
    • added check for duplicate pair definitions
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.7 KB
Line 
1#ifndef BI_HELIX_HXX
2#define BI_HELIX_HXX
3
4#ifndef ARB_ASSERT_H
5#include <arb_assert.h>
6#endif
7#define bi_assert(bed) arb_assert(bed)
8
9#ifndef _CPP_CSTDLIB
10#include <cstdlib>
11#endif
12#ifndef _CPP_CSTDIO
13#include <cstdio>
14#endif
15#ifndef _CPP_CSTRING
16#include <cstring>
17#endif
18
19#ifndef ARBDB_H
20#include <arbdb.h>
21#endif
22
23typedef enum {
24    HELIX_NONE,                                     // used in entries
25    HELIX_STRONG_PAIR,
26    HELIX_PAIR,                                     // used in entries
27    HELIX_WEAK_PAIR,
28    HELIX_NO_PAIR,                                  // used in entries
29    HELIX_USER0,
30    HELIX_USER1,
31    HELIX_USER2,
32    HELIX_USER3,
33    HELIX_DEFAULT,
34    HELIX_NON_STANDARD0,                            // used in entries
35    HELIX_NON_STANDARD1,                            // used in entries
36    HELIX_NON_STANDARD2,                            // used in entries
37    HELIX_NON_STANDARD3,                            // used in entries
38    HELIX_NON_STANDARD4,                            // used in entries
39    HELIX_NON_STANDARD5,                            // used in entries
40    HELIX_NON_STANDARD6,                            // used in entries
41    HELIX_NON_STANDARD7,                            // used in entries
42    HELIX_NON_STANDARD8,                            // used in entries
43    HELIX_NON_STANDARD9,                            // used in entries
44    HELIX_NO_MATCH,
45    HELIX_MAX
46} BI_PAIR_TYPE;
47
48struct BI_helix_entry {
49    long          pair_pos;
50    BI_PAIR_TYPE  pair_type;
51    char         *helix_nr;
52
53    long next_pair_pos;                             /* next position with pair_type != HELIX_NONE
54                                                     * contains
55                                                     *  0 if uninitialized,
56                                                     * -1 behind last position */
57    bool allocated;
58};
59
60class BI_helix {
61    BI_helix_entry *entries;
62    size_t          Size;
63
64    void _init(void);
65
66    static char *helix_error;                       // error occurring during init is stored here
67
68    const char *init(GBDATA *gb_main, const char *alignment_name, const char *helix_nr_name, const char *helix_name);
69
70protected:
71
72    char *pairs[HELIX_MAX];
73    char *char_bind[HELIX_MAX];
74   
75    bool is_pairtype(char left, char right, BI_PAIR_TYPE pair_type);
76
77public:
78
79    static char *get_error() { return helix_error; }
80    static void clear_error() { freeset(helix_error, NULL); }
81    static void set_error(const char *err) { freedup(helix_error, err); }
82
83    BI_helix(void);
84    ~BI_helix(void);
85
86    const char *init(GBDATA *gb_main);
87    const char *init(GBDATA *gb_main, const char *alignment_name);
88    const char *init(GBDATA *gb_helix_nr,GBDATA *gb_helix,size_t size);
89    const char *initFromData(const char *helix_nr, const char *helix, size_t size);
90
91    int check_pair(char left, char right, BI_PAIR_TYPE pair_type); // return 1 if bases form a pair
92
93    size_t size() const { return Size; }
94    bool has_entries() const { return entries; }
95    const BI_helix_entry& entry(size_t pos) const {
96        bi_assert(pos<Size);
97        bi_assert(entries);
98        return entries[pos];
99    }
100
101    size_t opposite_position(size_t pos) const {
102        const BI_helix_entry& Entry = entry(pos);
103        bi_assert(Entry.pair_type != HELIX_NONE); // not a pair -> no opposite position
104        return Entry.pair_pos;
105    }
106    BI_PAIR_TYPE pairtype(size_t pos) const { return pos<Size ? entry(pos).pair_type : HELIX_NONE; }
107    const char *helixNr(size_t pos) const { return pairtype(pos) == HELIX_NONE ? 0 : entry(pos).helix_nr; }
108    // Note: results of helixNr may be compared by == (instead of strcmp())
109
110    long first_pair_position() const; // first pair position (or -1)
111    long next_pair_position(size_t pos) const; // next pair position behind 'pos' (or -1)
112   
113    long first_position(const char *helixNr) const; // returns -1 for non-existing helixNr's
114    long last_position(const char *helixNr) const; // returns -1 for non-existing helixNr's
115};
116
117
118
119
120class BI_ecoli_ref {
121    size_t absLen;
122    size_t relLen;
123
124    size_t *abs2rel;
125    size_t *rel2abs;
126   
127    void bi_exit();
128
129public:
130    BI_ecoli_ref();
131    ~BI_ecoli_ref();
132
133    const char *init(GBDATA *gb_main);
134    const char *init(GBDATA *gb_main,char *alignment_name, char *ref_name);
135    const char *init(const char *seq, size_t size);
136
137    bool gotData() const { return abs2rel != 0; }
138   
139    size_t abs_2_rel(size_t abs) const {
140        bi_assert(gotData()); 
141        if (abs >= absLen) abs = absLen-1;
142        return abs2rel[abs];
143    }
144
145    size_t rel_2_abs(size_t rel) const {
146        bi_assert(gotData()); 
147        if (rel >= relLen) rel = relLen-1;
148        return rel2abs[rel];
149    }
150
151    size_t base_count() const { return relLen; }
152};
153
154
155#endif
Note: See TracBrowser for help on using the repository browser.