5 * Created by Sarah Westcott on 3/25/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "heatmapcommand.h"
13 //**********************************************************************************************************************
15 HeatMapCommand::HeatMapCommand(){
17 globaldata = GlobalData::getInstance();
18 heatmap = new HeatMap();
19 format = globaldata->getFormat();
22 cout << "Standard Error: " << e.what() << " has occurred in the HeatMapCommand class Function HeatMapCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
26 cout << "An unknown error has occurred in the HeatMapCommand class function HeatMapCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
30 //**********************************************************************************************************************
32 HeatMapCommand::~HeatMapCommand(){
38 //**********************************************************************************************************************
40 int HeatMapCommand::execute(){
43 RAbundVector* lastRAbund;
44 vector<SharedRAbundVector*> lastLookup;
46 if (format == "sharedfile") {
48 read = new ReadOTUFile(globaldata->inputFileName);
49 read->read(&*globaldata);
51 input = globaldata->ginput;
52 lookup = input->getSharedRAbundVectors();
54 }else if (format == "list") {
55 //you are using just a list file and have only one group
56 read = new ReadOTUFile(globaldata->inputFileName);
57 read->read(&*globaldata);
59 rabund = globaldata->rabund;
60 lastRAbund = globaldata->rabund;
61 input = globaldata->ginput;
64 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
65 set<string> processedLabels;
66 set<string> userLabels = globaldata->labels;
67 set<int> userLines = globaldata->lines;
69 if (format != "list") {
71 //as long as you are not at the end of the file or done wih the lines you want
72 while((lookup[0] != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
74 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){
76 cout << lookup[0]->getLabel() << '\t' << count << endl;
77 heatmap->getPic(lookup);
79 processedLabels.insert(lookup[0]->getLabel());
80 userLabels.erase(lookup[0]->getLabel());
81 userLines.erase(count);
84 if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLookup[0]->getLabel()) != 1)) {
85 cout << lastLookup[0]->getLabel() << '\t' << count << endl;
86 heatmap->getPic(lastLookup);
88 processedLabels.insert(lastLookup[0]->getLabel());
89 userLabels.erase(lastLookup[0]->getLabel());
93 if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } }
96 //get next line to process
97 lookup = input->getSharedRAbundVectors();
101 //output error messages about any remaining user labels
102 set<string>::iterator it;
103 bool needToRun = false;
104 for (it = userLabels.begin(); it != userLabels.end(); it++) {
105 cout << "Your file does not include the label "<< *it;
106 if (processedLabels.count(lastLookup[0]->getLabel()) != 1) {
107 cout << ". I will use " << lastLookup[0]->getLabel() << "." << endl;
110 cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl;
114 //run last line if you need to
115 if (needToRun == true) {
116 cout << lastLookup[0]->getLabel() << '\t' << count << endl;
117 heatmap->getPic(lastLookup);
120 for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; }
122 //reset groups parameter
123 globaldata->Groups.clear();
127 while((rabund != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
129 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(rabund->getLabel()) == 1){
131 cout << rabund->getLabel() << '\t' << count << endl;
132 heatmap->getPic(rabund);
134 processedLabels.insert(rabund->getLabel());
135 userLabels.erase(rabund->getLabel());
136 userLines.erase(count);
139 if ((anyLabelsToProcess(rabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastRAbund->getLabel()) != 1)) {
141 cout << lastRAbund->getLabel() << '\t' << count << endl;
142 heatmap->getPic(lastRAbund);
144 processedLabels.insert(lastRAbund->getLabel());
145 userLabels.erase(lastRAbund->getLabel());
148 if (count != 1) { delete lastRAbund; }
151 rabund = input->getRAbundVector();
155 //output error messages about any remaining user labels
156 set<string>::iterator it;
157 bool needToRun = false;
158 for (it = userLabels.begin(); it != userLabels.end(); it++) {
159 cout << "Your file does not include the label "<< *it;
160 if (processedLabels.count(lastRAbund->getLabel()) != 1) {
161 cout << ". I will use " << lastRAbund->getLabel() << "." << endl;
164 cout << ". Please refer to " << lastRAbund->getLabel() << "." << endl;
168 //run last line if you need to
169 if (needToRun == true) {
170 cout << lastRAbund->getLabel() << '\t' << count << endl;
171 heatmap->getPic(lastRAbund);
178 globaldata->setGroups("");
181 catch(exception& e) {
182 cout << "Standard Error: " << e.what() << " has occurred in the HeatMapCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
186 cout << "An unknown error has occurred in the HeatMapCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
191 //**********************************************************************************************************************