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