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"
52 #include "sharedjsd.h"
55 //**********************************************************************************************************************
56 vector<string> CollectSharedCommand::setParameters(){
58 CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none","",false,true,true); parameters.push_back(pshared);
59 CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel);
60 CommandParameter pfreq("freq", "Number", "", "100", "", "", "","",false,false); parameters.push_back(pfreq);
61 CommandParameter pcalc("calc", "Multiple", "sharedchao-sharedsobs-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-kstest-whittaker-sharednseqs-ochiai-anderberg-kulczynski-kulczynskicody-lennon-morisitahorn-braycurtis-odum-canberra-structeuclidean-structchord-hellinger-manhattan-structpearson-soergel-spearman-structkulczynski-speciesprofile-structchi2-hamming-gower-memchi2-memchord-memeuclidean-mempearson-jsd", "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan", "", "", "","",true,false,true); parameters.push_back(pcalc);
62 CommandParameter pall("all", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pall);
63 CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups);
64 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
65 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
67 vector<string> myArray;
68 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
72 m->errorOut(e, "CollectSharedCommand", "setParameters");
76 //**********************************************************************************************************************
77 string CollectSharedCommand::getHelpString(){
79 string helpString = "";
80 ValidCalculators validCalculator;
81 helpString += "The collect.shared command parameters are shared, label, freq, calc and groups. shared is required if there is no current sharedfile. \n";
82 helpString += "The collect.shared command should be in the following format: \n";
83 helpString += "collect.shared(label=yourLabel, freq=yourFreq, calc=yourEstimators, groups=yourGroups).\n";
84 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";
85 helpString += "The default values for freq is 100 and calc are sharedsobs-sharedchao-sharedace-jabund-sorensonabund-jclass-sorclass-jest-sorest-thetayc-thetan.\n";
86 helpString += "The default value for groups is all the groups in your groupfile.\n";
87 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";
88 helpString += validCalculator.printCalc("shared");
89 helpString += "The label parameter is used to analyze specific labels in your input.\n";
90 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";
91 helpString += "If you use sharedchao and run into memory issues, set all to false. \n";
92 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";
93 helpString += "Note: No spaces between parameter labels (i.e. shared), '=' and parameters (i.e.yourSharedfile).\n";
97 m->errorOut(e, "CollectSharedCommand", "getHelpString");
101 //**********************************************************************************************************************
102 string CollectSharedCommand::getOutputPattern(string type) {
106 if (type == "sharedchao") { pattern = "[filename],shared.chao"; }
107 else if (type == "sharedsobs") { pattern = "[filename],shared.sobs"; }
108 else if (type == "sharedace") { pattern = "[filename],shared.ace"; }
109 else if (type == "jabund") { pattern = "[filename],jabund"; }
110 else if (type == "sorabund") { pattern = "[filename],sorabund"; }
111 else if (type == "jclass") { pattern = "[filename],jclass"; }
112 else if (type == "sorclass") { pattern = "[filename],sorclass"; }
113 else if (type == "jest") { pattern = "[filename],jest"; }
114 else if (type == "sorest") { pattern = "[filename],sorest"; }
115 else if (type == "thetayc") { pattern = "[filename],thetayc"; }
116 else if (type == "thetan") { pattern = "[filename],thetan"; }
117 else if (type == "kstest") { pattern = "[filename],kstest"; }
118 else if (type == "whittaker") { pattern = "[filename],whittaker"; }
119 else if (type == "sharednseqs") { pattern = "[filename],shared.nseqs"; }
120 else if (type == "ochiai") { pattern = "[filename],ochiai"; }
121 else if (type == "anderberg") { pattern = "[filename],anderberg"; }
122 else if (type == "kulczynski") { pattern = "[filename],kulczynski"; }
123 else if (type == "kulczynskicody") { pattern = "[filename],kulczynskicody"; }
124 else if (type == "lennon") { pattern = "[filename],lennon"; }
125 else if (type == "morisitahorn") { pattern = "[filename],morisitahorn"; }
126 else if (type == "braycurtis") { pattern = "[filename],braycurtis"; }
127 else if (type == "odum") { pattern = "[filename],odum"; }
128 else if (type == "canberra") { pattern = "[filename],canberra"; }
129 else if (type == "structeuclidean") { pattern = "[filename],structeuclidean"; }
130 else if (type == "structchord") { pattern = "[filename],structchord"; }
131 else if (type == "hellinger") { pattern = "[filename],hellinger"; }
132 else if (type == "manhattan") { pattern = "[filename],manhattan"; }
133 else if (type == "structpearson") { pattern = "[filename],structpearson"; }
134 else if (type == "soergel") { pattern = "[filename],soergel"; }
135 else if (type == "spearman") { pattern = "[filename],spearman"; }
136 else if (type == "structkulczynski") { pattern = "[filename],structkulczynski";}
137 else if (type == "structchi2") { pattern = "[filename],structchi2"; }
138 else if (type == "speciesprofile") { pattern = "[filename],speciesprofile"; }
139 else if (type == "hamming") { pattern = "[filename],hamming"; }
140 else if (type == "gower") { pattern = "[filename],gower"; }
141 else if (type == "memchi2") { pattern = "[filename],memchi2"; }
142 else if (type == "memchord") { pattern = "[filename],memchord"; }
143 else if (type == "memeuclidean") { pattern = "[filename],memeuclidean"; }
144 else if (type == "mempearson") { pattern = "[filename],mempearson"; }
145 else if (type == "jsd") { pattern = "[filename],jsd"; }
146 else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; }
150 catch(exception& e) {
151 m->errorOut(e, "CollectSharedCommand", "getOutputPattern");
156 //**********************************************************************************************************************
157 CollectSharedCommand::CollectSharedCommand(){
159 abort = true; calledHelp = true;
161 vector<string> tempOutNames;
162 outputTypes["sharedchao"] = tempOutNames;
163 outputTypes["sharedsobs"] = tempOutNames;
164 outputTypes["sharedace"] = tempOutNames;
165 outputTypes["jabund"] = tempOutNames;
166 outputTypes["sorabund"] = tempOutNames;
167 outputTypes["jclass"] = tempOutNames;
168 outputTypes["sorclass"] = tempOutNames;
169 outputTypes["jest"] = tempOutNames;
170 outputTypes["sorest"] = tempOutNames;
171 outputTypes["thetayc"] = tempOutNames;
172 outputTypes["thetan"] = tempOutNames;
173 outputTypes["kstest"] = tempOutNames;
174 outputTypes["whittaker"] = tempOutNames;
175 outputTypes["sharednseqs"] = tempOutNames;
176 outputTypes["ochiai"] = tempOutNames;
177 outputTypes["anderberg"] = tempOutNames;
178 outputTypes["kulczynski"] = tempOutNames;
179 outputTypes["kulczynskicody"] = tempOutNames;
180 outputTypes["lennon"] = tempOutNames;
181 outputTypes["morisitahorn"] = tempOutNames;
182 outputTypes["braycurtis"] = tempOutNames;
183 outputTypes["odum"] = tempOutNames;
184 outputTypes["canberra"] = tempOutNames;
185 outputTypes["structeuclidean"] = tempOutNames;
186 outputTypes["structchord"] = tempOutNames;
187 outputTypes["hellinger"] = tempOutNames;
188 outputTypes["manhattan"] = tempOutNames;
189 outputTypes["structpearson"] = tempOutNames;
190 outputTypes["soergel"] = tempOutNames;
191 outputTypes["spearman"] = tempOutNames;
192 outputTypes["structkulczynski"] = tempOutNames;
193 outputTypes["structchi2"] = tempOutNames;
194 outputTypes["speciesprofile"] = tempOutNames;
195 outputTypes["hamming"] = tempOutNames;
196 outputTypes["gower"] = tempOutNames;
197 outputTypes["memchi2"] = tempOutNames;
198 outputTypes["memchord"] = tempOutNames;
199 outputTypes["memeuclidean"] = tempOutNames;
200 outputTypes["mempearson"] = tempOutNames;
201 outputTypes["jsd"] = tempOutNames;
204 catch(exception& e) {
205 m->errorOut(e, "CollectSharedCommand", "CollectSharedCommand");
209 //**********************************************************************************************************************
210 CollectSharedCommand::CollectSharedCommand(string option) {
212 abort = false; calledHelp = false;
215 //allow user to run help
216 if(option == "help") { help(); abort = true; calledHelp = true; }
217 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
220 vector<string> myArray = setParameters();
222 OptionParser parser(option);
223 map<string,string> parameters=parser.getParameters();
224 map<string,string>::iterator it;
226 ValidParameters validParameter;
228 //check to make sure all parameters are valid for command
229 for (it = parameters.begin(); it != parameters.end(); it++) {
230 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
233 //initialize outputTypes
234 vector<string> tempOutNames;
235 outputTypes["sharedchao"] = tempOutNames;
236 outputTypes["sharedsobs"] = tempOutNames;
237 outputTypes["sharedace"] = tempOutNames;
238 outputTypes["jabund"] = tempOutNames;
239 outputTypes["sorabund"] = tempOutNames;
240 outputTypes["jclass"] = tempOutNames;
241 outputTypes["sorclass"] = tempOutNames;
242 outputTypes["jest"] = tempOutNames;
243 outputTypes["sorest"] = tempOutNames;
244 outputTypes["thetayc"] = tempOutNames;
245 outputTypes["thetan"] = tempOutNames;
246 outputTypes["kstest"] = tempOutNames;
247 outputTypes["whittaker"] = tempOutNames;
248 outputTypes["sharednseqs"] = tempOutNames;
249 outputTypes["ochiai"] = tempOutNames;
250 outputTypes["anderberg"] = tempOutNames;
251 outputTypes["kulczynski"] = tempOutNames;
252 outputTypes["kulczynskicody"] = tempOutNames;
253 outputTypes["lennon"] = tempOutNames;
254 outputTypes["morisitahorn"] = tempOutNames;
255 outputTypes["braycurtis"] = tempOutNames;
256 outputTypes["odum"] = tempOutNames;
257 outputTypes["canberra"] = tempOutNames;
258 outputTypes["structeuclidean"] = tempOutNames;
259 outputTypes["structchord"] = tempOutNames;
260 outputTypes["hellinger"] = tempOutNames;
261 outputTypes["manhattan"] = tempOutNames;
262 outputTypes["structpearson"] = tempOutNames;
263 outputTypes["soergel"] = tempOutNames;
264 outputTypes["spearman"] = tempOutNames;
265 outputTypes["structkulczynski"] = tempOutNames;
266 outputTypes["speciesprofile"] = tempOutNames;
267 outputTypes["structchi2"] = tempOutNames;
268 outputTypes["hamming"] = tempOutNames;
269 outputTypes["gower"] = tempOutNames;
270 outputTypes["memchi2"] = tempOutNames;
271 outputTypes["memchord"] = tempOutNames;
272 outputTypes["memeuclidean"] = tempOutNames;
273 outputTypes["mempearson"] = tempOutNames;
274 outputTypes["jsd"] = tempOutNames;
277 //if the user changes the input directory command factory will send this info to us in the output parameter
278 string inputDir = validParameter.validFile(parameters, "inputdir", false);
279 if (inputDir == "not found"){ inputDir = ""; }
282 it = parameters.find("shared");
283 //user has given a template file
284 if(it != parameters.end()){
285 path = m->hasPath(it->second);
286 //if the user has not given a path then, add inputdir. else leave path alone.
287 if (path == "") { parameters["shared"] = inputDir + it->second; }
292 sharedfile = validParameter.validFile(parameters, "shared", true);
293 if (sharedfile == "not open") { sharedfile = ""; abort = true; }
294 else if (sharedfile == "not found") {
295 //if there is a current shared file, use it
296 sharedfile = m->getSharedFile();
297 if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
298 else { m->mothurOut("You have no current sharedfile and the shared parameter is required."); m->mothurOutEndLine(); abort = true; }
299 }else { m->setSharedFile(sharedfile); }
302 //if the user changes the output directory command factory will send this info to us in the output parameter
303 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(sharedfile); }
305 //check for optional parameter and set defaults
306 // ...at some point should added some additional type checking..
307 label = validParameter.validFile(parameters, "label", false);
308 if (label == "not found") { label = ""; }
310 if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
311 else { allLines = 1; }
314 calc = validParameter.validFile(parameters, "calc", false);
315 if (calc == "not found") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
317 if (calc == "default") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
319 m->splitAtDash(calc, Estimators);
320 if (m->inUsersGroups("citation", Estimators)) {
321 ValidCalculators validCalc; validCalc.printCitations(Estimators);
322 //remove citation from list of calcs
323 for (int i = 0; i < Estimators.size(); i++) { if (Estimators[i] == "citation") { Estimators.erase(Estimators.begin()+i); break; } }
326 groups = validParameter.validFile(parameters, "groups", false);
327 if (groups == "not found") { groups = ""; }
329 m->splitAtDash(groups, Groups);
331 m->setGroups(Groups);
334 temp = validParameter.validFile(parameters, "freq", false); if (temp == "not found") { temp = "100"; }
335 m->mothurConvert(temp, freq);
337 temp = validParameter.validFile(parameters, "all", false); if (temp == "not found") { temp = "false"; }
338 all = m->isTrue(temp);
340 if (abort == false) {
342 string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(sharedfile));
343 map<string, string> variables;
344 variables["[filename]"] = fileNameRoot;
346 ValidCalculators validCalculator;
348 for (int i=0; i<Estimators.size(); i++) {
349 if (validCalculator.isValidCalculator("shared", Estimators[i]) == true) {
350 if (Estimators[i] == "sharedchao") {
351 cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(getOutputFileName("sharedchao", variables))));
352 outputNames.push_back(getOutputFileName("sharedchao", variables)); outputTypes["sharedchao"].push_back(getOutputFileName("sharedchao", variables));
353 }else if (Estimators[i] == "sharedsobs") {
354 cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(getOutputFileName("sharedsobs", variables))));
355 outputNames.push_back(getOutputFileName("sharedsobs", variables)); outputTypes["sharedsobs"].push_back(getOutputFileName("sharedsobs", variables));
356 }else if (Estimators[i] == "sharedace") {
357 cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(getOutputFileName("sharedace", variables))));
358 outputNames.push_back(getOutputFileName("sharedace", variables)); outputTypes["sharedace"].push_back(getOutputFileName("sharedace", variables));
359 }else if (Estimators[i] == "jabund") {
360 cDisplays.push_back(new CollectDisplay(new JAbund(), new SharedOneColumnFile(getOutputFileName("jabund", variables))));
361 outputNames.push_back(getOutputFileName("jabund", variables)); outputTypes["jabund"].push_back(getOutputFileName("jabund", variables));
362 }else if (Estimators[i] == "sorabund") {
363 cDisplays.push_back(new CollectDisplay(new SorAbund(), new SharedOneColumnFile(getOutputFileName("sorabund", variables))));
364 outputNames.push_back(getOutputFileName("sorabund", variables)); outputTypes["sorabund"].push_back(getOutputFileName("sorabund", variables));
365 }else if (Estimators[i] == "jclass") {
366 cDisplays.push_back(new CollectDisplay(new Jclass(), new SharedOneColumnFile(getOutputFileName("jclass", variables))));
367 outputNames.push_back(getOutputFileName("jclass", variables)); outputTypes["jclass"].push_back(getOutputFileName("jclass", variables));
368 }else if (Estimators[i] == "sorclass") {
369 cDisplays.push_back(new CollectDisplay(new SorClass(), new SharedOneColumnFile(getOutputFileName("sorclass", variables))));
370 outputNames.push_back(getOutputFileName("sorclass", variables)); outputTypes["sorclass"].push_back(getOutputFileName("sorclass", variables));
371 }else if (Estimators[i] == "jest") {
372 cDisplays.push_back(new CollectDisplay(new Jest(), new SharedOneColumnFile(getOutputFileName("jest", variables))));
373 outputNames.push_back(getOutputFileName("jest", variables)); outputTypes["jest"].push_back(getOutputFileName("jest", variables));
374 }else if (Estimators[i] == "sorest") {
375 cDisplays.push_back(new CollectDisplay(new SorEst(), new SharedOneColumnFile(getOutputFileName("sorest", variables))));
376 outputNames.push_back(getOutputFileName("sorest", variables)); outputTypes["sorest"].push_back(getOutputFileName("sorest", variables));
377 }else if (Estimators[i] == "thetayc") {
378 cDisplays.push_back(new CollectDisplay(new ThetaYC(), new SharedOneColumnFile(getOutputFileName("thetayc", variables))));
379 outputNames.push_back(getOutputFileName("thetayc", variables)); outputTypes["thetayc"].push_back(getOutputFileName("thetayc", variables));
380 }else if (Estimators[i] == "thetan") {
381 cDisplays.push_back(new CollectDisplay(new ThetaN(), new SharedOneColumnFile(getOutputFileName("thetan", variables))));
382 outputNames.push_back(getOutputFileName("thetan", variables)); outputTypes["thetan"].push_back(getOutputFileName("thetan", variables));
383 }else if (Estimators[i] == "kstest") {
384 cDisplays.push_back(new CollectDisplay(new KSTest(), new SharedOneColumnFile(getOutputFileName("kstest", variables))));
385 outputNames.push_back(getOutputFileName("kstest", variables)); outputTypes["kstest"].push_back(getOutputFileName("kstest", variables));
386 }else if (Estimators[i] == "whittaker") {
387 cDisplays.push_back(new CollectDisplay(new Whittaker(), new SharedOneColumnFile(getOutputFileName("whittaker", variables))));
388 outputNames.push_back(getOutputFileName("whittaker", variables)); outputTypes["whittaker"].push_back(getOutputFileName("whittaker", variables));
389 }else if (Estimators[i] == "sharednseqs") {
390 cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(getOutputFileName("sharednseqs", variables))));
391 outputNames.push_back(getOutputFileName("sharednseqs", variables)); outputTypes["shared.nseqs"].push_back(getOutputFileName("sharednseqs", variables));
392 }else if (Estimators[i] == "ochiai") {
393 cDisplays.push_back(new CollectDisplay(new Ochiai(), new SharedOneColumnFile(getOutputFileName("ochiai", variables))));
394 outputNames.push_back(getOutputFileName("ochiai", variables)); outputTypes["ochiai"].push_back(getOutputFileName("ochiai", variables));
395 }else if (Estimators[i] == "anderberg") {
396 cDisplays.push_back(new CollectDisplay(new Anderberg(), new SharedOneColumnFile(getOutputFileName("anderberg", variables))));
397 outputNames.push_back(getOutputFileName("anderberg", variables)); outputTypes["anderberg"].push_back(getOutputFileName("anderberg", variables));
398 }else if (Estimators[i] == "kulczynski") {
399 cDisplays.push_back(new CollectDisplay(new Kulczynski(), new SharedOneColumnFile(getOutputFileName("kulczynski", variables))));
400 outputNames.push_back(getOutputFileName("kulczynski", variables)); outputTypes["kulczynski"].push_back(getOutputFileName("kulczynski", variables));
401 }else if (Estimators[i] == "kulczynskicody") {
402 cDisplays.push_back(new CollectDisplay(new KulczynskiCody(), new SharedOneColumnFile(getOutputFileName("kulczynskicody", variables))));
403 outputNames.push_back(getOutputFileName("kulczynskicody", variables)); outputTypes["kulczynskicody"].push_back(getOutputFileName("kulczynskicody", variables));
404 }else if (Estimators[i] == "lennon") {
405 cDisplays.push_back(new CollectDisplay(new Lennon(), new SharedOneColumnFile(getOutputFileName("lennon", variables))));
406 outputNames.push_back(getOutputFileName("lennon", variables)); outputTypes["lennon"].push_back(getOutputFileName("lennon", variables));
407 }else if (Estimators[i] == "morisitahorn") {
408 cDisplays.push_back(new CollectDisplay(new MorHorn(), new SharedOneColumnFile(getOutputFileName("morisitahorn", variables))));
409 outputNames.push_back(getOutputFileName("morisitahorn", variables)); outputTypes["morisitahorn"].push_back(getOutputFileName("morisitahorn", variables));
410 }else if (Estimators[i] == "braycurtis") {
411 cDisplays.push_back(new CollectDisplay(new BrayCurtis(), new SharedOneColumnFile(getOutputFileName("braycurtis", variables))));
412 outputNames.push_back(getOutputFileName("braycurtis", variables)); outputTypes["braycurtis"].push_back(getOutputFileName("braycurtis", variables));
413 }else if (Estimators[i] == "odum") {
414 cDisplays.push_back(new CollectDisplay(new Odum(), new SharedOneColumnFile(getOutputFileName("odum", variables))));
415 outputNames.push_back(getOutputFileName("odum", variables)); outputTypes["odum"].push_back(getOutputFileName("odum", variables));
416 }else if (Estimators[i] == "canberra") {
417 cDisplays.push_back(new CollectDisplay(new Canberra(), new SharedOneColumnFile(getOutputFileName("canberra", variables))));
418 outputNames.push_back(getOutputFileName("canberra", variables)); outputTypes["canberra"].push_back(getOutputFileName("canberra", variables));
419 }else if (Estimators[i] == "structeuclidean") {
420 cDisplays.push_back(new CollectDisplay(new StructEuclidean(), new SharedOneColumnFile(getOutputFileName("structeuclidean", variables))));
421 outputNames.push_back(getOutputFileName("structeuclidean", variables)); outputTypes["structeuclidean"].push_back(getOutputFileName("structeuclidean", variables));
422 }else if (Estimators[i] == "structchord") {
423 cDisplays.push_back(new CollectDisplay(new StructChord(), new SharedOneColumnFile(getOutputFileName("structchord", variables))));
424 outputNames.push_back(getOutputFileName("structchord", variables)); outputTypes["structchord"].push_back(getOutputFileName("structchord", variables));
425 }else if (Estimators[i] == "hellinger") {
426 cDisplays.push_back(new CollectDisplay(new Hellinger(), new SharedOneColumnFile(getOutputFileName("hellinger", variables))));
427 outputNames.push_back(getOutputFileName("hellinger", variables)); outputTypes["hellinger"].push_back(getOutputFileName("hellinger", variables));
428 }else if (Estimators[i] == "manhattan") {
429 cDisplays.push_back(new CollectDisplay(new Manhattan(), new SharedOneColumnFile(getOutputFileName("manhattan", variables))));
430 outputNames.push_back(getOutputFileName("manhattan", variables)); outputTypes["manhattan"].push_back(getOutputFileName("manhattan", variables));
431 }else if (Estimators[i] == "structpearson") {
432 cDisplays.push_back(new CollectDisplay(new StructPearson(), new SharedOneColumnFile(getOutputFileName("structpearson", variables))));
433 outputNames.push_back(getOutputFileName("structpearson", variables)); outputTypes["structpearson"].push_back(getOutputFileName("structpearson", variables));
434 }else if (Estimators[i] == "soergel") {
435 cDisplays.push_back(new CollectDisplay(new Soergel(), new SharedOneColumnFile(getOutputFileName("soergel", variables))));
436 outputNames.push_back(getOutputFileName("soergel", variables)); outputTypes["soergel"].push_back(getOutputFileName("soergel", variables));
437 }else if (Estimators[i] == "spearman") {
438 cDisplays.push_back(new CollectDisplay(new Spearman(), new SharedOneColumnFile(getOutputFileName("spearman", variables))));
439 outputNames.push_back(getOutputFileName("spearman", variables)); outputTypes["spearman"].push_back(getOutputFileName("spearman", variables));
440 }else if (Estimators[i] == "structkulczynski") {
441 cDisplays.push_back(new CollectDisplay(new StructKulczynski(), new SharedOneColumnFile(getOutputFileName("structkulczynski", variables))));
442 outputNames.push_back(getOutputFileName("structkulczynski", variables)); outputTypes["structkulczynski"].push_back(getOutputFileName("structkulczynski", variables));
443 }else if (Estimators[i] == "speciesprofile") {
444 cDisplays.push_back(new CollectDisplay(new SpeciesProfile(), new SharedOneColumnFile(getOutputFileName("speciesprofile", variables))));
445 outputNames.push_back(getOutputFileName("speciesprofile", variables)); outputTypes["speciesprofile"].push_back(getOutputFileName("speciesprofile", variables));
446 }else if (Estimators[i] == "hamming") {
447 cDisplays.push_back(new CollectDisplay(new Hamming(), new SharedOneColumnFile(getOutputFileName("hamming", variables))));
448 outputNames.push_back(getOutputFileName("hamming", variables)); outputTypes["hamming"].push_back(getOutputFileName("hamming", variables));
449 }else if (Estimators[i] == "structchi2") {
450 cDisplays.push_back(new CollectDisplay(new StructChi2(), new SharedOneColumnFile(getOutputFileName("structchi2", variables))));
451 outputNames.push_back(getOutputFileName("structchi2", variables)); outputTypes["structchi2"].push_back(getOutputFileName("structchi2", variables));
452 }else if (Estimators[i] == "gower") {
453 cDisplays.push_back(new CollectDisplay(new Gower(), new SharedOneColumnFile(getOutputFileName("gower", variables))));
454 outputNames.push_back(getOutputFileName("gower", variables)); outputTypes["gower"].push_back(getOutputFileName("gower", variables));
455 }else if (Estimators[i] == "memchi2") {
456 cDisplays.push_back(new CollectDisplay(new MemChi2(), new SharedOneColumnFile(getOutputFileName("memchi2", variables))));
457 outputNames.push_back(getOutputFileName("memchi2", variables)); outputTypes["memchi2"].push_back(getOutputFileName("memchi2", variables));
458 }else if (Estimators[i] == "memchord") {
459 cDisplays.push_back(new CollectDisplay(new MemChord(), new SharedOneColumnFile(getOutputFileName("memchord", variables))));
460 outputNames.push_back(getOutputFileName("memchord", variables)); outputTypes["memchord"].push_back(getOutputFileName("memchord", variables));
461 }else if (Estimators[i] == "memeuclidean") {
462 cDisplays.push_back(new CollectDisplay(new MemEuclidean(), new SharedOneColumnFile(getOutputFileName("memeuclidean", variables))));
463 outputNames.push_back(getOutputFileName("memeuclidean", variables)); outputTypes["memeuclidean"].push_back(getOutputFileName("memeuclidean", variables));
464 }else if (Estimators[i] == "mempearson") {
465 cDisplays.push_back(new CollectDisplay(new MemPearson(), new SharedOneColumnFile(getOutputFileName("mempearson", variables))));
466 outputNames.push_back(getOutputFileName("mempearson", variables)); outputTypes["mempearson"].push_back(getOutputFileName("mempearson", variables));
467 }else if (Estimators[i] == "jsd") {
468 cDisplays.push_back(new CollectDisplay(new JSD(), new SharedOneColumnFile(getOutputFileName("jsd", variables))));
469 outputNames.push_back(getOutputFileName("jsd", variables)); outputTypes["jsd"].push_back(getOutputFileName("jsd", variables));
478 catch(exception& e) {
479 m->errorOut(e, "CollectSharedCommand", "CollectSharedCommand");
483 //**********************************************************************************************************************
484 CollectSharedCommand::~CollectSharedCommand(){}
485 //**********************************************************************************************************************
487 int CollectSharedCommand::execute(){
490 if (abort == true) { if (calledHelp) { return 0; } return 2; }
492 //if the users entered no valid calculators don't execute command
493 if (cDisplays.size() == 0) { return 0; }
494 for(int i=0;i<cDisplays.size();i++){ cDisplays[i]->setAll(all); }
496 input = new InputData(sharedfile, "sharedfile");
497 order = input->getSharedOrderVector();
498 string lastLabel = order->getLabel();
500 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
501 set<string> processedLabels;
502 set<string> userLabels = labels;
505 SharedUtil* util = new SharedUtil();
506 Groups = m->getGroups();
507 vector<string> allGroups = m->getAllGroups();
508 util->setGroups(Groups, allGroups, "collect");
509 m->setGroups(Groups);
510 m->setAllGroups(allGroups);
513 while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
514 if (m->control_pressed) {
515 for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear();
516 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
517 delete order; delete input;
522 if(allLines == 1 || labels.count(order->getLabel()) == 1){
524 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
525 //create collectors curve
526 cCurve = new Collect(order, cDisplays);
527 cCurve->getSharedCurve(freq);
530 processedLabels.insert(order->getLabel());
531 userLabels.erase(order->getLabel());
534 //you have a label the user want that is smaller than this label and the last label has not already been processed
535 if ((m->anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
536 string saveLabel = order->getLabel();
539 order = input->getSharedOrderVector(lastLabel);
541 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
542 //create collectors curve
543 cCurve = new Collect(order, cDisplays);
544 cCurve->getSharedCurve(freq);
547 processedLabels.insert(order->getLabel());
548 userLabels.erase(order->getLabel());
550 //restore real lastlabel to save below
551 order->setLabel(saveLabel);
555 lastLabel = order->getLabel();
557 //get next line to process
559 order = input->getSharedOrderVector();
562 if (m->control_pressed) {
563 for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear();
564 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
570 //output error messages about any remaining user labels
571 set<string>::iterator it;
572 bool needToRun = false;
573 for (it = userLabels.begin(); it != userLabels.end(); it++) {
574 m->mothurOut("Your file does not include the label " + *it);
575 if (processedLabels.count(lastLabel) != 1) {
576 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
579 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
583 //run last label if you need to
584 if (needToRun == true) {
585 if (order != NULL) { delete order; }
586 order = input->getSharedOrderVector(lastLabel);
588 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
589 cCurve = new Collect(order, cDisplays);
590 cCurve->getSharedCurve(freq);
593 if (m->control_pressed) {
594 for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear();
595 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
605 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
607 //reset groups parameter
611 m->mothurOutEndLine();
612 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
613 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
614 m->mothurOutEndLine();
619 catch(exception& e) {
620 m->errorOut(e, "CollectSharedCommand", "execute");
625 /***********************************************************/