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