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();
17 sorted = globaldata->getSorted();
21 cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function HeatMap. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
25 cout << "An unknown error has occurred in the HeatMap class function HeatMap. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
29 //**********************************************************************************************************************
30 void HeatMap::getPic(OrderVector* order) {
34 rabund = order->getRAbundVector();
36 for (int i = 0; i < rabund.size(); i++) {
37 colorScale[rabund.get(i)] = "";
40 float scaler = 255 / (float) colorScale.size();
42 //go through map and give each score a color value
43 for (it = colorScale.begin(); it != colorScale.end(); it++) {
44 it->second = toHex(int(float(it->first) * scaler));
45 if(it->second.length() == 1) { it->second = "0" + it->second; }
48 string filenamesvg = globaldata->inputFileName + ".heatmap." + order->getLabel() + ".svg";
50 openOutputFile(filenamesvg, outsvg);
52 //scale max rank so the maxrank = bright red
55 outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 300 " + toString((rabund.getNumBins()*5 + 15)) + "\">\n";
62 for (int i = 0; i <= rabund.getNumBins(); i++) {
64 color = colorScale[rabund.get(i)];
66 outsvg << "<rect fill=\"#" + color + "0000\" stroke=\"#" + color + "0000\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\" width=\"300\" height=\"5\"/>\n";
69 outsvg << "</g>\n</svg>\n";
75 cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
79 cout << "An unknown error has occurred in the HeatMap class function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
83 //**********************************************************************************************************************
84 void HeatMap::getPic(SharedOrderVector* sharedorder) {
88 //fills vector of sharedsabunds - lookup
89 getSharedVectors(sharedorder);
91 //sort lookup so shared bins are on top
92 if (sorted == "1") { sortSharedVectors(); }
95 for (int i = 0; i < lookup.size(); i++) {
96 for (int j = 0; j < lookup[i]->size(); j++) {
97 colorScale[lookup[i]->getAbundance(j)] = "";
102 float scaler = 255 / (float) colorScale.size();
104 //go through map and give each score a color value
105 for (it = colorScale.begin(); it != colorScale.end(); it++) {
106 it->second = toHex(int(float(it->first) * scaler));
107 if(it->second.length() == 1) { it->second = "0" + it->second; }
110 string filenamesvg = globaldata->inputFileName + ".heatmap." + sharedorder->getLabel() + "." + groupComb + ".svg";
111 openOutputFile(filenamesvg, outsvg);
114 outsvg << "<svg width=\"100%\" height=\"100%\" viewBox=\"0 0 " + toString(lookup.size() * 300) + " " + toString((lookup[0]->getNumBins()*5 + 15)) + "\">\n";
121 for (int i = 0; i <= lookup[0]->getNumBins(); i++) {
123 for (int j = 0; j < lookup.size(); j++) {
125 color = colorScale[lookup[j]->getAbundance(i)];
127 outsvg << "<rect fill=\"#" + color + "0000\" stroke=\"#" + color + "0000\" x=\"" + toString(x) + "\" y=\"" + toString(y) + "\" width=\"300\" height=\"5\"/>\n";
133 outsvg << "</g>\n</svg>\n";
140 catch(exception& e) {
141 cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
145 cout << "An unknown error has occurred in the HeatMap class function getPic. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
149 //**********************************************************************************************************************
150 void HeatMap::getSharedVectors(SharedOrderVector* order){
154 for (int j = 0; j < lookup.size(); j++) {
162 //create and initialize vector of sharedvectors, one for each group
163 for (int i = 0; i < globaldata->Groups.size(); i++) {
164 SharedRAbundVector* temp = new SharedRAbundVector(order->getNumBins());
165 temp->setLabel(order->getLabel());
166 temp->setGroup(globaldata->Groups[i]);
167 groupComb += globaldata->Groups[i];
168 lookup.push_back(temp);
171 int numSeqs = order->size();
172 //sample all the members
173 for(int i=0;i<numSeqs;i++){
175 individual chosen = order->get(i);
178 //set info for sharedvector in chosens group
179 for (int j = 0; j < lookup.size(); j++) {
180 if (chosen.group == lookup[j]->getGroup()) {
181 abundance = lookup[j]->getAbundance(chosen.bin);
182 lookup[j]->set(chosen.bin, (abundance + 1), chosen.group);
189 catch(exception& e) {
190 cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
194 cout << "An unknown error has occurred in the HeatMap class function getSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
201 //**********************************************************************************************************************
202 void HeatMap::sortSharedVectors(){
204 //copy lookup and then clear it to refill with sorted.
205 //loop though lookup and determine if they are shared
206 //if they are then insert in the front
207 //if not push to back
210 vector<SharedRAbundVector*> looktemp;
212 //create and initialize looktemp as a copy of lookup
213 for (int i = 0; i < lookup.size(); i++) {
214 SharedRAbundVector* temp = new SharedRAbundVector(lookup[i]->getNumBins());
215 temp->setLabel(lookup[i]->getLabel());
216 temp->setGroup(lookup[i]->getGroup());
217 //copy lookup i's info
218 for (int j = 0; j < lookup[i]->size(); j++) {
219 temp->set(j, lookup[i]->getAbundance(j), lookup[i]->getGroup());
221 looktemp.push_back(temp);
224 //clear out lookup to create sorted lookup
227 //create and initialize lookup to empty vectors
228 for (int i = 0; i < looktemp.size(); i++) {
229 SharedRAbundVector* temp = new SharedRAbundVector();
230 lookup.push_back(temp);
234 for (int i = 0; i < looktemp[0]->size(); i++) {
237 for (int j = 0; j < looktemp.size(); j++) {
238 if (looktemp[j]->getAbundance(i) == 0) { shared = false; }
242 for (int j = 0; j < looktemp.size(); j++) {
243 //if they are not shared then push to back, if they are not insert in front
244 if (shared == false) { lookup[j]->push_back(looktemp[j]->getAbundance(i), i, looktemp[j]->getGroup()); }
245 else { lookup[j]->push_front(looktemp[j]->getAbundance(i), i, looktemp[j]->getGroup()); }
250 for (int j = 0; j < looktemp.size(); j++) {
255 catch(exception& e) {
256 cout << "Standard Error: " << e.what() << " has occurred in the HeatMap class Function sortSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
260 cout << "An unknown error has occurred in the HeatMap class function sortSharedVectors. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
266 //**********************************************************************************************************************