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;
68 if (format != "list") {
70 //as long as you are not at the end of the file or done wih the lines you want
71 while((lookup[0] != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
73 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){
75 cout << lookup[0]->getLabel() << '\t' << count << endl;
76 heatmap->getPic(lookup);
78 processedLabels.insert(lookup[0]->getLabel());
79 userLabels.erase(lookup[0]->getLabel());
82 if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLookup[0]->getLabel()) != 1)) {
83 cout << lastLookup[0]->getLabel() << '\t' << count << endl;
84 heatmap->getPic(lastLookup);
86 processedLabels.insert(lastLookup[0]->getLabel());
87 userLabels.erase(lastLookup[0]->getLabel());
91 if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } }
94 //get next line to process
95 lookup = input->getSharedRAbundVectors();
99 //output error messages about any remaining user labels
100 set<string>::iterator it;
101 bool needToRun = false;
102 for (it = userLabels.begin(); it != userLabels.end(); it++) {
103 cout << "Your file does not include the label "<< *it;
104 if (processedLabels.count(lastLookup[0]->getLabel()) != 1) {
105 cout << ". I will use " << lastLookup[0]->getLabel() << "." << endl;
108 cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl;
112 //run last line if you need to
113 if (needToRun == true) {
114 cout << lastLookup[0]->getLabel() << '\t' << count << endl;
115 heatmap->getPic(lastLookup);
118 for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; }
120 //reset groups parameter
121 globaldata->Groups.clear();
125 while((rabund != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
127 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(rabund->getLabel()) == 1){
129 cout << rabund->getLabel() << '\t' << count << endl;
130 heatmap->getPic(rabund);
132 processedLabels.insert(rabund->getLabel());
133 userLabels.erase(rabund->getLabel());
136 if ((anyLabelsToProcess(rabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastRAbund->getLabel()) != 1)) {
138 cout << lastRAbund->getLabel() << '\t' << count << endl;
139 heatmap->getPic(lastRAbund);
141 processedLabels.insert(lastRAbund->getLabel());
142 userLabels.erase(lastRAbund->getLabel());
145 if (count != 1) { delete lastRAbund; }
148 rabund = input->getRAbundVector();
152 //output error messages about any remaining user labels
153 set<string>::iterator it;
154 bool needToRun = false;
155 for (it = userLabels.begin(); it != userLabels.end(); it++) {
156 cout << "Your file does not include the label "<< *it;
157 if (processedLabels.count(lastRAbund->getLabel()) != 1) {
158 cout << ". I will use " << lastRAbund->getLabel() << "." << endl;
161 cout << ". Please refer to " << lastRAbund->getLabel() << "." << endl;
165 //run last line if you need to
166 if (needToRun == true) {
167 cout << lastRAbund->getLabel() << '\t' << count << endl;
168 heatmap->getPic(lastRAbund);
175 globaldata->setGroups("");
178 catch(exception& e) {
179 cout << "Standard Error: " << e.what() << " has occurred in the HeatMapCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
183 cout << "An unknown error has occurred in the HeatMapCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
188 //**********************************************************************************************************************