]> git.donarmstrong.com Git - mothur.git/blob - collectcommand.cpp
0f622c49b2a30632f53e4fa3ec0dfc3196113374
[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 "chao1.h"
14 #include "bootstrap.h"
15 #include "simpson.h"
16 #include "npshannon.h"
17 #include "shannon.h"
18 #include "jackknife.h"
19
20
21 //**********************************************************************************************************************
22
23
24 CollectCommand::CollectCommand(){
25         try {
26                 globaldata = GlobalData::getInstance();
27                 string fileNameRoot;
28                 fileNameRoot = getRootName(globaldata->inputFileName);
29                 int i;
30                 validCalculator = new ValidCalculators();
31                 
32                 for (i=0; i<globaldata->Estimators.size(); i++) {
33                         if (validCalculator->isValidCalculator("single", globaldata->Estimators[i]) == true) { 
34                                 if (globaldata->Estimators[i] == "sobs") { 
35                                         cDisplays.push_back(new CollectDisplay(new Sobs(), new OneColumnFile(fileNameRoot+"sobs")));
36                                 }else if (globaldata->Estimators[i] == "chao") { 
37                                         cDisplays.push_back(new CollectDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"chao")));
38                                 }else if (globaldata->Estimators[i] == "ace") { 
39                                         cDisplays.push_back(new CollectDisplay(new Ace(), new ThreeColumnFile(fileNameRoot+"ace")));
40                                 }else if (globaldata->Estimators[i] == "jack") { 
41                                         cDisplays.push_back(new CollectDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"jack")));
42                                 }else if (globaldata->Estimators[i] == "shannon") { 
43                                         cDisplays.push_back(new CollectDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"shannon")));
44                                 }else if (globaldata->Estimators[i] == "npshannon") { 
45                                         cDisplays.push_back(new CollectDisplay(new NPShannon(), new OneColumnFile(fileNameRoot+"np_shannon")));
46                                 }else if (globaldata->Estimators[i] == "simpson") { 
47                                         cDisplays.push_back(new CollectDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"simpson")));
48                                 }else if (globaldata->Estimators[i] == "bootstrap") { 
49                                         cDisplays.push_back(new CollectDisplay(new Bootstrap(), new OneColumnFile(fileNameRoot+"bootstrap")));
50                                 }
51                         }
52                 }
53                 
54                 //reset calc for next command
55                 globaldata->setCalc("");
56         }
57         catch(exception& e) {
58                 cout << "Standard Error: " << e.what() << " has occurred in the CollectCommand class Function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
59                 exit(1);
60         }
61         catch(...) {
62                 cout << "An unknown error has occurred in the CollectCommand class function CollectCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
63                 exit(1);
64         }       
65                         
66 }
67
68 //**********************************************************************************************************************
69
70 CollectCommand::~CollectCommand(){
71         delete order;
72         delete input;
73         delete cCurve;
74         delete read;
75 }
76
77 //**********************************************************************************************************************
78
79 int CollectCommand::execute(){
80         try {
81                 int count = 1;
82                 
83                 //if the users entered no valid calculators don't execute command
84                 if (cDisplays.size() == 0) { return 0; }
85
86                 read = new ReadPhilFile(globaldata->inputFileName);     
87                 read->read(&*globaldata); 
88                 
89                 order = globaldata->gorder;
90                 input = globaldata->ginput;
91                         
92                 while(order != NULL){
93                 
94                         if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
95                         
96                                 cCurve = new Collect(order, cDisplays);
97                                 convert(globaldata->getFreq(), freq);
98                                 cCurve->getCurve(freq);
99                         
100                                 delete cCurve;
101                         
102                                 cout << order->getLabel() << '\t' << count << endl;
103                         }
104                 
105                         order = (input->getOrderVector());
106                         count++;
107                 
108                 }
109         
110                 for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }       
111                 return 0;
112         }
113         catch(exception& e) {
114                 cout << "Standard Error: " << e.what() << " has occurred in the CollectCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
115                 exit(1);
116         }
117         catch(...) {
118                 cout << "An unknown error has occurred in the CollectCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
119                 exit(1);
120         }       
121 }
122
123 //**********************************************************************************************************************