]> git.donarmstrong.com Git - mothur.git/blob - collectsharedcommand.cpp
fixed bug with trim.seqs- when a file is blank for a grouping mothur removed it,...
[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 "whittaker.h"
34 #include "odum.h"
35 #include "canberra.h"
36 #include "stricteuclidean.h"
37 #include "strictchord.h"
38 #include "hellinger.h"
39 #include "manhattan.h"
40 #include "strictpearson.h"
41 #include "soergel.h"
42 #include "spearman.h"
43 #include "strictkulczynski.h"
44 #include "speciesprofile.h"
45 #include "hamming.h"
46
47 //**********************************************************************************************************************
48 vector<string> CollectSharedCommand::getValidParameters(){      
49         try {
50                 string AlignArray[] =  {"freq","label","calc","groups","all","outputdir","inputdir"};
51                 vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
52                 return myArray;
53         }
54         catch(exception& e) {
55                 m->errorOut(e, "CollectSharedCommand", "getValidParameters");
56                 exit(1);
57         }
58 }
59 //**********************************************************************************************************************
60 vector<string> CollectSharedCommand::getRequiredParameters(){   
61         try {
62                 vector<string> myArray;
63                 return myArray;
64         }
65         catch(exception& e) {
66                 m->errorOut(e, "CollectSharedCommand", "getRequiredParameters");
67                 exit(1);
68         }
69 }
70 //**********************************************************************************************************************
71 vector<string> CollectSharedCommand::getRequiredFiles(){        
72         try {
73                 string AlignArray[] =  {"shared"};
74                 vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
75                 return myArray;
76         }
77         catch(exception& e) {
78                 m->errorOut(e, "CollectSharedCommand", "getRequiredFiles");
79                 exit(1);
80         }
81 }
82 //**********************************************************************************************************************
83 CollectSharedCommand::CollectSharedCommand(){   
84         try {
85                 abort = true;
86                 //initialize outputTypes
87                 vector<string> tempOutNames;
88                 outputTypes["sharedchao"] = tempOutNames;
89                 outputTypes["sharedsobs"] = tempOutNames;
90                 outputTypes["sharedace"] = tempOutNames;
91                 outputTypes["jabund"] = tempOutNames;
92                 outputTypes["sorabund"] = tempOutNames;
93                 outputTypes["jclass"] = tempOutNames;
94                 outputTypes["sorclass"] = tempOutNames;
95                 outputTypes["jest"] = tempOutNames;
96                 outputTypes["sorest"] = tempOutNames;
97                 outputTypes["thetayc"] = tempOutNames;
98                 outputTypes["thetan"] = tempOutNames;
99                 outputTypes["kstest"] = tempOutNames;
100                 outputTypes["whittaker"] = tempOutNames;
101                 outputTypes["sharednseqs"] = tempOutNames;
102                 outputTypes["ochiai"] = tempOutNames;
103                 outputTypes["anderberg"] = tempOutNames;
104                 outputTypes["skulczynski"] = tempOutNames;
105                 outputTypes["kulczynskicody"] = tempOutNames;
106                 outputTypes["lennon"] = tempOutNames;
107                 outputTypes["morisitahorn"] = tempOutNames;
108                 outputTypes["braycurtis"] = tempOutNames;
109                 outputTypes["odum"] = tempOutNames;
110                 outputTypes["canberra"] = tempOutNames;
111                 outputTypes["stricteuclidean"] = tempOutNames;
112                 outputTypes["strictchord"] = tempOutNames;
113                 outputTypes["hellinger"] = tempOutNames;
114                 outputTypes["manhattan"] = tempOutNames;
115                 outputTypes["strictpearson"] = tempOutNames;
116                 outputTypes["soergel"] = tempOutNames;
117                 outputTypes["spearman"] = tempOutNames;
118                 outputTypes["strictkulczynski"] = tempOutNames;
119                 outputTypes["speciesprofile"] = tempOutNames;
120                 outputTypes["hamming"] = tempOutNames;
121                 
122         }
123         catch(exception& e) {
124                 m->errorOut(e, "CollectSharedCommand", "CollectSharedCommand");
125                 exit(1);
126         }
127 }
128 //**********************************************************************************************************************
129 CollectSharedCommand::CollectSharedCommand(string option)  {
130         try {
131                 globaldata = GlobalData::getInstance();
132                 abort = false;
133                 allLines = 1;
134                 labels.clear();
135                 Estimators.clear();
136                 Groups.clear();
137                 
138                 //allow user to run help
139                 if(option == "help") { validCalculator = new ValidCalculators(); help(); abort = true; }
140                 
141                 else {
142                         //valid paramters for this command
143                         string Array[] =  {"freq","label","calc","groups","all","outputdir","inputdir"};
144                         vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
145                         
146                         OptionParser parser(option);
147                         map<string,string> parameters=parser.getParameters();
148                         
149                         ValidParameters validParameter;
150                 
151                         //check to make sure all parameters are valid for command
152                         for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
153                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
154                         }
155                         
156                         //initialize outputTypes
157                         vector<string> tempOutNames;
158                         outputTypes["sharedchao"] = tempOutNames;
159                         outputTypes["sharedsobs"] = tempOutNames;
160                         outputTypes["sharedace"] = tempOutNames;
161                         outputTypes["jabund"] = tempOutNames;
162                         outputTypes["sorabund"] = tempOutNames;
163                         outputTypes["jclass"] = tempOutNames;
164                         outputTypes["sorclass"] = tempOutNames;
165                         outputTypes["jest"] = tempOutNames;
166                         outputTypes["sorest"] = tempOutNames;
167                         outputTypes["thetayc"] = tempOutNames;
168                         outputTypes["thetan"] = tempOutNames;
169                         outputTypes["kstest"] = tempOutNames;
170                         outputTypes["whittaker"] = tempOutNames;
171                         outputTypes["sharednseqs"] = tempOutNames;
172                         outputTypes["ochiai"] = tempOutNames;
173                         outputTypes["anderberg"] = tempOutNames;
174                         outputTypes["skulczynski"] = tempOutNames;
175                         outputTypes["kulczynskicody"] = tempOutNames;
176                         outputTypes["lennon"] = tempOutNames;
177                         outputTypes["morisitahorn"] = tempOutNames;
178                         outputTypes["braycurtis"] = tempOutNames;
179                         outputTypes["odum"] = tempOutNames;
180                         outputTypes["canberra"] = tempOutNames;
181                         outputTypes["stricteuclidean"] = tempOutNames;
182                         outputTypes["strictchord"] = tempOutNames;
183                         outputTypes["hellinger"] = tempOutNames;
184                         outputTypes["manhattan"] = tempOutNames;
185                         outputTypes["strictpearson"] = tempOutNames;
186                         outputTypes["soergel"] = tempOutNames;
187                         outputTypes["spearman"] = tempOutNames;
188                         outputTypes["strictkulczynski"] = tempOutNames;
189                         outputTypes["speciesprofile"] = tempOutNames;
190                         outputTypes["hamming"] = tempOutNames;
191
192                         
193                         //if the user changes the output directory command factory will send this info to us in the output parameter 
194                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
195                         
196                                                 
197                         //make sure the user has already run the read.otu command
198                         if (globaldata->getSharedFile() == "") {
199                                 if (globaldata->getListFile() == "") { m->mothurOut("You must read a list and a group, or a shared before you can use the collect.shared command."); m->mothurOutEndLine(); abort = true; }
200                                 else if (globaldata->getGroupFile() == "") { m->mothurOut("You must read a list and a group, or a shared before you can use the collect.shared command."); m->mothurOutEndLine(); abort = true; }
201                         }
202
203                         
204                         //check for optional parameter and set defaults
205                         // ...at some point should added some additional type checking..
206                         label = validParameter.validFile(parameters, "label", false);                   
207                         if (label == "not found") { label = ""; }
208                         else { 
209                                 if(label != "all") {  m->splitAtDash(label, labels);  allLines = 0;  }
210                                 else { allLines = 1;  }
211                         }
212                         
213                         //if the user has not specified any labels use the ones from read.otu
214                         if(label == "") {  
215                                 allLines = globaldata->allLines; 
216                                 labels = globaldata->labels; 
217                         }
218                                 
219                         calc = validParameter.validFile(parameters, "calc", false);                     
220                         if (calc == "not found") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan";  }
221                         else { 
222                                  if (calc == "default")  {  calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan";  }
223                         }
224                         m->splitAtDash(calc, Estimators);
225                         
226                         groups = validParameter.validFile(parameters, "groups", false);                 
227                         if (groups == "not found") { groups = ""; }
228                         else { 
229                                 m->splitAtDash(groups, Groups);
230                         }
231                         globaldata->Groups = Groups;
232                         
233                         string temp;
234                         temp = validParameter.validFile(parameters, "freq", false);                     if (temp == "not found") { temp = "100"; }
235                         convert(temp, freq); 
236                         
237                         temp = validParameter.validFile(parameters, "all", false);                              if (temp == "not found") { temp = "false"; }
238                         all = m->isTrue(temp);
239                                                 
240                         if (abort == false) {
241                                 
242                                 if (outputDir == "") { outputDir += m->hasPath(globaldata->inputFileName); }
243                                 string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName));
244                                 format = globaldata->getFormat();
245                                 int i;
246                                 
247                                 validCalculator = new ValidCalculators();
248                                 util = new SharedUtil();
249                                 
250                                 for (i=0; i<Estimators.size(); i++) {
251                                         if (validCalculator->isValidCalculator("shared", Estimators[i]) == true) { 
252                                                 if (Estimators[i] == "sharedchao") { 
253                                                         cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao")));
254                                                         outputNames.push_back(fileNameRoot+"shared.chao"); outputTypes["sharedchao"].push_back(fileNameRoot+"shared.chao");
255                                                 }else if (Estimators[i] == "sharedsobs") { 
256                                                         cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs")));
257                                                         outputNames.push_back(fileNameRoot+"shared.sobs"); outputTypes["sharedsobs"].push_back(fileNameRoot+"shared.sobs");
258                                                 }else if (Estimators[i] == "sharedace") { 
259                                                         cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace")));
260                                                         outputNames.push_back(fileNameRoot+"shared.ace"); outputTypes["sharedace"].push_back(fileNameRoot+"shared.ace");
261                                                 }else if (Estimators[i] == "jabund") {  
262                                                         cDisplays.push_back(new CollectDisplay(new JAbund(), new SharedOneColumnFile(fileNameRoot+"jabund")));
263                                                         outputNames.push_back(fileNameRoot+"jabund"); outputTypes["jabund"].push_back(fileNameRoot+"jabund");
264                                                 }else if (Estimators[i] == "sorabund") { 
265                                                         cDisplays.push_back(new CollectDisplay(new SorAbund(), new SharedOneColumnFile(fileNameRoot+"sorabund")));
266                                                         outputNames.push_back(fileNameRoot+"sorabund"); outputTypes["sorabund"].push_back(fileNameRoot+"sorabund");
267                                                 }else if (Estimators[i] == "jclass") { 
268                                                         cDisplays.push_back(new CollectDisplay(new Jclass(), new SharedOneColumnFile(fileNameRoot+"jclass")));
269                                                         outputNames.push_back(fileNameRoot+"jclass"); outputTypes["jclass"].push_back(fileNameRoot+"jclass");
270                                                 }else if (Estimators[i] == "sorclass") { 
271                                                         cDisplays.push_back(new CollectDisplay(new SorClass(), new SharedOneColumnFile(fileNameRoot+"sorclass")));
272                                                         outputNames.push_back(fileNameRoot+"sorclass"); outputTypes["sorclass"].push_back(fileNameRoot+"sorclass");
273                                                 }else if (Estimators[i] == "jest") { 
274                                                         cDisplays.push_back(new CollectDisplay(new Jest(), new SharedOneColumnFile(fileNameRoot+"jest")));
275                                                         outputNames.push_back(fileNameRoot+"jest"); outputTypes["jest"].push_back(fileNameRoot+"jest");
276                                                 }else if (Estimators[i] == "sorest") { 
277                                                         cDisplays.push_back(new CollectDisplay(new SorEst(), new SharedOneColumnFile(fileNameRoot+"sorest")));
278                                                         outputNames.push_back(fileNameRoot+"sorest"); outputTypes["sorest"].push_back(fileNameRoot+"sorest");
279                                                 }else if (Estimators[i] == "thetayc") { 
280                                                         cDisplays.push_back(new CollectDisplay(new ThetaYC(), new SharedOneColumnFile(fileNameRoot+"thetayc")));
281                                                         outputNames.push_back(fileNameRoot+"thetayc"); outputTypes["thetayc"].push_back(fileNameRoot+"thetayc");
282                                                 }else if (Estimators[i] == "thetan") { 
283                                                         cDisplays.push_back(new CollectDisplay(new ThetaN(), new SharedOneColumnFile(fileNameRoot+"thetan")));
284                                                         outputNames.push_back(fileNameRoot+"thetan"); outputTypes["thetan"].push_back(fileNameRoot+"thetan");
285                                                 }else if (Estimators[i] == "kstest") { 
286                                                         cDisplays.push_back(new CollectDisplay(new KSTest(), new SharedOneColumnFile(fileNameRoot+"kstest")));
287                                                         outputNames.push_back(fileNameRoot+"kstest"); outputTypes["kstest"].push_back(fileNameRoot+"kstest");
288                                                 }else if (Estimators[i] == "whittaker") { 
289                                                         cDisplays.push_back(new CollectDisplay(new Whittaker(), new SharedOneColumnFile(fileNameRoot+"whittaker")));
290                                                         outputNames.push_back(fileNameRoot+"whittaker"); outputTypes["whittaker"].push_back(fileNameRoot+"whittaker");
291                                                 }else if (Estimators[i] == "sharednseqs") { 
292                                                         cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(fileNameRoot+"shared.nseqs")));
293                                                         outputNames.push_back(fileNameRoot+"shared.nseqs"); outputTypes["shared.nseqs"].push_back(fileNameRoot+"shared.nseqs");
294                                                 }else if (Estimators[i] == "ochiai") { 
295                                                         cDisplays.push_back(new CollectDisplay(new Ochiai(), new SharedOneColumnFile(fileNameRoot+"ochiai")));
296                                                         outputNames.push_back(fileNameRoot+"ochiai"); outputTypes["ochiai"].push_back(fileNameRoot+"ochiai");
297                                                 }else if (Estimators[i] == "anderberg") { 
298                                                         cDisplays.push_back(new CollectDisplay(new Anderberg(), new SharedOneColumnFile(fileNameRoot+"anderberg")));
299                                                         outputNames.push_back(fileNameRoot+"anderberg"); outputTypes["anderberg"].push_back(fileNameRoot+"anderberg");
300                                                 }else if (Estimators[i] == "skulczynski") { 
301                                                         cDisplays.push_back(new CollectDisplay(new Kulczynski(), new SharedOneColumnFile(fileNameRoot+"kulczynski")));
302                                                         outputNames.push_back(fileNameRoot+"kulczynski"); outputTypes["kulczynski"].push_back(fileNameRoot+"kulczynski");
303                                                 }else if (Estimators[i] == "kulczynskicody") { 
304                                                         cDisplays.push_back(new CollectDisplay(new KulczynskiCody(), new SharedOneColumnFile(fileNameRoot+"kulczynskicody")));
305                                                         outputNames.push_back(fileNameRoot+"kulczynskicody"); outputTypes["kulczynskicody"].push_back(fileNameRoot+"kulczynskicody");
306                                                 }else if (Estimators[i] == "lennon") { 
307                                                         cDisplays.push_back(new CollectDisplay(new Lennon(), new SharedOneColumnFile(fileNameRoot+"lennon")));
308                                                         outputNames.push_back(fileNameRoot+"lennon"); outputTypes["lennon"].push_back(fileNameRoot+"lennon");
309                                                 }else if (Estimators[i] == "morisitahorn") { 
310                                                         cDisplays.push_back(new CollectDisplay(new MorHorn(), new SharedOneColumnFile(fileNameRoot+"morisitahorn")));
311                                                         outputNames.push_back(fileNameRoot+"morisitahorn"); outputTypes["morisitahorn"].push_back(fileNameRoot+"morisitahorn");
312                                                 }else if (Estimators[i] == "braycurtis") { 
313                                                         cDisplays.push_back(new CollectDisplay(new BrayCurtis(), new SharedOneColumnFile(fileNameRoot+"braycurtis")));
314                                                         outputNames.push_back(fileNameRoot+"braycurtis"); outputTypes["braycurtis"].push_back(fileNameRoot+"braycurtis");
315                                                 }else if (Estimators[i] == "odum") { 
316                                                         cDisplays.push_back(new CollectDisplay(new Odum(), new SharedOneColumnFile(fileNameRoot+"odum")));
317                                                         outputNames.push_back(fileNameRoot+"odum"); outputTypes["odum"].push_back(fileNameRoot+"odum");
318                                                 }else if (Estimators[i] == "canberra") { 
319                                                         cDisplays.push_back(new CollectDisplay(new Canberra(), new SharedOneColumnFile(fileNameRoot+"canberra")));
320                                                         outputNames.push_back(fileNameRoot+"canberra"); outputTypes["canberra"].push_back(fileNameRoot+"canberra");
321                                                 }else if (Estimators[i] == "stricteuclidean") { 
322                                                         cDisplays.push_back(new CollectDisplay(new StrictEuclidean(), new SharedOneColumnFile(fileNameRoot+"stricteuclidean")));
323                                                         outputNames.push_back(fileNameRoot+"stricteuclidean"); outputTypes["stricteuclidean"].push_back(fileNameRoot+"stricteuclidean");
324                                                 }else if (Estimators[i] == "strictchord") { 
325                                                         cDisplays.push_back(new CollectDisplay(new StrictChord(), new SharedOneColumnFile(fileNameRoot+"strictchord")));
326                                                         outputNames.push_back(fileNameRoot+"strictchord"); outputTypes["strictchord"].push_back(fileNameRoot+"strictchord");
327                                                 }else if (Estimators[i] == "hellinger") { 
328                                                         cDisplays.push_back(new CollectDisplay(new Hellinger(), new SharedOneColumnFile(fileNameRoot+"hellinger")));
329                                                         outputNames.push_back(fileNameRoot+"hellinger"); outputTypes["hellinger"].push_back(fileNameRoot+"hellinger");
330                                                 }else if (Estimators[i] == "manhattan") { 
331                                                         cDisplays.push_back(new CollectDisplay(new Manhattan(), new SharedOneColumnFile(fileNameRoot+"manhattan")));
332                                                         outputNames.push_back(fileNameRoot+"manhattan"); outputTypes["manhattan"].push_back(fileNameRoot+"manhattan");
333                                                 }else if (Estimators[i] == "strictpearson") { 
334                                                         cDisplays.push_back(new CollectDisplay(new StrictPearson(), new SharedOneColumnFile(fileNameRoot+"strictpearson")));
335                                                         outputNames.push_back(fileNameRoot+"strictpearson"); outputTypes["strictpearson"].push_back(fileNameRoot+"strictpearson");
336                                                 }else if (Estimators[i] == "soergel") { 
337                                                         cDisplays.push_back(new CollectDisplay(new Soergel(), new SharedOneColumnFile(fileNameRoot+"soergel")));
338                                                         outputNames.push_back(fileNameRoot+"soergel"); outputTypes["soergel"].push_back(fileNameRoot+"soergel");
339                                                 }else if (Estimators[i] == "spearman") { 
340                                                         cDisplays.push_back(new CollectDisplay(new Spearman(), new SharedOneColumnFile(fileNameRoot+"spearman")));
341                                                         outputNames.push_back(fileNameRoot+"spearman"); outputTypes["spearman"].push_back(fileNameRoot+"spearman");
342                                                 }else if (Estimators[i] == "strictkulczynski") { 
343                                                         cDisplays.push_back(new CollectDisplay(new StrictKulczynski(), new SharedOneColumnFile(fileNameRoot+"strictkulczynski")));
344                                                         outputNames.push_back(fileNameRoot+"strictkulczynski"); outputTypes["strictkulczynski"].push_back(fileNameRoot+"strictkulczynski");
345                                                 }else if (Estimators[i] == "speciesprofile") { 
346                                                         cDisplays.push_back(new CollectDisplay(new SpeciesProfile(), new SharedOneColumnFile(fileNameRoot+"speciesprofile")));
347                                                         outputNames.push_back(fileNameRoot+"speciesprofile"); outputTypes["speciesprofile"].push_back(fileNameRoot+"speciesprofile");
348                                                 }else if (Estimators[i] == "hamming") { 
349                                                         cDisplays.push_back(new CollectDisplay(new Hamming(), new SharedOneColumnFile(fileNameRoot+"hamming")));
350                                                         outputNames.push_back(fileNameRoot+"hamming"); outputTypes["hamming"].push_back(fileNameRoot+"hamming");
351                                                 }
352                                                 
353                                         }
354                                 }       
355                         }
356                 }
357
358         }
359         catch(exception& e) {
360                 m->errorOut(e, "CollectSharedCommand", "CollectSharedCommand");
361                 exit(1);
362         }
363 }
364 //**********************************************************************************************************************
365
366 void CollectSharedCommand::help(){
367         try {
368                 m->mothurOut("The collect.shared command can only be executed after a successful read.otu command.\n");
369                 m->mothurOut("The collect.shared command parameters are label, freq, calc and groups.  No parameters are required \n");
370                 m->mothurOut("The collect.shared command should be in the following format: \n");
371                 m->mothurOut("collect.shared(label=yourLabel, freq=yourFreq, calc=yourEstimators, groups=yourGroups).\n");
372                 m->mothurOut("Example collect.shared(label=unique-.01-.03, freq=10, groups=B-C, calc=sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan).\n");
373                 m->mothurOut("The default values for freq is 100 and calc are sharedsobs-sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan.\n");
374                 m->mothurOut("The default value for groups is all the groups in your groupfile.\n");
375                 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");
376                 validCalculator->printCalc("shared", cout);
377                 m->mothurOut("The label parameter is used to analyze specific labels in your input.\n");
378                 m->mothurOut("The all parameter is used to specify if you want the estimate of all your groups together.  This estimate can only be made for sharedsobs and sharedchao calculators. The default is false.\n");
379                 m->mothurOut("If you use sharedchao and run into memory issues, set all to false. \n");
380                 m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed.  You must enter at least 2 valid groups.\n");
381                 m->mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\n");
382                 
383         }
384         catch(exception& e) {
385                 m->errorOut(e, "CollectSharedCommand", "help");
386                 exit(1);
387         }
388 }
389
390 //**********************************************************************************************************************
391
392 CollectSharedCommand::~CollectSharedCommand(){
393         if (abort == false) {
394                 delete input; globaldata->ginput = NULL;
395                 delete read;
396                 delete util;
397                 delete validCalculator;
398                 globaldata->gorder = NULL;
399         }
400 }
401
402 //**********************************************************************************************************************
403
404 int CollectSharedCommand::execute(){
405         try {
406                 
407                 if (abort == true) {    return 0;       }
408                 
409                 //if the users entered no valid calculators don't execute command
410                 if (cDisplays.size() == 0) { return 0; }
411                 for(int i=0;i<cDisplays.size();i++){    cDisplays[i]->setAll(all);      }       
412         
413                 read = new ReadOTUFile(globaldata->inputFileName);      
414                 read->read(&*globaldata); 
415                 
416                 input = globaldata->ginput;
417                 order = input->getSharedOrderVector();
418                 string lastLabel = order->getLabel();
419                 
420                 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
421                 set<string> processedLabels;
422                 set<string> userLabels = labels;
423                         
424                 //set users groups
425                 util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "collect");
426                 util->updateGroupIndex(globaldata->Groups, globaldata->gGroupmap->groupIndex);
427
428                 while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
429                         if (m->control_pressed) { 
430                                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }  outputTypes.clear();
431                                         for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
432                                         delete order; 
433                                         globaldata->Groups.clear();
434                                         return 0;
435                         }
436
437                         if(allLines == 1 || labels.count(order->getLabel()) == 1){
438                         
439                                 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
440                                 //create collectors curve
441                                 cCurve = new Collect(order, cDisplays);
442                                 cCurve->getSharedCurve(freq);
443                                 delete cCurve;
444                         
445                                 processedLabels.insert(order->getLabel());
446                                 userLabels.erase(order->getLabel());
447                         }
448                         
449                         //you have a label the user want that is smaller than this label and the last label has not already been processed
450                         if ((m->anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
451                                 string saveLabel = order->getLabel();
452                                 
453                                 delete order;
454                                 order = input->getSharedOrderVector(lastLabel);
455                                 
456                                 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
457                                 //create collectors curve
458                                 cCurve = new Collect(order, cDisplays);
459                                 cCurve->getSharedCurve(freq);
460                                 delete cCurve;
461                                 
462                                 processedLabels.insert(order->getLabel());
463                                 userLabels.erase(order->getLabel());
464                                 
465                                 //restore real lastlabel to save below
466                                 order->setLabel(saveLabel);
467                         }
468                         
469                         
470                         lastLabel = order->getLabel();                  
471                         
472                         //get next line to process
473                         delete order;
474                         order = input->getSharedOrderVector();
475                 }
476                 
477                 if (m->control_pressed) { 
478                                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }   outputTypes.clear();
479                                         for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
480                                         globaldata->Groups.clear();
481                                         return 0;
482                 }
483                 
484                 //output error messages about any remaining user labels
485                 set<string>::iterator it;
486                 bool needToRun = false;
487                 for (it = userLabels.begin(); it != userLabels.end(); it++) {  
488                         m->mothurOut("Your file does not include the label " + *it); 
489                         if (processedLabels.count(lastLabel) != 1) {
490                                 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
491                                 needToRun = true;
492                         }else {
493                                 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
494                         }
495                 }
496                 
497                 //run last label if you need to
498                 if (needToRun == true)  {
499                         if (order != NULL) {  delete order;  }
500                         order = input->getSharedOrderVector(lastLabel);
501                         
502                         m->mothurOut(order->getLabel()); m->mothurOutEndLine();
503                         cCurve = new Collect(order, cDisplays);
504                         cCurve->getSharedCurve(freq);
505                         delete cCurve;
506                         
507                         if (m->control_pressed) { 
508                                 for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }  outputTypes.clear();
509                                 for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
510                                 delete order; 
511                                 globaldata->Groups.clear();
512                                 return 0;
513                         }
514
515                         delete order;
516                 }
517                 
518                 for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }       
519                 
520                 //reset groups parameter
521                 globaldata->Groups.clear(); 
522                 
523                 m->mothurOutEndLine();
524                 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
525                 for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
526                 m->mothurOutEndLine();
527
528                 
529                 return 0;
530         }
531         catch(exception& e) {
532                 m->errorOut(e, "CollectSharedCommand", "execute");
533                 exit(1);
534         }
535 }
536
537 /***********************************************************/