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