]> git.donarmstrong.com Git - mothur.git/blob - rarefactcommand.cpp
added read.shared, broke up globaldata a bit
[mothur.git] / rarefactcommand.cpp
1 /*
2  *  rarefactcommand.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 "rarefactcommand.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 RareFactCommand::RareFactCommand(){
24         try {
25                 globaldata = GlobalData::getInstance();
26                 string fileNameRoot;
27                 fileNameRoot = getRootName(globaldata->inputFileName);
28                 validCalculator = new ValidCalculators();
29                 
30                 int i;
31                 for (i=0; i<globaldata->Estimators.size(); i++) {
32                         if (validCalculator->isValidCalculator("rarefaction", globaldata->Estimators[i]) == true) { 
33                                 if (globaldata->Estimators[i] == "sobs") { 
34                                         rDisplays.push_back(new RareDisplay(new Sobs(), new ThreeColumnFile(fileNameRoot+"rarefaction")));
35                                 }else if (globaldata->Estimators[i] == "chao") { 
36                                         rDisplays.push_back(new RareDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"r_chao")));
37                                 }else if (globaldata->Estimators[i] == "ace") { 
38                                         rDisplays.push_back(new RareDisplay(new Ace(), new ThreeColumnFile(fileNameRoot+"r_ace")));
39                                 }else if (globaldata->Estimators[i] == "jack") { 
40                                         rDisplays.push_back(new RareDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"r_jack")));
41                                 }else if (globaldata->Estimators[i] == "shannon") { 
42                                         rDisplays.push_back(new RareDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"r_shannon")));
43                                 }else if (globaldata->Estimators[i] == "npshannon") { 
44                                         rDisplays.push_back(new RareDisplay(new NPShannon(), new ThreeColumnFile(fileNameRoot+"r_npshannon")));
45                                 }else if (globaldata->Estimators[i] == "simpson") { 
46                                         rDisplays.push_back(new RareDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"r_simpson")));
47                                 }else if (globaldata->Estimators[i] == "bootstrap") { 
48                                         rDisplays.push_back(new RareDisplay(new Bootstrap(), new ThreeColumnFile(fileNameRoot+"r_bootstrap")));
49                                 }
50                         }
51                 }
52                 
53                 //reset calc for next command
54                 globaldata->setCalc("");
55
56         }
57         catch(exception& e) {
58                 cout << "Standard Error: " << e.what() << " has occurred in the RareFactCommand class Function RareFactCommand. 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 RareFactCommand class function RareFactCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
63                 exit(1);
64         }       
65                         
66 }
67
68 //**********************************************************************************************************************
69
70 RareFactCommand::~RareFactCommand(){
71         delete order;
72         delete input;
73         delete rCurve;
74         delete read;
75 }
76
77 //**********************************************************************************************************************
78
79 int RareFactCommand::execute(){
80         try {
81                 int count = 1;
82                 
83                 //if the users entered no valid calculators don't execute command
84                 if (rDisplays.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                                 rCurve = new Rarefact(order, rDisplays);
97                                 convert(globaldata->getFreq(), freq);
98                                 convert(globaldata->getIters(), nIters);
99                                 rCurve->getCurve(freq, nIters);
100                         
101                                 delete rCurve;
102                         
103                                 cout << order->getLabel() << '\t' << count << endl;
104                         }
105                 
106                         order = (input->getOrderVector());
107                         count++;
108                 
109                 }
110         
111                 for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }       
112                 return 0;
113         }
114         catch(exception& e) {
115                 cout << "Standard Error: " << e.what() << " has occurred in the RareFactCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
116                 exit(1);
117         }
118         catch(...) {
119                 cout << "An unknown error has occurred in the RareFactCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
120                 exit(1);
121         }       
122 }
123
124 //**********************************************************************************************************************