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