1 | // =============================================================== // |
---|
2 | // // |
---|
3 | // File : awtc_next_neighbours.hxx // |
---|
4 | // Purpose : Search relatives via PT server // |
---|
5 | // // |
---|
6 | // Institute of Microbiology (Technical University Munich) // |
---|
7 | // http://www.arb-home.de/ // |
---|
8 | // // |
---|
9 | // =============================================================== // |
---|
10 | |
---|
11 | #ifndef AWTC_NEXT_NEIGHBOURS_HXX |
---|
12 | #define AWTC_NEXT_NEIGHBOURS_HXX |
---|
13 | |
---|
14 | #ifndef ARBDB_BASE_H |
---|
15 | #include <arbdb_base.h> |
---|
16 | #endif |
---|
17 | #ifndef ATTRIBUTES_H |
---|
18 | #include <attributes.h> |
---|
19 | #endif |
---|
20 | #ifndef ARB_ASSERT_H |
---|
21 | #include <arb_assert.h> |
---|
22 | #endif |
---|
23 | #ifndef _GLIBCXX_ALGORITHM |
---|
24 | #include <algorithm> |
---|
25 | #endif |
---|
26 | #ifndef ARBTOOLS_H |
---|
27 | #include <arbtools.h> |
---|
28 | #endif |
---|
29 | |
---|
30 | #define ff_assert(bed) arb_assert(bed) |
---|
31 | |
---|
32 | class FamilyList : virtual Noncopyable { |
---|
33 | // list is sorted either by 'matches' or 'rel_matches' (descending) |
---|
34 | // depending on 'rel_matches' parameter to PT_FamilyFinder::searchFamily() |
---|
35 | public: |
---|
36 | FamilyList *next; |
---|
37 | |
---|
38 | char *name; |
---|
39 | long matches; |
---|
40 | double rel_matches; |
---|
41 | |
---|
42 | FamilyList *insertSortedBy_matches(FamilyList *other); |
---|
43 | FamilyList *insertSortedBy_rel_matches(FamilyList *other); |
---|
44 | |
---|
45 | FamilyList(); |
---|
46 | ~FamilyList(); |
---|
47 | }; |
---|
48 | |
---|
49 | struct aisc_com; |
---|
50 | |
---|
51 | enum FF_complement { |
---|
52 | FF_FORWARD = 1, |
---|
53 | FF_REVERSE = 2, |
---|
54 | FF_REVERSE_COMPLEMENT = 4, |
---|
55 | FF_COMPLEMENT = 8, |
---|
56 | |
---|
57 | // do NOT change the order here w/o fixing ../PROBE/PT_family.cxx@FF_complement_dep |
---|
58 | }; |
---|
59 | |
---|
60 | class TargetRange { // @@@ move somewhere else, if needed independently from FamilyFinder |
---|
61 | int start; // -1 == unlimited |
---|
62 | int end; // -1 == unlimited |
---|
63 | |
---|
64 | public: |
---|
65 | TargetRange() : start(-1), end(-1) {} |
---|
66 | TargetRange(int start_, int end_) : start(start_), end(end_) { |
---|
67 | ff_assert(start >= -1); |
---|
68 | ff_assert(end >= -1); |
---|
69 | } |
---|
70 | |
---|
71 | int get_start() const { return start; } |
---|
72 | int get_end() const { return end; } |
---|
73 | |
---|
74 | int first_pos() const { return start == -1 ? 0 : start; } |
---|
75 | int last_pos(const int global_len) const { |
---|
76 | const int max_global_pos = global_len-1; |
---|
77 | return end == -1 ? max_global_pos : std::min(end, max_global_pos); |
---|
78 | } |
---|
79 | |
---|
80 | int length(size_t global_len) const { |
---|
81 | int len = last_pos(global_len)-first_pos()+1; |
---|
82 | return len<0 ? 0 : len; |
---|
83 | } |
---|
84 | |
---|
85 | bool is_restricted() const { return start != -1 || end != -1; } |
---|
86 | |
---|
87 | void copy_corresponding_part(char *dest, const char *source, size_t source_len) const; |
---|
88 | char *dup_corresponding_part(const char *source, size_t source_len) const __ATTR__USERESULT; |
---|
89 | |
---|
90 | bool operator == (const TargetRange& other) const { return start == other.start && end == other.end; } |
---|
91 | bool operator != (const TargetRange& other) const { return !(*this == other); } |
---|
92 | }; |
---|
93 | |
---|
94 | |
---|
95 | class FamilyFinder : virtual Noncopyable { |
---|
96 | bool rel_matches; |
---|
97 | |
---|
98 | protected: |
---|
99 | FamilyList *family_list; |
---|
100 | |
---|
101 | bool hits_truncated; |
---|
102 | |
---|
103 | #if defined(WARN_TODO) |
---|
104 | #warning change real_hits back to int when aisc_get() has been made failsafe |
---|
105 | #endif |
---|
106 | long real_hits; |
---|
107 | |
---|
108 | TargetRange range; |
---|
109 | |
---|
110 | public: |
---|
111 | FamilyFinder(bool rel_matches_); |
---|
112 | virtual ~FamilyFinder(); |
---|
113 | |
---|
114 | void restrict_2_region(const TargetRange& range_) { |
---|
115 | // Restrict oligo search to 'range_' |
---|
116 | // Only oligos which are completely inside that region are used for calculating relationship. |
---|
117 | // Has to be called before calling searchFamily. |
---|
118 | range = range_; |
---|
119 | } |
---|
120 | |
---|
121 | void unrestrict() { range = TargetRange(-1, -1); } |
---|
122 | const TargetRange& get_TargetRange() const { return range; } |
---|
123 | |
---|
124 | virtual GB_ERROR searchFamily(const char *sequence, FF_complement compl_mode, int max_results) = 0; |
---|
125 | |
---|
126 | const FamilyList *getFamilyList() const { return family_list; } |
---|
127 | void delete_family_list(); |
---|
128 | |
---|
129 | bool hits_were_truncated() const { return hits_truncated; } |
---|
130 | bool uses_rel_matches() const { return rel_matches; } |
---|
131 | int getRealHits() const { return real_hits; } |
---|
132 | }; |
---|
133 | |
---|
134 | class PT_FamilyFinder : public FamilyFinder { // derived from a Noncopyable |
---|
135 | GBDATA *gb_main; |
---|
136 | int server_id; |
---|
137 | int oligo_len; |
---|
138 | int mismatches; |
---|
139 | bool fast_flag; |
---|
140 | |
---|
141 | aisc_com *link; |
---|
142 | long com; |
---|
143 | long locs; |
---|
144 | |
---|
145 | GB_ERROR init_communication(); |
---|
146 | GB_ERROR open(const char *servername); |
---|
147 | GB_ERROR retrieve_family(const char *sequence, FF_complement compl_mode, int max_results) __ATTR__USERESULT; |
---|
148 | void close(); |
---|
149 | |
---|
150 | public: |
---|
151 | |
---|
152 | PT_FamilyFinder(GBDATA *gb_main_, int server_id_, int oligo_len_, int mismatches_, bool fast_flag_, bool rel_matches_); |
---|
153 | ~PT_FamilyFinder(); |
---|
154 | |
---|
155 | GB_ERROR searchFamily(const char *sequence, FF_complement compl_mode, int max_results) __ATTR__USERESULT; |
---|
156 | |
---|
157 | const char *results2string(); |
---|
158 | }; |
---|
159 | |
---|
160 | // -------------------------------------------------------------------------------- |
---|
161 | |
---|
162 | #define AWAR_NN_BASE "next_neighbours/" |
---|
163 | |
---|
164 | #define AWAR_NN_OLIGO_LEN AWAR_NN_BASE "oligo_len" |
---|
165 | #define AWAR_NN_MISMATCHES AWAR_NN_BASE "mismatches" |
---|
166 | #define AWAR_NN_FAST_MODE AWAR_NN_BASE "fast_mode" |
---|
167 | #define AWAR_NN_REL_MATCHES AWAR_NN_BASE "rel_matches" |
---|
168 | |
---|
169 | class AW_root; |
---|
170 | class AW_window; |
---|
171 | |
---|
172 | void AWTC_create_common_next_neighbour_vars(AW_root *aw_root); |
---|
173 | void AWTC_create_common_next_neighbour_fields(AW_window *aws); |
---|
174 | |
---|
175 | #else |
---|
176 | #error awtc_next_neighbours.hxx included twice |
---|
177 | #endif // AWTC_NEXT_NEIGHBOURS_HXX |
---|