5 * Created by Sarah Westcott on 3/25/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
12 //**********************************************************************************************************************
13 HeatMap::HeatMap(string sort, string scale, int num, int fsize, string dir, string i){
15 m = MothurOut::getInstance();
16 // format = globaldata->getFormat();
25 m->errorOut(e, "HeatMap", "HeatMap");
30 //**********************************************************************************************************************
32 string HeatMap::getPic(RAbundVector* rabund) {
35 int numBinsToDisplay = rabund->getNumBins();
37 if (numOTU != 0) { //user want to display a portion of the otus
38 if (numOTU < numBinsToDisplay) { numBinsToDisplay = numOTU; }
41 //sort lookup so shared bins are on top
42 if (sorted != "none") { sortRabund(rabund); }
44 float maxRelAbund = 0.0;
46 for(int i=0;i<rabund->size();i++){
47 float relAbund = rabund->get(i) / (float)rabund->getNumSeqs();
48 if(relAbund > maxRelAbund){ maxRelAbund = relAbund; }
51 vector<string> scaleRelAbund(numBinsToDisplay, "");
53 for(int i=0;i<numBinsToDisplay;i++){
54 float relAbund = rabund->get(i) / (float)rabund->getNumSeqs();
56 if (m->control_pressed) { return "control"; }
58 if (rabund->get(i) != 0) { //don't want log value of 0.
59 if (scaler == "log10") {
60 scaleRelAbund[i] = toHex(int(255 * log10(relAbund) / log10(maxRelAbund))) + "0000";
61 }else if (scaler == "log2") {
62 scaleRelAbund[i] = toHex(int(255 * log2(relAbund) / log2(maxRelAbund))) + "0000";
63 }else if (scaler == "linear") {
64 scaleRelAbund[i] = toHex(int(255 * relAbund / maxRelAbund)) + "0000";
65 }else { //if user enters invalid scaler option.
66 scaleRelAbund[i] = toHex(int(255 * log10(relAbund / log10(maxRelAbund)))) + "0000";
69 else { scaleRelAbund[i] = "FFFFFF"; }
73 string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + rabund->getLabel() + ".heatmap.bin.svg";
74 m->openOutputFile(filenamesvg, outsvg);
77 outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString(300) + " " + toString((numBinsToDisplay*5 + 120)) + "\">\n";
81 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(300) + "\" height=\"" + toString((numBinsToDisplay*5 + 120)) + "\"/>";
82 outsvg << "<text fill=\"black\" class=\"seri\" text-anchor=\"middle\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString((150) - 40) + "\" y=\"25\">Heatmap at distance " + rabund->getLabel() + "</text>\n";
84 //output legend and color labels
87 int y = 103 + (numBinsToDisplay*5);
88 printLegend(y, maxRelAbund);
92 for (int i = 0; i < scaleRelAbund.size(); i++) {
93 if (m->control_pressed) { outsvg.close(); return "control"; }
95 outsvg << "<rect fill=\"#" + scaleRelAbund[i] + "\" stroke=\"#" + scaleRelAbund[i] + "\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\" width=\"300\" height=\"5\"/>\n";
99 outsvg << "</g>\n</svg>\n";
104 catch(exception& e) {
105 m->errorOut(e, "HeatMap", "getPic");
110 //**********************************************************************************************************************
112 string HeatMap::getPic(vector<SharedRAbundVector*> lookup) {
115 int numBinsToDisplay = lookup[0]->size();
117 if (numOTU != 0) { //user want to display a portion of the otus
118 if (numOTU < numBinsToDisplay) { numBinsToDisplay = numOTU; }
121 //sort lookup so shared bins are on top
122 vector<string> sortedLabels = m->currentSharedBinLabels;
123 if (sorted != "none") { sortedLabels = sortSharedVectors(lookup); }
125 vector<vector<string> > scaleRelAbund;
126 vector<float> maxRelAbund(lookup[0]->size(), 0.0);
127 float superMaxRelAbund = 0;
129 for(int i = 0; i < lookup.size(); i++){
130 for(int j=0; j<lookup[i]->size(); j++){
132 float relAbund = lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs();
133 if(relAbund > maxRelAbund[i]){ maxRelAbund[i] = relAbund; }
135 if(maxRelAbund[i] > superMaxRelAbund){ superMaxRelAbund = maxRelAbund[i]; }
138 scaleRelAbund.resize(lookup.size());
139 for(int i=0;i<lookup.size();i++){
140 scaleRelAbund[i].assign(numBinsToDisplay, "");
141 for(int j=0;j<numBinsToDisplay;j++){
142 if (m->control_pressed) { return "control"; }
143 float relAbund = lookup[i]->getAbundance(j) / (float)lookup[i]->getNumSeqs();
145 if (lookup[i]->getAbundance(j) != 0) { //don't want log value of 0.
146 if (scaler == "log10") {
147 scaleRelAbund[i][j] = toHex(int(255 * log10(relAbund) / log10(maxRelAbund[i]))) + "0000";
148 }else if (scaler == "log2") {
149 scaleRelAbund[i][j] = toHex(int(255 * log2(relAbund) / log2(maxRelAbund[i]))) + "0000";
150 }else if (scaler == "linear") {
151 scaleRelAbund[i][j] = toHex(int(255 * relAbund / maxRelAbund[i])) + "0000";
152 }else { //if user enters invalid scaler option.
153 scaleRelAbund[i][j] = toHex(int(255 * log10(relAbund / log10(maxRelAbund[i])))) + "0000";
155 }else { scaleRelAbund[i][j] = "FFFFFF"; }
160 string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + ".heatmap.bin.svg";
161 m->openOutputFile(filenamesvg, outsvg);
167 outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString(lookup.size() * binWidth + labelBump) + " " + toString((numBinsToDisplay*binHeight + 120)) + "\">\n";
171 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(lookup.size() * binWidth+labelBump) + "\" height=\"" + toString((numBinsToDisplay*binHeight + 120)) + "\"/>";
172 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" text-anchor=\"middle\" x=\"" + toString((lookup.size() * 150) - 40) + "\" y=\"25\">Heatmap at distance " + lookup[0]->getLabel() + "</text>\n";
175 for (int h = 0; h < lookup.size()+1; h++) {
177 string tempLabel = "OTU";
178 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(labelBump-labelBump/2+1) + "\" y=\"50\">" + tempLabel + "</text>\n";
180 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(((binWidth * h) - 150) - ((int)lookup[h-1]->getGroup().length() / 2)+labelBump/2) + "\" y=\"50\">" + lookup[h-1]->getGroup() + "</text>\n";
184 //output legend and color labels
187 int y = 103 + (numBinsToDisplay*binHeight);
188 printLegend(y, superMaxRelAbund);
191 for (int i = 0; i < numBinsToDisplay; i++) {
192 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\">" + sortedLabels[i] + "</text>\n";
194 for (int j = 0; j < scaleRelAbund.size(); j++) {
195 if (m->control_pressed) { outsvg.close(); return "control"; }
197 outsvg << "<rect fill=\"#" + scaleRelAbund[j][i] + "\" stroke=\"#" + scaleRelAbund[j][i] + "\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\" width=\"" + toString(binWidth) + "\" height=\"" + toString(binHeight) + "\"/>\n";
204 outsvg << "</g>\n</svg>\n";
210 catch(exception& e) {
211 m->errorOut(e, "HeatMap", "getPic");
216 //**********************************************************************************************************************
217 vector<string> HeatMap::sortSharedVectors(vector<SharedRAbundVector*>& lookup){
220 vector<SharedRAbundVector*> looktemp;
221 map<int, int> place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2.
222 map<int, int>::iterator it;
224 vector<string> sortedLabels = m->currentSharedBinLabels;
226 /****************** find order of otus **********************/
227 if (sorted == "shared") {
228 place = orderShared(lookup);
229 }else if (sorted == "topotu") {
230 place = orderTopOtu(lookup);
231 }else if (sorted == "topgroup") {
232 place = orderTopGroup(lookup);
233 }else { m->mothurOut("Error: invalid sort option."); m->mothurOutEndLine(); return sortedLabels; }
236 /******************* create copy of lookup *********************/
237 //create and initialize looktemp as a copy of lookup
238 for (int i = 0; i < lookup.size(); i++) {
239 SharedRAbundVector* temp = new SharedRAbundVector(lookup[i]->getNumBins());
240 temp->setLabel(lookup[i]->getLabel());
241 temp->setGroup(lookup[i]->getGroup());
242 //copy lookup i's info
243 for (int j = 0; j < lookup[i]->size(); j++) {
244 temp->set(j, lookup[i]->getAbundance(j), lookup[i]->getGroup());
246 looktemp.push_back(temp);
249 /************************ fill lookup in order given by place *********************/
251 for (int i = 0; i < looktemp[0]->size(); i++) { //place
252 //fill lookup // 2 -> 1
253 for (int j = 0; j < looktemp.size(); j++) { // 3 -> 2
254 int newAbund = looktemp[j]->getAbundance(i); // 1 -> 3
255 lookup[j]->set(place[i], newAbund, looktemp[j]->getGroup()); //binNumber, abundance, group
257 sortedLabels[place[i]] = m->currentSharedBinLabels[i];
260 //delete looktemp -- Sarah look at - this is causing segmentation faults
261 for (int j = 0; j < looktemp.size(); j++) {
262 // delete looktemp[j];
268 catch(exception& e) {
269 m->errorOut(e, "HeatMap", "sortSharedVectors");
273 //**********************************************************************************************************************
274 map<int, int> HeatMap::orderShared(vector<SharedRAbundVector*>& lookup){
277 map<int, int> place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2.
278 map<int, int>::iterator it;
280 vector<int> sharedBins;
281 vector<int> uniqueBins;
284 for (int i = 0; i < lookup[0]->size(); i++) {
288 for (int j = 0; j < lookup.size(); j++) { if (lookup[j]->getAbundance(i) != 0) { count++; } }
290 if (count < 2) { uniqueBins.push_back(i); }
291 else { sharedBins.push_back(i); }
295 for (int i = 0; i < sharedBins.size(); i++) { place[sharedBins[i]] = i; }
296 for (int i = 0; i < uniqueBins.size(); i++) { place[uniqueBins[i]] = (sharedBins.size() + i); }
301 catch(exception& e) {
302 m->errorOut(e, "HeatMap", "orderShared");
306 //**********************************************************************************************************************
307 map<int, int> HeatMap::orderTopOtu(vector<SharedRAbundVector*>& lookup){
310 map<int, int> place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2.
311 map<int, int>::iterator it;
313 vector<binCount> totals;
316 for (int i = 0; i < lookup[0]->size(); i++) {
319 for (int j = 0; j < lookup.size(); j++) { total += lookup[j]->getAbundance(i); }
321 binCount temp(i, total);
323 totals.push_back(temp);
326 sort(totals.begin(), totals.end(), comparebinCounts);
329 for (int i = 0; i < totals.size(); i++) { place[totals[i].bin] = i; }
334 catch(exception& e) {
335 m->errorOut(e, "HeatMap", "orderTopOtu");
339 //**********************************************************************************************************************
340 map<int, int> HeatMap::orderTopGroup(vector<SharedRAbundVector*>& lookup){
343 map<int, int> place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2.
344 map<int, int>::iterator it;
346 vector < vector<binCount> > totals; //totals[0] = bin totals for group 0, totals[1] = bin totals for group 1, ...
347 totals.resize(lookup.size());
350 for (int i = 0; i < lookup[0]->size(); i++) {
351 for (int j = 0; j < lookup.size(); j++) {
352 binCount temp(i, (lookup[j]->getAbundance(i)));
353 totals[j].push_back(temp);
357 for (int i = 0; i < totals.size(); i++) { sort(totals[i].begin(), totals[i].end(), comparebinCounts); }
360 //grab the top otu for each group adding it if its not already added
362 for (int i = 0; i < totals[0].size(); i++) {
364 for (int j = 0; j < totals.size(); j++) {
365 it = place.find(totals[j][i].bin);
367 if (it == place.end()) { //not added yet
368 place[totals[j][i].bin] = count;
377 catch(exception& e) {
378 m->errorOut(e, "HeatMap", "orderTopGroup");
382 //**********************************************************************************************************************
384 void HeatMap::printLegend(int y, float maxbin) {
387 //output legend and color labels
388 //go through map and give each score a color value
393 for (int i = 1; i < 255; i++) {
394 color = toHex(int((float)(i)));
395 outsvg << "<rect fill=\"#" + color + "0000\" stroke=\"#" + color + "0000\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\" width=\"1\" height=\"10\"/>\n";
399 //prints legend labels
401 for (int i = 1; i<=5; i++) {
403 if(scaler== "log10") { label = maxbin * log10(51*i) / log10(255); }
404 else if(scaler== "log2") { label = maxbin * log2(51*i) / log2(255); }
405 else if(scaler== "linear") { label = maxbin * 51 * i / 255; }
406 else { label = maxbin * log10(51*i) / log10(255); }
407 label = int(label * 1000 + 0.5);
409 string text = toString(label, 3);
411 outsvg << "<text fill=\"black\" class=\"seri\" x=\"" + toString(x) + "\" y=\"" + toString(y-3) + "\">" + text + "</text>\n";
416 catch(exception& e) {
417 m->errorOut(e, "HeatMap", "printLegend");
421 //**********************************************************************************************************************
423 string HeatMap::getPic(vector<SharedRAbundFloatVector*> lookup) {
426 int numBinsToDisplay = lookup[0]->size();
428 if (numOTU != 0) { //user want to display a portion of the otus
429 if (numOTU < numBinsToDisplay) { numBinsToDisplay = numOTU; }
432 //sort lookup so shared bins are on top
433 vector<string> sortedLabels = m->currentSharedBinLabels;
434 if (sorted != "none") { sortedLabels = sortSharedVectors(lookup); }
436 vector<vector<string> > scaleRelAbund;
437 vector<float> maxRelAbund(lookup.size(), 0.0);
438 float superMaxRelAbund = 0;
440 for(int i = 0; i < lookup.size(); i++){
441 for(int j=0; j<lookup[i]->size(); j++){
443 float relAbund = lookup[i]->getAbundance(j);
444 if(relAbund > maxRelAbund[i]){ maxRelAbund[i] = relAbund; }
446 if(maxRelAbund[i] > superMaxRelAbund){ superMaxRelAbund = maxRelAbund[i]; }
449 scaleRelAbund.resize(lookup.size());
450 for(int i=0;i<lookup.size();i++){
451 scaleRelAbund[i].assign(numBinsToDisplay, "");
452 for(int j=0;j<numBinsToDisplay;j++){
453 if (m->control_pressed) { return "control"; }
454 float relAbund = lookup[i]->getAbundance(j);
456 if (lookup[i]->getAbundance(j) != 0) { //don't want log value of 0.
457 if (scaler == "log10") {
458 scaleRelAbund[i][j] = toHex(int(255 * log10(relAbund) / log10(maxRelAbund[i]))) + "0000";
459 }else if (scaler == "log2") {
460 scaleRelAbund[i][j] = toHex(int(255 * log2(relAbund) / log2(maxRelAbund[i]))) + "0000";
461 }else if (scaler == "linear") {
462 scaleRelAbund[i][j] = toHex(int(255 * relAbund / maxRelAbund[i])) + "0000";
463 }else { //if user enters invalid scaler option.
464 scaleRelAbund[i][j] = toHex(int(255 * log10(relAbund / log10(maxRelAbund[i])))) + "0000";
466 }else { scaleRelAbund[i][j] = "FFFFFF"; }
471 string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + ".heatmap.bin.svg";
472 m->openOutputFile(filenamesvg, outsvg);
479 outsvg << "<svg xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString(lookup.size() * binWidth + labelBump) + " " + toString((numBinsToDisplay*binHeight + 120)) + "\">\n";
483 outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(lookup.size() * binWidth+labelBump) + "\" height=\"" + toString((numBinsToDisplay*binHeight + 120)) + "\"/>";
484 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" text-anchor=\"middle\" x=\"" + toString((lookup.size() * 150) - 40) + "\" y=\"25\">Heatmap at distance " + lookup[0]->getLabel() + "</text>\n";
487 for (int h = 0; h < lookup.size()+1; h++) {
489 string tempLabel = "OTU";
490 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(labelBump-labelBump/2+1) + "\" y=\"50\">" + tempLabel + "</text>\n";
492 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(((binWidth * h) - 150) - ((int)lookup[h-1]->getGroup().length() / 2)+labelBump/2) + "\" y=\"50\">" + lookup[h-1]->getGroup() + "</text>\n";
496 //output legend and color labels
499 int y = 103 + (numBinsToDisplay*binHeight);
500 printLegend(y, superMaxRelAbund);
503 for (int i = 0; i < numBinsToDisplay; i++) {
504 outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\">" + sortedLabels[i] + "</text>\n";
506 for (int j = 0; j < scaleRelAbund.size(); j++) {
507 if (m->control_pressed) { outsvg.close(); return "control"; }
509 outsvg << "<rect fill=\"#" + scaleRelAbund[j][i] + "\" stroke=\"#" + scaleRelAbund[j][i] + "\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\" width=\"" + toString(binWidth) + "\" height=\"" + toString(binHeight) + "\"/>\n";
516 outsvg << "</g>\n</svg>\n";
522 catch(exception& e) {
523 m->errorOut(e, "HeatMap", "getPic");
527 //**********************************************************************************************************************
528 vector<string> HeatMap::sortSharedVectors(vector<SharedRAbundFloatVector*>& lookup){
531 vector<SharedRAbundFloatVector*> looktemp;
532 map<int, int> place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2.
533 map<int, int>::iterator it;
535 vector<string> sortedLabels = m->currentSharedBinLabels;
537 /****************** find order of otus **********************/
538 if (sorted == "shared") {
539 place = orderShared(lookup);
540 }else if (sorted == "topotu") {
541 place = orderTopOtu(lookup);
542 }else if (sorted == "topgroup") {
543 place = orderTopGroup(lookup);
544 }else { m->mothurOut("Error: invalid sort option."); m->mothurOutEndLine(); return sortedLabels; }
547 /******************* create copy of lookup *********************/
548 //create and initialize looktemp as a copy of lookup
549 for (int i = 0; i < lookup.size(); i++) {
550 SharedRAbundFloatVector* temp = new SharedRAbundFloatVector(lookup[i]->getNumBins());
551 temp->setLabel(lookup[i]->getLabel());
552 temp->setGroup(lookup[i]->getGroup());
553 //copy lookup i's info
554 for (int j = 0; j < lookup[i]->size(); j++) {
555 temp->set(j, lookup[i]->getAbundance(j), lookup[i]->getGroup());
557 looktemp.push_back(temp);
560 /************************ fill lookup in order given by place *********************/
562 for (int i = 0; i < looktemp[0]->size(); i++) { //place
563 //fill lookup // 2 -> 1
564 for (int j = 0; j < looktemp.size(); j++) { // 3 -> 2
565 float newAbund = looktemp[j]->getAbundance(i); // 1 -> 3
566 lookup[j]->set(place[i], newAbund, looktemp[j]->getGroup()); //binNumber, abundance, group
567 sortedLabels[place[i]] = m->currentSharedBinLabels[i];
571 //delete looktemp -- Sarah look at - this is causing segmentation faults
572 for (int j = 0; j < looktemp.size(); j++) {
573 // delete looktemp[j];
579 catch(exception& e) {
580 m->errorOut(e, "HeatMap", "sortSharedVectors");
584 //**********************************************************************************************************************
585 int HeatMap::sortRabund(RAbundVector*& r){
587 map<int, int> place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2.
588 map<int, int>::iterator it;
590 /****************** find order of otus **********************/
591 vector<binCount> totals;
594 for (int i = 0; i < r->getNumBins(); i++) {
595 binCount temp(i, r->get(i));
597 totals.push_back(temp);
600 sort(totals.begin(), totals.end(), comparebinCounts);
603 for (int i = 0; i < totals.size(); i++) { place[totals[i].bin] = i; }
605 /******************* create copy of lookup *********************/
606 //create and initialize rtemp as a copy of r
608 RAbundVector* rtemp = new RAbundVector(r->getNumBins());
609 for (int i = 0; i < r->size(); i++) { rtemp->set(i, r->get(i)); }
610 rtemp->setLabel(r->getLabel());
612 /************************ fill lookup in order given by place *********************/
614 for (int i = 0; i < rtemp->size(); i++) { //place
615 //fill lookup // 2 -> 1
617 int newAbund = rtemp->get(i); // 1 -> 3
618 r->set(place[i], newAbund); //binNumber, abundance
624 catch(exception& e) {
625 m->errorOut(e, "HeatMap", "sortRabund");
629 //**********************************************************************************************************************
630 map<int, int> HeatMap::orderShared(vector<SharedRAbundFloatVector*>& lookup){
633 map<int, int> place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2.
634 map<int, int>::iterator it;
636 vector<int> sharedBins;
637 vector<int> uniqueBins;
640 for (int i = 0; i < lookup[0]->size(); i++) {
644 for (int j = 0; j < lookup.size(); j++) { if (lookup[j]->getAbundance(i) != 0) { count++; } }
646 if (count < 2) { uniqueBins.push_back(i); }
647 else { sharedBins.push_back(i); }
651 for (int i = 0; i < sharedBins.size(); i++) { place[sharedBins[i]] = i; }
652 for (int i = 0; i < uniqueBins.size(); i++) { place[uniqueBins[i]] = (sharedBins.size() + i); }
657 catch(exception& e) {
658 m->errorOut(e, "HeatMap", "orderShared");
662 //**********************************************************************************************************************
663 map<int, int> HeatMap::orderTopOtu(vector<SharedRAbundFloatVector*>& lookup){
666 map<int, int> place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2.
667 map<int, int>::iterator it;
669 vector<binCountFloat> totals;
672 for (int i = 0; i < lookup[0]->size(); i++) {
675 for (int j = 0; j < lookup.size(); j++) { total += lookup[j]->getAbundance(i); }
677 binCountFloat temp(i, total);
679 totals.push_back(temp);
682 sort(totals.begin(), totals.end(), comparebinFloatCounts);
685 for (int i = 0; i < totals.size(); i++) { place[totals[i].bin] = i; }
690 catch(exception& e) {
691 m->errorOut(e, "HeatMap", "orderTopOtu");
695 //**********************************************************************************************************************
696 map<int, int> HeatMap::orderTopGroup(vector<SharedRAbundFloatVector*>& lookup){
699 map<int, int> place; //spot in lookup where you insert shared by, ie, 3 -> 2 if they are shared by 3 inset into location 2.
700 map<int, int>::iterator it;
702 vector < vector<binCountFloat> > totals; //totals[0] = bin totals for group 0, totals[1] = bin totals for group 1, ...
703 totals.resize(lookup.size());
706 for (int i = 0; i < lookup[0]->size(); i++) {
707 for (int j = 0; j < lookup.size(); j++) {
708 binCountFloat temp(i, (lookup[j]->getAbundance(i)));
709 totals[j].push_back(temp);
713 for (int i = 0; i < totals.size(); i++) { sort(totals[i].begin(), totals[i].end(), comparebinFloatCounts); }
716 //grab the top otu for each group adding it if its not already added
718 for (int i = 0; i < totals[0].size(); i++) {
720 for (int j = 0; j < totals.size(); j++) {
721 it = place.find(totals[j][i].bin);
723 if (it == place.end()) { //not added yet
724 place[totals[j][i].bin] = count;
733 catch(exception& e) {
734 m->errorOut(e, "HeatMap", "orderTopGroup");
738 //**********************************************************************************************************************