]> git.donarmstrong.com Git - mothur.git/blob - collectcommand.cpp
d317a06aff4ebf68557a081475cd15a4df58c86a
[mothur.git] / collectcommand.cpp
1 /*
2  *  collectcommand.cpp
3  *  Dotur
4  *
5  *  Created by Sarah Westcott on 1/2/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "collectcommand.h"
11 #include "ace.h"
12 #include "sobs.h"
13 #include "nseqs.h"
14 #include "chao1.h"
15 #include "bootstrap.h"
16 #include "simpson.h"
17 #include "npshannon.h"
18 #include "shannon.h"
19 #include "jackknife.h"
20 #include "geom.h"
21 #include "qstat.h"
22 #include "logsd.h"
23 #include "bergerparker.h"
24 #include "bstick.h"
25 #include "goodscoverage.h"
26 #include "efron.h"
27 #include "boneh.h"
28 #include "solow.h"
29 #include "shen.h"
30 #include "coverage.h"
31
32
33 //**********************************************************************************************************************
34 CollectCommand::CollectCommand(){
35         try {
36                 globaldata = GlobalData::getInstance();
37                 string fileNameRoot;
38                 fileNameRoot = getRootName(globaldata->inputFileName);
39                 int i;
40                 validCalculator = new ValidCalculators();
41                 for (i=0; i<globaldata->Estimators.size(); i++) {
42                         if (validCalculator->isValidCalculator("single", globaldata->Estimators[i]) == true) { 
43                                 if (globaldata->Estimators[i] == "sobs") { 
44                                         cDisplays.push_back(new CollectDisplay(new Sobs(), new OneColumnFile(fileNameRoot+"sobs")));
45                                 }else if (globaldata->Estimators[i] == "chao") { 
46                                         cDisplays.push_back(new CollectDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"chao")));
47                                 }else if (globaldata->Estimators[i] == "nseqs") { 
48                                         cDisplays.push_back(new CollectDisplay(new NSeqs(), new OneColumnFile(fileNameRoot+"nseqs")));
49                                 }else if (globaldata->Estimators[i] == "coverage") { 
50                                         cDisplays.push_back(new CollectDisplay(new Coverage(), new OneColumnFile(fileNameRoot+"coverage")));
51                                 }else if (globaldata->Estimators[i] == "ace") { 
52                                         convert(globaldata->getAbund(), abund);
53                                         cDisplays.push_back(new CollectDisplay(new Ace(abund), new ThreeColumnFile(fileNameRoot+"ace")));
54                                 }else if (globaldata->Estimators[i] == "jack") { 
55                                         cDisplays.push_back(new CollectDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"jack")));
56                                 }else if (globaldata->Estimators[i] == "shannon") { 
57                                         cDisplays.push_back(new CollectDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"shannon")));
58                                 }else if (globaldata->Estimators[i] == "npshannon") { 
59                                         cDisplays.push_back(new CollectDisplay(new NPShannon(), new OneColumnFile(fileNameRoot+"np_shannon")));
60                                 }else if (globaldata->Estimators[i] == "simpson") { 
61                                         cDisplays.push_back(new CollectDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"simpson")));
62                                 }else if (globaldata->Estimators[i] == "bootstrap") { 
63                                         cDisplays.push_back(new CollectDisplay(new Bootstrap(), new OneColumnFile(fileNameRoot+"bootstrap")));
64                                 }else if (globaldata->Estimators[i] == "geometric") { 
65                                         cDisplays.push_back(new CollectDisplay(new Geom(), new OneColumnFile(fileNameRoot+"geometric")));
66                                 }else if (globaldata->Estimators[i] == "qstat") { 
67                                         cDisplays.push_back(new CollectDisplay(new QStat(), new OneColumnFile(fileNameRoot+"qstat")));
68                                 }else if (globaldata->Estimators[i] == "logseries") { 
69                                         cDisplays.push_back(new CollectDisplay(new LogSD(), new OneColumnFile(fileNameRoot+"logseries")));
70                                 }else if (globaldata->Estimators[i] == "bergerparker") { 
71                                         cDisplays.push_back(new CollectDisplay(new BergerParker(), new OneColumnFile(fileNameRoot+"bergerparker")));
72                                 }else if (globaldata->Estimators[i] == "bstick") { 
73                                         cDisplays.push_back(new CollectDisplay(new BStick(), new ThreeColumnFile(fileNameRoot+"bstick")));
74                                 }else if (globaldata->Estimators[i] == "goodscoverage") { 
75                                         cDisplays.push_back(new CollectDisplay(new GoodsCoverage(), new OneColumnFile(fileNameRoot+"goodscoverage")));
76                                 }else if (globaldata->Estimators[i] == "efron") {
77                                         convert(globaldata->getSize(), size); 
78                                         cDisplays.push_back(new CollectDisplay(new Efron(size), new OneColumnFile(fileNameRoot+"efron")));
79                                 }else if (globaldata->Estimators[i] == "boneh") {
80                                         convert(globaldata->getSize(), size); 
81                                         cDisplays.push_back(new CollectDisplay(new Boneh(size), new OneColumnFile(fileNameRoot+"boneh")));
82                                 }else if (globaldata->Estimators[i] == "solow") {
83                                         convert(globaldata->getSize(), size); 
84                                         cDisplays.push_back(new CollectDisplay(new Solow(size), new OneColumnFile(fileNameRoot+"solow")));
85                                 }else if (globaldata->Estimators[i] == "shen") {
86                                         convert(globaldata->getSize(), size); 
87                                         cDisplays.push_back(new CollectDisplay(new Shen(size), new OneColumnFile(fileNameRoot+"shen")));
88                                 }
89                         }
90                 }
91                 
92                 //reset calc for next command
93                 globaldata->setCalc("");
94         }
95         catch(exception& e) {
96                 cout << "Standard Error: " << e.what() << " has occurred in the CollectCommand class Function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
97                 exit(1);
98         }
99         catch(...) {
100                 cout << "An unknown error has occurred in the CollectCommand class function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
101                 exit(1);
102         }       
103                         
104 }
105
106 //**********************************************************************************************************************
107
108 CollectCommand::~CollectCommand(){
109         delete order;
110         delete input;
111         delete cCurve;
112         delete read;
113 }
114
115 //**********************************************************************************************************************
116
117 int CollectCommand::execute(){
118         try {
119                 int count = 1;
120                 
121                 //if the users entered no valid calculators don't execute command
122                 if (cDisplays.size() == 0) { return 0; }
123
124                 read = new ReadOTUFile(globaldata->inputFileName);      
125                 read->read(&*globaldata); 
126                 
127                 order = globaldata->gorder;
128                 input = globaldata->ginput;
129                 set<string> orderList;  
130                 
131                 while(order != NULL){
132                 
133                         orderList.insert(order->getLabel());
134                         if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
135                                 cCurve = new Collect(order, cDisplays);
136                                 convert(globaldata->getFreq(), freq);
137                                 cCurve->getCurve(freq);
138                         
139                                 delete cCurve;
140                         
141                                 cout << order->getLabel() << '\t' << count << endl;
142                         }
143                         
144                         delete order;
145                         order = (input->getOrderVector());
146                         count++;
147                 }
148                 set<string>::iterator i;
149                 for(i = globaldata->labels.begin(); i != globaldata->labels.end(); ++i)
150                         if(orderList.count(*i) == 0)
151                                 cout << "'" << *i << "'" << " is not a valid label.\n";
152                 for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }       
153                 return 0;
154         }
155         catch(exception& e) {
156                 cout << "Standard Error: " << e.what() << " has occurred in the CollectCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
157                 exit(1);
158         }
159         catch(...) {
160                 cout << "An unknown error has occurred in the CollectCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
161                 exit(1);
162         }       
163 }
164
165 //**********************************************************************************************************************