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