]> git.donarmstrong.com Git - mothur.git/blob - collectsharedcommand.cpp
*** empty log message ***
[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 #include "sharedkstest.h"
23 #include "whittaker.h"
24 #include "sharednseqs.h"
25 #include "sharedochiai.h"
26 #include "sharedanderbergs.h"
27 #include "sharedkulczynski.h"
28 #include "sharedkulczynskicody.h"
29 #include "sharedlennon.h"
30 #include "sharedmorisitahorn.h"
31 #include "sharedbraycurtis.h"
32 #include "sharedjackknife.h"
33 #include "sharedwhittaker.h"
34
35
36
37 //**********************************************************************************************************************
38
39 CollectSharedCommand::CollectSharedCommand(){
40         try {
41                 globaldata = GlobalData::getInstance();
42                 string fileNameRoot;
43                 fileNameRoot = getRootName(globaldata->inputFileName);
44                 format = globaldata->getFormat();
45                 validCalculator = new ValidCalculators();
46                 util = new SharedUtil();
47                 
48                 int i;
49                 for (i=0; i<globaldata->Estimators.size(); i++) {
50                         if (validCalculator->isValidCalculator("shared", globaldata->Estimators[i]) == true) { 
51                                 if (globaldata->Estimators[i] == "sharedchao") { 
52                                         cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao")));
53                                 }else if (globaldata->Estimators[i] == "sharedsobs") { 
54                                         cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs")));
55                                 }else if (globaldata->Estimators[i] == "sharedace") { 
56                                         cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace")));
57                                 }else if (globaldata->Estimators[i] == "jabund") {      
58                                         cDisplays.push_back(new CollectDisplay(new JAbund(), new SharedOneColumnFile(fileNameRoot+"jabund")));
59                                 }else if (globaldata->Estimators[i] == "sorabund") { 
60                                         cDisplays.push_back(new CollectDisplay(new SorAbund(), new SharedOneColumnFile(fileNameRoot+"sorabund")));
61                                 }else if (globaldata->Estimators[i] == "jclass") { 
62                                         cDisplays.push_back(new CollectDisplay(new Jclass(), new SharedOneColumnFile(fileNameRoot+"jclass")));
63                                 }else if (globaldata->Estimators[i] == "sorclass") { 
64                                         cDisplays.push_back(new CollectDisplay(new SorClass(), new SharedOneColumnFile(fileNameRoot+"sorclass")));
65                                 }else if (globaldata->Estimators[i] == "jest") { 
66                                         cDisplays.push_back(new CollectDisplay(new Jest(), new SharedOneColumnFile(fileNameRoot+"jest")));
67                                 }else if (globaldata->Estimators[i] == "sorest") { 
68                                         cDisplays.push_back(new CollectDisplay(new SorEst(), new SharedOneColumnFile(fileNameRoot+"sorest")));
69                                 }else if (globaldata->Estimators[i] == "thetayc") { 
70                                         cDisplays.push_back(new CollectDisplay(new ThetaYC(), new SharedOneColumnFile(fileNameRoot+"thetayc")));
71                                 }else if (globaldata->Estimators[i] == "thetan") { 
72                                         cDisplays.push_back(new CollectDisplay(new ThetaN(), new SharedOneColumnFile(fileNameRoot+"thetan")));
73                                 }else if (globaldata->Estimators[i] == "kstest") { 
74                                         cDisplays.push_back(new CollectDisplay(new KSTest(), new SharedOneColumnFile(fileNameRoot+"kstest")));
75                                 }else if (globaldata->Estimators[i] == "whittaker") { 
76                                         cDisplays.push_back(new CollectDisplay(new Whittaker(), new SharedOneColumnFile(fileNameRoot+"whittaker")));
77                                 }else if (globaldata->Estimators[i] == "sharednseqs") { 
78                                         cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(fileNameRoot+"shared.nseqs")));
79
80                                 }else if (globaldata->Estimators[i] == "ochiai") { 
81                                         cDisplays.push_back(new CollectDisplay(new Ochiai(), new SharedOneColumnFile(fileNameRoot+"ochiai")));
82                                 }else if (globaldata->Estimators[i] == "anderberg") { 
83                                         cDisplays.push_back(new CollectDisplay(new Anderberg(), new SharedOneColumnFile(fileNameRoot+"anderberg")));
84                                 }else if (globaldata->Estimators[i] == "skulczynski") { 
85                                         cDisplays.push_back(new CollectDisplay(new Kulczynski(), new SharedOneColumnFile(fileNameRoot+"kulczynski")));
86                                 }else if (globaldata->Estimators[i] == "kulczynskicody") { 
87                                         cDisplays.push_back(new CollectDisplay(new KulczynskiCody(), new SharedOneColumnFile(fileNameRoot+"kulczynskicody")));
88                                 }else if (globaldata->Estimators[i] == "lennon") { 
89                                         cDisplays.push_back(new CollectDisplay(new Lennon(), new SharedOneColumnFile(fileNameRoot+"lennon")));
90                                 }else if (globaldata->Estimators[i] == "morisitahorn") { 
91                                         cDisplays.push_back(new CollectDisplay(new MorHorn(), new SharedOneColumnFile(fileNameRoot+"morisitahorn")));
92                                 }else if (globaldata->Estimators[i] == "braycurtis") { 
93                                         cDisplays.push_back(new CollectDisplay(new BrayCurtis(), new SharedOneColumnFile(fileNameRoot+"braycurtis")));
94                                 }
95                         }
96                 }
97                 
98                 //reset calc for next command
99                 globaldata->setCalc("");
100
101         }
102         catch(exception& e) {
103                 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function CollectSharedCommand. 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 CollectSharedCommand class function CollectSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
108                 exit(1);
109         }       
110                         
111 }
112
113 //**********************************************************************************************************************
114
115 CollectSharedCommand::~CollectSharedCommand(){
116         delete order;
117         delete input;
118         delete cCurve;
119         delete read;
120         delete util;
121 }
122
123 //**********************************************************************************************************************
124
125 int CollectSharedCommand::execute(){
126         try {
127                 int count = 1;
128                 
129                 //if the users entered no valid calculators don't execute command
130                 if (cDisplays.size() == 0) { return 0; }
131                 
132                 if (format == "sharedfile") {
133                         read = new ReadOTUFile(globaldata->inputFileName);      
134                         read->read(&*globaldata); 
135                         
136                         input = globaldata->ginput;
137                         order = input->getSharedOrderVector();
138                 }else {
139                         //you are using a list and a groupfile
140                         read = new ReadOTUFile(globaldata->inputFileName);      
141                         read->read(&*globaldata); 
142                 
143                         input = globaldata->ginput;
144                         SharedList = globaldata->gSharedList;
145                         order = SharedList->getSharedOrderVector();
146                 }
147                 set<string> orderList;
148                 
149                 //set users groups
150                 util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "collect");
151                 util->updateGroupIndex(globaldata->Groups, globaldata->gGroupmap->groupIndex);
152
153                 while(order != NULL){
154                         orderList.insert(order->getLabel());
155                         if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
156                                 //create collectors curve
157                                 cCurve = new Collect(order, cDisplays);
158                                 convert(globaldata->getFreq(), freq);
159                                 cCurve->getSharedCurve(freq);
160                         
161                                 delete cCurve;
162                         
163                                 cout << order->getLabel() << '\t' << count << endl;
164                         }
165                         
166                         //get next line to process
167                         if (format == "sharedfile") {
168                                 order = input->getSharedOrderVector();
169                         }else {
170                                 //you are using a list and a groupfile
171                                 SharedList = input->getSharedListVector(); //get new list vector to process
172                                 if (SharedList != NULL) {
173                                         order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
174                                 }else {
175                                         break;
176                                 }
177                         }
178                         
179                         count++;
180                 }
181                 set<string>::iterator i;
182                 for(i = globaldata->labels.begin(); i != globaldata->labels.end(); ++i)
183                         if(orderList.count(*i) == 0)
184                                 cout << "'" << *i << "'" << " is not a valid label.\n";
185                 for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }       
186                 
187                 //reset groups parameter
188                 globaldata->Groups.clear();  globaldata->setGroups("");
189                 
190                 return 0;
191         }
192         catch(exception& e) {
193                 cout << "Standard Error: " << e.what() << " has occurred in the CollectSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
194                 exit(1);
195         }
196         catch(...) {
197                 cout << "An unknown error has occurred in the CollectSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
198                 exit(1);
199         }       
200 }
201
202 /***********************************************************/
203