| 1 | // =============================================================== // |
|---|
| 2 | // // |
|---|
| 3 | // File : MultiProbe.hxx // |
|---|
| 4 | // Purpose : // |
|---|
| 5 | // // |
|---|
| 6 | // Institute of Microbiology (Technical University Munich) // |
|---|
| 7 | // http://www.arb-home.de/ // |
|---|
| 8 | // // |
|---|
| 9 | // =============================================================== // |
|---|
| 10 | |
|---|
| 11 | #ifndef MULTIPROBE_HXX |
|---|
| 12 | #define MULTIPROBE_HXX |
|---|
| 13 | |
|---|
| 14 | #ifndef SOTL_HXX |
|---|
| 15 | #include "SoTl.hxx" |
|---|
| 16 | #endif |
|---|
| 17 | #ifndef MPDEFS_H |
|---|
| 18 | #include "mpdefs.h" |
|---|
| 19 | #endif |
|---|
| 20 | #ifndef AW_AWAR_HXX |
|---|
| 21 | #include <aw_awar.hxx> |
|---|
| 22 | #endif |
|---|
| 23 | #ifndef AW_BASE_HXX |
|---|
| 24 | #include <aw_base.hxx> |
|---|
| 25 | #endif |
|---|
| 26 | #ifndef ARB_STRING_H |
|---|
| 27 | #include <arb_string.h> |
|---|
| 28 | #endif |
|---|
| 29 | |
|---|
| 30 | #define mp_assert(x) arb_assert(x) |
|---|
| 31 | |
|---|
| 32 | class MP_Main; |
|---|
| 33 | class MP_Window; |
|---|
| 34 | class AW_window; |
|---|
| 35 | class AW_root; |
|---|
| 36 | class AW_window_simple; |
|---|
| 37 | class TREE_canvas; |
|---|
| 38 | class ProbeValuation; |
|---|
| 39 | |
|---|
| 40 | struct ST_Container; |
|---|
| 41 | class Bitvector; |
|---|
| 42 | class Sonde; |
|---|
| 43 | |
|---|
| 44 | #define MP_AWAR_SEQIN "tmp/mp/seqin" |
|---|
| 45 | #define MP_AWAR_SELECTEDPROBES "mp/selectedprobes" |
|---|
| 46 | #define MP_AWAR_PROBELIST "mp/probelist" |
|---|
| 47 | #define MP_AWAR_WEIGHTEDMISMATCHES "mp/weightedmismatches" |
|---|
| 48 | #define MP_AWAR_COMPLEMENT "mp/complement" |
|---|
| 49 | #define MP_AWAR_MISMATCHES "mp/mismatches" |
|---|
| 50 | #define MP_AWAR_PTSERVER AWAR_PT_SERVER |
|---|
| 51 | #define MP_AWAR_LOADLIST "mp/loadlist" |
|---|
| 52 | #define MP_AWAR_RESULTPROBES "mp/resultprobes" |
|---|
| 53 | #define MP_AWAR_RESULTPROBESCOMMENT "mp/resultprobescomment" |
|---|
| 54 | #define MP_AWAR_NOOFPROBES "mp/noofprobes" |
|---|
| 55 | #define MP_AWAR_QUALITY "mp/quality" |
|---|
| 56 | #define MP_AWAR_SINGLEMISMATCHES "mp/singlemismatches" |
|---|
| 57 | #define MP_AWAR_OUTSIDEMISMATCHES "mp/outsidemismatches" |
|---|
| 58 | #define MP_AWAR_QUALITYBORDER1 "mp/qualityborder1" |
|---|
| 59 | #define MP_AWAR_GREYZONE "mp/greyzone" |
|---|
| 60 | #define MP_AWAR_EMPHASIS "mp/emphasis" |
|---|
| 61 | #define MP_AWAR_ECOLIPOS "mp/ecolipos" |
|---|
| 62 | #define MP_AWAR_AUTOADVANCE "mp/auto_advance" |
|---|
| 63 | |
|---|
| 64 | #define QUALITYDEFAULT 3 |
|---|
| 65 | #define MAXPROBECOMBIS 6 // Maximale Anzahl der Sondenkombinationen |
|---|
| 66 | #define MAXMISMATCHES 6 // von 0 bis 5 !!!! |
|---|
| 67 | #define FITNESSSCALEFACTOR 10 // wird benutzt um intern die hammingtabelle feiner zu granulieren |
|---|
| 68 | // siehe probe_combi_statistic::calc_fitness |
|---|
| 69 | |
|---|
| 70 | #define MULTROULETTEFACTOR 10 // macht aus z.B. 4,231 42 |
|---|
| 71 | #define MAXINITPOPULATION 50 // Ausgangsgroesse der Population |
|---|
| 72 | #define MAXPOPULATION MAXINITPOPULATION |
|---|
| 73 | #define CROSSOVER_WS 60 // Crossoverwahrscheinlichkeit liegt bei CROSSOVER_WS Prozent !!! |
|---|
| 74 | #define MUTATION_WS 33 // Mutationswahrscheinlichkeit liegt bei 1/MUTATION_WS Prozent!!! |
|---|
| 75 | #define SIGMATRUNCATION_CONST 2 // die Standardwerte liegen zwischen 1 und 3 |
|---|
| 76 | #define C_MULT 1.4 // Werte zwischen 1.2 und 2.0 |
|---|
| 77 | |
|---|
| 78 | // #define USE_SIGMATRUNCATION // definieren, wenn sigma_truncation in der linearen Skal. (=fitness skalierung) verwendet werden soll |
|---|
| 79 | // #define USE_LINEARSCALING // definieren, wenn lineare_skalierung (=fitness skalierung) verwendet werden soll |
|---|
| 80 | // #define USE_DUP_TREE // definieren, wenn eine Sondenkombination nur einmal pro generation vorkommen soll |
|---|
| 81 | |
|---|
| 82 | #define LIST(TYP) ((List<Sonde>*) TYP) |
|---|
| 83 | |
|---|
| 84 | #define MAXSONDENHASHSIZE 1000 // max 1000 Sonden koennen gecached werden, bei Bedarf aendern !!!! |
|---|
| 85 | |
|---|
| 86 | |
|---|
| 87 | struct awar_vars { |
|---|
| 88 | char *selected_probes; |
|---|
| 89 | char *probelist; |
|---|
| 90 | char *result_probes; |
|---|
| 91 | char *result_probes_comment; |
|---|
| 92 | float outside_mismatches_difference; |
|---|
| 93 | long weightedmismatches; |
|---|
| 94 | long complement; |
|---|
| 95 | long no_of_mismatches; |
|---|
| 96 | long no_of_probes; |
|---|
| 97 | long singlemismatches; |
|---|
| 98 | long ptserver; |
|---|
| 99 | long probe_quality; |
|---|
| 100 | long qualityborder_best; |
|---|
| 101 | long emphasis; |
|---|
| 102 | long ecolipos; |
|---|
| 103 | float min_weight; |
|---|
| 104 | float max_weight; |
|---|
| 105 | float greyzone; |
|---|
| 106 | }; |
|---|
| 107 | |
|---|
| 108 | class AW_selection_list; |
|---|
| 109 | |
|---|
| 110 | extern AW_selection_list *selected_list; |
|---|
| 111 | extern char MP_probe_tab[256]; |
|---|
| 112 | extern AW_selection_list *result_probes_list; |
|---|
| 113 | extern int remembered_mismatches; |
|---|
| 114 | extern int anz_elem_marked; |
|---|
| 115 | extern int anz_elem_unmarked; |
|---|
| 116 | extern unsigned char **hamming_tab; |
|---|
| 117 | extern int **system3_tab; |
|---|
| 118 | extern bool pt_server_different; |
|---|
| 119 | extern bool new_pt_server; |
|---|
| 120 | |
|---|
| 121 | long k_chosenFrom_n(int k, int n); // binomial coefficient |
|---|
| 122 | extern int get_random(int min, int max); // gibt eine Zufallszahl x mit der Eigenschaft : min <= x <= max |
|---|
| 123 | |
|---|
| 124 | // ******************************************************** |
|---|
| 125 | |
|---|
| 126 | extern MP_Main *mp_main; |
|---|
| 127 | extern awar_vars mp_gl_awars; // globale Variable, die manuell eingegebene Sequenz enthaelt |
|---|
| 128 | |
|---|
| 129 | // ******************************************************** |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | class MP_Main : virtual Noncopyable { |
|---|
| 134 | MP_Window *mp_window; |
|---|
| 135 | AW_root *aw_root; |
|---|
| 136 | TREE_canvas *scr; |
|---|
| 137 | ST_Container *stc; |
|---|
| 138 | ProbeValuation *p_eval; |
|---|
| 139 | |
|---|
| 140 | void create_awars(); |
|---|
| 141 | |
|---|
| 142 | public: |
|---|
| 143 | MP_Window *get_mp_window() { return mp_window; }; |
|---|
| 144 | AW_root *get_aw_root() { return aw_root; }; |
|---|
| 145 | TREE_canvas *get_canvas() { return scr; }; |
|---|
| 146 | ProbeValuation *get_p_eval() { return p_eval; }; |
|---|
| 147 | ST_Container *get_stc() { return stc; }; |
|---|
| 148 | void set_stc(ST_Container *stopfC) { stc = stopfC; } |
|---|
| 149 | void set_p_eval (ProbeValuation *y) { p_eval = y; }; |
|---|
| 150 | ProbeValuation *new_probe_eval(char **field, int size, int* array, int *mismatches); |
|---|
| 151 | void destroy_probe_eval(); |
|---|
| 152 | |
|---|
| 153 | MP_Main(AW_root *awr, TREE_canvas *canvas); |
|---|
| 154 | ~MP_Main(); |
|---|
| 155 | }; |
|---|
| 156 | |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | class MP_Window : virtual Noncopyable { |
|---|
| 160 | AW_window_simple *aws; |
|---|
| 161 | AW_window_simple *result_window; |
|---|
| 162 | |
|---|
| 163 | public: |
|---|
| 164 | AW_window_simple *get_window() { return aws; }; |
|---|
| 165 | AW_window_simple *get_result_window() { return result_window; }; |
|---|
| 166 | |
|---|
| 167 | AW_window_simple *create_result_window(AW_root *aw_root); |
|---|
| 168 | |
|---|
| 169 | MP_Window(AW_root *aw_root, GBDATA *gb_main); |
|---|
| 170 | ~MP_Window(); |
|---|
| 171 | }; |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | // ***************************************************** |
|---|
| 176 | // Globale Klassenlose Funktionen |
|---|
| 177 | // ***************************************************** |
|---|
| 178 | void MP_compute(AW_window*, GBDATA *gb_main); |
|---|
| 179 | |
|---|
| 180 | |
|---|
| 181 | class Bakt_Info : virtual Noncopyable { |
|---|
| 182 | char* name; |
|---|
| 183 | long hit_flag; |
|---|
| 184 | |
|---|
| 185 | public: |
|---|
| 186 | const char* get_name() { return name; }; |
|---|
| 187 | long inc_hit_flag() { return ++hit_flag; }; |
|---|
| 188 | long get_hit_flag() { return hit_flag; }; |
|---|
| 189 | void kill_flag() { hit_flag = 0; }; |
|---|
| 190 | |
|---|
| 191 | Bakt_Info(const char* n); |
|---|
| 192 | ~Bakt_Info(); |
|---|
| 193 | }; |
|---|
| 194 | |
|---|
| 195 | class Hit : virtual Noncopyable { |
|---|
| 196 | double *mismatch; |
|---|
| 197 | long baktid; |
|---|
| 198 | |
|---|
| 199 | public: |
|---|
| 200 | double* get_mismatch() { return mismatch; }; |
|---|
| 201 | long get_baktid() { return baktid; }; |
|---|
| 202 | void set_mismatch_at_pos(int pos, double mm) { mismatch[pos] = mm; }; |
|---|
| 203 | double get_mismatch_at_pos(int pos) { return mismatch[pos]; }; |
|---|
| 204 | |
|---|
| 205 | Hit(long baktnummer); |
|---|
| 206 | ~Hit(); |
|---|
| 207 | }; |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | class probe_tabs; |
|---|
| 211 | |
|---|
| 212 | class Sondentopf : virtual Noncopyable { |
|---|
| 213 | List<void*> *Listenliste; // @@@ change type to List<Sonde> ? |
|---|
| 214 | GB_HASH *color_hash; |
|---|
| 215 | MO_Liste *BaktList; |
|---|
| 216 | MO_Liste *Auswahllist; |
|---|
| 217 | |
|---|
| 218 | public: |
|---|
| 219 | probe_tabs* fill_Stat_Arrays(); |
|---|
| 220 | double** gen_Mergefeld(); |
|---|
| 221 | void put_Sonde(const char *name, int allowed_mis, double outside_mis); |
|---|
| 222 | long get_length_hitliste(); |
|---|
| 223 | void gen_color_hash(positiontype anz_sonden); |
|---|
| 224 | GB_HASH *get_color_hash() { return color_hash; }; |
|---|
| 225 | |
|---|
| 226 | Sondentopf(MO_Liste *BL, MO_Liste *AL); |
|---|
| 227 | ~Sondentopf(); |
|---|
| 228 | }; |
|---|
| 229 | |
|---|
| 230 | class Sonde : virtual Noncopyable { |
|---|
| 231 | char* kennung; // Nukleinsaeuren, z.B. "atgatgatg" |
|---|
| 232 | Bitvector* bitkennung; // Sonde 1 Platz eins, ...zwei..., ... Analog zum Aufbau der Listenliste |
|---|
| 233 | Hit **hitliste; // start bei index 0, letztes element enthaelt NULp |
|---|
| 234 | long length_hitliste; |
|---|
| 235 | long minelem; |
|---|
| 236 | long maxelem; |
|---|
| 237 | positiontype kombi_far, kombi_mor; |
|---|
| 238 | long *Allowed_Mismatch; |
|---|
| 239 | double *Outside_Mismatch; |
|---|
| 240 | |
|---|
| 241 | public: |
|---|
| 242 | double get_Allowed_Mismatch_no(int no) { return (Allowed_Mismatch) ? Allowed_Mismatch[no] : 100; }; |
|---|
| 243 | double get_Outside_Mismatch_no(int no) { return (Outside_Mismatch) ? Outside_Mismatch[no] : 100; }; |
|---|
| 244 | const char* get_name() { return kennung; }; |
|---|
| 245 | Hit* get_hitdata_by_number(long index); |
|---|
| 246 | Hit** get_Hitliste() { return hitliste; }; |
|---|
| 247 | long get_length_hitliste() { return length_hitliste; }; |
|---|
| 248 | long get_minelem() { return minelem; }; |
|---|
| 249 | long get_maxelem() { return maxelem; }; |
|---|
| 250 | positiontype get_far() { return kombi_far; }; |
|---|
| 251 | positiontype get_mor() { return kombi_mor; }; |
|---|
| 252 | Bitvector* get_bitkennung() { return bitkennung; }; |
|---|
| 253 | |
|---|
| 254 | void set_bitkennung(Bitvector* bv); // Setzt eine Leere Bitkennung der laenge bits |
|---|
| 255 | void set_far(positiontype far) { kombi_far = far; }; |
|---|
| 256 | void set_mor(positiontype mor) { kombi_mor = mor; }; |
|---|
| 257 | |
|---|
| 258 | void print(); |
|---|
| 259 | void sink(long i, long t, MO_Mismatch** A); |
|---|
| 260 | void heapsort(long feldlaenge, MO_Mismatch** Nr_Mm_Feld); |
|---|
| 261 | double check_for_min(long k, MO_Mismatch** probebacts, long laenge); |
|---|
| 262 | |
|---|
| 263 | MO_Mismatch** get_matching_species(int ptserver_id, |
|---|
| 264 | bool match_also_revcompl, |
|---|
| 265 | int match_weight, |
|---|
| 266 | int match_mis, |
|---|
| 267 | const char *match_seq, |
|---|
| 268 | MO_Liste *convert, |
|---|
| 269 | long *number_of_species, |
|---|
| 270 | GB_ERROR& error); |
|---|
| 271 | |
|---|
| 272 | int gen_Hitliste(MO_Liste *Bakterienliste); |
|---|
| 273 | |
|---|
| 274 | Sonde(const char* bezeichner, int num_probes, int allowed_mis, double outside_mis); |
|---|
| 275 | ~Sonde(); |
|---|
| 276 | }; |
|---|
| 277 | // ##################################### Sondentopf Container ########################### |
|---|
| 278 | |
|---|
| 279 | struct ST_Container : virtual Noncopyable { |
|---|
| 280 | MO_Liste *Bakterienliste; |
|---|
| 281 | MO_Liste *Auswahlliste; |
|---|
| 282 | Sondentopf *sondentopf; // Wird einmal eine Sondentopfliste |
|---|
| 283 | List<Sondentopf> *ST_Liste; |
|---|
| 284 | int anzahl_basissonden; |
|---|
| 285 | GB_HASH* cachehash; |
|---|
| 286 | List<char> *Sondennamen; |
|---|
| 287 | |
|---|
| 288 | Sonde* cache_Sonde(const char *name, int allowed_mis, double outside_mis); |
|---|
| 289 | Sonde* get_cached_sonde(const char* name); |
|---|
| 290 | ST_Container(int anz_sonden); |
|---|
| 291 | ~ST_Container(); |
|---|
| 292 | }; |
|---|
| 293 | |
|---|
| 294 | // ##################################### MO_Liste ##################################### |
|---|
| 295 | /* Die Namen werden in die Hashtabelle mit fortlaufender Nummer abgespeichert |
|---|
| 296 | * Die Nummer bezeichnet das Feld in einem Array, indem momentan der B.-Name steht, |
|---|
| 297 | * spaeter |
|---|
| 298 | * aber auch z.B. ein Pointer auf eine Klasse mit mehr Informationen stehen kann |
|---|
| 299 | ACHTUNG:: Es kann passieren, dass eine Sonde mehrmals an einen Bakter bindet. Dann wird der Bakter nur einmal in die |
|---|
| 300 | Liste eingetragen, und damit ist die laenge nicht mehr aussagekraeftig. current-1 enthaelt das letzte element der liste, die |
|---|
| 301 | Liste beginnt bei 1 |
|---|
| 302 | */ |
|---|
| 303 | |
|---|
| 304 | class MO_Liste : virtual Noncopyable { |
|---|
| 305 | Bakt_Info** mo_liste; |
|---|
| 306 | long laenge; |
|---|
| 307 | long current; // zeigt auf den ersten freien eintrag |
|---|
| 308 | GB_HASH* hashptr; |
|---|
| 309 | |
|---|
| 310 | static GBDATA *gb_main; |
|---|
| 311 | |
|---|
| 312 | public: |
|---|
| 313 | positiontype fill_marked_bakts(); |
|---|
| 314 | GB_ERROR get_all_species(int ptserver_id); |
|---|
| 315 | long debug_get_current(); |
|---|
| 316 | long get_laenge() const; |
|---|
| 317 | long put_entry(const char* name); |
|---|
| 318 | const char* get_entry_by_index(long index) const; |
|---|
| 319 | long get_index_by_entry(const char* key); |
|---|
| 320 | Bakt_Info* get_bakt_info_by_index(long index); |
|---|
| 321 | |
|---|
| 322 | Bakt_Info** get_mo_liste() { return mo_liste; } |
|---|
| 323 | |
|---|
| 324 | static void set_gb_main(GBDATA *gb_main_) { |
|---|
| 325 | mp_assert(implicated(gb_main, gb_main == gb_main_)); |
|---|
| 326 | gb_main = gb_main_; |
|---|
| 327 | } |
|---|
| 328 | |
|---|
| 329 | MO_Liste(); |
|---|
| 330 | ~MO_Liste(); |
|---|
| 331 | }; |
|---|
| 332 | |
|---|
| 333 | |
|---|
| 334 | class Bitvector : virtual Noncopyable { |
|---|
| 335 | // Bitpositionen sind 0 bis 7 |
|---|
| 336 | char* vector; |
|---|
| 337 | int len; |
|---|
| 338 | int num_of_bits; |
|---|
| 339 | public: |
|---|
| 340 | int gen_id(); |
|---|
| 341 | Bitvector* merge(Bitvector* x); |
|---|
| 342 | int subset(Bitvector* Obermenge); |
|---|
| 343 | int readbit(int pos); |
|---|
| 344 | int setbit(int pos); |
|---|
| 345 | int delbit(int pos); |
|---|
| 346 | void rshift(); |
|---|
| 347 | void print(); |
|---|
| 348 | |
|---|
| 349 | const char* get_vector() { return vector; }; |
|---|
| 350 | int get_num_of_bits() { return num_of_bits; }; |
|---|
| 351 | int get_len() { return len; }; |
|---|
| 352 | |
|---|
| 353 | void set_vector(char* back) { vector = back; }; // @@@ pass char*& and use reassign? |
|---|
| 354 | |
|---|
| 355 | Bitvector(int bits); |
|---|
| 356 | ~Bitvector(); |
|---|
| 357 | }; |
|---|
| 358 | |
|---|
| 359 | #else |
|---|
| 360 | #error MultiProbe.hxx included twice |
|---|
| 361 | #endif // MULTIPROBE_HXX |
|---|