]> git.donarmstrong.com Git - mothur.git/blob - summarycommand.cpp
modified some calculators and other stuff - pds
[mothur.git] / summarycommand.cpp
1 /*
2  *  summarycommand.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 "summarycommand.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 "logsd.h"
22 #include "qstat.h"
23 #include "bergerparker.h"
24 #include "bstick.h"
25 #include "coverage.h"
26
27 //**********************************************************************************************************************
28
29 SummaryCommand::SummaryCommand(){
30         try {
31                 globaldata = GlobalData::getInstance();
32                 validCalculator = new ValidCalculators();
33                 int i;
34                 
35                 for (i=0; i<globaldata->Estimators.size(); i++) {
36                         if (validCalculator->isValidCalculator("summary", globaldata->Estimators[i]) == true) { 
37                                 if(globaldata->Estimators[i] == "sobs"){
38                                         sumCalculators.push_back(new Sobs());
39                                 }else if(globaldata->Estimators[i] == "chao"){
40                                         sumCalculators.push_back(new Chao1());
41                                 }else if(globaldata->Estimators[i] == "coverage"){
42                                         sumCalculators.push_back(new Coverage());
43                                 }else if(globaldata->Estimators[i] == "geometric"){
44                                         sumCalculators.push_back(new Geom());
45                                 }else if(globaldata->Estimators[i] == "logseries"){
46                                         sumCalculators.push_back(new LogSD());
47                                 }else if(globaldata->Estimators[i] == "qstat"){
48                                         sumCalculators.push_back(new QStat());
49                                 }else if(globaldata->Estimators[i] == "bergerparker"){
50                                         sumCalculators.push_back(new BergerParker());
51                                 }else if(globaldata->Estimators[i] == "bstick"){
52                                         sumCalculators.push_back(new BStick());
53                                 }else if(globaldata->Estimators[i] == "ace"){
54                                         convert(globaldata->getAbund(), abund);
55                                         if(abund < 5)
56                                                 abund = 10;
57                                         sumCalculators.push_back(new Ace(abund));
58                                 }else if(globaldata->Estimators[i] == "jack"){
59                                         sumCalculators.push_back(new Jackknife());
60                                 }else if(globaldata->Estimators[i] == "shannon"){
61                                         sumCalculators.push_back(new Shannon());
62                                 }else if(globaldata->Estimators[i] == "npshannon"){
63                                         sumCalculators.push_back(new NPShannon());
64                                 }else if(globaldata->Estimators[i] == "simpson"){
65                                         sumCalculators.push_back(new Simpson());
66                                 }else if(globaldata->Estimators[i] == "bootstrap"){
67                                         sumCalculators.push_back(new Bootstrap());
68                                 }else if (globaldata->Estimators[i] == "nseqs") { 
69                                         sumCalculators.push_back(new NSeqs());
70                                 }
71                         }
72                 }
73                 
74                 //reset calc for next command
75                 globaldata->setCalc("");
76
77         }
78         catch(exception& e) {
79                 cout << "Standard Error: " << e.what() << " has occurred in the SummaryCommand class Function SummaryCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
80                 exit(1);
81         }
82         catch(...) {
83                 cout << "An unknown error has occurred in the SummaryCommand class function SummaryCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
84                 exit(1);
85         }       
86 }
87 //**********************************************************************************************************************
88
89 SummaryCommand::~SummaryCommand(){
90         delete sabund;
91         delete input;
92         delete read;
93 }
94
95 //**********************************************************************************************************************
96
97 int SummaryCommand::execute(){
98         try {
99         
100                 //if the users entered no valid calculators don't execute command
101                 if (sumCalculators.size() == 0) { return 0; }
102
103                 outputFileName = ((getRootName(globaldata->inputFileName)) + "summary");
104                 openOutputFile(outputFileName, outputFileHandle);
105                 outputFileHandle << "label";
106         
107                 read = new ReadOTUFile(globaldata->inputFileName);      
108                 read->read(&*globaldata); 
109
110                 for(int i=0;i<sumCalculators.size();i++){
111                         if(sumCalculators[i]->getCols() == 1){
112                                 outputFileHandle << '\t' << sumCalculators[i]->getName();
113                         }
114                         else{
115                                 outputFileHandle << '\t' << sumCalculators[i]->getName() << "\t" << sumCalculators[i]->getName() << "_lci\t" << sumCalculators[i]->getName() << "_hci";
116                         }
117                 }
118                 outputFileHandle << endl;
119                 
120                 sabund = globaldata->sabund;
121                 input = globaldata->ginput;
122                 int count = 1;
123                 while(sabund != NULL){
124                 
125                         if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(sabund->getLabel()) == 1){                      
126         
127                                 cout << sabund->getLabel() << '\t' << count << endl;
128                                 
129                                 outputFileHandle << sabund->getLabel();
130                                 for(int i=0;i<sumCalculators.size();i++){
131                                         vector<double> data = sumCalculators[i]->getValues(sabund);
132                                         outputFileHandle << '\t';
133                                         sumCalculators[i]->print(outputFileHandle);
134                                 }
135                                 
136                                 outputFileHandle << endl;
137                         }
138                         sabund = input->getSAbundVector();
139                         count++;
140                 }
141         
142                 return 0;
143         }
144         catch(exception& e) {
145                 cout << "Standard Error: " << e.what() << " has occurred in the SummaryCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
146                 exit(1);
147         }
148         catch(...) {
149                 cout << "An unknown error has occurred in the SummaryCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
150                 exit(1);
151         }               
152 }
153
154 //**********************************************************************************************************************