+ if (numOTU != 0) { //user want to display a portion of the otus
+ if (numOTU < numBinsToDisplay) { numBinsToDisplay = numOTU; }
+ }
+
+ //sort lookup so shared bins are on top
+ vector<string> sortedLabels = m->currentSharedBinLabels;
+ if (sorted != "none") { sortedLabels = sortSharedVectors(lookup); }
+
+ vector<vector<string> > scaleRelAbund;
+ vector<float> maxRelAbund(lookup.size(), 0.0);
+ float superMaxRelAbund = 0;
+
+ for(int i = 0; i < lookup.size(); i++){
+ for(int j=0; j<lookup[i]->size(); j++){
+
+ float relAbund = lookup[i]->getAbundance(j);
+ if(relAbund > maxRelAbund[i]){ maxRelAbund[i] = relAbund; }
+ }
+ if(maxRelAbund[i] > superMaxRelAbund){ superMaxRelAbund = maxRelAbund[i]; }
+ }
+
+ scaleRelAbund.resize(lookup.size());
+ for(int i=0;i<lookup.size();i++){
+ scaleRelAbund[i].assign(numBinsToDisplay, "");
+ for(int j=0;j<numBinsToDisplay;j++){
+ if (m->control_pressed) { return "control"; }
+ float relAbund = lookup[i]->getAbundance(j);
+
+ if (lookup[i]->getAbundance(j) != 0) { //don't want log value of 0.
+ if (scaler == "log10") {
+ scaleRelAbund[i][j] = toHex(int(255 * log10(relAbund) / log10(maxRelAbund[i]))) + "0000";
+ }else if (scaler == "log2") {
+ scaleRelAbund[i][j] = toHex(int(255 * log2(relAbund) / log2(maxRelAbund[i]))) + "0000";
+ }else if (scaler == "linear") {
+ scaleRelAbund[i][j] = toHex(int(255 * relAbund / maxRelAbund[i])) + "0000";
+ }else { //if user enters invalid scaler option.
+ scaleRelAbund[i][j] = toHex(int(255 * log10(relAbund / log10(maxRelAbund[i])))) + "0000";
+ }
+ }else { scaleRelAbund[i][j] = "FFFFFF"; }
+
+ }
+ }
+
+ string filenamesvg = outputDir + m->getRootName(m->getSimpleName(inputfile)) + lookup[0]->getLabel() + ".heatmap.bin.svg";
+ m->openOutputFile(filenamesvg, outsvg);
+
+ int binHeight = 20;
+ int labelBump = 100;
+ int binWidth = 300;
+
+ //svg image
+ 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";
+ outsvg << "<g>\n";
+
+ //white backround
+ outsvg << "<rect fill=\"white\" stroke=\"white\" x=\"0\" y=\"0\" width=\"" + toString(lookup.size() * binWidth+labelBump) + "\" height=\"" + toString((numBinsToDisplay*binHeight + 120)) + "\"/>";
+ 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";
+
+ //column labels
+ for (int h = 0; h < lookup.size()+1; h++) {
+ if (h == 0) {
+ string tempLabel = "OTU";
+ outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(labelBump-labelBump/2+1) + "\" y=\"50\">" + tempLabel + "</text>\n";
+ }else {
+ 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";
+ }
+ }
+
+ //output legend and color labels
+ string color;
+ int x = 0;
+ int y = 103 + (numBinsToDisplay*binHeight);
+ printLegend(y, superMaxRelAbund);
+
+ y = 70;
+ for (int i = 0; i < numBinsToDisplay; i++) {
+ outsvg << "<text fill=\"black\" class=\"seri\" font-size=\"" + toString(fontSize) + "\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\">" + sortedLabels[i] + "</text>\n";
+ x += labelBump;
+ for (int j = 0; j < scaleRelAbund.size(); j++) {
+ if (m->control_pressed) { outsvg.close(); return "control"; }
+
+ outsvg << "<rect fill=\"#" + scaleRelAbund[j][i] + "\" stroke=\"#" + scaleRelAbund[j][i] + "\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\" width=\"" + toString(binWidth) + "\" height=\"" + toString(binHeight) + "\"/>\n";
+ x += binWidth;
+ }
+ x = 0;
+ y += binHeight;
+ }
+
+ outsvg << "</g>\n</svg>\n";
+ outsvg.close();