]> git.donarmstrong.com Git - mothur.git/blob - rarefactcommand.cpp
Added get.line command.
[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                                         convert(globaldata->getAbund(), abund);
39                                         if(abund < 5)
40                                                 abund = 10;
41                                         rDisplays.push_back(new RareDisplay(new Ace(abund), new ThreeColumnFile(fileNameRoot+"r_ace")));
42                                 }else if (globaldata->Estimators[i] == "jack") { 
43                                         rDisplays.push_back(new RareDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"r_jack")));
44                                 }else if (globaldata->Estimators[i] == "shannon") { 
45                                         rDisplays.push_back(new RareDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"r_shannon")));
46                                 }else if (globaldata->Estimators[i] == "npshannon") { 
47                                         rDisplays.push_back(new RareDisplay(new NPShannon(), new ThreeColumnFile(fileNameRoot+"r_npshannon")));
48                                 }else if (globaldata->Estimators[i] == "simpson") { 
49                                         rDisplays.push_back(new RareDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"r_simpson")));
50                                 }else if (globaldata->Estimators[i] == "bootstrap") { 
51                                         rDisplays.push_back(new RareDisplay(new Bootstrap(), new ThreeColumnFile(fileNameRoot+"r_bootstrap")));
52                                 }
53                         }
54                 }
55                 
56                 //reset calc for next command
57                 globaldata->setCalc("");
58
59         }
60         catch(exception& e) {
61                 cout << "Standard Error: " << e.what() << " has occurred in the RareFactCommand class Function RareFactCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
62                 exit(1);
63         }
64         catch(...) {
65                 cout << "An unknown error has occurred in the RareFactCommand class function RareFactCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
66                 exit(1);
67         }       
68                         
69 }
70
71 //**********************************************************************************************************************
72
73 RareFactCommand::~RareFactCommand(){
74         delete order;
75         delete input;
76         delete rCurve;
77         delete read;
78 }
79
80 //**********************************************************************************************************************
81
82 int RareFactCommand::execute(){
83         try {
84                 int count = 1;
85                 
86                 //if the users entered no valid calculators don't execute command
87                 if (rDisplays.size() == 0) { return 0; }
88
89                 read = new ReadPhilFile(globaldata->inputFileName);     
90                 read->read(&*globaldata); 
91
92                 order = globaldata->gorder;
93                 input = globaldata->ginput;
94         
95                 while(order != NULL){
96                 
97                         if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
98                         
99                                 rCurve = new Rarefact(order, rDisplays);
100                                 convert(globaldata->getFreq(), freq);
101                                 convert(globaldata->getIters(), nIters);
102                                 rCurve->getCurve(freq, nIters);
103                         
104                                 delete rCurve;
105                         
106                                 cout << order->getLabel() << '\t' << count << endl;
107                         }
108                 
109                         order = (input->getOrderVector());
110                         count++;
111                 
112                 }
113         
114                 for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }       
115                 return 0;
116         }
117         catch(exception& e) {
118                 cout << "Standard Error: " << e.what() << " has occurred in the RareFactCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
119                 exit(1);
120         }
121         catch(...) {
122                 cout << "An unknown error has occurred in the RareFactCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
123                 exit(1);
124         }       
125 }
126
127 //**********************************************************************************************************************