]> git.donarmstrong.com Git - mothur.git/blob - summarycommand.cpp
Initial revision
[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 "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 SummaryCommand::SummaryCommand(){
23         try {
24                 globaldata = GlobalData::getInstance();
25                 int i;
26                 for (i=0; i<globaldata->summaryEstimators.size(); i++) {
27                         if(globaldata->summaryEstimators[i] == "sobs"){
28                                 sumCalculators.push_back(new Sobs());
29                         }else if(globaldata->summaryEstimators[i] == "chao"){
30                                 sumCalculators.push_back(new Chao1());
31                         }else if(globaldata->summaryEstimators[i] == "ace"){
32                                 sumCalculators.push_back(new Ace());
33                         }else if(globaldata->summaryEstimators[i] == "jack"){
34                                 sumCalculators.push_back(new Jackknife());
35                         }else if(globaldata->summaryEstimators[i] == "shannon"){
36                                 sumCalculators.push_back(new Shannon());
37                         }else if(globaldata->summaryEstimators[i] == "npshannon"){
38                                 sumCalculators.push_back(new NPShannon());
39                         }else if(globaldata->summaryEstimators[i] == "simpson"){
40                                 sumCalculators.push_back(new Simpson());
41                         }else if(globaldata->summaryEstimators[i] == "bootstrap"){
42                                 sumCalculators.push_back(new Bootstrap());
43                         }
44                 }
45         }
46         catch(exception& e) {
47                 cout << "Standard Error: " << e.what() << " has occurred in the SummaryCommand class Function SummaryCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
48                 exit(1);
49         }
50         catch(...) {
51                 cout << "An unknown error has occurred in the SummaryCommand class function SummaryCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
52                 exit(1);
53         }       
54 }
55 //**********************************************************************************************************************
56
57 SummaryCommand::~SummaryCommand(){
58         delete sabund;
59         delete input;
60         delete read;
61 }
62
63 //**********************************************************************************************************************
64
65 int SummaryCommand::execute(){
66         try {
67                 outputFileName = ((getRootName(globaldata->inputFileName)) + "summary");
68                 openOutputFile(outputFileName, outputFileHandle);
69                 outputFileHandle << "label";
70         
71                 read = new ReadPhilFile(globaldata->inputFileName);     
72                 read->read(&*globaldata); 
73
74                 for(int i=0;i<sumCalculators.size();i++){
75                         if(sumCalculators[i]->getCols() == 1){
76                                 outputFileHandle << '\t' << sumCalculators[i]->getName();
77                         }
78                         else{
79                                 outputFileHandle << '\t' << sumCalculators[i]->getName() << "\t" << sumCalculators[i]->getName() << "_lci\t" << sumCalculators[i]->getName() << "_hci";
80                         }
81                 }
82                 outputFileHandle << endl;
83                 
84                 sabund = globaldata->sabund;
85                 input = globaldata->ginput;
86                 int count = 1;
87                 while(sabund != NULL){
88                 
89                         if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(sabund->getLabel()) == 1){                      
90         
91                                 cout << sabund->getLabel() << '\t' << count << endl;
92                         
93                                 outputFileHandle << sabund->getLabel();
94                                 for(int i=0;i<sumCalculators.size();i++){
95                                         vector<double> data = sumCalculators[i]->getValues(sabund);
96                                         outputFileHandle << '\t';
97                                         sumCalculators[i]->print(outputFileHandle);
98                                 }
99                                 outputFileHandle << endl;
100                         }
101                 
102                         sabund = input->getSAbundVector();
103                         count++;
104                 }
105         
106                 return 0;
107         }
108         catch(exception& e) {
109                 cout << "Standard Error: " << e.what() << " has occurred in the SummaryCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
110                 exit(1);
111         }
112         catch(...) {
113                 cout << "An unknown error has occurred in the SummaryCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
114                 exit(1);
115         }               
116 }
117
118 //**********************************************************************************************************************