]> git.donarmstrong.com Git - mothur.git/blob - collectcommand.cpp
added boneh, efron, and solow calculators
[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
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                                 }
86                         }
87                 }
88                 
89                 //reset calc for next command
90                 globaldata->setCalc("");
91         }
92         catch(exception& e) {
93                 cout << "Standard Error: " << e.what() << " has occurred in the CollectCommand class Function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
94                 exit(1);
95         }
96         catch(...) {
97                 cout << "An unknown error has occurred in the CollectCommand class function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
98                 exit(1);
99         }       
100                         
101 }
102
103 //**********************************************************************************************************************
104
105 CollectCommand::~CollectCommand(){
106         delete order;
107         delete input;
108         delete cCurve;
109         delete read;
110 }
111
112 //**********************************************************************************************************************
113
114 int CollectCommand::execute(){
115         try {
116                 int count = 1;
117                 
118                 //if the users entered no valid calculators don't execute command
119                 if (cDisplays.size() == 0) { return 0; }
120
121                 read = new ReadOTUFile(globaldata->inputFileName);      
122                 read->read(&*globaldata); 
123                 
124                 order = globaldata->gorder;
125                 input = globaldata->ginput;
126                 set<string> orderList;  
127                 
128                 while(order != NULL){
129                 
130                         orderList.insert(order->getLabel());
131                         if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
132                                 cCurve = new Collect(order, cDisplays);
133                                 convert(globaldata->getFreq(), freq);
134                                 cCurve->getCurve(freq);
135                         
136                                 delete cCurve;
137                         
138                                 cout << order->getLabel() << '\t' << count << endl;
139                         }
140                         
141                         delete order;
142                         order = (input->getOrderVector());
143                         count++;
144                 }
145                 set<string>::iterator i;
146                 for(i = globaldata->labels.begin(); i != globaldata->labels.end(); ++i)
147                         if(orderList.count(*i) == 0)
148                                 cout << "'" << *i << "'" << " is not a valid label.\n";
149                 for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }       
150                 return 0;
151         }
152         catch(exception& e) {
153                 cout << "Standard Error: " << e.what() << " has occurred in the CollectCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
154                 exit(1);
155         }
156         catch(...) {
157                 cout << "An unknown error has occurred in the CollectCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
158                 exit(1);
159         }       
160 }
161
162 //**********************************************************************************************************************