]> git.donarmstrong.com Git - mothur.git/blob - rarefactcommand.cpp
Initial revision
[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                 int i;
29                 for (i=0; i<globaldata->rareEstimators.size(); i++) {
30                         if (globaldata->rareEstimators[i] == "sobs") { 
31                                 rDisplays.push_back(new RareDisplay(new Sobs(), new ThreeColumnFile(fileNameRoot+"rarefaction")));
32                         }else if (globaldata->rareEstimators[i] == "chao") { 
33                                 rDisplays.push_back(new RareDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"r_chao")));
34                         }else if (globaldata->rareEstimators[i] == "ace") { 
35                                 rDisplays.push_back(new RareDisplay(new Ace(), new ThreeColumnFile(fileNameRoot+"r_ace")));
36                         }else if (globaldata->rareEstimators[i] == "jack") { 
37                                 rDisplays.push_back(new RareDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"r_jack")));
38                         }else if (globaldata->rareEstimators[i] == "shannon") { 
39                                 rDisplays.push_back(new RareDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"r_shannon")));
40                         }else if (globaldata->rareEstimators[i] == "npshannon") { 
41                                 rDisplays.push_back(new RareDisplay(new NPShannon(), new ThreeColumnFile(fileNameRoot+"r_npshannon")));
42                         }else if (globaldata->rareEstimators[i] == "simpson") { 
43                                 rDisplays.push_back(new RareDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"r_simpson")));
44                         }else if (globaldata->rareEstimators[i] == "bootstrap") { 
45                                 rDisplays.push_back(new RareDisplay(new Bootstrap(), new ThreeColumnFile(fileNameRoot+"r_bootstrap")));
46                         }
47                 }
48         
49         
50         }
51         catch(exception& e) {
52                 cout << "Standard Error: " << e.what() << " has occurred in the RareFactCommand class Function RareFactCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
53                 exit(1);
54         }
55         catch(...) {
56                 cout << "An unknown error has occurred in the RareFactCommand class function RareFactCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
57                 exit(1);
58         }       
59                         
60 }
61
62 //**********************************************************************************************************************
63
64 RareFactCommand::~RareFactCommand(){
65         delete order;
66         delete input;
67         delete rCurve;
68         delete read;
69 }
70
71 //**********************************************************************************************************************
72
73 int RareFactCommand::execute(){
74         try {
75                 int count = 1;
76                 read = new ReadPhilFile(globaldata->inputFileName);     
77                 read->read(&*globaldata); 
78
79                 order = globaldata->gorder;
80                 input = globaldata->ginput;
81         
82                 while(order != NULL){
83                 
84                         if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
85                         
86                                 rCurve = new Rarefact(order, rDisplays);
87                                 convert(globaldata->getFreq(), freq);
88                                 convert(globaldata->getIters(), nIters);
89                                 rCurve->getCurve(freq, nIters);
90                         
91                                 delete rCurve;
92                         
93                                 cout << order->getLabel() << '\t' << count << endl;
94                         }
95                 
96                         order = (input->getOrderVector());
97                         count++;
98                 
99                 }
100         
101                 for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }       
102                 return 0;
103         }
104         catch(exception& e) {
105                 cout << "Standard Error: " << e.what() << " has occurred in the RareFactCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
106                 exit(1);
107         }
108         catch(...) {
109                 cout << "An unknown error has occurred in the RareFactCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
110                 exit(1);
111         }       
112 }
113
114 //**********************************************************************************************************************