]> git.donarmstrong.com Git - mothur.git/blob - collectcommand.cpp
b3e8d8fbfa817900f6f1802310d9c18680bc1c15
[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
26
27 //**********************************************************************************************************************
28
29
30 CollectCommand::CollectCommand(){
31         try {
32                 globaldata = GlobalData::getInstance();
33                 string fileNameRoot;
34                 fileNameRoot = getRootName(globaldata->inputFileName);
35                 int i;
36                 validCalculator = new ValidCalculators();
37                 for (i=0; i<globaldata->Estimators.size(); i++) {
38                         if (validCalculator->isValidCalculator("single", globaldata->Estimators[i]) == true) { 
39                                 if (globaldata->Estimators[i] == "sobs") { 
40                                         cDisplays.push_back(new CollectDisplay(new Sobs(), new OneColumnFile(fileNameRoot+"sobs")));
41                                 }else if (globaldata->Estimators[i] == "chao") { 
42                                         cDisplays.push_back(new CollectDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"chao")));
43                                 }else if (globaldata->Estimators[i] == "nseqs") { 
44                                         cDisplays.push_back(new CollectDisplay(new NSeqs(), new OneColumnFile(fileNameRoot+"nseqs")));
45                                 }else if (globaldata->Estimators[i] == "ace") { 
46                                         convert(globaldata->getAbund(), abund);
47                                         cDisplays.push_back(new CollectDisplay(new Ace(abund), new ThreeColumnFile(fileNameRoot+"ace")));
48                                 }else if (globaldata->Estimators[i] == "jack") { 
49                                         cDisplays.push_back(new CollectDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"jack")));
50                                 }else if (globaldata->Estimators[i] == "shannon") { 
51                                         cDisplays.push_back(new CollectDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"shannon")));
52                                 }else if (globaldata->Estimators[i] == "npshannon") { 
53                                         cDisplays.push_back(new CollectDisplay(new NPShannon(), new OneColumnFile(fileNameRoot+"np_shannon")));
54                                 }else if (globaldata->Estimators[i] == "simpson") { 
55                                         cDisplays.push_back(new CollectDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"simpson")));
56                                 }else if (globaldata->Estimators[i] == "bootstrap") { 
57                                         cDisplays.push_back(new CollectDisplay(new Bootstrap(), new OneColumnFile(fileNameRoot+"bootstrap")));
58                                 }else if (globaldata->Estimators[i] == "geom") { 
59                                         cDisplays.push_back(new CollectDisplay(new Geom(), new OneColumnFile(fileNameRoot+"geom")));
60                                 }else if (globaldata->Estimators[i] == "qstat") { 
61                                         cDisplays.push_back(new CollectDisplay(new QStat(), new OneColumnFile(fileNameRoot+"qstat")));
62                                 }else if (globaldata->Estimators[i] == "logsd") { 
63                                         cDisplays.push_back(new CollectDisplay(new LogSD(), new OneColumnFile(fileNameRoot+"logsd")));
64                                 }else if (globaldata->Estimators[i] == "bergerparker") { 
65                                         cDisplays.push_back(new CollectDisplay(new BergerParker(), new OneColumnFile(fileNameRoot+"bergerparker")));
66                                 }else if (globaldata->Estimators[i] == "bstick") { 
67                                         cDisplays.push_back(new CollectDisplay(new BStick(), new OneColumnFile(fileNameRoot+"bstick")));
68                                 }
69                         }
70                 }
71                 
72                 //reset calc for next command
73                 globaldata->setCalc("");
74         }
75         catch(exception& e) {
76                 cout << "Standard Error: " << e.what() << " has occurred in the CollectCommand class Function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
77                 exit(1);
78         }
79         catch(...) {
80                 cout << "An unknown error has occurred in the CollectCommand class function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
81                 exit(1);
82         }       
83                         
84 }
85
86 //**********************************************************************************************************************
87
88 CollectCommand::~CollectCommand(){
89         delete order;
90         delete input;
91         delete cCurve;
92         delete read;
93 }
94
95 //**********************************************************************************************************************
96
97 int CollectCommand::execute(){
98         try {
99                 int count = 1;
100                 
101                 //if the users entered no valid calculators don't execute command
102                 if (cDisplays.size() == 0) { return 0; }
103
104                 read = new ReadPhilFile(globaldata->inputFileName);     
105                 read->read(&*globaldata); 
106                 
107                 order = globaldata->gorder;
108                 input = globaldata->ginput;
109                 set<string> orderList;  
110                 
111                 while(order != NULL){
112                 
113                         orderList.insert(order->getLabel());
114                         if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
115                                 cCurve = new Collect(order, cDisplays);
116                                 convert(globaldata->getFreq(), freq);
117                                 cCurve->getCurve(freq);
118                         
119                                 delete cCurve;
120                         
121                                 cout << order->getLabel() << '\t' << count << endl;
122                         }
123                         order = (input->getOrderVector());
124                         count++;
125                 }
126                 set<string>::iterator i;
127                 for(i = globaldata->labels.begin(); i != globaldata->labels.end(); ++i)
128                         if(orderList.count(*i) == 0)
129                                 cout << "'" << *i << "'" << " is not a valid label.\n";
130                 for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }       
131                 return 0;
132         }
133         catch(exception& e) {
134                 cout << "Standard Error: " << e.what() << " has occurred in the CollectCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
135                 exit(1);
136         }
137         catch(...) {
138                 cout << "An unknown error has occurred in the CollectCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
139                 exit(1);
140         }       
141 }
142
143 //**********************************************************************************************************************