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