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,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-kulczynski-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,true); 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 string CollectSharedCommand::getOutputPattern(string type) {
105 if (type == "sharedchao") { pattern = "[filename],shared.chao"; }
106 else if (type == "sharedsobs") { pattern = "[filename],shared.sobs"; }
107 else if (type == "sharedace") { pattern = "[filename],shared.ace"; }
108 else if (type == "jabund") { pattern = "[filename],jabund"; }
109 else if (type == "sorabund") { pattern = "[filename],sorabund"; }
110 else if (type == "jclass") { pattern = "[filename],jclass"; }
111 else if (type == "sorclass") { pattern = "[filename],sorclass"; }
112 else if (type == "jest") { pattern = "[filename],jest"; }
113 else if (type == "sorest") { pattern = "[filename],sorest"; }
114 else if (type == "thetayc") { pattern = "[filename],thetayc"; }
115 else if (type == "thetan") { pattern = "[filename],thetan"; }
116 else if (type == "kstest") { pattern = "[filename],kstest"; }
117 else if (type == "whittaker") { pattern = "[filename],whittaker"; }
118 else if (type == "sharednseqs") { pattern = "[filename],shared.nseqs"; }
119 else if (type == "ochiai") { pattern = "[filename],ochiai"; }
120 else if (type == "anderberg") { pattern = "[filename],anderberg"; }
121 else if (type == "kulczynski") { pattern = "[filename],kulczynski"; }
122 else if (type == "kulczynskicody") { pattern = "[filename],kulczynskicody"; }
123 else if (type == "lennon") { pattern = "[filename],lennon"; }
124 else if (type == "morisitahorn") { pattern = "[filename],morisitahorn"; }
125 else if (type == "braycurtis") { pattern = "[filename],braycurtis"; }
126 else if (type == "odum") { pattern = "[filename],odum"; }
127 else if (type == "canberra") { pattern = "[filename],canberra"; }
128 else if (type == "structeuclidean") { pattern = "[filename],structeuclidean"; }
129 else if (type == "structchord") { pattern = "[filename],structchord"; }
130 else if (type == "hellinger") { pattern = "[filename],hellinger"; }
131 else if (type == "manhattan") { pattern = "[filename],manhattan"; }
132 else if (type == "structpearson") { pattern = "[filename],structpearson"; }
133 else if (type == "soergel") { pattern = "[filename],soergel"; }
134 else if (type == "spearman") { pattern = "[filename],spearman"; }
135 else if (type == "structkulczynski") { pattern = "[filename],structkulczynski";}
136 else if (type == "structchi2") { pattern = "[filename],structchi2"; }
137 else if (type == "speciesprofile") { pattern = "[filename],speciesprofile"; }
138 else if (type == "hamming") { pattern = "[filename],hamming"; }
139 else if (type == "gower") { pattern = "[filename],gower"; }
140 else if (type == "memchi2") { pattern = "[filename],memchi2"; }
141 else if (type == "memchord") { pattern = "[filename],memchord"; }
142 else if (type == "memeuclidean") { pattern = "[filename],memeuclidean"; }
143 else if (type == "mempearson") { pattern = "[filename],mempearson"; }
144 else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; }
148 catch(exception& e) {
149 m->errorOut(e, "CollectSharedCommand", "getOutputPattern");
154 //**********************************************************************************************************************
155 CollectSharedCommand::CollectSharedCommand(){
157 abort = true; calledHelp = true;
159 vector<string> tempOutNames;
160 outputTypes["sharedchao"] = tempOutNames;
161 outputTypes["sharedsobs"] = tempOutNames;
162 outputTypes["sharedace"] = tempOutNames;
163 outputTypes["jabund"] = tempOutNames;
164 outputTypes["sorabund"] = tempOutNames;
165 outputTypes["jclass"] = tempOutNames;
166 outputTypes["sorclass"] = tempOutNames;
167 outputTypes["jest"] = tempOutNames;
168 outputTypes["sorest"] = tempOutNames;
169 outputTypes["thetayc"] = tempOutNames;
170 outputTypes["thetan"] = tempOutNames;
171 outputTypes["kstest"] = tempOutNames;
172 outputTypes["whittaker"] = tempOutNames;
173 outputTypes["sharednseqs"] = tempOutNames;
174 outputTypes["ochiai"] = tempOutNames;
175 outputTypes["anderberg"] = tempOutNames;
176 outputTypes["kulczynski"] = tempOutNames;
177 outputTypes["kulczynskicody"] = tempOutNames;
178 outputTypes["lennon"] = tempOutNames;
179 outputTypes["morisitahorn"] = tempOutNames;
180 outputTypes["braycurtis"] = tempOutNames;
181 outputTypes["odum"] = tempOutNames;
182 outputTypes["canberra"] = tempOutNames;
183 outputTypes["structeuclidean"] = tempOutNames;
184 outputTypes["structchord"] = tempOutNames;
185 outputTypes["hellinger"] = tempOutNames;
186 outputTypes["manhattan"] = tempOutNames;
187 outputTypes["structpearson"] = tempOutNames;
188 outputTypes["soergel"] = tempOutNames;
189 outputTypes["spearman"] = tempOutNames;
190 outputTypes["structkulczynski"] = tempOutNames;
191 outputTypes["structchi2"] = tempOutNames;
192 outputTypes["speciesprofile"] = tempOutNames;
193 outputTypes["hamming"] = tempOutNames;
194 outputTypes["gower"] = tempOutNames;
195 outputTypes["memchi2"] = tempOutNames;
196 outputTypes["memchord"] = tempOutNames;
197 outputTypes["memeuclidean"] = tempOutNames;
198 outputTypes["mempearson"] = tempOutNames;
201 catch(exception& e) {
202 m->errorOut(e, "CollectSharedCommand", "CollectSharedCommand");
206 //**********************************************************************************************************************
207 CollectSharedCommand::CollectSharedCommand(string option) {
209 abort = false; calledHelp = false;
212 //allow user to run help
213 if(option == "help") { help(); abort = true; calledHelp = true; }
214 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
217 vector<string> myArray = setParameters();
219 OptionParser parser(option);
220 map<string,string> parameters=parser.getParameters();
221 map<string,string>::iterator it;
223 ValidParameters validParameter;
225 //check to make sure all parameters are valid for command
226 for (it = parameters.begin(); it != parameters.end(); it++) {
227 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
230 //initialize outputTypes
231 vector<string> tempOutNames;
232 outputTypes["sharedchao"] = tempOutNames;
233 outputTypes["sharedsobs"] = tempOutNames;
234 outputTypes["sharedace"] = tempOutNames;
235 outputTypes["jabund"] = tempOutNames;
236 outputTypes["sorabund"] = tempOutNames;
237 outputTypes["jclass"] = tempOutNames;
238 outputTypes["sorclass"] = tempOutNames;
239 outputTypes["jest"] = tempOutNames;
240 outputTypes["sorest"] = tempOutNames;
241 outputTypes["thetayc"] = tempOutNames;
242 outputTypes["thetan"] = tempOutNames;
243 outputTypes["kstest"] = tempOutNames;
244 outputTypes["whittaker"] = tempOutNames;
245 outputTypes["sharednseqs"] = tempOutNames;
246 outputTypes["ochiai"] = tempOutNames;
247 outputTypes["anderberg"] = tempOutNames;
248 outputTypes["kulczynski"] = tempOutNames;
249 outputTypes["kulczynskicody"] = tempOutNames;
250 outputTypes["lennon"] = tempOutNames;
251 outputTypes["morisitahorn"] = tempOutNames;
252 outputTypes["braycurtis"] = tempOutNames;
253 outputTypes["odum"] = tempOutNames;
254 outputTypes["canberra"] = tempOutNames;
255 outputTypes["structeuclidean"] = tempOutNames;
256 outputTypes["structchord"] = tempOutNames;
257 outputTypes["hellinger"] = tempOutNames;
258 outputTypes["manhattan"] = tempOutNames;
259 outputTypes["structpearson"] = tempOutNames;
260 outputTypes["soergel"] = tempOutNames;
261 outputTypes["spearman"] = tempOutNames;
262 outputTypes["structkulczynski"] = tempOutNames;
263 outputTypes["speciesprofile"] = tempOutNames;
264 outputTypes["structchi2"] = tempOutNames;
265 outputTypes["hamming"] = tempOutNames;
266 outputTypes["gower"] = tempOutNames;
267 outputTypes["memchi2"] = tempOutNames;
268 outputTypes["memchord"] = tempOutNames;
269 outputTypes["memeuclidean"] = tempOutNames;
270 outputTypes["mempearson"] = tempOutNames;
273 //if the user changes the input directory command factory will send this info to us in the output parameter
274 string inputDir = validParameter.validFile(parameters, "inputdir", false);
275 if (inputDir == "not found"){ inputDir = ""; }
278 it = parameters.find("shared");
279 //user has given a template file
280 if(it != parameters.end()){
281 path = m->hasPath(it->second);
282 //if the user has not given a path then, add inputdir. else leave path alone.
283 if (path == "") { parameters["shared"] = inputDir + it->second; }
288 sharedfile = validParameter.validFile(parameters, "shared", true);
289 if (sharedfile == "not open") { sharedfile = ""; abort = true; }
290 else if (sharedfile == "not found") {
291 //if there is a current shared file, use it
292 sharedfile = m->getSharedFile();
293 if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
294 else { m->mothurOut("You have no current sharedfile and the shared parameter is required."); m->mothurOutEndLine(); abort = true; }
295 }else { m->setSharedFile(sharedfile); }
298 //if the user changes the output directory command factory will send this info to us in the output parameter
299 outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = m->hasPath(sharedfile); }
301 //check for optional parameter and set defaults
302 // ...at some point should added some additional type checking..
303 label = validParameter.validFile(parameters, "label", false);
304 if (label == "not found") { label = ""; }
306 if(label != "all") { m->splitAtDash(label, labels); allLines = 0; }
307 else { allLines = 1; }
310 calc = validParameter.validFile(parameters, "calc", false);
311 if (calc == "not found") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
313 if (calc == "default") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
315 m->splitAtDash(calc, Estimators);
316 if (m->inUsersGroups("citation", Estimators)) {
317 ValidCalculators validCalc; validCalc.printCitations(Estimators);
318 //remove citation from list of calcs
319 for (int i = 0; i < Estimators.size(); i++) { if (Estimators[i] == "citation") { Estimators.erase(Estimators.begin()+i); break; } }
322 groups = validParameter.validFile(parameters, "groups", false);
323 if (groups == "not found") { groups = ""; }
325 m->splitAtDash(groups, Groups);
327 m->setGroups(Groups);
330 temp = validParameter.validFile(parameters, "freq", false); if (temp == "not found") { temp = "100"; }
331 m->mothurConvert(temp, freq);
333 temp = validParameter.validFile(parameters, "all", false); if (temp == "not found") { temp = "false"; }
334 all = m->isTrue(temp);
336 if (abort == false) {
338 string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(sharedfile));
339 map<string, string> variables;
340 variables["[filename]"] = fileNameRoot;
342 ValidCalculators validCalculator;
344 for (int i=0; i<Estimators.size(); i++) {
345 if (validCalculator.isValidCalculator("shared", Estimators[i]) == true) {
346 if (Estimators[i] == "sharedchao") {
347 cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(getOutputFileName("sharedchao", variables))));
348 outputNames.push_back(getOutputFileName("sharedchao", variables)); outputTypes["sharedchao"].push_back(getOutputFileName("sharedchao", variables));
349 }else if (Estimators[i] == "sharedsobs") {
350 cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(getOutputFileName("sharedsobs", variables))));
351 outputNames.push_back(getOutputFileName("sharedsobs", variables)); outputTypes["sharedsobs"].push_back(getOutputFileName("sharedsobs", variables));
352 }else if (Estimators[i] == "sharedace") {
353 cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(getOutputFileName("sharedace", variables))));
354 outputNames.push_back(getOutputFileName("sharedace", variables)); outputTypes["sharedace"].push_back(getOutputFileName("sharedace", variables));
355 }else if (Estimators[i] == "jabund") {
356 cDisplays.push_back(new CollectDisplay(new JAbund(), new SharedOneColumnFile(getOutputFileName("jabund", variables))));
357 outputNames.push_back(getOutputFileName("jabund", variables)); outputTypes["jabund"].push_back(getOutputFileName("jabund", variables));
358 }else if (Estimators[i] == "sorabund") {
359 cDisplays.push_back(new CollectDisplay(new SorAbund(), new SharedOneColumnFile(getOutputFileName("sorabund", variables))));
360 outputNames.push_back(getOutputFileName("sorabund", variables)); outputTypes["sorabund"].push_back(getOutputFileName("sorabund", variables));
361 }else if (Estimators[i] == "jclass") {
362 cDisplays.push_back(new CollectDisplay(new Jclass(), new SharedOneColumnFile(getOutputFileName("jclass", variables))));
363 outputNames.push_back(getOutputFileName("jclass", variables)); outputTypes["jclass"].push_back(getOutputFileName("jclass", variables));
364 }else if (Estimators[i] == "sorclass") {
365 cDisplays.push_back(new CollectDisplay(new SorClass(), new SharedOneColumnFile(getOutputFileName("sorclass", variables))));
366 outputNames.push_back(getOutputFileName("sorclass", variables)); outputTypes["sorclass"].push_back(getOutputFileName("sorclass", variables));
367 }else if (Estimators[i] == "jest") {
368 cDisplays.push_back(new CollectDisplay(new Jest(), new SharedOneColumnFile(getOutputFileName("jest", variables))));
369 outputNames.push_back(getOutputFileName("jest", variables)); outputTypes["jest"].push_back(getOutputFileName("jest", variables));
370 }else if (Estimators[i] == "sorest") {
371 cDisplays.push_back(new CollectDisplay(new SorEst(), new SharedOneColumnFile(getOutputFileName("sorest", variables))));
372 outputNames.push_back(getOutputFileName("sorest", variables)); outputTypes["sorest"].push_back(getOutputFileName("sorest", variables));
373 }else if (Estimators[i] == "thetayc") {
374 cDisplays.push_back(new CollectDisplay(new ThetaYC(), new SharedOneColumnFile(getOutputFileName("thetayc", variables))));
375 outputNames.push_back(getOutputFileName("thetayc", variables)); outputTypes["thetayc"].push_back(getOutputFileName("thetayc", variables));
376 }else if (Estimators[i] == "thetan") {
377 cDisplays.push_back(new CollectDisplay(new ThetaN(), new SharedOneColumnFile(getOutputFileName("thetan", variables))));
378 outputNames.push_back(getOutputFileName("thetan", variables)); outputTypes["thetan"].push_back(getOutputFileName("thetan", variables));
379 }else if (Estimators[i] == "kstest") {
380 cDisplays.push_back(new CollectDisplay(new KSTest(), new SharedOneColumnFile(getOutputFileName("kstest", variables))));
381 outputNames.push_back(getOutputFileName("kstest", variables)); outputTypes["kstest"].push_back(getOutputFileName("kstest", variables));
382 }else if (Estimators[i] == "whittaker") {
383 cDisplays.push_back(new CollectDisplay(new Whittaker(), new SharedOneColumnFile(getOutputFileName("whittaker", variables))));
384 outputNames.push_back(getOutputFileName("whittaker", variables)); outputTypes["whittaker"].push_back(getOutputFileName("whittaker", variables));
385 }else if (Estimators[i] == "sharednseqs") {
386 cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(getOutputFileName("sharednseqs", variables))));
387 outputNames.push_back(getOutputFileName("sharednseqs", variables)); outputTypes["shared.nseqs"].push_back(getOutputFileName("sharednseqs", variables));
388 }else if (Estimators[i] == "ochiai") {
389 cDisplays.push_back(new CollectDisplay(new Ochiai(), new SharedOneColumnFile(getOutputFileName("ochiai", variables))));
390 outputNames.push_back(getOutputFileName("ochiai", variables)); outputTypes["ochiai"].push_back(getOutputFileName("ochiai", variables));
391 }else if (Estimators[i] == "anderberg") {
392 cDisplays.push_back(new CollectDisplay(new Anderberg(), new SharedOneColumnFile(getOutputFileName("anderberg", variables))));
393 outputNames.push_back(getOutputFileName("anderberg", variables)); outputTypes["anderberg"].push_back(getOutputFileName("anderberg", variables));
394 }else if (Estimators[i] == "kulczynski") {
395 cDisplays.push_back(new CollectDisplay(new Kulczynski(), new SharedOneColumnFile(getOutputFileName("kulczynski", variables))));
396 outputNames.push_back(getOutputFileName("kulczynski", variables)); outputTypes["kulczynski"].push_back(getOutputFileName("kulczynski", variables));
397 }else if (Estimators[i] == "kulczynskicody") {
398 cDisplays.push_back(new CollectDisplay(new KulczynskiCody(), new SharedOneColumnFile(getOutputFileName("kulczynskicody", variables))));
399 outputNames.push_back(getOutputFileName("kulczynskicody", variables)); outputTypes["kulczynskicody"].push_back(getOutputFileName("kulczynskicody", variables));
400 }else if (Estimators[i] == "lennon") {
401 cDisplays.push_back(new CollectDisplay(new Lennon(), new SharedOneColumnFile(getOutputFileName("lennon", variables))));
402 outputNames.push_back(getOutputFileName("lennon", variables)); outputTypes["lennon"].push_back(getOutputFileName("lennon", variables));
403 }else if (Estimators[i] == "morisitahorn") {
404 cDisplays.push_back(new CollectDisplay(new MorHorn(), new SharedOneColumnFile(getOutputFileName("morisitahorn", variables))));
405 outputNames.push_back(getOutputFileName("morisitahorn", variables)); outputTypes["morisitahorn"].push_back(getOutputFileName("morisitahorn", variables));
406 }else if (Estimators[i] == "braycurtis") {
407 cDisplays.push_back(new CollectDisplay(new BrayCurtis(), new SharedOneColumnFile(getOutputFileName("braycurtis", variables))));
408 outputNames.push_back(getOutputFileName("braycurtis", variables)); outputTypes["braycurtis"].push_back(getOutputFileName("braycurtis", variables));
409 }else if (Estimators[i] == "odum") {
410 cDisplays.push_back(new CollectDisplay(new Odum(), new SharedOneColumnFile(getOutputFileName("odum", variables))));
411 outputNames.push_back(getOutputFileName("odum", variables)); outputTypes["odum"].push_back(getOutputFileName("odum", variables));
412 }else if (Estimators[i] == "canberra") {
413 cDisplays.push_back(new CollectDisplay(new Canberra(), new SharedOneColumnFile(getOutputFileName("canberra", variables))));
414 outputNames.push_back(getOutputFileName("canberra", variables)); outputTypes["canberra"].push_back(getOutputFileName("canberra", variables));
415 }else if (Estimators[i] == "structeuclidean") {
416 cDisplays.push_back(new CollectDisplay(new StructEuclidean(), new SharedOneColumnFile(getOutputFileName("structeuclidean", variables))));
417 outputNames.push_back(getOutputFileName("structeuclidean", variables)); outputTypes["structeuclidean"].push_back(getOutputFileName("structeuclidean", variables));
418 }else if (Estimators[i] == "structchord") {
419 cDisplays.push_back(new CollectDisplay(new StructChord(), new SharedOneColumnFile(getOutputFileName("structchord", variables))));
420 outputNames.push_back(getOutputFileName("structchord", variables)); outputTypes["structchord"].push_back(getOutputFileName("structchord", variables));
421 }else if (Estimators[i] == "hellinger") {
422 cDisplays.push_back(new CollectDisplay(new Hellinger(), new SharedOneColumnFile(getOutputFileName("hellinger", variables))));
423 outputNames.push_back(getOutputFileName("hellinger", variables)); outputTypes["hellinger"].push_back(getOutputFileName("hellinger", variables));
424 }else if (Estimators[i] == "manhattan") {
425 cDisplays.push_back(new CollectDisplay(new Manhattan(), new SharedOneColumnFile(getOutputFileName("manhattan", variables))));
426 outputNames.push_back(getOutputFileName("manhattan", variables)); outputTypes["manhattan"].push_back(getOutputFileName("manhattan", variables));
427 }else if (Estimators[i] == "structpearson") {
428 cDisplays.push_back(new CollectDisplay(new StructPearson(), new SharedOneColumnFile(getOutputFileName("structpearson", variables))));
429 outputNames.push_back(getOutputFileName("structpearson", variables)); outputTypes["structpearson"].push_back(getOutputFileName("structpearson", variables));
430 }else if (Estimators[i] == "soergel") {
431 cDisplays.push_back(new CollectDisplay(new Soergel(), new SharedOneColumnFile(getOutputFileName("soergel", variables))));
432 outputNames.push_back(getOutputFileName("soergel", variables)); outputTypes["soergel"].push_back(getOutputFileName("soergel", variables));
433 }else if (Estimators[i] == "spearman") {
434 cDisplays.push_back(new CollectDisplay(new Spearman(), new SharedOneColumnFile(getOutputFileName("spearman", variables))));
435 outputNames.push_back(getOutputFileName("spearman", variables)); outputTypes["spearman"].push_back(getOutputFileName("spearman", variables));
436 }else if (Estimators[i] == "structkulczynski") {
437 cDisplays.push_back(new CollectDisplay(new StructKulczynski(), new SharedOneColumnFile(getOutputFileName("structkulczynski", variables))));
438 outputNames.push_back(getOutputFileName("structkulczynski", variables)); outputTypes["structkulczynski"].push_back(getOutputFileName("structkulczynski", variables));
439 }else if (Estimators[i] == "speciesprofile") {
440 cDisplays.push_back(new CollectDisplay(new SpeciesProfile(), new SharedOneColumnFile(getOutputFileName("speciesprofile", variables))));
441 outputNames.push_back(getOutputFileName("speciesprofile", variables)); outputTypes["speciesprofile"].push_back(getOutputFileName("speciesprofile", variables));
442 }else if (Estimators[i] == "hamming") {
443 cDisplays.push_back(new CollectDisplay(new Hamming(), new SharedOneColumnFile(getOutputFileName("hamming", variables))));
444 outputNames.push_back(getOutputFileName("hamming", variables)); outputTypes["hamming"].push_back(getOutputFileName("hamming", variables));
445 }else if (Estimators[i] == "structchi2") {
446 cDisplays.push_back(new CollectDisplay(new StructChi2(), new SharedOneColumnFile(getOutputFileName("structchi2", variables))));
447 outputNames.push_back(getOutputFileName("structchi2", variables)); outputTypes["structchi2"].push_back(getOutputFileName("structchi2", variables));
448 }else if (Estimators[i] == "gower") {
449 cDisplays.push_back(new CollectDisplay(new Gower(), new SharedOneColumnFile(getOutputFileName("gower", variables))));
450 outputNames.push_back(getOutputFileName("gower", variables)); outputTypes["gower"].push_back(getOutputFileName("gower", variables));
451 }else if (Estimators[i] == "memchi2") {
452 cDisplays.push_back(new CollectDisplay(new MemChi2(), new SharedOneColumnFile(getOutputFileName("memchi2", variables))));
453 outputNames.push_back(getOutputFileName("memchi2", variables)); outputTypes["memchi2"].push_back(getOutputFileName("memchi2", variables));
454 }else if (Estimators[i] == "memchord") {
455 cDisplays.push_back(new CollectDisplay(new MemChord(), new SharedOneColumnFile(getOutputFileName("memchord", variables))));
456 outputNames.push_back(getOutputFileName("memchord", variables)); outputTypes["memchord"].push_back(getOutputFileName("memchord", variables));
457 }else if (Estimators[i] == "memeuclidean") {
458 cDisplays.push_back(new CollectDisplay(new MemEuclidean(), new SharedOneColumnFile(getOutputFileName("memeuclidean", variables))));
459 outputNames.push_back(getOutputFileName("memeuclidean", variables)); outputTypes["memeuclidean"].push_back(getOutputFileName("memeuclidean", variables));
460 }else if (Estimators[i] == "mempearson") {
461 cDisplays.push_back(new CollectDisplay(new MemPearson(), new SharedOneColumnFile(getOutputFileName("mempearson", variables))));
462 outputNames.push_back(getOutputFileName("mempearson", variables)); outputTypes["mempearson"].push_back(getOutputFileName("mempearson", variables));
471 catch(exception& e) {
472 m->errorOut(e, "CollectSharedCommand", "CollectSharedCommand");
476 //**********************************************************************************************************************
477 CollectSharedCommand::~CollectSharedCommand(){}
478 //**********************************************************************************************************************
480 int CollectSharedCommand::execute(){
483 if (abort == true) { if (calledHelp) { return 0; } return 2; }
485 //if the users entered no valid calculators don't execute command
486 if (cDisplays.size() == 0) { return 0; }
487 for(int i=0;i<cDisplays.size();i++){ cDisplays[i]->setAll(all); }
489 input = new InputData(sharedfile, "sharedfile");
490 order = input->getSharedOrderVector();
491 string lastLabel = order->getLabel();
493 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
494 set<string> processedLabels;
495 set<string> userLabels = labels;
498 SharedUtil* util = new SharedUtil();
499 Groups = m->getGroups();
500 vector<string> allGroups = m->getAllGroups();
501 util->setGroups(Groups, allGroups, "collect");
502 m->setGroups(Groups);
503 m->setAllGroups(allGroups);
506 while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
507 if (m->control_pressed) {
508 for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear();
509 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
510 delete order; delete input;
515 if(allLines == 1 || labels.count(order->getLabel()) == 1){
517 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
518 //create collectors curve
519 cCurve = new Collect(order, cDisplays);
520 cCurve->getSharedCurve(freq);
523 processedLabels.insert(order->getLabel());
524 userLabels.erase(order->getLabel());
527 //you have a label the user want that is smaller than this label and the last label has not already been processed
528 if ((m->anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
529 string saveLabel = order->getLabel();
532 order = input->getSharedOrderVector(lastLabel);
534 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
535 //create collectors curve
536 cCurve = new Collect(order, cDisplays);
537 cCurve->getSharedCurve(freq);
540 processedLabels.insert(order->getLabel());
541 userLabels.erase(order->getLabel());
543 //restore real lastlabel to save below
544 order->setLabel(saveLabel);
548 lastLabel = order->getLabel();
550 //get next line to process
552 order = input->getSharedOrderVector();
555 if (m->control_pressed) {
556 for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear();
557 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
563 //output error messages about any remaining user labels
564 set<string>::iterator it;
565 bool needToRun = false;
566 for (it = userLabels.begin(); it != userLabels.end(); it++) {
567 m->mothurOut("Your file does not include the label " + *it);
568 if (processedLabels.count(lastLabel) != 1) {
569 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
572 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
576 //run last label if you need to
577 if (needToRun == true) {
578 if (order != NULL) { delete order; }
579 order = input->getSharedOrderVector(lastLabel);
581 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
582 cCurve = new Collect(order, cDisplays);
583 cCurve->getSharedCurve(freq);
586 if (m->control_pressed) {
587 for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear();
588 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
598 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
600 //reset groups parameter
604 m->mothurOutEndLine();
605 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
606 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
607 m->mothurOutEndLine();
612 catch(exception& e) {
613 m->errorOut(e, "CollectSharedCommand", "execute");
618 /***********************************************************/