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