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