ARB
MP_sondentopf.cxx
Go to the documentation of this file.
1 // ============================================================= //
2 // //
3 // File : MP_sondentopf.cxx //
4 // Purpose : //
5 // //
6 // Institute of Microbiology (Technical University Munich) //
7 // http://www.arb-home.de/ //
8 // //
9 // ============================================================= //
10 
11 #include "MultiProbe.hxx"
12 #include "MP_probe.hxx"
13 
14 #include <AP_TreeColors.hxx>
15 #include <aw_msg.hxx>
16 #include <arbdbt.h>
17 
18 #include <cmath>
19 
20 ST_Container::ST_Container(int anz_sonden) {
21  long laenge_markierte;
22 
23  Sondennamen = new List<char>;
24 
25  Auswahlliste = new MO_Liste;
27 
29 
30  if (pt_server_different) return;
31  laenge_markierte = Auswahlliste->fill_marked_bakts();
32 
33  anz_elem_unmarked = Bakterienliste->debug_get_current()-1 - laenge_markierte;
34  // STATISTIK
35 
36  anzahl_basissonden = anz_sonden;
37 
39  // hashlaenge darf nicht 0 sein, groesser schadet nicht
40 
42  // Momentan wird auf diesem sondentopf gearbeitet
43 }
44 
45 
47  char* Sname;
48  Sonde* csonde;
49 
50  delete Bakterienliste;
51  delete Auswahlliste;
52  delete sondentopf;
53 
54  Sname = Sondennamen->get_first();
55  while (Sname) {
56  csonde = get_cached_sonde(Sname);
57  delete csonde;
58  free(Sname);
60  Sname = Sondennamen->get_first();
61  }
62 
63  delete Sondennamen;
65 }
66 
67 
68 
69 Sonde* ST_Container::cache_Sonde(char *name, int allowed_mis, double outside_mis) {
70  char* name_for_plist = ARB_strdup(name);
71  Sonde* s = new Sonde(name, allowed_mis, outside_mis);
72 
73  Sondennamen->insert_as_first(name_for_plist);
75 
76  GBS_write_hash(cachehash, name, (long) s);
77  // Reine Sonde plus Hitliste geschrieben, der Zeiger auf die Sonde liegt als long gecastet im Hash
78  return s;
79 }
80 
82  return name ? (Sonde*)GBS_read_hash(cachehash, name) : NULp;
83 }
84 
85 // ############################################################################################
86 /*
87  Zu jeder Kombination von Mehrfachsonden gehoert ein Sondentopf. Dieser enthaelt eine Liste mit
88  Sonden und eine Liste mit Kombinationen aus diesen Sonden. Die Kombinationen entstehen aus den
89  Sonden und/oder aus Kombinationen durch Verknuepfung mit der Methode Probe_AND.
90 */
91 // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~Methoden SONDENTOPF ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
92 
94  // @@@ use assertions here?
95  if (!BL) GBK_terminate("List of species is empty");
96  if (!AL) GBK_terminate("List of marked species is empty");
97 
98  Listenliste = new List<void*>;
99  color_hash = GBS_create_hash(BL->get_laenge()*1.25+1, GB_IGNORE_CASE);
100 
101  BaktList = BL;
102  Auswahllist = AL;
103 
104  Listenliste->insert_as_last((void**) new List<Sonde>);
105 }
106 
107 
108 
110  // darf nur delete auf die listenliste machen, nicht auf die MO_Lists, da die zu dem ST_Container gehoeren
111  Sonde *stmp = NULp;
112 
113  List<Sonde> *ltmp = LIST(Listenliste->get_first());
114  if (ltmp) {
115  stmp = ltmp->get_first();
116  }
117  while (ltmp) {
118  while (stmp) {
119  ltmp->remove_first();
120  stmp = ltmp->get_first();
121  }
122  Listenliste->remove_first();
123  delete ltmp;
124  ltmp = LIST(Listenliste->get_first());
125  }
126 
127  delete Listenliste;
128  GBS_free_hash(color_hash);
129 }
130 
131 
132 
133 void Sondentopf::put_Sonde(char *name, int allowed_mis, double outside_mis) {
134  if (!name) GBK_terminate("No name specified for species");
135 
136  positiontype pos;
137  ST_Container *stc = mp_main->get_stc();
138  List<Sonde> *Sondenliste = LIST(Listenliste->get_first());
139  Sonde *s;
140  int i = 0;
141 
142  if (!Sondenliste) {
143  Sondenliste = new List<Sonde>;
144  Listenliste->insert_as_last((void**) Sondenliste);
145  }
146 
147  s = stc->get_cached_sonde(name);
148  if (!s) {
149  s = stc->cache_Sonde(name, allowed_mis, outside_mis);
150  }
151  pos = Sondenliste->insert_as_last(s);
152  if (! s->get_bitkennung())
153  s->set_bitkennung(new Bitvector(((int) pos)));
154  s->set_far(0);
155  s->set_mor(pos);
156  s->get_bitkennung()->setbit(pos-1);
157  // im cache steht die Mismatch info noch an Stelle 0. Hier muss sie an Stelle pos verschoben werden
158  if (pos!=0)
159  for (i=0; i<s->get_length_hitliste(); i++)
160  if (s->get_hitdata_by_number(i))
161  s->get_hitdata_by_number(i)->set_mismatch_at_pos(pos, s->get_hitdata_by_number(i)->get_mismatch_at_pos(0));
162 }
163 
164 
166  // Zaehler
167  int i, j;
168 
169  Sonde* sonde;
170 
171  List<Sonde>* Sondenliste = LIST(Listenliste->get_first());
172  long alle_bakterien = BaktList->debug_get_current()-1;
173  long H_laenge, sondennummer;
174  double** Mergefeld = new double*[alle_bakterien+1];
175 
176  for (i=0; i<alle_bakterien+1; i++) {
177  Mergefeld[i] = new double[mp_gl_awars.no_of_probes];
178  for (j=0; j<mp_gl_awars.no_of_probes; j++) { // LOOP_VECTORIZED
179  Mergefeld[i][j] = 100;
180  }
181  }
182 
183  sondennummer=0;
184  sonde = Sondenliste->get_first();
185  while (sonde) {
186  H_laenge = sonde->get_length_hitliste();
187  for (i=0; i<H_laenge; i++) {
188  Mergefeld[sonde->get_hitdata_by_number(i)->get_baktid()][sondennummer] =
190  }
191 
192  sondennummer++;
193  sonde = Sondenliste->get_next();
194  }
195 
196  return Mergefeld;
197 }
198 
200  // erstmal generische Felder
201  List<Sonde>* Sondenliste = LIST(Listenliste->get_first());
202  long feldlen = (long) pow(3.0, (int)(mp_gl_awars.no_of_probes));
203  int* markierte = new int[feldlen]; // MEL
204  int* unmarkierte = new int[feldlen]; // MEL
205  int i=0, j=0;
206  long alle_bakterien = BaktList->debug_get_current()-1;
207  double** Mergefeld;
208  int* AllowedMismatchFeld = new int[mp_gl_awars.no_of_probes];
209  Sonde* sonde;
210 
211  sonde = Sondenliste->get_first();
212  for (i=0; i<mp_gl_awars.no_of_probes; i++) {
213  AllowedMismatchFeld[i] = (int) sonde->get_Allowed_Mismatch_no(0);
214  sonde = Sondenliste->get_next();
215  }
216 
217 
218  for (i=0; i<feldlen; i++) { // LOOP_VECTORIZED[!>=5]
219  markierte[i] = 0;
220  unmarkierte[i] = 0;
221  }
222 
223  int faktor=0;
224  Mergefeld = gen_Mergefeld();
225 
226 
227  for (i=0; i < alle_bakterien+1; i++) {
228  if (BaktList->get_entry_by_index(i)) {
229  long wertigkeit = 0;
230  for (j=0; j<mp_gl_awars.no_of_probes; j++) {
231  if (Mergefeld[i][j] <= ((double) AllowedMismatchFeld[j] + (double) mp_gl_awars.greyzone)) {
232  faktor = 0;
233  }
234  else if (Mergefeld[i][j] <= ((double) AllowedMismatchFeld[j] +
235  (double) mp_gl_awars.greyzone +
237  {
238  faktor = 1;
239  }
240  else {
241  faktor = 2;
242  }
243 
244  wertigkeit += faktor * (long) pow(3, j);
245  }
246 
247  if (Auswahllist->get_index_by_entry(BaktList->get_entry_by_index(i))) {
248  markierte[wertigkeit]++;
249  }
250  else {
251  unmarkierte[wertigkeit]++;
252  }
253  }
254  }
255 
256  for (i=0; i<alle_bakterien+1; i++) {
257  delete [] Mergefeld[i];
258  }
259  delete [] Mergefeld;
260  delete [] AllowedMismatchFeld;
261  probe_tabs *pt = new probe_tabs(markierte, unmarkierte, feldlen); // MEL (sollte bei Andrej passieren
262  return pt;
263 }
264 
265 
267  if (!anz_sonden) return;
268 
269  List<Sonde>* Sondenliste = LIST(Listenliste->get_first());
270  double** Mergefeld;
271  long alle_bakterien = BaktList->debug_get_current() -1;
272  int* AllowedMismatchFeld = new int[mp_gl_awars.no_of_probes]; // MEL
273  int* rgb = new int[3]; // MEL
274  Sonde* sonde;
275  int i=0, j=0;
276 
277  sonde = Sondenliste->get_first();
278  for (i=0; i<mp_gl_awars.no_of_probes; i++) {
279  AllowedMismatchFeld[i] = (int) sonde->get_Allowed_Mismatch_no(0);
280  sonde = Sondenliste->get_next();
281  }
282 
283 
284  Mergefeld = gen_Mergefeld();
285 
286 
287  for (i=1; i < alle_bakterien+1; i++) {
288  rgb[0]=0; rgb[1]=0; rgb[2]=0;
289 
290  for (j=0; j<mp_gl_awars.no_of_probes; j++) {
291  if (Mergefeld[i][j] <= ((double) AllowedMismatchFeld[j] + (double) mp_gl_awars.greyzone + mp_gl_awars.outside_mismatches_difference)) {
292  rgb[j%3]++;
293  }
294  }
295 
296  int color = 0;
297 
298  if (!rgb[0] && !rgb[1] && !rgb[2]) { color = AWT_GC_BLACK; }
299  else if ( rgb[0] && !rgb[1] && !rgb[2]) { color = AWT_GC_RED; }
300  else if (!rgb[0] && rgb[1] && !rgb[2]) { color = AWT_GC_GREEN; }
301  else if (!rgb[0] && !rgb[1] && rgb[2]) { color = AWT_GC_BLUE; }
302  else if ( rgb[0] && rgb[1] && !rgb[2]) { color = AWT_GC_YELLOW; }
303  else if ( rgb[0] && !rgb[1] && rgb[2]) { color = AWT_GC_MAGENTA; }
304  else if (!rgb[0] && rgb[1] && rgb[2]) { color = AWT_GC_CYAN; }
305  else if ( rgb[0] && rgb[1] && rgb[2]) { color = AWT_GC_WHITE; }
306  else {
307  GBK_terminate("logic error: should never be reached");
308  }
309 
310  GBS_write_hash(color_hash, BaktList->get_entry_by_index(i), (long)color);
311  }
312 
313  for (i=0; i<alle_bakterien+1; i++)
314  delete [] Mergefeld[i];
315  delete [] Mergefeld;
316 
317 
318  delete [] AllowedMismatchFeld;
319  delete [] rgb;
320 }
321 
Hit * get_hitdata_by_number(long index)
Definition: MP_sonde.cxx:263
bool pt_server_different
Definition: MP_main.cxx:29
positiontype insert_as_last(Type *object)
Definition: SoTl.hxx:433
long debug_get_current()
GB_HASH * cachehash
Definition: MultiProbe.hxx:289
long GBS_write_hash(GB_HASH *hs, const char *key, long val)
Definition: adhash.cxx:457
long get_length_hitliste()
Definition: MultiProbe.hxx:247
long get_laenge()
long
Definition: AW_awar.cxx:154
double get_mismatch_at_pos(int pos)
Definition: MultiProbe.hxx:203
char * ARB_strdup(const char *str)
Definition: arb_string.h:27
#define LIST(TYP)
Definition: MultiProbe.hxx:82
void GBS_free_hash(GB_HASH *hs)
Definition: adhash.cxx:541
void remove_first()
Definition: SoTl.hxx:584
MP_Main * mp_main
Definition: MP_main.cxx:24
Sonde * get_cached_sonde(char *name)
Type * get_next()
Definition: SoTl.hxx:385
positiontype fill_marked_bakts()
Sondentopf * sondentopf
Definition: MultiProbe.hxx:286
MO_Liste * Auswahlliste
Definition: MultiProbe.hxx:285
void GBK_terminate(const char *error) __ATTR__NORETURN
Definition: arb_msg.cxx:463
probe_tabs * fill_Stat_Arrays()
double get_Allowed_Mismatch_no(int no)
Definition: MultiProbe.hxx:242
long get_index_by_entry(const char *key)
unsigned long positiontype
Definition: SoTl.hxx:42
Sonde * cache_Sonde(char *name, int allowed_mis, double outside_mis)
void put_Sonde(char *name, int allowed_mis, double outside_mis)
char * get_entry_by_index(long index)
int gen_Hitliste(MO_Liste *Bakterienliste)
Definition: MP_sonde.cxx:175
Sondentopf(MO_Liste *BL, MO_Liste *AL)
ST_Container(int anz_sonden)
double ** gen_Mergefeld()
float outside_mismatches_difference
Definition: MultiProbe.hxx:92
float greyzone
Definition: MultiProbe.hxx:105
List< char > * Sondennamen
Definition: MultiProbe.hxx:290
Type * get_first()
Definition: SoTl.hxx:335
MO_Liste * Bakterienliste
Definition: MultiProbe.hxx:284
void gen_color_hash(positiontype anz_sonden)
#define NULp
Definition: cxxforward.h:97
long no_of_probes
Definition: MultiProbe.hxx:96
long get_baktid()
Definition: MultiProbe.hxx:201
awar_vars mp_gl_awars
Definition: MP_main.cxx:23
ST_Container * get_stc()
Definition: MultiProbe.hxx:147
void get_all_species()
Definition: MP_mo_liste.cxx:42
long GBS_read_hash(const GB_HASH *hs, const char *key)
Definition: adhash.cxx:395
int anz_elem_unmarked
Definition: MP_main.cxx:28
positiontype insert_as_first(Type *object)
Definition: SoTl.hxx:413
GB_HASH * GBS_create_hash(long estimated_elements, GB_CASE case_sens)
Definition: adhash.cxx:253
int anzahl_basissonden
Definition: MultiProbe.hxx:288
GB_write_int const char s
Definition: AW_awar.cxx:156