2 * heatmapsimcommand.cpp
5 * Created by Sarah Westcott on 6/8/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "heatmapsimcommand.h"
11 #include "sharedjabund.h"
12 #include "sharedsorabund.h"
13 #include "sharedjclass.h"
14 #include "sharedsorclass.h"
15 #include "sharedjest.h"
16 #include "sharedsorest.h"
17 #include "sharedthetayc.h"
18 #include "sharedthetan.h"
19 #include "sharedmorisitahorn.h"
20 #include "sharedbraycurtis.h"
23 //**********************************************************************************************************************
25 HeatMapSimCommand::HeatMapSimCommand(){
27 globaldata = GlobalData::getInstance();
28 validCalculator = new ValidCalculators();
29 heatmap = new HeatMapSim();
32 for (i=0; i<globaldata->Estimators.size(); i++) {
33 if (validCalculator->isValidCalculator("heat", globaldata->Estimators[i]) == true) {
34 if (globaldata->Estimators[i] == "jabund") {
35 heatCalculators.push_back(new JAbund());
36 }else if (globaldata->Estimators[i] == "sorabund") {
37 heatCalculators.push_back(new SorAbund());
38 }else if (globaldata->Estimators[i] == "jclass") {
39 heatCalculators.push_back(new Jclass());
40 }else if (globaldata->Estimators[i] == "sorclass") {
41 heatCalculators.push_back(new SorClass());
42 }else if (globaldata->Estimators[i] == "jest") {
43 heatCalculators.push_back(new Jest());
44 }else if (globaldata->Estimators[i] == "sorest") {
45 heatCalculators.push_back(new SorEst());
46 }else if (globaldata->Estimators[i] == "thetayc") {
47 heatCalculators.push_back(new ThetaYC());
48 }else if (globaldata->Estimators[i] == "thetan") {
49 heatCalculators.push_back(new ThetaN());
50 }else if (globaldata->Estimators[i] == "morisitahorn") {
51 heatCalculators.push_back(new MorHorn());
52 }else if (globaldata->Estimators[i] == "braycurtis") {
53 heatCalculators.push_back(new BrayCurtis());
58 //reset calc for next command
59 globaldata->setCalc("");
64 cout << "Standard Error: " << e.what() << " has occurred in the HeatMapSimCommand class Function HeatMapSimCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
68 cout << "An unknown error has occurred in the HeatMapSimCommand class function HeatMapSimCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
72 //**********************************************************************************************************************
74 HeatMapSimCommand::~HeatMapSimCommand(){
80 //**********************************************************************************************************************
82 int HeatMapSimCommand::execute(){
86 //if the users entered no valid calculators don't execute command
87 if (heatCalculators.size() == 0) { cout << "No valid calculators." << endl; return 0; }
90 read = new ReadOTUFile(globaldata->inputFileName);
91 read->read(&*globaldata);
93 input = globaldata->ginput;
94 lookup = input->getSharedRAbundVectors();
95 vector<SharedRAbundVector*> lastLookup = lookup;
97 if (lookup.size() < 2) { cout << "You have not provided enough valid groups. I cannot run the command." << endl; return 0;}
99 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
100 set<string> processedLabels;
101 set<string> userLabels = globaldata->labels;
102 set<int> userLines = globaldata->lines;
105 //as long as you are not at the end of the file or done wih the lines you want
106 while((lookup[0] != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
108 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){
110 cout << lookup[0]->getLabel() << '\t' << count << endl;
111 heatmap->getPic(lookup, heatCalculators);
113 processedLabels.insert(lookup[0]->getLabel());
114 userLabels.erase(lookup[0]->getLabel());
115 userLines.erase(count);
118 if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLookup[0]->getLabel()) != 1)) {
119 cout << lastLookup[0]->getLabel() << '\t' << count << endl;
120 heatmap->getPic(lastLookup, heatCalculators);
122 processedLabels.insert(lastLookup[0]->getLabel());
123 userLabels.erase(lastLookup[0]->getLabel());
126 //prevent memory leak
127 if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } }
130 //get next line to process
131 lookup = input->getSharedRAbundVectors();
135 //output error messages about any remaining user labels
136 set<string>::iterator it;
137 bool needToRun = false;
138 for (it = userLabels.begin(); it != userLabels.end(); it++) {
139 cout << "Your file does not include the label "<< *it;
140 if (processedLabels.count(lastLookup[0]->getLabel()) != 1) {
141 cout << ". I will use " << lastLookup[0]->getLabel() << "." << endl;
144 cout << ". Please refer to " << lastLookup[0]->getLabel() << "." << endl;
148 //run last line if you need to
149 if (needToRun == true) {
150 cout << lastLookup[0]->getLabel() << '\t' << count << endl;
151 heatmap->getPic(lastLookup, heatCalculators);
154 for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; }
156 //reset groups parameter
157 globaldata->Groups.clear();
158 globaldata->setGroups("");
162 catch(exception& e) {
163 cout << "Standard Error: " << e.what() << " has occurred in the HeatMapSimCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
167 cout << "An unknown error has occurred in the HeatMapSimCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
172 //**********************************************************************************************************************