5 * Created by Sarah Westcott on 3/25/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
12 //**********************************************************************************************************************
15 globaldata = GlobalData::getInstance();
16 format = globaldata->getFormat();
20 cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function HeatMap. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
24 cout << "An unknown error has occurred in the HeatMap class function HeatMap. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
28 //**********************************************************************************************************************
29 void HeatMap::getPic(OrderVector* order) {
33 rabund = order->getRAbundVector();
35 for (int i = 0; i < rabund.size(); i++) {
36 colorScale[rabund.get(i)] = "";
39 float scaler = 255 / (float) colorScale.size();
41 //go through map and give each score a color value
42 for (it = colorScale.begin(); it != colorScale.end(); it++) {
43 it->second = toHex(int(float(it->first) * scaler));
44 if(it->second.length() == 1) { it->second = "0" + it->second; }
47 string filenamesvg = globaldata->inputFileName + ".heatmap." + order->getLabel() + ".svg";
49 openOutputFile(filenamesvg, outsvg);
51 //scale max rank so the maxrank = bright red
54 outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 300 " + toString((rabund.getNumBins()*5 + 15)) + "\">\n";
61 for (int i = 0; i <= rabund.getNumBins(); i++) {
63 color = colorScale[rabund.get(i)];
65 outsvg << "<rect fill=\"#" + color + "0000\" stroke=\"#" + color + "0000\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\" width=\"300\" height=\"5\"/>\n";
68 outsvg << "</g>\n</svg>\n";
74 cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
78 cout << "An unknown error has occurred in the HeatMap class function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
82 //**********************************************************************************************************************
83 void HeatMap::getPic(SharedOrderVector* sharedorder) {
87 //fills vector of sharedsabunds - lookup
88 getSharedVectors(sharedorder);
90 //sort lookup so shared bins are on top
94 for (int i = 0; i < lookup.size(); i++) {
95 for (int j = 0; j < lookup[i]->size(); j++) {
96 colorScale[lookup[i]->getAbundance(j)] = "";
101 float scaler = 255 / (float) colorScale.size();
103 //go through map and give each score a color value
104 for (it = colorScale.begin(); it != colorScale.end(); it++) {
105 it->second = toHex(int(float(it->first) * scaler));
106 if(it->second.length() == 1) { it->second = "0" + it->second; }
109 string filenamesvg = globaldata->inputFileName + ".heatmap." + sharedorder->getLabel() + "." + groupComb + ".svg";
110 openOutputFile(filenamesvg, outsvg);
113 outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString(lookup.size() * 300) + " " + toString((lookup[0]->getNumBins()*5 + 15)) + "\">\n";
120 for (int i = 0; i <= lookup[0]->getNumBins(); i++) {
122 for (int j = 0; j < lookup.size(); j++) {
124 color = colorScale[lookup[j]->getAbundance(i)];
126 outsvg << "<rect fill=\"#" + color + "0000\" stroke=\"#" + color + "0000\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\" width=\"300\" height=\"5\"/>\n";
132 outsvg << "</g>\n</svg>\n";
139 catch(exception& e) {
140 cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
144 cout << "An unknown error has occurred in the HeatMap class function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
148 //**********************************************************************************************************************
149 void HeatMap::getSharedVectors(SharedOrderVector* order){
153 for (int j = 0; j < lookup.size(); j++) {
161 //create and initialize vector of sharedvectors, one for each group
162 for (int i = 0; i < globaldata->Groups.size(); i++) {
163 SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins());
164 temp->setLabel(order->getLabel());
165 temp->setGroup(globaldata->Groups[i]);
166 groupComb += globaldata->Groups[i];
167 lookup.push_back(temp);
170 int numSeqs = order->size();
171 //sample all the members
172 for(int i=0;i<numSeqs;i++){
174 individual chosen = order->get(i);
177 //set info for sharedvector in chosens group
178 for (int j = 0; j < lookup.size(); j++) {
179 if (chosen.group == lookup[j]->getGroup()) {
180 abundance = lookup[j]->getAbundance(chosen.bin);
181 lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
188 catch(exception& e) {
189 cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
193 cout << "An unknown error has occurred in the HeatMap class function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
200 //**********************************************************************************************************************
201 void HeatMap::sortSharedVectors(){
203 //copy lookup and then clear it to refill with sorted.
204 //loop though lookup and determine if they are shared
205 //if they are then insert in the front
206 //if not push to back
209 vector<SharedRAbundVector*> looktemp;
211 //create and initialize looktemp as a copy of lookup
212 for (int i = 0; i < lookup.size(); i++) {
213 SharedRAbundVector* temp = new SharedRAbundVector(lookup[i]->getNumBins());
214 temp->setLabel(lookup[i]->getLabel());
215 temp->setGroup(lookup[i]->getGroup());
216 //copy lookup i's info
217 for (int j = 0; j < lookup[i]->size(); j++) {
218 temp->set(j, lookup[i]->getAbundance(j), lookup[i]->getGroup());
220 looktemp.push_back(temp);
223 //clear out lookup to create sorted lookup
226 //create and initialize lookup to empty vectors
227 for (int i = 0; i < looktemp.size(); i++) {
228 SharedRAbundVector* temp = new SharedRAbundVector();
229 lookup.push_back(temp);
233 for (int i = 0; i < looktemp[0]->size(); i++) {
236 for (int j = 0; j < looktemp.size(); j++) {
237 if (looktemp[j]->getAbundance(i) == 0) { shared = false; }
241 for (int j = 0; j < looktemp.size(); j++) {
242 //if they are not shared then push to back, if they are not insert in front
243 if (shared == false) { lookup[j]->push_back(looktemp[j]->getAbundance(i), i, looktemp[j]->getGroup()); }
244 else { lookup[j]->push_front(looktemp[j]->getAbundance(i), i, looktemp[j]->getGroup()); }
249 for (int j = 0; j < looktemp.size(); j++) {
254 catch(exception& e) {
255 cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function sortSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
259 cout << "An unknown error has occurred in the HeatMap class function sortSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
265 //**********************************************************************************************************************