| 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_ASSERT_H |
|---|
| 27 | #include <arb_assert.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 AWT_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 AW_selection_list *probelist; |
|---|
| 112 | extern char MP_probe_tab[256]; |
|---|
| 113 | extern AW_selection_list *result_probes_list; |
|---|
| 114 | extern int remembered_mismatches; |
|---|
| 115 | extern int anz_elem_marked; |
|---|
| 116 | extern int anz_elem_unmarked; |
|---|
| 117 | extern unsigned char **hamming_tab; |
|---|
| 118 | extern int **system3_tab; |
|---|
| 119 | extern bool pt_server_different; |
|---|
| 120 | extern bool new_pt_server; |
|---|
| 121 | |
|---|
| 122 | long k_aus_n(int k, int n); // Berechnung k aus n |
|---|
| 123 | extern int get_random(int min, int max); // gibt eine Zufallszahl x mit der Eigenschaft : min <= x <= max |
|---|
| 124 | |
|---|
| 125 | // ******************************************************** |
|---|
| 126 | |
|---|
| 127 | extern MP_Main *mp_main; |
|---|
| 128 | extern awar_vars mp_gl_awars; // globale Variable, die manuell eingegebene Sequenz enthaelt |
|---|
| 129 | |
|---|
| 130 | // ******************************************************** |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | class MP_Main : virtual Noncopyable { |
|---|
| 135 | MP_Window *mp_window; |
|---|
| 136 | AW_root *aw_root; |
|---|
| 137 | AWT_canvas *scr; |
|---|
| 138 | ST_Container *stc; |
|---|
| 139 | ProbeValuation *p_eval; |
|---|
| 140 | |
|---|
| 141 | void create_awars(); |
|---|
| 142 | |
|---|
| 143 | public: |
|---|
| 144 | MP_Window *get_mp_window() { return mp_window; }; |
|---|
| 145 | AW_root *get_aw_root() { return aw_root; }; |
|---|
| 146 | AWT_canvas *get_canvas() { return scr; }; |
|---|
| 147 | ProbeValuation *get_p_eval() { return p_eval; }; |
|---|
| 148 | ST_Container *get_stc() { return stc; }; |
|---|
| 149 | void set_stc(ST_Container *stopfC) { stc = stopfC; } |
|---|
| 150 | void set_p_eval (ProbeValuation *y) { p_eval = y; }; |
|---|
| 151 | ProbeValuation *new_probe_eval(char **field, int size, int* array, int *mismatches); |
|---|
| 152 | void destroy_probe_eval(); |
|---|
| 153 | |
|---|
| 154 | MP_Main(AW_root *awr, AWT_canvas *canvas); |
|---|
| 155 | ~MP_Main(); |
|---|
| 156 | }; |
|---|
| 157 | |
|---|
| 158 | |
|---|
| 159 | |
|---|
| 160 | class MP_Window : virtual Noncopyable { |
|---|
| 161 | AW_window_simple *aws; |
|---|
| 162 | AW_window_simple *result_window; |
|---|
| 163 | |
|---|
| 164 | void build_pt_server_list(); |
|---|
| 165 | // zeigt auf naechstes Zeichen |
|---|
| 166 | |
|---|
| 167 | public: |
|---|
| 168 | AW_window_simple *get_window() { return aws; }; |
|---|
| 169 | AW_window_simple *get_result_window() { return result_window; }; |
|---|
| 170 | |
|---|
| 171 | AW_window_simple *create_result_window(AW_root *aw_root); |
|---|
| 172 | |
|---|
| 173 | MP_Window(AW_root *aw_root, GBDATA *gb_main); |
|---|
| 174 | ~MP_Window(); |
|---|
| 175 | }; |
|---|
| 176 | |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | // ***************************************************** |
|---|
| 180 | // Globale Klassenlose Funktionen |
|---|
| 181 | // ***************************************************** |
|---|
| 182 | void MP_compute(AW_window *, AW_CL cl_gb_main); |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | class Bakt_Info : virtual Noncopyable { |
|---|
| 186 | char* name; |
|---|
| 187 | long hit_flag; |
|---|
| 188 | |
|---|
| 189 | public: |
|---|
| 190 | char* get_name() { return name; }; |
|---|
| 191 | long inc_hit_flag() { return (++hit_flag); }; |
|---|
| 192 | long get_hit_flag() { return (hit_flag); }; |
|---|
| 193 | void kill_flag() { hit_flag = 0; }; |
|---|
| 194 | |
|---|
| 195 | Bakt_Info(const char* n); |
|---|
| 196 | ~Bakt_Info(); |
|---|
| 197 | }; |
|---|
| 198 | |
|---|
| 199 | class Hit : virtual Noncopyable { |
|---|
| 200 | double *mismatch; |
|---|
| 201 | long baktid; |
|---|
| 202 | |
|---|
| 203 | public: |
|---|
| 204 | double* get_mismatch() { return mismatch; }; |
|---|
| 205 | long get_baktid() { return baktid; }; |
|---|
| 206 | void set_mismatch_at_pos(int pos, double mm) { mismatch[pos] = mm; }; |
|---|
| 207 | double get_mismatch_at_pos(int pos) { return mismatch[pos]; }; |
|---|
| 208 | |
|---|
| 209 | Hit(long baktnummer); |
|---|
| 210 | ~Hit(); |
|---|
| 211 | }; |
|---|
| 212 | |
|---|
| 213 | |
|---|
| 214 | class probe_tabs; |
|---|
| 215 | |
|---|
| 216 | class Sondentopf : virtual Noncopyable { |
|---|
| 217 | List<void*> *Listenliste; // @@@ change type to List<Sonde> ? |
|---|
| 218 | GB_HASH *color_hash; |
|---|
| 219 | MO_Liste *BaktList; |
|---|
| 220 | MO_Liste *Auswahllist; |
|---|
| 221 | |
|---|
| 222 | public: |
|---|
| 223 | probe_tabs* fill_Stat_Arrays(); |
|---|
| 224 | double** gen_Mergefeld(); |
|---|
| 225 | void put_Sonde(char *name, int allowed_mis, double outside_mis); |
|---|
| 226 | long get_length_hitliste(); |
|---|
| 227 | void gen_color_hash(positiontype anz_sonden); |
|---|
| 228 | GB_HASH *get_color_hash() { return color_hash; }; |
|---|
| 229 | |
|---|
| 230 | Sondentopf(MO_Liste *BL, MO_Liste *AL); |
|---|
| 231 | ~Sondentopf(); |
|---|
| 232 | }; |
|---|
| 233 | |
|---|
| 234 | class Sonde : virtual Noncopyable { |
|---|
| 235 | char* kennung; // Nukleinsaeuren, z.B. "atgatgatg" |
|---|
| 236 | Bitvector* bitkennung; // Sonde 1 Platz eins, ...zwei..., ... Analog zum Aufbau der Listenliste |
|---|
| 237 | Hit **hitliste; // start bei index 0, letztes element enthaelt NULL |
|---|
| 238 | long length_hitliste; |
|---|
| 239 | long minelem; |
|---|
| 240 | long maxelem; |
|---|
| 241 | positiontype kombi_far, kombi_mor; |
|---|
| 242 | long *Allowed_Mismatch; |
|---|
| 243 | double *Outside_Mismatch; |
|---|
| 244 | |
|---|
| 245 | public: |
|---|
| 246 | double get_Allowed_Mismatch_no(int no) { return ((Allowed_Mismatch) ? Allowed_Mismatch[no] : 100); }; |
|---|
| 247 | double get_Outside_Mismatch_no(int no) { return ((Outside_Mismatch) ? Outside_Mismatch[no] : 100); }; |
|---|
| 248 | char* get_name() { return kennung; }; |
|---|
| 249 | Hit* get_hitdata_by_number(long index); |
|---|
| 250 | Hit** get_Hitliste() { return hitliste; }; |
|---|
| 251 | long get_length_hitliste() { return length_hitliste; }; |
|---|
| 252 | long get_minelem() { return minelem; }; |
|---|
| 253 | long get_maxelem() { return maxelem; }; |
|---|
| 254 | positiontype get_far() { return kombi_far; }; |
|---|
| 255 | positiontype get_mor() { return kombi_mor; }; |
|---|
| 256 | Bitvector* get_bitkennung() { return bitkennung; }; |
|---|
| 257 | |
|---|
| 258 | void set_Allowed_Mismatch_no(int pos, int no) { Allowed_Mismatch[pos] = no; }; |
|---|
| 259 | void set_Outside_Mismatch_no(int pos, int no) { Outside_Mismatch[pos] = no; }; |
|---|
| 260 | void set_bitkennung(Bitvector* bv); // Setzt eine Leere Bitkennung der laenge bits |
|---|
| 261 | void set_name(char* name) { kennung = strdup(name); }; |
|---|
| 262 | void set_Hitliste(Hit** hitptr) { hitliste = hitptr; }; |
|---|
| 263 | void set_length_hitliste(long lhl) { length_hitliste = lhl; }; |
|---|
| 264 | void set_minelem(long min) { minelem = min; }; |
|---|
| 265 | void set_maxelem(long max) { maxelem = max; }; |
|---|
| 266 | void set_far(positiontype far) { kombi_far = far; }; |
|---|
| 267 | void set_mor(positiontype mor) { kombi_mor = mor; }; |
|---|
| 268 | |
|---|
| 269 | void print(); |
|---|
| 270 | void sink(long i, long t, MO_Mismatch** A); |
|---|
| 271 | void heapsort(long feldlaenge, MO_Mismatch** Nr_Mm_Feld); |
|---|
| 272 | double check_for_min(long k, MO_Mismatch** probebacts, long laenge); |
|---|
| 273 | |
|---|
| 274 | MO_Mismatch** get_matching_species(bool match_kompl, |
|---|
| 275 | int match_weight, |
|---|
| 276 | int match_mis, |
|---|
| 277 | char *match_seq, |
|---|
| 278 | MO_Liste *convert, |
|---|
| 279 | long *number_of_species); |
|---|
| 280 | int gen_Hitliste(MO_Liste *Bakterienliste); |
|---|
| 281 | |
|---|
| 282 | Sonde(char* bezeichner, int allowed_mis, double outside_mis); |
|---|
| 283 | ~Sonde(); |
|---|
| 284 | }; |
|---|
| 285 | // ##################################### Sondentopf Container ########################### |
|---|
| 286 | |
|---|
| 287 | struct ST_Container : virtual Noncopyable { |
|---|
| 288 | MO_Liste *Bakterienliste; |
|---|
| 289 | MO_Liste *Auswahlliste; |
|---|
| 290 | Sondentopf *sondentopf; // Wird einmal eine Sondentopfliste |
|---|
| 291 | List<Sondentopf> *ST_Liste; |
|---|
| 292 | int anzahl_basissonden; |
|---|
| 293 | GB_HASH* cachehash; |
|---|
| 294 | List<char> *Sondennamen; |
|---|
| 295 | |
|---|
| 296 | Sonde* cache_Sonde(char *name, int allowed_mis, double outside_mis); |
|---|
| 297 | Sonde* get_cached_sonde(char* name); |
|---|
| 298 | ST_Container(int anz_sonden); |
|---|
| 299 | ~ST_Container(); |
|---|
| 300 | }; |
|---|
| 301 | |
|---|
| 302 | // ##################################### MO_Liste ##################################### |
|---|
| 303 | /* Die Namen werden in die Hashtabelle mit fortlaufender Nummer abgespeichert |
|---|
| 304 | * Die Nummer bezeichnet das Feld in einem Array, indem momentan der B.-Name steht, |
|---|
| 305 | * spaeter |
|---|
| 306 | * aber auch z.B. ein Pointer auf eine Klasse mit mehr Informationen stehen kann |
|---|
| 307 | ACHTUNG:: Es kann passieren, dass eine Sonde mehrmals an einen Bakter bindet. Dann wird der Bakter nur einmal in die |
|---|
| 308 | Liste eingetragen, und damit ist die laenge nicht mehr aussagekraeftig. current-1 enthaelt das letzte element der liste, die |
|---|
| 309 | Liste beginnt bei 1 |
|---|
| 310 | */ |
|---|
| 311 | |
|---|
| 312 | class MO_Liste : virtual Noncopyable { |
|---|
| 313 | Bakt_Info** mo_liste; |
|---|
| 314 | long laenge; |
|---|
| 315 | long current; // zeigt auf den ersten freien eintrag |
|---|
| 316 | GB_HASH* hashptr; |
|---|
| 317 | |
|---|
| 318 | static GBDATA *gb_main; |
|---|
| 319 | |
|---|
| 320 | public: |
|---|
| 321 | positiontype fill_marked_bakts(); |
|---|
| 322 | void get_all_species(); |
|---|
| 323 | long debug_get_current(); |
|---|
| 324 | long get_laenge(); |
|---|
| 325 | long put_entry(const char* name); |
|---|
| 326 | char* get_entry_by_index(long index); |
|---|
| 327 | long get_index_by_entry(const char* key); |
|---|
| 328 | Bakt_Info* get_bakt_info_by_index(long index); |
|---|
| 329 | |
|---|
| 330 | Bakt_Info** get_mo_liste() { return mo_liste; } |
|---|
| 331 | |
|---|
| 332 | static void set_gb_main(GBDATA *gb_main_) { |
|---|
| 333 | mp_assert(implicated(gb_main, gb_main == gb_main_)); |
|---|
| 334 | gb_main = gb_main_; |
|---|
| 335 | } |
|---|
| 336 | |
|---|
| 337 | MO_Liste(); |
|---|
| 338 | ~MO_Liste(); |
|---|
| 339 | }; |
|---|
| 340 | |
|---|
| 341 | |
|---|
| 342 | class Bitvector : virtual Noncopyable { |
|---|
| 343 | // Bitpositionen sind 0 bis 7 |
|---|
| 344 | char* vector; |
|---|
| 345 | int len; |
|---|
| 346 | int num_of_bits; |
|---|
| 347 | public: |
|---|
| 348 | int gen_id(); |
|---|
| 349 | Bitvector* merge(Bitvector* x); |
|---|
| 350 | int subset(Bitvector* Obermenge); |
|---|
| 351 | int readbit(int pos); |
|---|
| 352 | int setbit(int pos); |
|---|
| 353 | int delbit(int pos); |
|---|
| 354 | void rshift(); |
|---|
| 355 | void print(); |
|---|
| 356 | |
|---|
| 357 | char* get_vector() { return vector; }; |
|---|
| 358 | int get_num_of_bits() { return num_of_bits; }; |
|---|
| 359 | int get_len() { return len; }; |
|---|
| 360 | |
|---|
| 361 | void set_vector(char* back) { vector = back; }; |
|---|
| 362 | |
|---|
| 363 | Bitvector(int bits); |
|---|
| 364 | ~Bitvector(); |
|---|
| 365 | }; |
|---|
| 366 | |
|---|
| 367 | #else |
|---|
| 368 | #error MultiProbe.hxx included twice |
|---|
| 369 | #endif // MULTIPROBE_HXX |
|---|