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(){
91 abort = true; calledHelp = true;
92 vector<string> tempOutNames;
93 outputTypes["sharedchao"] = tempOutNames;
94 outputTypes["sharedsobs"] = tempOutNames;
95 outputTypes["sharedace"] = tempOutNames;
96 outputTypes["jabund"] = tempOutNames;
97 outputTypes["sorabund"] = tempOutNames;
98 outputTypes["jclass"] = tempOutNames;
99 outputTypes["sorclass"] = tempOutNames;
100 outputTypes["jest"] = tempOutNames;
101 outputTypes["sorest"] = tempOutNames;
102 outputTypes["thetayc"] = tempOutNames;
103 outputTypes["thetan"] = tempOutNames;
104 outputTypes["kstest"] = tempOutNames;
105 outputTypes["whittaker"] = tempOutNames;
106 outputTypes["sharednseqs"] = tempOutNames;
107 outputTypes["ochiai"] = tempOutNames;
108 outputTypes["anderberg"] = tempOutNames;
109 outputTypes["skulczynski"] = tempOutNames;
110 outputTypes["kulczynskicody"] = tempOutNames;
111 outputTypes["lennon"] = tempOutNames;
112 outputTypes["morisitahorn"] = tempOutNames;
113 outputTypes["braycurtis"] = tempOutNames;
114 outputTypes["odum"] = tempOutNames;
115 outputTypes["canberra"] = tempOutNames;
116 outputTypes["structeuclidean"] = tempOutNames;
117 outputTypes["structchord"] = tempOutNames;
118 outputTypes["hellinger"] = tempOutNames;
119 outputTypes["manhattan"] = tempOutNames;
120 outputTypes["structpearson"] = tempOutNames;
121 outputTypes["soergel"] = tempOutNames;
122 outputTypes["spearman"] = tempOutNames;
123 outputTypes["structkulczynski"] = tempOutNames;
124 outputTypes["structchi2"] = tempOutNames;
125 outputTypes["speciesprofile"] = tempOutNames;
126 outputTypes["hamming"] = tempOutNames;
127 outputTypes["gower"] = tempOutNames;
128 outputTypes["memchi2"] = tempOutNames;
129 outputTypes["memchord"] = tempOutNames;
130 outputTypes["memeuclidean"] = tempOutNames;
131 outputTypes["mempearson"] = tempOutNames;
134 catch(exception& e) {
135 m->errorOut(e, "CollectSharedCommand", "CollectSharedCommand");
139 //**********************************************************************************************************************
140 CollectSharedCommand::CollectSharedCommand(string option) {
142 globaldata = GlobalData::getInstance();
143 abort = false; calledHelp = false;
149 //allow user to run help
150 if(option == "help") { validCalculator = new ValidCalculators(); help(); abort = true; calledHelp = true; }
153 //valid paramters for this command
154 string Array[] = {"freq","label","calc","groups","all","outputdir","inputdir"};
155 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
157 OptionParser parser(option);
158 map<string,string> parameters=parser.getParameters();
160 ValidParameters validParameter;
162 //check to make sure all parameters are valid for command
163 for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
164 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
167 //initialize outputTypes
168 vector<string> tempOutNames;
169 outputTypes["sharedchao"] = tempOutNames;
170 outputTypes["sharedsobs"] = tempOutNames;
171 outputTypes["sharedace"] = tempOutNames;
172 outputTypes["jabund"] = tempOutNames;
173 outputTypes["sorabund"] = tempOutNames;
174 outputTypes["jclass"] = tempOutNames;
175 outputTypes["sorclass"] = tempOutNames;
176 outputTypes["jest"] = tempOutNames;
177 outputTypes["sorest"] = tempOutNames;
178 outputTypes["thetayc"] = tempOutNames;
179 outputTypes["thetan"] = tempOutNames;
180 outputTypes["kstest"] = tempOutNames;
181 outputTypes["whittaker"] = tempOutNames;
182 outputTypes["sharednseqs"] = tempOutNames;
183 outputTypes["ochiai"] = tempOutNames;
184 outputTypes["anderberg"] = tempOutNames;
185 outputTypes["skulczynski"] = tempOutNames;
186 outputTypes["kulczynskicody"] = tempOutNames;
187 outputTypes["lennon"] = tempOutNames;
188 outputTypes["morisitahorn"] = tempOutNames;
189 outputTypes["braycurtis"] = tempOutNames;
190 outputTypes["odum"] = tempOutNames;
191 outputTypes["canberra"] = tempOutNames;
192 outputTypes["structeuclidean"] = tempOutNames;
193 outputTypes["structchord"] = tempOutNames;
194 outputTypes["hellinger"] = tempOutNames;
195 outputTypes["manhattan"] = tempOutNames;
196 outputTypes["structpearson"] = tempOutNames;
197 outputTypes["soergel"] = tempOutNames;
198 outputTypes["spearman"] = tempOutNames;
199 outputTypes["structkulczynski"] = tempOutNames;
200 outputTypes["speciesprofile"] = tempOutNames;
201 outputTypes["structchi2"] = tempOutNames;
202 outputTypes["hamming"] = tempOutNames;
203 outputTypes["gower"] = tempOutNames;
204 outputTypes["memchi2"] = tempOutNames;
205 outputTypes["memchord"] = tempOutNames;
206 outputTypes["memeuclidean"] = tempOutNames;
207 outputTypes["mempearson"] = tempOutNames;
209 //if the user changes the output directory command factory will send this info to us in the output parameter
210 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
213 //make sure the user has already run the read.otu command
214 if (globaldata->getSharedFile() == "") {
215 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; }
216 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; }
220 //check for optional parameter and set defaults
221 // ...at some point should added some additional type checking..
222 label = validParameter.validFile(parameters, "label", false);
223 if (label == "not found") { label = ""; }
225 if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
226 else { allLines = 1; }
229 //if the user has not specified any labels use the ones from read.otu
231 allLines = globaldata->allLines;
232 labels = globaldata->labels;
235 calc = validParameter.validFile(parameters, "calc", false);
236 if (calc == "not found") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
238 if (calc == "default") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
240 m->splitAtDash(calc, Estimators);
242 groups = validParameter.validFile(parameters, "groups", false);
243 if (groups == "not found") { groups = ""; }
245 m->splitAtDash(groups, Groups);
247 globaldata->Groups = Groups;
250 temp = validParameter.validFile(parameters, "freq", false); if (temp == "not found") { temp = "100"; }
253 temp = validParameter.validFile(parameters, "all", false); if (temp == "not found") { temp = "false"; }
254 all = m->isTrue(temp);
256 if (abort == false) {
258 if (outputDir == "") { outputDir += m->hasPath(globaldata->inputFileName); }
259 string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName));
260 format = globaldata->getFormat();
263 validCalculator = new ValidCalculators();
264 util = new SharedUtil();
266 for (i=0; i<Estimators.size(); i++) {
267 if (validCalculator->isValidCalculator("shared", Estimators[i]) == true) {
268 if (Estimators[i] == "sharedchao") {
269 cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao")));
270 outputNames.push_back(fileNameRoot+"shared.chao"); outputTypes["sharedchao"].push_back(fileNameRoot+"shared.chao");
271 }else if (Estimators[i] == "sharedsobs") {
272 cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs")));
273 outputNames.push_back(fileNameRoot+"shared.sobs"); outputTypes["sharedsobs"].push_back(fileNameRoot+"shared.sobs");
274 }else if (Estimators[i] == "sharedace") {
275 cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace")));
276 outputNames.push_back(fileNameRoot+"shared.ace"); outputTypes["sharedace"].push_back(fileNameRoot+"shared.ace");
277 }else if (Estimators[i] == "jabund") {
278 cDisplays.push_back(new CollectDisplay(new JAbund(), new SharedOneColumnFile(fileNameRoot+"jabund")));
279 outputNames.push_back(fileNameRoot+"jabund"); outputTypes["jabund"].push_back(fileNameRoot+"jabund");
280 }else if (Estimators[i] == "sorabund") {
281 cDisplays.push_back(new CollectDisplay(new SorAbund(), new SharedOneColumnFile(fileNameRoot+"sorabund")));
282 outputNames.push_back(fileNameRoot+"sorabund"); outputTypes["sorabund"].push_back(fileNameRoot+"sorabund");
283 }else if (Estimators[i] == "jclass") {
284 cDisplays.push_back(new CollectDisplay(new Jclass(), new SharedOneColumnFile(fileNameRoot+"jclass")));
285 outputNames.push_back(fileNameRoot+"jclass"); outputTypes["jclass"].push_back(fileNameRoot+"jclass");
286 }else if (Estimators[i] == "sorclass") {
287 cDisplays.push_back(new CollectDisplay(new SorClass(), new SharedOneColumnFile(fileNameRoot+"sorclass")));
288 outputNames.push_back(fileNameRoot+"sorclass"); outputTypes["sorclass"].push_back(fileNameRoot+"sorclass");
289 }else if (Estimators[i] == "jest") {
290 cDisplays.push_back(new CollectDisplay(new Jest(), new SharedOneColumnFile(fileNameRoot+"jest")));
291 outputNames.push_back(fileNameRoot+"jest"); outputTypes["jest"].push_back(fileNameRoot+"jest");
292 }else if (Estimators[i] == "sorest") {
293 cDisplays.push_back(new CollectDisplay(new SorEst(), new SharedOneColumnFile(fileNameRoot+"sorest")));
294 outputNames.push_back(fileNameRoot+"sorest"); outputTypes["sorest"].push_back(fileNameRoot+"sorest");
295 }else if (Estimators[i] == "thetayc") {
296 cDisplays.push_back(new CollectDisplay(new ThetaYC(), new SharedOneColumnFile(fileNameRoot+"thetayc")));
297 outputNames.push_back(fileNameRoot+"thetayc"); outputTypes["thetayc"].push_back(fileNameRoot+"thetayc");
298 }else if (Estimators[i] == "thetan") {
299 cDisplays.push_back(new CollectDisplay(new ThetaN(), new SharedOneColumnFile(fileNameRoot+"thetan")));
300 outputNames.push_back(fileNameRoot+"thetan"); outputTypes["thetan"].push_back(fileNameRoot+"thetan");
301 }else if (Estimators[i] == "kstest") {
302 cDisplays.push_back(new CollectDisplay(new KSTest(), new SharedOneColumnFile(fileNameRoot+"kstest")));
303 outputNames.push_back(fileNameRoot+"kstest"); outputTypes["kstest"].push_back(fileNameRoot+"kstest");
304 }else if (Estimators[i] == "whittaker") {
305 cDisplays.push_back(new CollectDisplay(new Whittaker(), new SharedOneColumnFile(fileNameRoot+"whittaker")));
306 outputNames.push_back(fileNameRoot+"whittaker"); outputTypes["whittaker"].push_back(fileNameRoot+"whittaker");
307 }else if (Estimators[i] == "sharednseqs") {
308 cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(fileNameRoot+"shared.nseqs")));
309 outputNames.push_back(fileNameRoot+"shared.nseqs"); outputTypes["shared.nseqs"].push_back(fileNameRoot+"shared.nseqs");
310 }else if (Estimators[i] == "ochiai") {
311 cDisplays.push_back(new CollectDisplay(new Ochiai(), new SharedOneColumnFile(fileNameRoot+"ochiai")));
312 outputNames.push_back(fileNameRoot+"ochiai"); outputTypes["ochiai"].push_back(fileNameRoot+"ochiai");
313 }else if (Estimators[i] == "anderberg") {
314 cDisplays.push_back(new CollectDisplay(new Anderberg(), new SharedOneColumnFile(fileNameRoot+"anderberg")));
315 outputNames.push_back(fileNameRoot+"anderberg"); outputTypes["anderberg"].push_back(fileNameRoot+"anderberg");
316 }else if (Estimators[i] == "skulczynski") {
317 cDisplays.push_back(new CollectDisplay(new Kulczynski(), new SharedOneColumnFile(fileNameRoot+"kulczynski")));
318 outputNames.push_back(fileNameRoot+"kulczynski"); outputTypes["kulczynski"].push_back(fileNameRoot+"kulczynski");
319 }else if (Estimators[i] == "kulczynskicody") {
320 cDisplays.push_back(new CollectDisplay(new KulczynskiCody(), new SharedOneColumnFile(fileNameRoot+"kulczynskicody")));
321 outputNames.push_back(fileNameRoot+"kulczynskicody"); outputTypes["kulczynskicody"].push_back(fileNameRoot+"kulczynskicody");
322 }else if (Estimators[i] == "lennon") {
323 cDisplays.push_back(new CollectDisplay(new Lennon(), new SharedOneColumnFile(fileNameRoot+"lennon")));
324 outputNames.push_back(fileNameRoot+"lennon"); outputTypes["lennon"].push_back(fileNameRoot+"lennon");
325 }else if (Estimators[i] == "morisitahorn") {
326 cDisplays.push_back(new CollectDisplay(new MorHorn(), new SharedOneColumnFile(fileNameRoot+"morisitahorn")));
327 outputNames.push_back(fileNameRoot+"morisitahorn"); outputTypes["morisitahorn"].push_back(fileNameRoot+"morisitahorn");
328 }else if (Estimators[i] == "braycurtis") {
329 cDisplays.push_back(new CollectDisplay(new BrayCurtis(), new SharedOneColumnFile(fileNameRoot+"braycurtis")));
330 outputNames.push_back(fileNameRoot+"braycurtis"); outputTypes["braycurtis"].push_back(fileNameRoot+"braycurtis");
331 }else if (Estimators[i] == "odum") {
332 cDisplays.push_back(new CollectDisplay(new Odum(), new SharedOneColumnFile(fileNameRoot+"odum")));
333 outputNames.push_back(fileNameRoot+"odum"); outputTypes["odum"].push_back(fileNameRoot+"odum");
334 }else if (Estimators[i] == "canberra") {
335 cDisplays.push_back(new CollectDisplay(new Canberra(), new SharedOneColumnFile(fileNameRoot+"canberra")));
336 outputNames.push_back(fileNameRoot+"canberra"); outputTypes["canberra"].push_back(fileNameRoot+"canberra");
337 }else if (Estimators[i] == "structeuclidean") {
338 cDisplays.push_back(new CollectDisplay(new StructEuclidean(), new SharedOneColumnFile(fileNameRoot+"structeuclidean")));
339 outputNames.push_back(fileNameRoot+"structeuclidean"); outputTypes["structeuclidean"].push_back(fileNameRoot+"structeuclidean");
340 }else if (Estimators[i] == "structchord") {
341 cDisplays.push_back(new CollectDisplay(new StructChord(), new SharedOneColumnFile(fileNameRoot+"structchord")));
342 outputNames.push_back(fileNameRoot+"structchord"); outputTypes["structchord"].push_back(fileNameRoot+"structchord");
343 }else if (Estimators[i] == "hellinger") {
344 cDisplays.push_back(new CollectDisplay(new Hellinger(), new SharedOneColumnFile(fileNameRoot+"hellinger")));
345 outputNames.push_back(fileNameRoot+"hellinger"); outputTypes["hellinger"].push_back(fileNameRoot+"hellinger");
346 }else if (Estimators[i] == "manhattan") {
347 cDisplays.push_back(new CollectDisplay(new Manhattan(), new SharedOneColumnFile(fileNameRoot+"manhattan")));
348 outputNames.push_back(fileNameRoot+"manhattan"); outputTypes["manhattan"].push_back(fileNameRoot+"manhattan");
349 }else if (Estimators[i] == "structpearson") {
350 cDisplays.push_back(new CollectDisplay(new StructPearson(), new SharedOneColumnFile(fileNameRoot+"structpearson")));
351 outputNames.push_back(fileNameRoot+"structpearson"); outputTypes["structpearson"].push_back(fileNameRoot+"structpearson");
352 }else if (Estimators[i] == "soergel") {
353 cDisplays.push_back(new CollectDisplay(new Soergel(), new SharedOneColumnFile(fileNameRoot+"soergel")));
354 outputNames.push_back(fileNameRoot+"soergel"); outputTypes["soergel"].push_back(fileNameRoot+"soergel");
355 }else if (Estimators[i] == "spearman") {
356 cDisplays.push_back(new CollectDisplay(new Spearman(), new SharedOneColumnFile(fileNameRoot+"spearman")));
357 outputNames.push_back(fileNameRoot+"spearman"); outputTypes["spearman"].push_back(fileNameRoot+"spearman");
358 }else if (Estimators[i] == "structkulczynski") {
359 cDisplays.push_back(new CollectDisplay(new StructKulczynski(), new SharedOneColumnFile(fileNameRoot+"structkulczynski")));
360 outputNames.push_back(fileNameRoot+"structkulczynski"); outputTypes["structkulczynski"].push_back(fileNameRoot+"structkulczynski");
361 }else if (Estimators[i] == "speciesprofile") {
362 cDisplays.push_back(new CollectDisplay(new SpeciesProfile(), new SharedOneColumnFile(fileNameRoot+"speciesprofile")));
363 outputNames.push_back(fileNameRoot+"speciesprofile"); outputTypes["speciesprofile"].push_back(fileNameRoot+"speciesprofile");
364 }else if (Estimators[i] == "hamming") {
365 cDisplays.push_back(new CollectDisplay(new Hamming(), new SharedOneColumnFile(fileNameRoot+"hamming")));
366 outputNames.push_back(fileNameRoot+"hamming"); outputTypes["hamming"].push_back(fileNameRoot+"hamming");
367 }else if (Estimators[i] == "structchi2") {
368 cDisplays.push_back(new CollectDisplay(new StructChi2(), new SharedOneColumnFile(fileNameRoot+"structchi2")));
369 outputNames.push_back(fileNameRoot+"structchi2"); outputTypes["structchi2"].push_back(fileNameRoot+"structchi2");
370 }else if (Estimators[i] == "gower") {
371 cDisplays.push_back(new CollectDisplay(new Gower(), new SharedOneColumnFile(fileNameRoot+"gower")));
372 outputNames.push_back(fileNameRoot+"gower"); outputTypes["gower"].push_back(fileNameRoot+"gower");
373 }else if (Estimators[i] == "memchi2") {
374 cDisplays.push_back(new CollectDisplay(new MemChi2(), new SharedOneColumnFile(fileNameRoot+"memchi2")));
375 outputNames.push_back(fileNameRoot+"memchi2"); outputTypes["memchi2"].push_back(fileNameRoot+"memchi2");
376 }else if (Estimators[i] == "memchord") {
377 cDisplays.push_back(new CollectDisplay(new MemChord(), new SharedOneColumnFile(fileNameRoot+"memchord")));
378 outputNames.push_back(fileNameRoot+"memchord"); outputTypes["memchord"].push_back(fileNameRoot+"memchord");
379 }else if (Estimators[i] == "memeuclidean") {
380 cDisplays.push_back(new CollectDisplay(new MemEuclidean(), new SharedOneColumnFile(fileNameRoot+"memeuclidean")));
381 outputNames.push_back(fileNameRoot+"memeuclidean"); outputTypes["memeuclidean"].push_back(fileNameRoot+"memeuclidean");
382 }else if (Estimators[i] == "mempearson") {
383 cDisplays.push_back(new CollectDisplay(new MemPearson(), new SharedOneColumnFile(fileNameRoot+"mempearson")));
384 outputNames.push_back(fileNameRoot+"mempearson"); outputTypes["mempearson"].push_back(fileNameRoot+"mempearson");
393 catch(exception& e) {
394 m->errorOut(e, "CollectSharedCommand", "CollectSharedCommand");
398 //**********************************************************************************************************************
400 void CollectSharedCommand::help(){
402 m->mothurOut("The collect.shared command can only be executed after a successful read.otu command.\n");
403 m->mothurOut("The collect.shared command parameters are label, freq, calc and groups. No parameters are required \n");
404 m->mothurOut("The collect.shared command should be in the following format: \n");
405 m->mothurOut("collect.shared(label=yourLabel, freq=yourFreq, calc=yourEstimators, groups=yourGroups).\n");
406 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");
407 m->mothurOut("The default values for freq is 100 and calc are sharedsobs-sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan.\n");
408 m->mothurOut("The default value for groups is all the groups in your groupfile.\n");
409 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");
410 validCalculator->printCalc("shared", cout);
411 m->mothurOut("The label parameter is used to analyze specific labels in your input.\n");
412 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");
413 m->mothurOut("If you use sharedchao and run into memory issues, set all to false. \n");
414 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");
415 m->mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\n");
418 catch(exception& e) {
419 m->errorOut(e, "CollectSharedCommand", "help");
424 //**********************************************************************************************************************
426 CollectSharedCommand::~CollectSharedCommand(){
427 if (abort == false) {
428 delete input; globaldata->ginput = NULL;
431 delete validCalculator;
432 globaldata->gorder = NULL;
436 //**********************************************************************************************************************
438 int CollectSharedCommand::execute(){
441 if (abort == true) { if (calledHelp) { return 0; } return 2; }
443 //if the users entered no valid calculators don't execute command
444 if (cDisplays.size() == 0) { return 0; }
445 for(int i=0;i<cDisplays.size();i++){ cDisplays[i]->setAll(all); }
447 read = new ReadOTUFile(globaldata->inputFileName);
448 read->read(&*globaldata);
450 input = globaldata->ginput;
451 order = input->getSharedOrderVector();
452 string lastLabel = order->getLabel();
454 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
455 set<string> processedLabels;
456 set<string> userLabels = labels;
459 util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "collect");
460 util->updateGroupIndex(globaldata->Groups, globaldata->gGroupmap->groupIndex);
462 while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
463 if (m->control_pressed) {
464 for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear();
465 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
467 globaldata->Groups.clear();
471 if(allLines == 1 || labels.count(order->getLabel()) == 1){
473 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
474 //create collectors curve
475 cCurve = new Collect(order, cDisplays);
476 cCurve->getSharedCurve(freq);
479 processedLabels.insert(order->getLabel());
480 userLabels.erase(order->getLabel());
483 //you have a label the user want that is smaller than this label and the last label has not already been processed
484 if ((m->anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
485 string saveLabel = order->getLabel();
488 order = input->getSharedOrderVector(lastLabel);
490 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
491 //create collectors curve
492 cCurve = new Collect(order, cDisplays);
493 cCurve->getSharedCurve(freq);
496 processedLabels.insert(order->getLabel());
497 userLabels.erase(order->getLabel());
499 //restore real lastlabel to save below
500 order->setLabel(saveLabel);
504 lastLabel = order->getLabel();
506 //get next line to process
508 order = input->getSharedOrderVector();
511 if (m->control_pressed) {
512 for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear();
513 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
514 globaldata->Groups.clear();
518 //output error messages about any remaining user labels
519 set<string>::iterator it;
520 bool needToRun = false;
521 for (it = userLabels.begin(); it != userLabels.end(); it++) {
522 m->mothurOut("Your file does not include the label " + *it);
523 if (processedLabels.count(lastLabel) != 1) {
524 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
527 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
531 //run last label if you need to
532 if (needToRun == true) {
533 if (order != NULL) { delete order; }
534 order = input->getSharedOrderVector(lastLabel);
536 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
537 cCurve = new Collect(order, cDisplays);
538 cCurve->getSharedCurve(freq);
541 if (m->control_pressed) {
542 for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear();
543 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
545 globaldata->Groups.clear();
552 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
554 //reset groups parameter
555 globaldata->Groups.clear();
557 m->mothurOutEndLine();
558 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
559 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
560 m->mothurOutEndLine();
565 catch(exception& e) {
566 m->errorOut(e, "CollectSharedCommand", "execute");
571 /***********************************************************/