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"
54 //**********************************************************************************************************************
55 vector<string> CollectSharedCommand::setParameters(){
57 CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared);
58 CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel);
59 CommandParameter pfreq("freq", "Number", "", "100", "", "", "",false,false); parameters.push_back(pfreq);
60 CommandParameter pcalc("calc", "Multiple", "sharedchao-sharedsobs-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-kstest-whittaker-sharednseqs-ochiai-anderberg-skulczynski-kulczynskicody-lennon-morisitahorn-braycurtis-odum-canberra-structeuclidean-structchord-hellinger-manhattan-structpearson-soergel-spearman-structkulczynski-speciesprofile-structchi2-hamming-gower-memchi2-memchord-memeuclidean-mempearson", "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan", "", "", "",true,false); parameters.push_back(pcalc);
61 CommandParameter pall("all", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pall);
62 CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups);
63 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
64 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
66 vector<string> myArray;
67 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
71 m->errorOut(e, "CollectSharedCommand", "setParameters");
75 //**********************************************************************************************************************
76 string CollectSharedCommand::getHelpString(){
78 string helpString = "";
79 ValidCalculators validCalculator;
80 helpString += "The collect.shared command parameters are shared, label, freq, calc and groups. shared is required if there is no current sharedfile. \n";
81 helpString += "The collect.shared command should be in the following format: \n";
82 helpString += "collect.shared(label=yourLabel, freq=yourFreq, calc=yourEstimators, groups=yourGroups).\n";
83 helpString += "Example collect.shared(label=unique-.01-.03, freq=10, groups=B-C, calc=sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan).\n";
84 helpString += "The default values for freq is 100 and calc are sharedsobs-sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan.\n";
85 helpString += "The default value for groups is all the groups in your groupfile.\n";
86 helpString += "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";
87 helpString += validCalculator.printCalc("shared");
88 helpString += "The label parameter is used to analyze specific labels in your input.\n";
89 helpString += "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";
90 helpString += "If you use sharedchao and run into memory issues, set all to false. \n";
91 helpString += "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";
92 helpString += "Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n";
96 m->errorOut(e, "CollectSharedCommand", "getHelpString");
100 //**********************************************************************************************************************
101 CollectSharedCommand::CollectSharedCommand(){
103 abort = true; calledHelp = true;
105 vector<string> tempOutNames;
106 outputTypes["sharedchao"] = tempOutNames;
107 outputTypes["sharedsobs"] = tempOutNames;
108 outputTypes["sharedace"] = tempOutNames;
109 outputTypes["jabund"] = tempOutNames;
110 outputTypes["sorabund"] = tempOutNames;
111 outputTypes["jclass"] = tempOutNames;
112 outputTypes["sorclass"] = tempOutNames;
113 outputTypes["jest"] = tempOutNames;
114 outputTypes["sorest"] = tempOutNames;
115 outputTypes["thetayc"] = tempOutNames;
116 outputTypes["thetan"] = tempOutNames;
117 outputTypes["kstest"] = tempOutNames;
118 outputTypes["whittaker"] = tempOutNames;
119 outputTypes["sharednseqs"] = tempOutNames;
120 outputTypes["ochiai"] = tempOutNames;
121 outputTypes["anderberg"] = tempOutNames;
122 outputTypes["skulczynski"] = tempOutNames;
123 outputTypes["kulczynskicody"] = tempOutNames;
124 outputTypes["lennon"] = tempOutNames;
125 outputTypes["morisitahorn"] = tempOutNames;
126 outputTypes["braycurtis"] = tempOutNames;
127 outputTypes["odum"] = tempOutNames;
128 outputTypes["canberra"] = tempOutNames;
129 outputTypes["structeuclidean"] = tempOutNames;
130 outputTypes["structchord"] = tempOutNames;
131 outputTypes["hellinger"] = tempOutNames;
132 outputTypes["manhattan"] = tempOutNames;
133 outputTypes["structpearson"] = tempOutNames;
134 outputTypes["soergel"] = tempOutNames;
135 outputTypes["spearman"] = tempOutNames;
136 outputTypes["structkulczynski"] = tempOutNames;
137 outputTypes["structchi2"] = tempOutNames;
138 outputTypes["speciesprofile"] = tempOutNames;
139 outputTypes["hamming"] = tempOutNames;
140 outputTypes["gower"] = tempOutNames;
141 outputTypes["memchi2"] = tempOutNames;
142 outputTypes["memchord"] = tempOutNames;
143 outputTypes["memeuclidean"] = tempOutNames;
144 outputTypes["mempearson"] = tempOutNames;
147 catch(exception& e) {
148 m->errorOut(e, "CollectSharedCommand", "CollectSharedCommand");
152 //**********************************************************************************************************************
153 CollectSharedCommand::CollectSharedCommand(string option) {
155 abort = false; calledHelp = false;
158 //allow user to run help
159 if(option == "help") { help(); abort = true; calledHelp = true; }
162 vector<string> myArray = setParameters();
164 OptionParser parser(option);
165 map<string,string> parameters=parser.getParameters();
166 map<string,string>::iterator it;
168 ValidParameters validParameter;
170 //check to make sure all parameters are valid for command
171 for (it = parameters.begin(); it != parameters.end(); it++) {
172 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
175 //initialize outputTypes
176 vector<string> tempOutNames;
177 outputTypes["sharedchao"] = tempOutNames;
178 outputTypes["sharedsobs"] = tempOutNames;
179 outputTypes["sharedace"] = tempOutNames;
180 outputTypes["jabund"] = tempOutNames;
181 outputTypes["sorabund"] = tempOutNames;
182 outputTypes["jclass"] = tempOutNames;
183 outputTypes["sorclass"] = tempOutNames;
184 outputTypes["jest"] = tempOutNames;
185 outputTypes["sorest"] = tempOutNames;
186 outputTypes["thetayc"] = tempOutNames;
187 outputTypes["thetan"] = tempOutNames;
188 outputTypes["kstest"] = tempOutNames;
189 outputTypes["whittaker"] = tempOutNames;
190 outputTypes["sharednseqs"] = tempOutNames;
191 outputTypes["ochiai"] = tempOutNames;
192 outputTypes["anderberg"] = tempOutNames;
193 outputTypes["skulczynski"] = tempOutNames;
194 outputTypes["kulczynskicody"] = tempOutNames;
195 outputTypes["lennon"] = tempOutNames;
196 outputTypes["morisitahorn"] = tempOutNames;
197 outputTypes["braycurtis"] = tempOutNames;
198 outputTypes["odum"] = tempOutNames;
199 outputTypes["canberra"] = tempOutNames;
200 outputTypes["structeuclidean"] = tempOutNames;
201 outputTypes["structchord"] = tempOutNames;
202 outputTypes["hellinger"] = tempOutNames;
203 outputTypes["manhattan"] = tempOutNames;
204 outputTypes["structpearson"] = tempOutNames;
205 outputTypes["soergel"] = tempOutNames;
206 outputTypes["spearman"] = tempOutNames;
207 outputTypes["structkulczynski"] = tempOutNames;
208 outputTypes["speciesprofile"] = tempOutNames;
209 outputTypes["structchi2"] = tempOutNames;
210 outputTypes["hamming"] = tempOutNames;
211 outputTypes["gower"] = tempOutNames;
212 outputTypes["memchi2"] = tempOutNames;
213 outputTypes["memchord"] = tempOutNames;
214 outputTypes["memeuclidean"] = tempOutNames;
215 outputTypes["mempearson"] = tempOutNames;
218 //if the user changes the input directory command factory will send this info to us in the output parameter
219 string inputDir = validParameter.validFile(parameters, "inputdir", false);
220 if (inputDir == "not found"){ inputDir = ""; }
223 it = parameters.find("shared");
224 //user has given a template file
225 if(it != parameters.end()){
226 path = m->hasPath(it->second);
227 //if the user has not given a path then, add inputdir. else leave path alone.
228 if (path == "") { parameters["shared"] = inputDir + it->second; }
233 sharedfile = validParameter.validFile(parameters, "shared", true);
234 if (sharedfile == "not open") { sharedfile = ""; abort = true; }
235 else if (sharedfile == "not found") {
236 //if there is a current shared file, use it
237 sharedfile = m->getSharedFile();
238 if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
239 else { m->mothurOut("You have no current sharedfile and the shared parameter is required."); m->mothurOutEndLine(); abort = true; }
243 //if the user changes the output directory command factory will send this info to us in the output parameter
244 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(sharedfile); }
246 //check for optional parameter and set defaults
247 // ...at some point should added some additional type checking..
248 label = validParameter.validFile(parameters, "label", false);
249 if (label == "not found") { label = ""; }
251 if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
252 else { allLines = 1; }
255 calc = validParameter.validFile(parameters, "calc", false);
256 if (calc == "not found") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
258 if (calc == "default") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
260 m->splitAtDash(calc, Estimators);
262 groups = validParameter.validFile(parameters, "groups", false);
263 if (groups == "not found") { groups = ""; }
265 m->splitAtDash(groups, Groups);
270 temp = validParameter.validFile(parameters, "freq", false); if (temp == "not found") { temp = "100"; }
273 temp = validParameter.validFile(parameters, "all", false); if (temp == "not found") { temp = "false"; }
274 all = m->isTrue(temp);
276 if (abort == false) {
278 string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(sharedfile));
280 ValidCalculators validCalculator;
282 for (int i=0; i<Estimators.size(); i++) {
283 if (validCalculator.isValidCalculator("shared", Estimators[i]) == true) {
284 if (Estimators[i] == "sharedchao") {
285 cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao")));
286 outputNames.push_back(fileNameRoot+"shared.chao"); outputTypes["sharedchao"].push_back(fileNameRoot+"shared.chao");
287 }else if (Estimators[i] == "sharedsobs") {
288 cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs")));
289 outputNames.push_back(fileNameRoot+"shared.sobs"); outputTypes["sharedsobs"].push_back(fileNameRoot+"shared.sobs");
290 }else if (Estimators[i] == "sharedace") {
291 cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace")));
292 outputNames.push_back(fileNameRoot+"shared.ace"); outputTypes["sharedace"].push_back(fileNameRoot+"shared.ace");
293 }else if (Estimators[i] == "jabund") {
294 cDisplays.push_back(new CollectDisplay(new JAbund(), new SharedOneColumnFile(fileNameRoot+"jabund")));
295 outputNames.push_back(fileNameRoot+"jabund"); outputTypes["jabund"].push_back(fileNameRoot+"jabund");
296 }else if (Estimators[i] == "sorabund") {
297 cDisplays.push_back(new CollectDisplay(new SorAbund(), new SharedOneColumnFile(fileNameRoot+"sorabund")));
298 outputNames.push_back(fileNameRoot+"sorabund"); outputTypes["sorabund"].push_back(fileNameRoot+"sorabund");
299 }else if (Estimators[i] == "jclass") {
300 cDisplays.push_back(new CollectDisplay(new Jclass(), new SharedOneColumnFile(fileNameRoot+"jclass")));
301 outputNames.push_back(fileNameRoot+"jclass"); outputTypes["jclass"].push_back(fileNameRoot+"jclass");
302 }else if (Estimators[i] == "sorclass") {
303 cDisplays.push_back(new CollectDisplay(new SorClass(), new SharedOneColumnFile(fileNameRoot+"sorclass")));
304 outputNames.push_back(fileNameRoot+"sorclass"); outputTypes["sorclass"].push_back(fileNameRoot+"sorclass");
305 }else if (Estimators[i] == "jest") {
306 cDisplays.push_back(new CollectDisplay(new Jest(), new SharedOneColumnFile(fileNameRoot+"jest")));
307 outputNames.push_back(fileNameRoot+"jest"); outputTypes["jest"].push_back(fileNameRoot+"jest");
308 }else if (Estimators[i] == "sorest") {
309 cDisplays.push_back(new CollectDisplay(new SorEst(), new SharedOneColumnFile(fileNameRoot+"sorest")));
310 outputNames.push_back(fileNameRoot+"sorest"); outputTypes["sorest"].push_back(fileNameRoot+"sorest");
311 }else if (Estimators[i] == "thetayc") {
312 cDisplays.push_back(new CollectDisplay(new ThetaYC(), new SharedOneColumnFile(fileNameRoot+"thetayc")));
313 outputNames.push_back(fileNameRoot+"thetayc"); outputTypes["thetayc"].push_back(fileNameRoot+"thetayc");
314 }else if (Estimators[i] == "thetan") {
315 cDisplays.push_back(new CollectDisplay(new ThetaN(), new SharedOneColumnFile(fileNameRoot+"thetan")));
316 outputNames.push_back(fileNameRoot+"thetan"); outputTypes["thetan"].push_back(fileNameRoot+"thetan");
317 }else if (Estimators[i] == "kstest") {
318 cDisplays.push_back(new CollectDisplay(new KSTest(), new SharedOneColumnFile(fileNameRoot+"kstest")));
319 outputNames.push_back(fileNameRoot+"kstest"); outputTypes["kstest"].push_back(fileNameRoot+"kstest");
320 }else if (Estimators[i] == "whittaker") {
321 cDisplays.push_back(new CollectDisplay(new Whittaker(), new SharedOneColumnFile(fileNameRoot+"whittaker")));
322 outputNames.push_back(fileNameRoot+"whittaker"); outputTypes["whittaker"].push_back(fileNameRoot+"whittaker");
323 }else if (Estimators[i] == "sharednseqs") {
324 cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(fileNameRoot+"shared.nseqs")));
325 outputNames.push_back(fileNameRoot+"shared.nseqs"); outputTypes["shared.nseqs"].push_back(fileNameRoot+"shared.nseqs");
326 }else if (Estimators[i] == "ochiai") {
327 cDisplays.push_back(new CollectDisplay(new Ochiai(), new SharedOneColumnFile(fileNameRoot+"ochiai")));
328 outputNames.push_back(fileNameRoot+"ochiai"); outputTypes["ochiai"].push_back(fileNameRoot+"ochiai");
329 }else if (Estimators[i] == "anderberg") {
330 cDisplays.push_back(new CollectDisplay(new Anderberg(), new SharedOneColumnFile(fileNameRoot+"anderberg")));
331 outputNames.push_back(fileNameRoot+"anderberg"); outputTypes["anderberg"].push_back(fileNameRoot+"anderberg");
332 }else if (Estimators[i] == "skulczynski") {
333 cDisplays.push_back(new CollectDisplay(new Kulczynski(), new SharedOneColumnFile(fileNameRoot+"kulczynski")));
334 outputNames.push_back(fileNameRoot+"kulczynski"); outputTypes["kulczynski"].push_back(fileNameRoot+"kulczynski");
335 }else if (Estimators[i] == "kulczynskicody") {
336 cDisplays.push_back(new CollectDisplay(new KulczynskiCody(), new SharedOneColumnFile(fileNameRoot+"kulczynskicody")));
337 outputNames.push_back(fileNameRoot+"kulczynskicody"); outputTypes["kulczynskicody"].push_back(fileNameRoot+"kulczynskicody");
338 }else if (Estimators[i] == "lennon") {
339 cDisplays.push_back(new CollectDisplay(new Lennon(), new SharedOneColumnFile(fileNameRoot+"lennon")));
340 outputNames.push_back(fileNameRoot+"lennon"); outputTypes["lennon"].push_back(fileNameRoot+"lennon");
341 }else if (Estimators[i] == "morisitahorn") {
342 cDisplays.push_back(new CollectDisplay(new MorHorn(), new SharedOneColumnFile(fileNameRoot+"morisitahorn")));
343 outputNames.push_back(fileNameRoot+"morisitahorn"); outputTypes["morisitahorn"].push_back(fileNameRoot+"morisitahorn");
344 }else if (Estimators[i] == "braycurtis") {
345 cDisplays.push_back(new CollectDisplay(new BrayCurtis(), new SharedOneColumnFile(fileNameRoot+"braycurtis")));
346 outputNames.push_back(fileNameRoot+"braycurtis"); outputTypes["braycurtis"].push_back(fileNameRoot+"braycurtis");
347 }else if (Estimators[i] == "odum") {
348 cDisplays.push_back(new CollectDisplay(new Odum(), new SharedOneColumnFile(fileNameRoot+"odum")));
349 outputNames.push_back(fileNameRoot+"odum"); outputTypes["odum"].push_back(fileNameRoot+"odum");
350 }else if (Estimators[i] == "canberra") {
351 cDisplays.push_back(new CollectDisplay(new Canberra(), new SharedOneColumnFile(fileNameRoot+"canberra")));
352 outputNames.push_back(fileNameRoot+"canberra"); outputTypes["canberra"].push_back(fileNameRoot+"canberra");
353 }else if (Estimators[i] == "structeuclidean") {
354 cDisplays.push_back(new CollectDisplay(new StructEuclidean(), new SharedOneColumnFile(fileNameRoot+"structeuclidean")));
355 outputNames.push_back(fileNameRoot+"structeuclidean"); outputTypes["structeuclidean"].push_back(fileNameRoot+"structeuclidean");
356 }else if (Estimators[i] == "structchord") {
357 cDisplays.push_back(new CollectDisplay(new StructChord(), new SharedOneColumnFile(fileNameRoot+"structchord")));
358 outputNames.push_back(fileNameRoot+"structchord"); outputTypes["structchord"].push_back(fileNameRoot+"structchord");
359 }else if (Estimators[i] == "hellinger") {
360 cDisplays.push_back(new CollectDisplay(new Hellinger(), new SharedOneColumnFile(fileNameRoot+"hellinger")));
361 outputNames.push_back(fileNameRoot+"hellinger"); outputTypes["hellinger"].push_back(fileNameRoot+"hellinger");
362 }else if (Estimators[i] == "manhattan") {
363 cDisplays.push_back(new CollectDisplay(new Manhattan(), new SharedOneColumnFile(fileNameRoot+"manhattan")));
364 outputNames.push_back(fileNameRoot+"manhattan"); outputTypes["manhattan"].push_back(fileNameRoot+"manhattan");
365 }else if (Estimators[i] == "structpearson") {
366 cDisplays.push_back(new CollectDisplay(new StructPearson(), new SharedOneColumnFile(fileNameRoot+"structpearson")));
367 outputNames.push_back(fileNameRoot+"structpearson"); outputTypes["structpearson"].push_back(fileNameRoot+"structpearson");
368 }else if (Estimators[i] == "soergel") {
369 cDisplays.push_back(new CollectDisplay(new Soergel(), new SharedOneColumnFile(fileNameRoot+"soergel")));
370 outputNames.push_back(fileNameRoot+"soergel"); outputTypes["soergel"].push_back(fileNameRoot+"soergel");
371 }else if (Estimators[i] == "spearman") {
372 cDisplays.push_back(new CollectDisplay(new Spearman(), new SharedOneColumnFile(fileNameRoot+"spearman")));
373 outputNames.push_back(fileNameRoot+"spearman"); outputTypes["spearman"].push_back(fileNameRoot+"spearman");
374 }else if (Estimators[i] == "structkulczynski") {
375 cDisplays.push_back(new CollectDisplay(new StructKulczynski(), new SharedOneColumnFile(fileNameRoot+"structkulczynski")));
376 outputNames.push_back(fileNameRoot+"structkulczynski"); outputTypes["structkulczynski"].push_back(fileNameRoot+"structkulczynski");
377 }else if (Estimators[i] == "speciesprofile") {
378 cDisplays.push_back(new CollectDisplay(new SpeciesProfile(), new SharedOneColumnFile(fileNameRoot+"speciesprofile")));
379 outputNames.push_back(fileNameRoot+"speciesprofile"); outputTypes["speciesprofile"].push_back(fileNameRoot+"speciesprofile");
380 }else if (Estimators[i] == "hamming") {
381 cDisplays.push_back(new CollectDisplay(new Hamming(), new SharedOneColumnFile(fileNameRoot+"hamming")));
382 outputNames.push_back(fileNameRoot+"hamming"); outputTypes["hamming"].push_back(fileNameRoot+"hamming");
383 }else if (Estimators[i] == "structchi2") {
384 cDisplays.push_back(new CollectDisplay(new StructChi2(), new SharedOneColumnFile(fileNameRoot+"structchi2")));
385 outputNames.push_back(fileNameRoot+"structchi2"); outputTypes["structchi2"].push_back(fileNameRoot+"structchi2");
386 }else if (Estimators[i] == "gower") {
387 cDisplays.push_back(new CollectDisplay(new Gower(), new SharedOneColumnFile(fileNameRoot+"gower")));
388 outputNames.push_back(fileNameRoot+"gower"); outputTypes["gower"].push_back(fileNameRoot+"gower");
389 }else if (Estimators[i] == "memchi2") {
390 cDisplays.push_back(new CollectDisplay(new MemChi2(), new SharedOneColumnFile(fileNameRoot+"memchi2")));
391 outputNames.push_back(fileNameRoot+"memchi2"); outputTypes["memchi2"].push_back(fileNameRoot+"memchi2");
392 }else if (Estimators[i] == "memchord") {
393 cDisplays.push_back(new CollectDisplay(new MemChord(), new SharedOneColumnFile(fileNameRoot+"memchord")));
394 outputNames.push_back(fileNameRoot+"memchord"); outputTypes["memchord"].push_back(fileNameRoot+"memchord");
395 }else if (Estimators[i] == "memeuclidean") {
396 cDisplays.push_back(new CollectDisplay(new MemEuclidean(), new SharedOneColumnFile(fileNameRoot+"memeuclidean")));
397 outputNames.push_back(fileNameRoot+"memeuclidean"); outputTypes["memeuclidean"].push_back(fileNameRoot+"memeuclidean");
398 }else if (Estimators[i] == "mempearson") {
399 cDisplays.push_back(new CollectDisplay(new MemPearson(), new SharedOneColumnFile(fileNameRoot+"mempearson")));
400 outputNames.push_back(fileNameRoot+"mempearson"); outputTypes["mempearson"].push_back(fileNameRoot+"mempearson");
409 catch(exception& e) {
410 m->errorOut(e, "CollectSharedCommand", "CollectSharedCommand");
414 //**********************************************************************************************************************
415 CollectSharedCommand::~CollectSharedCommand(){}
416 //**********************************************************************************************************************
418 int CollectSharedCommand::execute(){
421 if (abort == true) { if (calledHelp) { return 0; } return 2; }
423 //if the users entered no valid calculators don't execute command
424 if (cDisplays.size() == 0) { return 0; }
425 for(int i=0;i<cDisplays.size();i++){ cDisplays[i]->setAll(all); }
427 input = new InputData(sharedfile, "sharedfile");
428 order = input->getSharedOrderVector();
429 string lastLabel = order->getLabel();
431 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
432 set<string> processedLabels;
433 set<string> userLabels = labels;
436 SharedUtil* util = new SharedUtil();
437 util->setGroups(m->Groups, m->namesOfGroups, "collect");
440 while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
441 if (m->control_pressed) {
442 for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear();
443 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
444 delete order; delete input;
449 if(allLines == 1 || labels.count(order->getLabel()) == 1){
451 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
452 //create collectors curve
453 cCurve = new Collect(order, cDisplays);
454 cCurve->getSharedCurve(freq);
457 processedLabels.insert(order->getLabel());
458 userLabels.erase(order->getLabel());
461 //you have a label the user want that is smaller than this label and the last label has not already been processed
462 if ((m->anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
463 string saveLabel = order->getLabel();
466 order = input->getSharedOrderVector(lastLabel);
468 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
469 //create collectors curve
470 cCurve = new Collect(order, cDisplays);
471 cCurve->getSharedCurve(freq);
474 processedLabels.insert(order->getLabel());
475 userLabels.erase(order->getLabel());
477 //restore real lastlabel to save below
478 order->setLabel(saveLabel);
482 lastLabel = order->getLabel();
484 //get next line to process
486 order = input->getSharedOrderVector();
489 if (m->control_pressed) {
490 for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear();
491 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
497 //output error messages about any remaining user labels
498 set<string>::iterator it;
499 bool needToRun = false;
500 for (it = userLabels.begin(); it != userLabels.end(); it++) {
501 m->mothurOut("Your file does not include the label " + *it);
502 if (processedLabels.count(lastLabel) != 1) {
503 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
506 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
510 //run last label if you need to
511 if (needToRun == true) {
512 if (order != NULL) { delete order; }
513 order = input->getSharedOrderVector(lastLabel);
515 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
516 cCurve = new Collect(order, cDisplays);
517 cCurve->getSharedCurve(freq);
520 if (m->control_pressed) {
521 for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } outputTypes.clear();
522 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
532 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
534 //reset groups parameter
538 m->mothurOutEndLine();
539 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
540 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
541 m->mothurOutEndLine();
546 catch(exception& e) {
547 m->errorOut(e, "CollectSharedCommand", "execute");
552 /***********************************************************/