2 * collectsharedcommand.cpp
5 * Created by Sarah Westcott on 1/2/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "collectsharedcommand.h"
11 #include "sharedsobscollectsummary.h"
12 #include "sharedchao1.h"
13 #include "sharedace.h"
14 #include "sharedjabund.h"
15 #include "sharedsorabund.h"
16 #include "sharedjclass.h"
17 #include "sharedsorclass.h"
18 #include "sharedjest.h"
19 #include "sharedsorest.h"
20 #include "sharedthetayc.h"
21 #include "sharedthetan.h"
22 #include "sharedkstest.h"
23 #include "whittaker.h"
24 #include "sharednseqs.h"
25 #include "sharedochiai.h"
26 #include "sharedanderbergs.h"
27 #include "sharedkulczynski.h"
28 #include "sharedkulczynskicody.h"
29 #include "sharedlennon.h"
30 #include "sharedmorisitahorn.h"
31 #include "sharedbraycurtis.h"
32 #include "sharedjackknife.h"
33 #include "whittaker.h"
37 //**********************************************************************************************************************
39 CollectSharedCommand::CollectSharedCommand(){
41 globaldata = GlobalData::getInstance();
43 fileNameRoot = getRootName(globaldata->inputFileName);
44 format = globaldata->getFormat();
45 convert(globaldata->getFreq(), freq);
46 validCalculator = new ValidCalculators();
47 util = new SharedUtil();
50 for (i=0; i<globaldata->Estimators.size(); i++) {
51 if (validCalculator->isValidCalculator("shared", globaldata->Estimators[i]) == true) {
52 if (globaldata->Estimators[i] == "sharedchao") {
53 cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao")));
54 }else if (globaldata->Estimators[i] == "sharedsobs") {
55 cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs")));
56 }else if (globaldata->Estimators[i] == "sharedace") {
57 cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace")));
58 }else if (globaldata->Estimators[i] == "jabund") {
59 cDisplays.push_back(new CollectDisplay(new JAbund(), new SharedOneColumnFile(fileNameRoot+"jabund")));
60 }else if (globaldata->Estimators[i] == "sorabund") {
61 cDisplays.push_back(new CollectDisplay(new SorAbund(), new SharedOneColumnFile(fileNameRoot+"sorabund")));
62 }else if (globaldata->Estimators[i] == "jclass") {
63 cDisplays.push_back(new CollectDisplay(new Jclass(), new SharedOneColumnFile(fileNameRoot+"jclass")));
64 }else if (globaldata->Estimators[i] == "sorclass") {
65 cDisplays.push_back(new CollectDisplay(new SorClass(), new SharedOneColumnFile(fileNameRoot+"sorclass")));
66 }else if (globaldata->Estimators[i] == "jest") {
67 cDisplays.push_back(new CollectDisplay(new Jest(), new SharedOneColumnFile(fileNameRoot+"jest")));
68 }else if (globaldata->Estimators[i] == "sorest") {
69 cDisplays.push_back(new CollectDisplay(new SorEst(), new SharedOneColumnFile(fileNameRoot+"sorest")));
70 }else if (globaldata->Estimators[i] == "thetayc") {
71 cDisplays.push_back(new CollectDisplay(new ThetaYC(), new SharedOneColumnFile(fileNameRoot+"thetayc")));
72 }else if (globaldata->Estimators[i] == "thetan") {
73 cDisplays.push_back(new CollectDisplay(new ThetaN(), new SharedOneColumnFile(fileNameRoot+"thetan")));
74 }else if (globaldata->Estimators[i] == "kstest") {
75 cDisplays.push_back(new CollectDisplay(new KSTest(), new SharedOneColumnFile(fileNameRoot+"kstest")));
76 }else if (globaldata->Estimators[i] == "whittaker") {
77 cDisplays.push_back(new CollectDisplay(new Whittaker(), new SharedOneColumnFile(fileNameRoot+"whittaker")));
78 }else if (globaldata->Estimators[i] == "sharednseqs") {
79 cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(fileNameRoot+"shared.nseqs")));
81 }else if (globaldata->Estimators[i] == "ochiai") {
82 cDisplays.push_back(new CollectDisplay(new Ochiai(), new SharedOneColumnFile(fileNameRoot+"ochiai")));
83 }else if (globaldata->Estimators[i] == "anderberg") {
84 cDisplays.push_back(new CollectDisplay(new Anderberg(), new SharedOneColumnFile(fileNameRoot+"anderberg")));
85 }else if (globaldata->Estimators[i] == "skulczynski") {
86 cDisplays.push_back(new CollectDisplay(new Kulczynski(), new SharedOneColumnFile(fileNameRoot+"kulczynski")));
87 }else if (globaldata->Estimators[i] == "kulczynskicody") {
88 cDisplays.push_back(new CollectDisplay(new KulczynskiCody(), new SharedOneColumnFile(fileNameRoot+"kulczynskicody")));
89 }else if (globaldata->Estimators[i] == "lennon") {
90 cDisplays.push_back(new CollectDisplay(new Lennon(), new SharedOneColumnFile(fileNameRoot+"lennon")));
91 }else if (globaldata->Estimators[i] == "morisitahorn") {
92 cDisplays.push_back(new CollectDisplay(new MorHorn(), new SharedOneColumnFile(fileNameRoot+"morisitahorn")));
93 }else if (globaldata->Estimators[i] == "braycurtis") {
94 cDisplays.push_back(new CollectDisplay(new BrayCurtis(), new SharedOneColumnFile(fileNameRoot+"braycurtis")));
99 //reset calc for next command
100 globaldata->setCalc("");
103 catch(exception& e) {
104 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
108 cout << "An unknown error has occurred in the CollectSharedCommand class function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
114 //**********************************************************************************************************************
116 CollectSharedCommand::~CollectSharedCommand(){
124 //**********************************************************************************************************************
126 int CollectSharedCommand::execute(){
130 //if the users entered no valid calculators don't execute command
131 if (cDisplays.size() == 0) { return 0; }
133 read = new ReadOTUFile(globaldata->inputFileName);
134 read->read(&*globaldata);
136 input = globaldata->ginput;
137 order = input->getSharedOrderVector();
138 SharedOrderVector* lastOrder = order;
140 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
141 set<string> processedLabels;
142 set<string> userLabels = globaldata->labels;
145 util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "collect");
146 util->updateGroupIndex(globaldata->Groups, globaldata->gGroupmap->groupIndex);
148 while((order != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
150 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
152 //create collectors curve
153 cCurve = new Collect(order, cDisplays);
154 cCurve->getSharedCurve(freq);
157 cout << order->getLabel() << '\t' << count << endl;
158 processedLabels.insert(order->getLabel());
159 userLabels.erase(order->getLabel());
161 //you have a label the user want that is smaller than this line and the last line has not already been processed
164 if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastOrder->getLabel()) != 1)) {
165 //create collectors curve
166 cCurve = new Collect(lastOrder, cDisplays);
167 cCurve->getSharedCurve(freq);
170 cout << lastOrder->getLabel() << '\t' << count << endl;
171 processedLabels.insert(lastOrder->getLabel());
172 userLabels.erase(lastOrder->getLabel());
175 if (count != 1) { delete lastOrder; }
178 //get next line to process
179 order = input->getSharedOrderVector();
183 //output error messages about any remaining user labels
184 set<string>::iterator it;
185 bool needToRun = false;
186 for (it = userLabels.begin(); it != userLabels.end(); it++) {
187 cout << "Your file does not include the label "<< *it;
188 if (processedLabels.count(lastOrder->getLabel()) != 1) {
189 cout << ". I will use " << lastOrder->getLabel() << "." << endl;
192 cout << ". Please refer to " << lastOrder->getLabel() << "." << endl;
196 //run last line if you need to
197 if (needToRun == true) {
198 cCurve = new Collect(lastOrder, cDisplays);
199 cCurve->getCurve(freq);
202 cout << lastOrder->getLabel() << '\t' << count << endl;
206 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
208 //reset groups parameter
209 globaldata->Groups.clear(); globaldata->setGroups("");
213 catch(exception& e) {
214 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
218 cout << "An unknown error has occurred in the CollectSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
223 /***********************************************************/