source: tags/ms_r17q3/EDIT4/ed4_search.hxx

Last change on this file was 14426, checked in by westram, 9 years ago
  • use typed window callbacks in EDIT4
  • 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      : ed4_search.hxx                                    //
4//   Purpose   :                                                   //
5//                                                                 //
6//   Coded by Ralf Westram (coder@reallysoft.de)                   //
7//   Institute of Microbiology (Technical University Munich)       //
8//   http://www.arb-home.de/                                       //
9//                                                                 //
10// =============================================================== //
11
12#ifndef ED4_SEARCH_HXX
13#define ED4_SEARCH_HXX
14
15enum ED4_SEARCH_CASE {
16    ED4_SC_CASE_SENSITIVE,
17    ED4_SC_CASE_INSENSITIVE
18};
19
20enum ED4_SEARCH_TU {
21    ED4_ST_T_NOT_EQUAL_U,
22    ED4_ST_T_EQUAL_U
23};
24
25enum ED4_SEARCH_GAPS {
26    ED4_SG_CONSIDER_GAPS,
27    ED4_SG_IGNORE_GAPS
28};
29
30// --------------------------------------------------------------------------------
31
32#define MAX_MISMATCHES  5
33
34enum ED4_SearchPositionType {
35    ED4_USER1_PATTERN = 0,
36    ED4_USER2_PATTERN,
37    ED4_PROBE_PATTERN,
38    ED4_PRIMER1_PATTERN,
39    ED4_PRIMER2_PATTERN,
40    ED4_PRIMER3_PATTERN,
41    ED4_SIG1_PATTERN,
42    ED4_SIG2_PATTERN,
43    ED4_SIG3_PATTERN,
44    SEARCH_PATTERNS, // counter
45    ED4_ANY_PATTERN   = SEARCH_PATTERNS
46};
47
48extern const char *ED4_SearchPositionTypeId[];
49
50inline int ED4_encodeSearchDescriptor(int direction, ED4_SearchPositionType pattern)
51{
52    e4_assert(direction==-1 || direction==1);
53    e4_assert(pattern>=0 && pattern<(SEARCH_PATTERNS+1));
54    return (direction==1) + pattern*2;
55}
56
57// #define TEST_SEARCH_POSITION
58
59
60
61class ED4_SearchPosition {
62    // one found position
63    int start_pos, end_pos;
64    int mismatch[MAX_MISMATCHES]; // contains positions of mismatches (or -1)
65    ED4_SearchPositionType whatsFound;
66    GB_CSTR comment;
67    ED4_SearchPosition *next;
68
69    static char *lastShownComment;
70
71    int cmp(const ED4_SearchPosition& sp2) const
72    {
73        int c = start_pos - sp2.get_start_pos();
74        if (!c) c = end_pos - sp2.get_end_pos();
75        return c;
76    }
77
78public:
79
80    ED4_SearchPosition(int sp, int ep, ED4_SearchPositionType wf, GB_CSTR found_comment, int mismatches[MAX_MISMATCHES]);
81    ~ED4_SearchPosition() { delete next; }
82
83    ED4_SearchPosition(const ED4_SearchPosition& other); // copy-ctor ('next' is always zero)
84    DECLARE_ASSIGNMENT_OPERATOR(ED4_SearchPosition);
85
86    ED4_SearchPosition *insert(ED4_SearchPosition *toAdd);
87    ED4_SearchPosition *remove(ED4_SearchPositionType typeToRemove);
88
89    ED4_SearchPosition *get_next() const          { return next; }
90    int get_start_pos() const                     { return start_pos; }
91    int get_end_pos() const                       { return end_pos; }
92    ED4_SearchPositionType get_whatsFound() const { return whatsFound; }
93    GB_CSTR get_comment() const;
94
95    const int *getMismatches() const              { return mismatch; }
96
97    int containsPos(int pos) const { return start_pos<=pos && end_pos>=pos; }
98
99    ED4_SearchPosition *get_next_at(int pos) const;
100
101#ifdef TEST_SEARCH_POSITION
102    int ok() const;
103#endif
104};
105
106class ED4_sequence_terminal;
107
108class ED4_SearchResults : virtual Noncopyable {
109    // list head
110
111    int arraySize;              // ==0 -> 'first' is a list
112    // >0 -> 'array' is an array of 'ED4_SearchPosition*' with 'arraySize' elements
113
114    ED4_SearchPosition *first;  // ==0 -> no results, this list is sorted by start_pos, end_pos
115    ED4_SearchPosition **array; // ==0 -> no results, same sorting as 'first'
116    int timeOf[SEARCH_PATTERNS];
117
118    static int timeOfLastSearch[SEARCH_PATTERNS]; // timestamp used at last search
119    static int timeOfNextSearch[SEARCH_PATTERNS]; // timestamp used at next search
120    static int shown[SEARCH_PATTERNS]; // copy of ED4_AWAR_xxx_SEARCH_SHOW
121    static int bufferSize;
122    static char *buffer; // buffer for buildColorString
123    static int initialized;
124
125    int is_list() const { return arraySize==0; }
126    int is_array() const { return arraySize>0; }
127
128    void to_array();      // ensures that result is in array-format (used to improve search performance)
129    void to_list();       // ensures that result is in list-format (used to improve insert performance)
130
131public:
132
133    ED4_SearchResults();
134    ~ED4_SearchResults();
135
136    void search(const ED4_sequence_terminal *seq_terminal);
137    void addSearchPosition(ED4_SearchPosition *pos);
138
139    ED4_SearchPosition *get_first() const { return first; }
140    ED4_SearchPosition *get_first_at(ED4_SearchPositionType type, int start, int end) const;
141    ED4_SearchPosition *get_first_starting_after(ED4_SearchPositionType type, int pos, int mustBeShown) const;
142    ED4_SearchPosition *get_last_starting_before(ED4_SearchPositionType type, int pos, int mustBeShown) const;
143    ED4_SearchPosition *get_shown_at(int pos) const;
144
145    static void setNewSearch(ED4_SearchPositionType type);
146    void searchAgain();
147
148    char *buildColorString(const ED4_sequence_terminal *seq_terminal, int start, int end);
149};
150
151// global functions
152
153class ED4_window;
154void  ED4_search_cb(UNFIXED, int searchDescriptor, ED4_window *ed4w);
155
156GB_ERROR ED4_repeat_last_search(class ED4_window *ed4w);
157void ED4_popup_search_window(AW_window *aww, ED4_SearchPositionType type);
158
159void ED4_create_search_awars(AW_root *root);
160
161#else
162#error ed4_search.hxx included twice
163#endif // ED4_SEARCH_HXX
164
Note: See TracBrowser for help on using the repository browser.