2 * collectsharedcommand.cpp
5 * Created by Sarah Westcott on 1/2/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
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"
36 #include "structeuclidean.h"
37 #include "structchord.h"
38 #include "hellinger.h"
39 #include "manhattan.h"
40 #include "structpearson.h"
43 #include "structkulczynski.h"
44 #include "structchi2.h"
45 #include "speciesprofile.h"
50 #include "memeuclidean.h"
51 #include "mempearson.h"
53 //**********************************************************************************************************************
54 vector<string> CollectSharedCommand::getValidParameters(){
56 string AlignArray[] = {"freq","label","calc","groups","all","outputdir","inputdir"};
57 vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
61 m->errorOut(e, "CollectSharedCommand", "getValidParameters");
65 //**********************************************************************************************************************
66 vector<string> CollectSharedCommand::getRequiredParameters(){
68 vector<string> myArray;
72 m->errorOut(e, "CollectSharedCommand", "getRequiredParameters");
76 //**********************************************************************************************************************
77 vector<string> CollectSharedCommand::getRequiredFiles(){
79 string AlignArray[] = {"shared"};
80 vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
84 m->errorOut(e, "CollectSharedCommand", "getRequiredFiles");
88 //**********************************************************************************************************************
89 CollectSharedCommand::CollectSharedCommand(){
92 //initialize outputTypes
93 vector<string> tempOutNames;
94 outputTypes["sharedchao"] = tempOutNames;
95 outputTypes["sharedsobs"] = tempOutNames;
96 outputTypes["sharedace"] = tempOutNames;
97 outputTypes["jabund"] = tempOutNames;
98 outputTypes["sorabund"] = tempOutNames;
99 outputTypes["jclass"] = tempOutNames;
100 outputTypes["sorclass"] = tempOutNames;
101 outputTypes["jest"] = tempOutNames;
102 outputTypes["sorest"] = tempOutNames;
103 outputTypes["thetayc"] = tempOutNames;
104 outputTypes["thetan"] = tempOutNames;
105 outputTypes["kstest"] = tempOutNames;
106 outputTypes["whittaker"] = tempOutNames;
107 outputTypes["sharednseqs"] = tempOutNames;
108 outputTypes["ochiai"] = tempOutNames;
109 outputTypes["anderberg"] = tempOutNames;
110 outputTypes["skulczynski"] = tempOutNames;
111 outputTypes["kulczynskicody"] = tempOutNames;
112 outputTypes["lennon"] = tempOutNames;
113 outputTypes["morisitahorn"] = tempOutNames;
114 outputTypes["braycurtis"] = tempOutNames;
115 outputTypes["odum"] = tempOutNames;
116 outputTypes["canberra"] = tempOutNames;
117 outputTypes["structeuclidean"] = tempOutNames;
118 outputTypes["structchord"] = tempOutNames;
119 outputTypes["hellinger"] = tempOutNames;
120 outputTypes["manhattan"] = tempOutNames;
121 outputTypes["structpearson"] = tempOutNames;
122 outputTypes["soergel"] = tempOutNames;
123 outputTypes["spearman"] = tempOutNames;
124 outputTypes["structkulczynski"] = tempOutNames;
125 outputTypes["structchi2"] = tempOutNames;
126 outputTypes["speciesprofile"] = tempOutNames;
127 outputTypes["hamming"] = tempOutNames;
128 outputTypes["gower"] = tempOutNames;
129 outputTypes["memchi2"] = tempOutNames;
130 outputTypes["memchord"] = tempOutNames;
131 outputTypes["memeuclidean"] = tempOutNames;
132 outputTypes["mempearson"] = tempOutNames;
135 catch(exception& e) {
136 m->errorOut(e, "CollectSharedCommand", "CollectSharedCommand");
140 //**********************************************************************************************************************
141 CollectSharedCommand::CollectSharedCommand(string option) {
143 globaldata = GlobalData::getInstance();
150 //allow user to run help
151 if(option == "help") { validCalculator = new ValidCalculators(); help(); abort = true; }
154 //valid paramters for this command
155 string Array[] = {"freq","label","calc","groups","all","outputdir","inputdir"};
156 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
158 OptionParser parser(option);
159 map<string,string> parameters=parser.getParameters();
161 ValidParameters validParameter;
163 //check to make sure all parameters are valid for command
164 for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
165 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
168 //initialize outputTypes
169 vector<string> tempOutNames;
170 outputTypes["sharedchao"] = tempOutNames;
171 outputTypes["sharedsobs"] = tempOutNames;
172 outputTypes["sharedace"] = tempOutNames;
173 outputTypes["jabund"] = tempOutNames;
174 outputTypes["sorabund"] = tempOutNames;
175 outputTypes["jclass"] = tempOutNames;
176 outputTypes["sorclass"] = tempOutNames;
177 outputTypes["jest"] = tempOutNames;
178 outputTypes["sorest"] = tempOutNames;
179 outputTypes["thetayc"] = tempOutNames;
180 outputTypes["thetan"] = tempOutNames;
181 outputTypes["kstest"] = tempOutNames;
182 outputTypes["whittaker"] = tempOutNames;
183 outputTypes["sharednseqs"] = tempOutNames;
184 outputTypes["ochiai"] = tempOutNames;
185 outputTypes["anderberg"] = tempOutNames;
186 outputTypes["skulczynski"] = tempOutNames;
187 outputTypes["kulczynskicody"] = tempOutNames;
188 outputTypes["lennon"] = tempOutNames;
189 outputTypes["morisitahorn"] = tempOutNames;
190 outputTypes["braycurtis"] = tempOutNames;
191 outputTypes["odum"] = tempOutNames;
192 outputTypes["canberra"] = tempOutNames;
193 outputTypes["structeuclidean"] = tempOutNames;
194 outputTypes["structchord"] = tempOutNames;
195 outputTypes["hellinger"] = tempOutNames;
196 outputTypes["manhattan"] = tempOutNames;
197 outputTypes["structpearson"] = tempOutNames;
198 outputTypes["soergel"] = tempOutNames;
199 outputTypes["spearman"] = tempOutNames;
200 outputTypes["structkulczynski"] = tempOutNames;
201 outputTypes["speciesprofile"] = tempOutNames;
202 outputTypes["structchi2"] = tempOutNames;
203 outputTypes["hamming"] = tempOutNames;
204 outputTypes["gower"] = tempOutNames;
205 outputTypes["memchi2"] = tempOutNames;
206 outputTypes["memchord"] = tempOutNames;
207 outputTypes["memeuclidean"] = tempOutNames;
208 outputTypes["mempearson"] = tempOutNames;
210 //if the user changes the output directory command factory will send this info to us in the output parameter
211 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
214 //make sure the user has already run the read.otu command
215 if (globaldata->getSharedFile() == "") {
216 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; }
217 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; }
221 //check for optional parameter and set defaults
222 // ...at some point should added some additional type checking..
223 label = validParameter.validFile(parameters, "label", false);
224 if (label == "not found") { label = ""; }
226 if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
227 else { allLines = 1; }
230 //if the user has not specified any labels use the ones from read.otu
232 allLines = globaldata->allLines;
233 labels = globaldata->labels;
236 calc = validParameter.validFile(parameters, "calc", false);
237 if (calc == "not found") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
239 if (calc == "default") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
241 m->splitAtDash(calc, Estimators);
243 groups = validParameter.validFile(parameters, "groups", false);
244 if (groups == "not found") { groups = ""; }
246 m->splitAtDash(groups, Groups);
248 globaldata->Groups = Groups;
251 temp = validParameter.validFile(parameters, "freq", false); if (temp == "not found") { temp = "100"; }
254 temp = validParameter.validFile(parameters, "all", false); if (temp == "not found") { temp = "false"; }
255 all = m->isTrue(temp);
257 if (abort == false) {
259 if (outputDir == "") { outputDir += m->hasPath(globaldata->inputFileName); }
260 string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName));
261 format = globaldata->getFormat();
264 validCalculator = new ValidCalculators();
265 util = new SharedUtil();
267 for (i=0; i<Estimators.size(); i++) {
268 if (validCalculator->isValidCalculator("shared", Estimators[i]) == true) {
269 if (Estimators[i] == "sharedchao") {
270 cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao")));
271 outputNames.push_back(fileNameRoot+"shared.chao"); outputTypes["sharedchao"].push_back(fileNameRoot+"shared.chao");
272 }else if (Estimators[i] == "sharedsobs") {
273 cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs")));
274 outputNames.push_back(fileNameRoot+"shared.sobs"); outputTypes["sharedsobs"].push_back(fileNameRoot+"shared.sobs");
275 }else if (Estimators[i] == "sharedace") {
276 cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace")));
277 outputNames.push_back(fileNameRoot+"shared.ace"); outputTypes["sharedace"].push_back(fileNameRoot+"shared.ace");
278 }else if (Estimators[i] == "jabund") {
279 cDisplays.push_back(new CollectDisplay(new JAbund(), new SharedOneColumnFile(fileNameRoot+"jabund")));
280 outputNames.push_back(fileNameRoot+"jabund"); outputTypes["jabund"].push_back(fileNameRoot+"jabund");
281 }else if (Estimators[i] == "sorabund") {
282 cDisplays.push_back(new CollectDisplay(new SorAbund(), new SharedOneColumnFile(fileNameRoot+"sorabund")));
283 outputNames.push_back(fileNameRoot+"sorabund"); outputTypes["sorabund"].push_back(fileNameRoot+"sorabund");
284 }else if (Estimators[i] == "jclass") {
285 cDisplays.push_back(new CollectDisplay(new Jclass(), new SharedOneColumnFile(fileNameRoot+"jclass")));
286 outputNames.push_back(fileNameRoot+"jclass"); outputTypes["jclass"].push_back(fileNameRoot+"jclass");
287 }else if (Estimators[i] == "sorclass") {
288 cDisplays.push_back(new CollectDisplay(new SorClass(), new SharedOneColumnFile(fileNameRoot+"sorclass")));
289 outputNames.push_back(fileNameRoot+"sorclass"); outputTypes["sorclass"].push_back(fileNameRoot+"sorclass");
290 }else if (Estimators[i] == "jest") {
291 cDisplays.push_back(new CollectDisplay(new Jest(), new SharedOneColumnFile(fileNameRoot+"jest")));
292 outputNames.push_back(fileNameRoot+"jest"); outputTypes["jest"].push_back(fileNameRoot+"jest");
293 }else if (Estimators[i] == "sorest") {
294 cDisplays.push_back(new CollectDisplay(new SorEst(), new SharedOneColumnFile(fileNameRoot+"sorest")));
295 outputNames.push_back(fileNameRoot+"sorest"); outputTypes["sorest"].push_back(fileNameRoot+"sorest");
296 }else if (Estimators[i] == "thetayc") {
297 cDisplays.push_back(new CollectDisplay(new ThetaYC(), new SharedOneColumnFile(fileNameRoot+"thetayc")));
298 outputNames.push_back(fileNameRoot+"thetayc"); outputTypes["thetayc"].push_back(fileNameRoot+"thetayc");
299 }else if (Estimators[i] == "thetan") {
300 cDisplays.push_back(new CollectDisplay(new ThetaN(), new SharedOneColumnFile(fileNameRoot+"thetan")));
301 outputNames.push_back(fileNameRoot+"thetan"); outputTypes["thetan"].push_back(fileNameRoot+"thetan");
302 }else if (Estimators[i] == "kstest") {
303 cDisplays.push_back(new CollectDisplay(new KSTest(), new SharedOneColumnFile(fileNameRoot+"kstest")));
304 outputNames.push_back(fileNameRoot+"kstest"); outputTypes["kstest"].push_back(fileNameRoot+"kstest");
305 }else if (Estimators[i] == "whittaker") {
306 cDisplays.push_back(new CollectDisplay(new Whittaker(), new SharedOneColumnFile(fileNameRoot+"whittaker")));
307 outputNames.push_back(fileNameRoot+"whittaker"); outputTypes["whittaker"].push_back(fileNameRoot+"whittaker");
308 }else if (Estimators[i] == "sharednseqs") {
309 cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(fileNameRoot+"shared.nseqs")));
310 outputNames.push_back(fileNameRoot+"shared.nseqs"); outputTypes["shared.nseqs"].push_back(fileNameRoot+"shared.nseqs");
311 }else if (Estimators[i] == "ochiai") {
312 cDisplays.push_back(new CollectDisplay(new Ochiai(), new SharedOneColumnFile(fileNameRoot+"ochiai")));
313 outputNames.push_back(fileNameRoot+"ochiai"); outputTypes["ochiai"].push_back(fileNameRoot+"ochiai");
314 }else if (Estimators[i] == "anderberg") {
315 cDisplays.push_back(new CollectDisplay(new Anderberg(), new SharedOneColumnFile(fileNameRoot+"anderberg")));
316 outputNames.push_back(fileNameRoot+"anderberg"); outputTypes["anderberg"].push_back(fileNameRoot+"anderberg");
317 }else if (Estimators[i] == "skulczynski") {
318 cDisplays.push_back(new CollectDisplay(new Kulczynski(), new SharedOneColumnFile(fileNameRoot+"kulczynski")));
319 outputNames.push_back(fileNameRoot+"kulczynski"); outputTypes["kulczynski"].push_back(fileNameRoot+"kulczynski");
320 }else if (Estimators[i] == "kulczynskicody") {
321 cDisplays.push_back(new CollectDisplay(new KulczynskiCody(), new SharedOneColumnFile(fileNameRoot+"kulczynskicody")));
322 outputNames.push_back(fileNameRoot+"kulczynskicody"); outputTypes["kulczynskicody"].push_back(fileNameRoot+"kulczynskicody");
323 }else if (Estimators[i] == "lennon") {
324 cDisplays.push_back(new CollectDisplay(new Lennon(), new SharedOneColumnFile(fileNameRoot+"lennon")));
325 outputNames.push_back(fileNameRoot+"lennon"); outputTypes["lennon"].push_back(fileNameRoot+"lennon");
326 }else if (Estimators[i] == "morisitahorn") {
327 cDisplays.push_back(new CollectDisplay(new MorHorn(), new SharedOneColumnFile(fileNameRoot+"morisitahorn")));
328 outputNames.push_back(fileNameRoot+"morisitahorn"); outputTypes["morisitahorn"].push_back(fileNameRoot+"morisitahorn");
329 }else if (Estimators[i] == "braycurtis") {
330 cDisplays.push_back(new CollectDisplay(new BrayCurtis(), new SharedOneColumnFile(fileNameRoot+"braycurtis")));
331 outputNames.push_back(fileNameRoot+"braycurtis"); outputTypes["braycurtis"].push_back(fileNameRoot+"braycurtis");
332 }else if (Estimators[i] == "odum") {
333 cDisplays.push_back(new CollectDisplay(new Odum(), new SharedOneColumnFile(fileNameRoot+"odum")));
334 outputNames.push_back(fileNameRoot+"odum"); outputTypes["odum"].push_back(fileNameRoot+"odum");
335 }else if (Estimators[i] == "canberra") {
336 cDisplays.push_back(new CollectDisplay(new Canberra(), new SharedOneColumnFile(fileNameRoot+"canberra")));
337 outputNames.push_back(fileNameRoot+"canberra"); outputTypes["canberra"].push_back(fileNameRoot+"canberra");
338 }else if (Estimators[i] == "structeuclidean") {
339 cDisplays.push_back(new CollectDisplay(new StructEuclidean(), new SharedOneColumnFile(fileNameRoot+"structeuclidean")));
340 outputNames.push_back(fileNameRoot+"structeuclidean"); outputTypes["structeuclidean"].push_back(fileNameRoot+"structeuclidean");
341 }else if (Estimators[i] == "structchord") {
342 cDisplays.push_back(new CollectDisplay(new StructChord(), new SharedOneColumnFile(fileNameRoot+"structchord")));
343 outputNames.push_back(fileNameRoot+"structchord"); outputTypes["structchord"].push_back(fileNameRoot+"structchord");
344 }else if (Estimators[i] == "hellinger") {
345 cDisplays.push_back(new CollectDisplay(new Hellinger(), new SharedOneColumnFile(fileNameRoot+"hellinger")));
346 outputNames.push_back(fileNameRoot+"hellinger"); outputTypes["hellinger"].push_back(fileNameRoot+"hellinger");
347 }else if (Estimators[i] == "manhattan") {
348 cDisplays.push_back(new CollectDisplay(new Manhattan(), new SharedOneColumnFile(fileNameRoot+"manhattan")));
349 outputNames.push_back(fileNameRoot+"manhattan"); outputTypes["manhattan"].push_back(fileNameRoot+"manhattan");
350 }else if (Estimators[i] == "structpearson") {
351 cDisplays.push_back(new CollectDisplay(new StructPearson(), new SharedOneColumnFile(fileNameRoot+"structpearson")));
352 outputNames.push_back(fileNameRoot+"structpearson"); outputTypes["structpearson"].push_back(fileNameRoot+"structpearson");
353 }else if (Estimators[i] == "soergel") {
354 cDisplays.push_back(new CollectDisplay(new Soergel(), new SharedOneColumnFile(fileNameRoot+"soergel")));
355 outputNames.push_back(fileNameRoot+"soergel"); outputTypes["soergel"].push_back(fileNameRoot+"soergel");
356 }else if (Estimators[i] == "spearman") {
357 cDisplays.push_back(new CollectDisplay(new Spearman(), new SharedOneColumnFile(fileNameRoot+"spearman")));
358 outputNames.push_back(fileNameRoot+"spearman"); outputTypes["spearman"].push_back(fileNameRoot+"spearman");
359 }else if (Estimators[i] == "structkulczynski") {
360 cDisplays.push_back(new CollectDisplay(new StructKulczynski(), new SharedOneColumnFile(fileNameRoot+"structkulczynski")));
361 outputNames.push_back(fileNameRoot+"structkulczynski"); outputTypes["structkulczynski"].push_back(fileNameRoot+"structkulczynski");
362 }else if (Estimators[i] == "speciesprofile") {
363 cDisplays.push_back(new CollectDisplay(new SpeciesProfile(), new SharedOneColumnFile(fileNameRoot+"speciesprofile")));
364 outputNames.push_back(fileNameRoot+"speciesprofile"); outputTypes["speciesprofile"].push_back(fileNameRoot+"speciesprofile");
365 }else if (Estimators[i] == "hamming") {
366 cDisplays.push_back(new CollectDisplay(new Hamming(), new SharedOneColumnFile(fileNameRoot+"hamming")));
367 outputNames.push_back(fileNameRoot+"hamming"); outputTypes["hamming"].push_back(fileNameRoot+"hamming");
368 }else if (Estimators[i] == "structchi2") {
369 cDisplays.push_back(new CollectDisplay(new StructChi2(), new SharedOneColumnFile(fileNameRoot+"structchi2")));
370 outputNames.push_back(fileNameRoot+"structchi2"); outputTypes["structchi2"].push_back(fileNameRoot+"structchi2");
371 }else if (Estimators[i] == "gower") {
372 cDisplays.push_back(new CollectDisplay(new Gower(), new SharedOneColumnFile(fileNameRoot+"gower")));
373 outputNames.push_back(fileNameRoot+"gower"); outputTypes["gower"].push_back(fileNameRoot+"gower");
374 }else if (Estimators[i] == "memchi2") {
375 cDisplays.push_back(new CollectDisplay(new MemChi2(), new SharedOneColumnFile(fileNameRoot+"memchi2")));
376 outputNames.push_back(fileNameRoot+"memchi2"); outputTypes["memchi2"].push_back(fileNameRoot+"memchi2");
377 }else if (Estimators[i] == "memchord") {
378 cDisplays.push_back(new CollectDisplay(new MemChord(), new SharedOneColumnFile(fileNameRoot+"memchord")));
379 outputNames.push_back(fileNameRoot+"memchord"); outputTypes["memchord"].push_back(fileNameRoot+"memchord");
380 }else if (Estimators[i] == "memeuclidean") {
381 cDisplays.push_back(new CollectDisplay(new MemEuclidean(), new SharedOneColumnFile(fileNameRoot+"memeuclidean")));
382 outputNames.push_back(fileNameRoot+"memeuclidean"); outputTypes["memeuclidean"].push_back(fileNameRoot+"memeuclidean");
383 }else if (Estimators[i] == "mempearson") {
384 cDisplays.push_back(new CollectDisplay(new MemPearson(), new SharedOneColumnFile(fileNameRoot+"mempearson")));
385 outputNames.push_back(fileNameRoot+"mempearson"); outputTypes["mempearson"].push_back(fileNameRoot+"mempearson");
394 catch(exception& e) {
395 m->errorOut(e, "CollectSharedCommand", "CollectSharedCommand");
399 //**********************************************************************************************************************
401 void CollectSharedCommand::help(){
403 m->mothurOut("The collect.shared command can only be executed after a successful read.otu command.\n");
404 m->mothurOut("The collect.shared command parameters are label, freq, calc and groups. No parameters are required \n");
405 m->mothurOut("The collect.shared command should be in the following format: \n");
406 m->mothurOut("collect.shared(label=yourLabel, freq=yourFreq, calc=yourEstimators, groups=yourGroups).\n");
407 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");
408 m->mothurOut("The default values for freq is 100 and calc are sharedsobs-sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan.\n");
409 m->mothurOut("The default value for groups is all the groups in your groupfile.\n");
410 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");
411 validCalculator->printCalc("shared", cout);
412 m->mothurOut("The label parameter is used to analyze specific labels in your input.\n");
413 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");
414 m->mothurOut("If you use sharedchao and run into memory issues, set all to false. \n");
415 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");
416 m->mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\n");
419 catch(exception& e) {
420 m->errorOut(e, "CollectSharedCommand", "help");
425 //**********************************************************************************************************************
427 CollectSharedCommand::~CollectSharedCommand(){
428 if (abort == false) {
429 delete input; globaldata->ginput = NULL;
432 delete validCalculator;
433 globaldata->gorder = NULL;
437 //**********************************************************************************************************************
439 int CollectSharedCommand::execute(){
442 if (abort == true) { return 0; }
444 //if the users entered no valid calculators don't execute command
445 if (cDisplays.size() == 0) { return 0; }
446 for(int i=0;i<cDisplays.size();i++){ cDisplays[i]->setAll(all); }
448 read = new ReadOTUFile(globaldata->inputFileName);
449 read->read(&*globaldata);
451 input = globaldata->ginput;
452 order = input->getSharedOrderVector();
453 string lastLabel = order->getLabel();
455 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
456 set<string> processedLabels;
457 set<string> userLabels = labels;
460 util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "collect");
461 util->updateGroupIndex(globaldata->Groups, globaldata->gGroupmap->groupIndex);
463 while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
464 if (m->control_pressed) {
465 for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear();
466 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
468 globaldata->Groups.clear();
472 if(allLines == 1 || labels.count(order->getLabel()) == 1){
474 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
475 //create collectors curve
476 cCurve = new Collect(order, cDisplays);
477 cCurve->getSharedCurve(freq);
480 processedLabels.insert(order->getLabel());
481 userLabels.erase(order->getLabel());
484 //you have a label the user want that is smaller than this label and the last label has not already been processed
485 if ((m->anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
486 string saveLabel = order->getLabel();
489 order = input->getSharedOrderVector(lastLabel);
491 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
492 //create collectors curve
493 cCurve = new Collect(order, cDisplays);
494 cCurve->getSharedCurve(freq);
497 processedLabels.insert(order->getLabel());
498 userLabels.erase(order->getLabel());
500 //restore real lastlabel to save below
501 order->setLabel(saveLabel);
505 lastLabel = order->getLabel();
507 //get next line to process
509 order = input->getSharedOrderVector();
512 if (m->control_pressed) {
513 for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear();
514 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
515 globaldata->Groups.clear();
519 //output error messages about any remaining user labels
520 set<string>::iterator it;
521 bool needToRun = false;
522 for (it = userLabels.begin(); it != userLabels.end(); it++) {
523 m->mothurOut("Your file does not include the label " + *it);
524 if (processedLabels.count(lastLabel) != 1) {
525 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
528 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
532 //run last label if you need to
533 if (needToRun == true) {
534 if (order != NULL) { delete order; }
535 order = input->getSharedOrderVector(lastLabel);
537 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
538 cCurve = new Collect(order, cDisplays);
539 cCurve->getSharedCurve(freq);
542 if (m->control_pressed) {
543 for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear();
544 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
546 globaldata->Groups.clear();
553 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
555 //reset groups parameter
556 globaldata->Groups.clear();
558 m->mothurOutEndLine();
559 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
560 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
561 m->mothurOutEndLine();
566 catch(exception& e) {
567 m->errorOut(e, "CollectSharedCommand", "execute");
572 /***********************************************************/