]> git.donarmstrong.com Git - mothur.git/blob - collectcommand.cpp
added pipeline commands which involved change to command factory and command class...
[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 "nseqs.h"
14 #include "chao1.h"
15 #include "bootstrap.h"
16 #include "simpson.h"
17 #include "simpsoneven.h"
18 #include "invsimpson.h"
19 #include "npshannon.h"
20 #include "shannon.h"
21 #include "smithwilson.h"
22 #include "heip.h"
23 #include "shannoneven.h"
24 #include "jackknife.h"
25 #include "geom.h"
26 #include "qstat.h"
27 #include "logsd.h"
28 #include "bergerparker.h"
29 #include "bstick.h"
30 #include "goodscoverage.h"
31 #include "efron.h"
32 #include "boneh.h"
33 #include "solow.h"
34 #include "shen.h"
35 #include "coverage.h"
36
37 //**********************************************************************************************************************
38 vector<string> CollectCommand::getValidParameters(){    
39         try {
40                 string AlignArray[] =  {"freq","label","calc","abund","size","outputdir","inputdir"};
41                 vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
42                 return myArray;
43         }
44         catch(exception& e) {
45                 m->errorOut(e, "CollectCommand", "getValidParameters");
46                 exit(1);
47         }
48 }
49 //**********************************************************************************************************************
50 vector<string> CollectCommand::getRequiredParameters(){ 
51         try {
52                 vector<string> myArray;
53                 return myArray;
54         }
55         catch(exception& e) {
56                 m->errorOut(e, "CollectCommand", "getRequiredParameters");
57                 exit(1);
58         }
59 }
60 //**********************************************************************************************************************
61 vector<string> CollectCommand::getRequiredFiles(){      
62         try {
63                 string AlignArray[] =  {"shared","list","rabund","sabund","or"};
64                 vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
65                 return myArray;
66         }
67         catch(exception& e) {
68                 m->errorOut(e, "CollectCommand", "getRequiredFiles");
69                 exit(1);
70         }
71 }
72 //**********************************************************************************************************************
73 CollectCommand::CollectCommand(){       
74         try {
75                 //initialize outputTypes
76                 vector<string> tempOutNames;
77                 outputTypes["sobs"] = tempOutNames;
78                 outputTypes["chao"] = tempOutNames;
79                 outputTypes["nseqs"] = tempOutNames;
80                 outputTypes["coverage"] = tempOutNames;
81                 outputTypes["ace"] = tempOutNames;
82                 outputTypes["jack"] = tempOutNames;
83                 outputTypes["shannon"] = tempOutNames;
84                 outputTypes["shannoneven"] = tempOutNames;
85                 outputTypes["np_shannon"] = tempOutNames;
86                 outputTypes["heip"] = tempOutNames;
87                 outputTypes["smithwilson"] = tempOutNames;
88                 outputTypes["simpson"] = tempOutNames;
89                 outputTypes["simpsoneven"] = tempOutNames;
90                 outputTypes["invsimpson"] = tempOutNames;
91                 outputTypes["bootstrap"] = tempOutNames;
92                 outputTypes["geometric"] = tempOutNames;
93                 outputTypes["qstat"] = tempOutNames;
94                 outputTypes["logseries"] = tempOutNames;
95                 outputTypes["bergerparker"] = tempOutNames;
96                 outputTypes["bstick"] = tempOutNames;
97                 outputTypes["goodscoverage"] = tempOutNames;
98                 outputTypes["efron"] = tempOutNames;
99                 outputTypes["boneh"] = tempOutNames;
100                 outputTypes["solow"] = tempOutNames;
101                 outputTypes["shen"] = tempOutNames;
102         }
103         catch(exception& e) {
104                 m->errorOut(e, "CollectCommand", "CollectCommand");
105                 exit(1);
106         }
107 }
108 //**********************************************************************************************************************
109 CollectCommand::CollectCommand(string option)  {
110         try {
111                 globaldata = GlobalData::getInstance();
112                 abort = false;
113                 allLines = 1;
114                 labels.clear();
115                 Estimators.clear();
116                 
117                 //allow user to run help
118                 if(option == "help") { validCalculator = new ValidCalculators(); help(); delete validCalculator; abort = true; }
119                 
120                 else {
121                         //valid paramters for this command
122                         string Array[] =  {"freq","label","calc","abund","size","outputdir","inputdir"};
123                         vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
124                         
125                         OptionParser parser(option);
126                         map<string,string> parameters = parser.getParameters();
127                         
128                         ValidParameters validParameter;
129                 
130                         //check to make sure all parameters are valid for command
131                         for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
132                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
133                         }
134                         
135                         //initialize outputTypes
136                         vector<string> tempOutNames;
137                         outputTypes["sobs"] = tempOutNames;
138                         outputTypes["chao"] = tempOutNames;
139                         outputTypes["nseqs"] = tempOutNames;
140                         outputTypes["coverage"] = tempOutNames;
141                         outputTypes["ace"] = tempOutNames;
142                         outputTypes["jack"] = tempOutNames;
143                         outputTypes["shannon"] = tempOutNames;
144                         outputTypes["shannoneven"] = tempOutNames;
145                         outputTypes["np_shannon"] = tempOutNames;
146                         outputTypes["heip"] = tempOutNames;
147                         outputTypes["smithwilson"] = tempOutNames;
148                         outputTypes["simpson"] = tempOutNames;
149                         outputTypes["simpsoneven"] = tempOutNames;
150                         outputTypes["invsimpson"] = tempOutNames;
151                         outputTypes["bootstrap"] = tempOutNames;
152                         outputTypes["geometric"] = tempOutNames;
153                         outputTypes["qstat"] = tempOutNames;
154                         outputTypes["logseries"] = tempOutNames;
155                         outputTypes["bergerparker"] = tempOutNames;
156                         outputTypes["bstick"] = tempOutNames;
157                         outputTypes["goodscoverage"] = tempOutNames;
158                         outputTypes["efron"] = tempOutNames;
159                         outputTypes["boneh"] = tempOutNames;
160                         outputTypes["solow"] = tempOutNames;
161                         outputTypes["shen"] = tempOutNames;
162                         
163                         //if the user changes the output directory command factory will send this info to us in the output parameter 
164                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
165                         
166                         //make sure the user has already run the read.otu command
167                         if ((globaldata->getSharedFile() == "") && (globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { m->mothurOut("You must read a list, sabund, rabund or shared file before you can use the collect.single command."); m->mothurOutEndLine(); abort = true; }
168                         
169                         //check for optional parameter and set defaults
170                         // ...at some point should added some additional type checking...
171                         label = validParameter.validFile(parameters, "label", false);                   
172                         if (label == "not found") { label = ""; }
173                         else { 
174                                 if(label != "all") {  m->splitAtDash(label, labels);  allLines = 0;  }
175                                 else { allLines = 1;  }
176                         }
177                         
178                         //if the user has not specified any labels use the ones from read.otu
179                         if (label == "") {  
180                                 allLines = globaldata->allLines; 
181                                 labels = globaldata->labels; 
182                         }
183                                 
184                         calc = validParameter.validFile(parameters, "calc", false);                     
185                         if (calc == "not found") { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson";  }
186                         else { 
187                                  if (calc == "default")  {  calc = "sobs-chao-ace-jack-shannon-npshannon-simpson";  }
188                         }
189                         m->splitAtDash(calc, Estimators);
190
191                         string temp;
192                         temp = validParameter.validFile(parameters, "freq", false);                     if (temp == "not found") { temp = "100"; }
193                         convert(temp, freq); 
194                         
195                         temp = validParameter.validFile(parameters, "abund", false);            if (temp == "not found") { temp = "10"; }
196                         convert(temp, abund); 
197                         
198                         temp = validParameter.validFile(parameters, "size", false);                     if (temp == "not found") { temp = "0"; }
199                         convert(temp, size); 
200                 }
201                 
202         }
203         catch(exception& e) {
204                 m->errorOut(e, "CollectCommand", "CollectCommand");
205                 exit(1);
206         }                       
207 }
208 //**********************************************************************************************************************
209
210 void CollectCommand::help(){
211         try {
212                 m->mothurOut("The collect.single command can only be executed after a successful read.otu command. WITH ONE EXECEPTION. \n");
213                 m->mothurOut("The collect.single command can be executed after a successful cluster command.  It will use the .list file from the output of the cluster.\n");
214                 m->mothurOut("The collect.single command parameters are label, freq, calc and abund.  No parameters are required. \n");
215                 m->mothurOut("The collect.single command should be in the following format: \n");
216                 m->mothurOut("The freq parameter is used indicate when to output your data, by default it is set to 100. But you can set it to a percentage of the number of sequence. For example freq=0.10, means 10%. \n");
217                 m->mothurOut("collect.single(label=yourLabel, iters=yourIters, freq=yourFreq, calc=yourEstimators).\n");
218                 m->mothurOut("Example collect(label=unique-.01-.03, iters=10000, freq=10, calc=sobs-chao-ace-jack).\n");
219                 m->mothurOut("The default values for freq is 100, and calc are sobs-chao-ace-jack-shannon-npshannon-simpson.\n");
220                 validCalculator->printCalc("single", cout);
221                 m->mothurOut("The label parameter is used to analyze specific labels in your input.\n");
222                 m->mothurOut("Note: No spaces between parameter labels (i.e. freq), '=' and parameters (i.e.yourFreq).\n\n");
223         }
224         catch(exception& e) {
225                 m->errorOut(e, "CollectCommand", "help");
226                 exit(1);
227         }
228 }
229
230 //**********************************************************************************************************************
231
232 CollectCommand::~CollectCommand(){}
233
234 //**********************************************************************************************************************
235
236 int CollectCommand::execute(){
237         try {
238                 
239                 if (abort == true) { return 0; }
240                 
241                 string hadShared = "";
242                 if ((globaldata->getFormat() != "sharedfile")) { inputFileNames.push_back(globaldata->inputFileName);  }
243                 else { hadShared = globaldata->getSharedFile(); inputFileNames = parseSharedFile(globaldata->getSharedFile());  globaldata->setFormat("rabund");  }
244         
245                 for (int p = 0; p < inputFileNames.size(); p++) {
246                         
247                         if (m->control_pressed) {  outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }  globaldata->Groups.clear(); if (hadShared != "") {  globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile");  } return 0; }
248                         
249                         if (outputDir == "") { outputDir += m->hasPath(inputFileNames[p]); }
250                         string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p]));
251                         globaldata->inputFileName = inputFileNames[p];
252                 
253                         if (inputFileNames.size() > 1) {
254                                 m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine();
255                         }
256                 
257                         validCalculator = new ValidCalculators();
258                         
259                         for (int i=0; i<Estimators.size(); i++) {
260                                 if (validCalculator->isValidCalculator("single", Estimators[i]) == true) { 
261                                         if (Estimators[i] == "sobs") { 
262                                                 cDisplays.push_back(new CollectDisplay(new Sobs(), new OneColumnFile(fileNameRoot+"sobs")));
263                                                 outputNames.push_back(fileNameRoot+"sobs"); outputTypes["sobs"].push_back(fileNameRoot+"sobs");
264                                         }else if (Estimators[i] == "chao") { 
265                                                 cDisplays.push_back(new CollectDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"chao")));
266                                                 outputNames.push_back(fileNameRoot+"chao"); outputTypes["chao"].push_back(fileNameRoot+"chao");
267                                         }else if (Estimators[i] == "nseqs") { 
268                                                 cDisplays.push_back(new CollectDisplay(new NSeqs(), new OneColumnFile(fileNameRoot+"nseqs")));
269                                                 outputNames.push_back(fileNameRoot+"nseqs"); outputTypes["nseqs"].push_back(fileNameRoot+"nseqs");
270                                         }else if (Estimators[i] == "coverage") { 
271                                                 cDisplays.push_back(new CollectDisplay(new Coverage(), new OneColumnFile(fileNameRoot+"coverage")));
272                                                 outputNames.push_back(fileNameRoot+"coverage"); outputTypes["coverage"].push_back(fileNameRoot+"coverage");
273                                         }else if (Estimators[i] == "ace") { 
274                                                 cDisplays.push_back(new CollectDisplay(new Ace(abund), new ThreeColumnFile(fileNameRoot+"ace")));
275                                                 outputNames.push_back(fileNameRoot+"ace"); outputTypes["ace"].push_back(fileNameRoot+"ace");
276                                         }else if (Estimators[i] == "jack") { 
277                                                 cDisplays.push_back(new CollectDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"jack")));
278                                                 outputNames.push_back(fileNameRoot+"jack"); outputTypes["jack"].push_back(fileNameRoot+"jack");
279                                         }else if (Estimators[i] == "shannon") { 
280                                                 cDisplays.push_back(new CollectDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"shannon")));
281                                                 outputNames.push_back(fileNameRoot+"shannon"); outputTypes["shannon"].push_back(fileNameRoot+"shannon");
282                                         }else if (Estimators[i] == "shannoneven") { 
283                                                 cDisplays.push_back(new CollectDisplay(new ShannonEven(), new OneColumnFile(fileNameRoot+"shannoneven")));
284                                                 outputNames.push_back(fileNameRoot+"shannoneven"); outputTypes["shannoneven"].push_back(fileNameRoot+"shannoneven");
285                                         }else if (Estimators[i] == "npshannon") { 
286                                                 cDisplays.push_back(new CollectDisplay(new NPShannon(), new OneColumnFile(fileNameRoot+"np_shannon")));
287                                                 outputNames.push_back(fileNameRoot+"np_shannon"); outputTypes["np_shannon"].push_back(fileNameRoot+"np_shannon");
288                                         }else if (Estimators[i] == "heip") { 
289                                                 cDisplays.push_back(new CollectDisplay(new Heip(), new OneColumnFile(fileNameRoot+"heip")));
290                                                 outputNames.push_back(fileNameRoot+"heip"); outputTypes["heip"].push_back(fileNameRoot+"heip");
291                                         }else if (Estimators[i] == "smithwilson") { 
292                                                 cDisplays.push_back(new CollectDisplay(new SmithWilson(), new OneColumnFile(fileNameRoot+"smithwilson")));
293                                                 outputNames.push_back(fileNameRoot+"smithwilson"); outputTypes["smithwilson"].push_back(fileNameRoot+"smithwilson");
294                                         }else if (Estimators[i] == "simpson") { 
295                                                 cDisplays.push_back(new CollectDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"simpson")));
296                                                 outputNames.push_back(fileNameRoot+"simpson"); outputTypes["simpson"].push_back(fileNameRoot+"simpson");
297                                         }else if (Estimators[i] == "simpsoneven") { 
298                                                 cDisplays.push_back(new CollectDisplay(new SimpsonEven(), new OneColumnFile(fileNameRoot+"simpsoneven")));
299                                                 outputNames.push_back(fileNameRoot+"simpsoneven"); outputTypes["simpsoneven"].push_back(fileNameRoot+"simpsoneven");
300                                         }else if (Estimators[i] == "invsimpson") { 
301                                                 cDisplays.push_back(new CollectDisplay(new InvSimpson(), new ThreeColumnFile(fileNameRoot+"invsimpson")));
302                                                 outputNames.push_back(fileNameRoot+"invsimpson"); outputTypes["invsimpson"].push_back(fileNameRoot+"invsimpson");
303                                         }else if (Estimators[i] == "bootstrap") { 
304                                                 cDisplays.push_back(new CollectDisplay(new Bootstrap(), new OneColumnFile(fileNameRoot+"bootstrap")));
305                                                 outputNames.push_back(fileNameRoot+"bootstrap"); outputTypes["bootstrap"].push_back(fileNameRoot+"bootstrap");
306                                         }else if (Estimators[i] == "geometric") { 
307                                                 cDisplays.push_back(new CollectDisplay(new Geom(), new OneColumnFile(fileNameRoot+"geometric")));
308                                                 outputNames.push_back(fileNameRoot+"geometric"); outputTypes["geometric"].push_back(fileNameRoot+"geometric");
309                                         }else if (Estimators[i] == "qstat") { 
310                                                 cDisplays.push_back(new CollectDisplay(new QStat(), new OneColumnFile(fileNameRoot+"qstat")));
311                                                 outputNames.push_back(fileNameRoot+"qstat"); outputTypes["qstat"].push_back(fileNameRoot+"qstat");
312                                         }else if (Estimators[i] == "logseries") { 
313                                                 cDisplays.push_back(new CollectDisplay(new LogSD(), new OneColumnFile(fileNameRoot+"logseries")));
314                                                 outputNames.push_back(fileNameRoot+"logseries"); outputTypes["logseries"].push_back(fileNameRoot+"logseries");
315                                         }else if (Estimators[i] == "bergerparker") { 
316                                                 cDisplays.push_back(new CollectDisplay(new BergerParker(), new OneColumnFile(fileNameRoot+"bergerparker")));
317                                                 outputNames.push_back(fileNameRoot+"bergerparker"); outputTypes["bergerparker"].push_back(fileNameRoot+"bergerparker");
318                                         }else if (Estimators[i] == "bstick") { 
319                                                 cDisplays.push_back(new CollectDisplay(new BStick(), new ThreeColumnFile(fileNameRoot+"bstick")));
320                                                 outputNames.push_back(fileNameRoot+"bstick"); outputTypes["bstick"].push_back(fileNameRoot+"bstick");
321                                         }else if (Estimators[i] == "goodscoverage") { 
322                                                 cDisplays.push_back(new CollectDisplay(new GoodsCoverage(), new OneColumnFile(fileNameRoot+"goodscoverage")));
323                                                 outputNames.push_back(fileNameRoot+"goodscoverage"); outputTypes["goodscoverage"].push_back(fileNameRoot+"goodscoverage");
324                                         }else if (Estimators[i] == "efron") {
325                                                 cDisplays.push_back(new CollectDisplay(new Efron(size), new OneColumnFile(fileNameRoot+"efron")));
326                                                 outputNames.push_back(fileNameRoot+"efron"); outputTypes["efron"].push_back(fileNameRoot+"efron");
327                                         }else if (Estimators[i] == "boneh") {
328                                                 cDisplays.push_back(new CollectDisplay(new Boneh(size), new OneColumnFile(fileNameRoot+"boneh")));
329                                                 outputNames.push_back(fileNameRoot+"boneh"); outputTypes["boneh"].push_back(fileNameRoot+"boneh");
330                                         }else if (Estimators[i] == "solow") {
331                                                 cDisplays.push_back(new CollectDisplay(new Solow(size), new OneColumnFile(fileNameRoot+"solow")));
332                                                 outputNames.push_back(fileNameRoot+"solow"); outputTypes["solow"].push_back(fileNameRoot+"solow");
333                                         }else if (Estimators[i] == "shen") {
334                                                 cDisplays.push_back(new CollectDisplay(new Shen(size, abund), new OneColumnFile(fileNameRoot+"shen")));
335                                                 outputNames.push_back(fileNameRoot+"shen"); outputTypes["shen"].push_back(fileNameRoot+"shen");
336                                         }
337                                 }
338                         }
339                 
340                         //if the users entered no valid calculators don't execute command
341                         if (cDisplays.size() == 0) { if (hadShared != "") {  globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile");  } return 0; }
342                         
343                         read = new ReadOTUFile(inputFileNames[p]);      
344                         read->read(&*globaldata); 
345                 
346                         order = globaldata->gorder;
347                         string lastLabel = order->getLabel();
348                         input = globaldata->ginput;
349                         
350                         //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
351                         set<string> processedLabels;
352                         set<string> userLabels = labels;
353                         
354                         if (m->control_pressed) {  
355                                 for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
356                                 for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         } outputTypes.clear(); 
357                                 delete input;  globaldata->ginput = NULL;
358                                 delete read;
359                                 delete order; globaldata->gorder = NULL;
360                                 delete validCalculator;
361                                 globaldata->Groups.clear();
362                                 if (hadShared != "") {  globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile");  }
363                                 return 0;
364                         }
365
366
367                         while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
368                         
369                                 if (m->control_pressed) { 
370                                         for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
371                                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         } outputTypes.clear(); 
372                                         delete input;  globaldata->ginput = NULL;
373                                         delete read;
374                                         delete order; globaldata->gorder = NULL;
375                                         delete validCalculator;
376                                         globaldata->Groups.clear();
377                                         if (hadShared != "") {  globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile");  }
378                                         return 0;
379                                 }
380
381                                 
382                                 if(allLines == 1 || labels.count(order->getLabel()) == 1){
383                                 
384                                         m->mothurOut(order->getLabel()); m->mothurOutEndLine();
385                                         cCurve = new Collect(order, cDisplays);
386                                         cCurve->getCurve(freq);
387                                         delete cCurve;
388                                         
389                                         processedLabels.insert(order->getLabel());
390                                         userLabels.erase(order->getLabel());
391                                         
392                                         
393                                 }
394                                 //you have a label the user want that is smaller than this label and the last label has not already been processed 
395                                 if ((m->anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
396                                         string saveLabel = order->getLabel();
397                                         
398                                         delete order;
399                                         order = (input->getOrderVector(lastLabel));
400                                         
401                                         m->mothurOut(order->getLabel()); m->mothurOutEndLine();
402                                         cCurve = new Collect(order, cDisplays);
403                                         cCurve->getCurve(freq);
404                                         delete cCurve;
405                                         
406                                         
407                                         processedLabels.insert(order->getLabel());
408                                         userLabels.erase(order->getLabel());
409                                         
410                                         //restore real lastlabel to save below
411                                         order->setLabel(saveLabel);
412                                 }
413                                 
414                                 lastLabel = order->getLabel();  
415                                 
416                                 delete order;           
417                                 order = (input->getOrderVector());
418                         }
419                         
420                         
421                         if (m->control_pressed) { 
422                                         for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
423                                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         } outputTypes.clear(); 
424                                         delete input;  globaldata->ginput = NULL;
425                                         delete read;
426                                         delete validCalculator;
427                                         globaldata->Groups.clear();
428                                         if (hadShared != "") {  globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile");  }
429                                         return 0;
430                         }
431                                 
432                         //output error messages about any remaining user labels
433                         set<string>::iterator it;
434                         bool needToRun = false;
435                         for (it = userLabels.begin(); it != userLabels.end(); it++) {  
436                                 m->mothurOut("Your file does not include the label " + *it); 
437                                 if (processedLabels.count(lastLabel) != 1) {
438                                         m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
439                                         needToRun = true;
440                                 }else {
441                                         m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
442                                 }
443                         }
444                         
445                         //run last label if you need to
446                         if (needToRun == true)  {
447                                 if (order != NULL) {    delete order;   }
448                                 order = (input->getOrderVector(lastLabel));
449                                 
450                                 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
451                                 
452                                 cCurve = new Collect(order, cDisplays);
453                                 cCurve->getCurve(freq);
454                                 delete cCurve;
455                                 
456                                 if (m->control_pressed) { 
457                                         for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
458                                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         } outputTypes.clear(); 
459                                         delete input;  globaldata->ginput = NULL;
460                                         delete read;
461                                         delete order; globaldata->gorder = NULL;
462                                         delete validCalculator;
463                                         globaldata->Groups.clear();
464                                         if (hadShared != "") {  globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile");  }
465                                         return 0;
466                                 }
467                                 delete order;
468                         }
469                         
470                         for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
471                         cDisplays.clear();
472                         delete input;  globaldata->ginput = NULL;
473                         delete read;
474                         globaldata->gorder = NULL;
475                         delete validCalculator;
476                 }
477                 
478                 //return to shared mode if you changed above
479                 if (hadShared != "") {  globaldata->setSharedFile(hadShared); globaldata->setFormat("sharedfile");  }
480
481                 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        remove(outputNames[i].c_str());         } return 0; }
482                                 
483                 m->mothurOutEndLine();
484                 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
485                 for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
486                 m->mothurOutEndLine();
487
488                 
489                 return 0;
490         }
491         catch(exception& e) {
492                 m->errorOut(e, "CollectCommand", "execute");
493                 exit(1);
494         }
495 }
496
497 //**********************************************************************************************************************
498 vector<string> CollectCommand::parseSharedFile(string filename) {
499         try {
500                 vector<string> filenames;
501                 
502                 map<string, ofstream*> filehandles;
503                 map<string, ofstream*>::iterator it3;
504                 
505                                 
506                 //read first line
507                 read = new ReadOTUFile(filename);       
508                 read->read(&*globaldata); 
509                         
510                 input = globaldata->ginput;
511                 vector<SharedRAbundVector*> lookup = input->getSharedRAbundVectors();
512                 
513                 string sharedFileRoot = m->getRootName(filename);
514                 
515                 //clears file before we start to write to it below
516                 for (int i=0; i<lookup.size(); i++) {
517                         remove((sharedFileRoot + lookup[i]->getGroup() + ".rabund").c_str());
518                         filenames.push_back((sharedFileRoot + lookup[i]->getGroup() + ".rabund"));
519                 }
520                 
521                 ofstream* temp;
522                 for (int i=0; i<lookup.size(); i++) {
523                         temp = new ofstream;
524                         filehandles[lookup[i]->getGroup()] = temp;
525                         groups.push_back(lookup[i]->getGroup());
526                 }
527
528                 while(lookup[0] != NULL) {
529                 
530                         for (int i = 0; i < lookup.size(); i++) {
531                                 RAbundVector rav = lookup[i]->getRAbundVector();
532                                 m->openOutputFileAppend(sharedFileRoot + lookup[i]->getGroup() + ".rabund", *(filehandles[lookup[i]->getGroup()]));
533                                 rav.print(*(filehandles[lookup[i]->getGroup()]));
534                                 (*(filehandles[lookup[i]->getGroup()])).close();
535                         }
536                 
537                         for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
538                         lookup = input->getSharedRAbundVectors();
539                 }
540                 
541                 //free memory
542                 for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
543                         delete it3->second;
544                 }
545                 delete read;
546                 delete input;
547                 globaldata->ginput = NULL;
548
549                 return filenames;
550         }
551         catch(exception& e) {
552                 m->errorOut(e, "CollectCommand", "parseSharedFile");
553                 exit(1);
554         }
555 }
556 //**********************************************************************************************************************
557