]> git.donarmstrong.com Git - mothur.git/blob - collectsharedcommand.cpp
Added get.line command.
[mothur.git] / collectsharedcommand.cpp
1 /*
2  *  collectsharedcommand.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 "collectsharedcommand.h"
11 #include "sharedsobscollectsummary.h"
12 #include "sharedchao1.h"
13 #include "sharedace.h"
14 #include "sharedjabund.h"
15 #include "sharedsorabund.h"
16 #include "sharedjclass.h"
17 #include "sharedsorclass.h"
18 #include "sharedjest.h"
19 #include "sharedsorest.h"
20 #include "sharedthetayc.h"
21 #include "sharedthetan.h"
22
23
24 //**********************************************************************************************************************
25
26 CollectSharedCommand::CollectSharedCommand(){
27         try {
28                 globaldata = GlobalData::getInstance();
29                 string fileNameRoot;
30                 fileNameRoot = getRootName(globaldata->inputFileName);
31                 format = globaldata->getFormat();
32                 validCalculator = new ValidCalculators();
33                 
34                 int i;
35                 for (i=0; i<globaldata->Estimators.size(); i++) {
36                         if (validCalculator->isValidCalculator("shared", globaldata->Estimators[i]) == true) { 
37                                 if (globaldata->Estimators[i] == "sharedchao") { 
38                                         cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao")));
39                                 }else if (globaldata->Estimators[i] == "sharedsobs") { 
40                                         cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs")));
41                                 }else if (globaldata->Estimators[i] == "sharedace") { 
42                                         cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace")));
43                                 }else if (globaldata->Estimators[i] == "sharedjabund") {        
44                                         cDisplays.push_back(new CollectDisplay(new SharedJAbund(), new SharedOneColumnFile(fileNameRoot+"shared.jabund")));
45                                 }else if (globaldata->Estimators[i] == "sharedsorensonabund") { 
46                                         cDisplays.push_back(new CollectDisplay(new SharedSorAbund(), new SharedOneColumnFile(fileNameRoot+"shared.sorabund")));
47                                 }else if (globaldata->Estimators[i] == "sharedjclass") { 
48                                         cDisplays.push_back(new CollectDisplay(new SharedJclass(), new SharedOneColumnFile(fileNameRoot+"shared.jclass")));
49                                 }else if (globaldata->Estimators[i] == "sharedsorclass") { 
50                                         cDisplays.push_back(new CollectDisplay(new SharedSorClass(), new SharedOneColumnFile(fileNameRoot+"shared.sorclass")));
51                                 }else if (globaldata->Estimators[i] == "sharedjest") { 
52                                         cDisplays.push_back(new CollectDisplay(new SharedJest(), new SharedOneColumnFile(fileNameRoot+"shared.jest")));
53                                 }else if (globaldata->Estimators[i] == "sharedsorest") { 
54                                         cDisplays.push_back(new CollectDisplay(new SharedSorEst(), new SharedOneColumnFile(fileNameRoot+"shared.sorest")));
55                                 }else if (globaldata->Estimators[i] == "sharedthetayc") { 
56                                         cDisplays.push_back(new CollectDisplay(new SharedThetaYC(), new SharedOneColumnFile(fileNameRoot+"shared.thetayc")));
57                                 }else if (globaldata->Estimators[i] == "sharedthetan") { 
58                                         cDisplays.push_back(new CollectDisplay(new SharedThetaN(), new SharedOneColumnFile(fileNameRoot+"shared.thetan")));
59                                 }
60                         }
61                 }
62                 
63                 //reset calc for next command
64                 globaldata->setCalc("");
65
66         }
67         catch(exception& e) {
68                 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
69                 exit(1);
70         }
71         catch(...) {
72                 cout << "An unknown error has occurred in the CollectSharedCommand class function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
73                 exit(1);
74         }       
75                         
76 }
77
78 //**********************************************************************************************************************
79
80 CollectSharedCommand::~CollectSharedCommand(){
81         delete order;
82         delete input;
83         delete cCurve;
84         delete read;
85 }
86
87 //**********************************************************************************************************************
88
89 int CollectSharedCommand::execute(){
90         try {
91                 int count = 1;
92                 
93                 //if the users entered no valid calculators don't execute command
94                 if (cDisplays.size() == 0) { return 0; }
95                 
96                 if (format == "sharedfile") {
97                         read = new ReadPhilFile(globaldata->inputFileName);     
98                         read->read(&*globaldata); 
99                         
100                         input = globaldata->ginput;
101                         order = input->getSharedOrderVector();
102                 }else {
103                         //you are using a list and a groupfile
104                         read = new ReadPhilFile(globaldata->inputFileName);     
105                         read->read(&*globaldata); 
106                 
107                         input = globaldata->ginput;
108                         SharedList = globaldata->gSharedList;
109                         order = SharedList->getSharedOrderVector();
110                 }
111                 set<string> orderList;
112
113                 while(order != NULL){
114                         orderList.insert(order->getLabel());
115                         if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
116                                 //create collectors curve
117                                 cCurve = new Collect(order, cDisplays);
118                                 convert(globaldata->getFreq(), freq);
119                                 cCurve->getSharedCurve(freq);
120                         
121                                 delete cCurve;
122                         
123                                 cout << order->getLabel() << '\t' << count << endl;
124                         }
125                         
126                         //get next line to process
127                         if (format == "sharedfile") {
128                                 order = input->getSharedOrderVector();
129                         }else {
130                                 //you are using a list and a groupfile
131                                 SharedList = input->getSharedListVector(); //get new list vector to process
132                                 if (SharedList != NULL) {
133                                         order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
134                                 }else {
135                                         break;
136                                 }
137                         }
138                         
139                         count++;
140                 }
141                 set<string>::iterator i;
142                 for(i = globaldata->labels.begin(); i != globaldata->labels.end(); ++i)
143                         if(orderList.count(*i) == 0)
144                                 cout << "'" << *i << "'" << " is not a valid label.\n";
145                 globaldata->clearLabels();
146                 for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }       
147                 return 0;
148         }
149         catch(exception& e) {
150                 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
151                 exit(1);
152         }
153         catch(...) {
154                 cout << "An unknown error has occurred in the CollectSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
155                 exit(1);
156         }       
157 }
158
159
160 //**********************************************************************************************************************