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