2 * collectsharedcommand.cpp
5 * Created by Sarah Westcott on 1/2/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "collectsharedcommand.h"
11 #include "sharedsobscollectsummary.h"
12 #include "sharedchao1.h"
13 #include "sharedace.h"
14 #include "sharedjabund.h"
15 #include "sharedsorabund.h"
16 #include "sharedjclass.h"
17 #include "sharedsorclass.h"
18 #include "sharedjest.h"
19 #include "sharedsorest.h"
20 #include "sharedthetayc.h"
21 #include "sharedthetan.h"
22 #include "sharedkstest.h"
23 #include "whittaker.h"
24 #include "sharednseqs.h"
25 #include "sharedochiai.h"
26 #include "sharedanderbergs.h"
27 #include "sharedkulczynski.h"
28 #include "sharedkulczynskicody.h"
29 #include "sharedlennon.h"
30 #include "sharedmorisitahorn.h"
31 #include "sharedbraycurtis.h"
32 #include "sharedjackknife.h"
33 #include "whittaker.h"
36 #include "structeuclidean.h"
37 #include "structchord.h"
38 #include "hellinger.h"
39 #include "manhattan.h"
40 #include "structpearson.h"
43 #include "structkulczynski.h"
44 #include "structchi2.h"
45 #include "speciesprofile.h"
50 #include "memeuclidean.h"
51 #include "mempearson.h"
54 //**********************************************************************************************************************
55 vector<string> CollectSharedCommand::setParameters(){
57 CommandParameter pshared("shared", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pshared);
58 CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel);
59 CommandParameter pfreq("freq", "Number", "", "100", "", "", "",false,false); parameters.push_back(pfreq);
60 CommandParameter pcalc("calc", "Multiple", "sharedchao-sharedsobs-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-kstest-whittaker-sharednseqs-ochiai-anderberg-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); 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::getOutputFileNameTag(string type, string inputName=""){
103 string outputFileName = "";
104 map<string, vector<string> >::iterator it;
106 //is this a type this command creates
107 it = outputTypes.find(type);
108 if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); }
110 if (type == "sharedchao") { outputFileName = "shared.chao"; }
111 else if (type == "sharedsobs") { outputFileName = "shared.sobs"; }
112 else if (type == "sharedace") { outputFileName = "shared.ace"; }
113 else if (type == "jabund") { outputFileName = "jabund"; }
114 else if (type == "sorabund") { outputFileName = "sorabund"; }
115 else if (type == "jclass") { outputFileName = "jclass"; }
116 else if (type == "sorclass") { outputFileName = "sorclass"; }
117 else if (type == "jest") { outputFileName = "jest"; }
118 else if (type == "sorest") { outputFileName = "sorest"; }
119 else if (type == "thetayc") { outputFileName = "thetayc"; }
120 else if (type == "thetan") { outputFileName = "thetan"; }
121 else if (type == "kstest") { outputFileName = "kstest"; }
122 else if (type == "whittaker") { outputFileName = "whittaker"; }
123 else if (type == "sharednseqs") { outputFileName = "shared.nseqs"; }
124 else if (type == "ochiai") { outputFileName = "ochiai"; }
125 else if (type == "anderberg") { outputFileName = "anderberg"; }
126 else if (type == "kulczynski") { outputFileName = "kulczynski"; }
127 else if (type == "kulczynskicody") { outputFileName = "kulczynskicody"; }
128 else if (type == "lennon") { outputFileName = "lennon"; }
129 else if (type == "morisitahorn") { outputFileName = "morisitahorn"; }
130 else if (type == "braycurtis") { outputFileName = "braycurtis"; }
131 else if (type == "odum") { outputFileName = "odum"; }
132 else if (type == "canberra") { outputFileName = "canberra"; }
133 else if (type == "structeuclidean") { outputFileName = "structeuclidean"; }
134 else if (type == "structchord") { outputFileName = "structchord"; }
135 else if (type == "hellinger") { outputFileName = "hellinger"; }
136 else if (type == "manhattan") { outputFileName = "manhattan"; }
137 else if (type == "structpearson") { outputFileName = "structpearson"; }
138 else if (type == "soergel") { outputFileName = "soergel"; }
139 else if (type == "spearman") { outputFileName = "spearman"; }
140 else if (type == "structkulczynski") { outputFileName = "structkulczynski";}
141 else if (type == "structchi2") { outputFileName = "structchi2"; }
142 else if (type == "speciesprofile") { outputFileName = "speciesprofile"; }
143 else if (type == "hamming") { outputFileName = "hamming"; }
144 else if (type == "gower") { outputFileName = "gower"; }
145 else if (type == "memchi2") { outputFileName = "memchi2"; }
146 else if (type == "memchord") { outputFileName = "memchord"; }
147 else if (type == "memeuclidean") { outputFileName = "memeuclidean"; }
148 else if (type == "mempearson") { outputFileName = "mempearson"; }
149 else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; }
151 return outputFileName;
153 catch(exception& e) {
154 m->errorOut(e, "CollectSharedCommand", "getOutputFileNameTag");
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;
205 catch(exception& e) {
206 m->errorOut(e, "CollectSharedCommand", "CollectSharedCommand");
210 //**********************************************************************************************************************
211 CollectSharedCommand::CollectSharedCommand(string option) {
213 abort = false; calledHelp = false;
216 //allow user to run help
217 if(option == "help") { help(); abort = true; calledHelp = true; }
218 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
221 vector<string> myArray = setParameters();
223 OptionParser parser(option);
224 map<string,string> parameters=parser.getParameters();
225 map<string,string>::iterator it;
227 ValidParameters validParameter;
229 //check to make sure all parameters are valid for command
230 for (it = parameters.begin(); it != parameters.end(); it++) {
231 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
234 //initialize outputTypes
235 vector<string> tempOutNames;
236 outputTypes["sharedchao"] = tempOutNames;
237 outputTypes["sharedsobs"] = tempOutNames;
238 outputTypes["sharedace"] = tempOutNames;
239 outputTypes["jabund"] = tempOutNames;
240 outputTypes["sorabund"] = tempOutNames;
241 outputTypes["jclass"] = tempOutNames;
242 outputTypes["sorclass"] = tempOutNames;
243 outputTypes["jest"] = tempOutNames;
244 outputTypes["sorest"] = tempOutNames;
245 outputTypes["thetayc"] = tempOutNames;
246 outputTypes["thetan"] = tempOutNames;
247 outputTypes["kstest"] = tempOutNames;
248 outputTypes["whittaker"] = tempOutNames;
249 outputTypes["sharednseqs"] = tempOutNames;
250 outputTypes["ochiai"] = tempOutNames;
251 outputTypes["anderberg"] = tempOutNames;
252 outputTypes["kulczynski"] = tempOutNames;
253 outputTypes["kulczynskicody"] = tempOutNames;
254 outputTypes["lennon"] = tempOutNames;
255 outputTypes["morisitahorn"] = tempOutNames;
256 outputTypes["braycurtis"] = tempOutNames;
257 outputTypes["odum"] = tempOutNames;
258 outputTypes["canberra"] = tempOutNames;
259 outputTypes["structeuclidean"] = tempOutNames;
260 outputTypes["structchord"] = tempOutNames;
261 outputTypes["hellinger"] = tempOutNames;
262 outputTypes["manhattan"] = tempOutNames;
263 outputTypes["structpearson"] = tempOutNames;
264 outputTypes["soergel"] = tempOutNames;
265 outputTypes["spearman"] = tempOutNames;
266 outputTypes["structkulczynski"] = tempOutNames;
267 outputTypes["speciesprofile"] = tempOutNames;
268 outputTypes["structchi2"] = tempOutNames;
269 outputTypes["hamming"] = tempOutNames;
270 outputTypes["gower"] = tempOutNames;
271 outputTypes["memchi2"] = tempOutNames;
272 outputTypes["memchord"] = tempOutNames;
273 outputTypes["memeuclidean"] = tempOutNames;
274 outputTypes["mempearson"] = 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));
344 ValidCalculators validCalculator;
346 for (int i=0; i<Estimators.size(); i++) {
347 if (validCalculator.isValidCalculator("shared", Estimators[i]) == true) {
348 if (Estimators[i] == "sharedchao") {
349 cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("sharedchao"))));
350 outputNames.push_back(fileNameRoot+getOutputFileNameTag("sharedchao")); outputTypes["sharedchao"].push_back(fileNameRoot+getOutputFileNameTag("sharedchao"));
351 }else if (Estimators[i] == "sharedsobs") {
352 cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("sharedsobs"))));
353 outputNames.push_back(fileNameRoot+getOutputFileNameTag("sharedsobs")); outputTypes["sharedsobs"].push_back(fileNameRoot+getOutputFileNameTag("sharedsobs"));
354 }else if (Estimators[i] == "sharedace") {
355 cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("sharedace"))));
356 outputNames.push_back(fileNameRoot+getOutputFileNameTag("sharedace")); outputTypes["sharedace"].push_back(fileNameRoot+getOutputFileNameTag("sharedace"));
357 }else if (Estimators[i] == "jabund") {
358 cDisplays.push_back(new CollectDisplay(new JAbund(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("jabund"))));
359 outputNames.push_back(fileNameRoot+getOutputFileNameTag("jabund")); outputTypes["jabund"].push_back(fileNameRoot+getOutputFileNameTag("jabund"));
360 }else if (Estimators[i] == "sorabund") {
361 cDisplays.push_back(new CollectDisplay(new SorAbund(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("sorabund"))));
362 outputNames.push_back(fileNameRoot+getOutputFileNameTag("sorabund")); outputTypes["sorabund"].push_back(fileNameRoot+getOutputFileNameTag("sorabund"));
363 }else if (Estimators[i] == "jclass") {
364 cDisplays.push_back(new CollectDisplay(new Jclass(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("jclass"))));
365 outputNames.push_back(fileNameRoot+getOutputFileNameTag("jclass")); outputTypes["jclass"].push_back(fileNameRoot+getOutputFileNameTag("jclass"));
366 }else if (Estimators[i] == "sorclass") {
367 cDisplays.push_back(new CollectDisplay(new SorClass(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("sorclass"))));
368 outputNames.push_back(fileNameRoot+getOutputFileNameTag("sorclass")); outputTypes["sorclass"].push_back(fileNameRoot+getOutputFileNameTag("sorclass"));
369 }else if (Estimators[i] == "jest") {
370 cDisplays.push_back(new CollectDisplay(new Jest(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("jest"))));
371 outputNames.push_back(fileNameRoot+getOutputFileNameTag("jest")); outputTypes["jest"].push_back(fileNameRoot+getOutputFileNameTag("jest"));
372 }else if (Estimators[i] == "sorest") {
373 cDisplays.push_back(new CollectDisplay(new SorEst(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("sorest"))));
374 outputNames.push_back(fileNameRoot+getOutputFileNameTag("sorest")); outputTypes["sorest"].push_back(fileNameRoot+getOutputFileNameTag("sorest"));
375 }else if (Estimators[i] == "thetayc") {
376 cDisplays.push_back(new CollectDisplay(new ThetaYC(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("thetayc"))));
377 outputNames.push_back(fileNameRoot+getOutputFileNameTag("thetayc")); outputTypes["thetayc"].push_back(fileNameRoot+getOutputFileNameTag("thetayc"));
378 }else if (Estimators[i] == "thetan") {
379 cDisplays.push_back(new CollectDisplay(new ThetaN(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("thetan"))));
380 outputNames.push_back(fileNameRoot+getOutputFileNameTag("thetan")); outputTypes["thetan"].push_back(fileNameRoot+getOutputFileNameTag("thetan"));
381 }else if (Estimators[i] == "kstest") {
382 cDisplays.push_back(new CollectDisplay(new KSTest(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("kstest"))));
383 outputNames.push_back(fileNameRoot+getOutputFileNameTag("kstest")); outputTypes["kstest"].push_back(fileNameRoot+getOutputFileNameTag("kstest"));
384 }else if (Estimators[i] == "whittaker") {
385 cDisplays.push_back(new CollectDisplay(new Whittaker(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("whittaker"))));
386 outputNames.push_back(fileNameRoot+getOutputFileNameTag("whittaker")); outputTypes["whittaker"].push_back(fileNameRoot+getOutputFileNameTag("whittaker"));
387 }else if (Estimators[i] == "sharednseqs") {
388 cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("sharednseqs"))));
389 outputNames.push_back(fileNameRoot+getOutputFileNameTag("sharednseqs")); outputTypes["shared.nseqs"].push_back(fileNameRoot+getOutputFileNameTag("sharednseqs"));
390 }else if (Estimators[i] == "ochiai") {
391 cDisplays.push_back(new CollectDisplay(new Ochiai(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("ochiai"))));
392 outputNames.push_back(fileNameRoot+getOutputFileNameTag("ochiai")); outputTypes["ochiai"].push_back(fileNameRoot+getOutputFileNameTag("ochiai"));
393 }else if (Estimators[i] == "anderberg") {
394 cDisplays.push_back(new CollectDisplay(new Anderberg(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("anderberg"))));
395 outputNames.push_back(fileNameRoot+getOutputFileNameTag("anderberg")); outputTypes["anderberg"].push_back(fileNameRoot+getOutputFileNameTag("anderberg"));
396 }else if (Estimators[i] == "kulczynski") {
397 cDisplays.push_back(new CollectDisplay(new Kulczynski(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("kulczynski"))));
398 outputNames.push_back(fileNameRoot+getOutputFileNameTag("kulczynski")); outputTypes["kulczynski"].push_back(fileNameRoot+getOutputFileNameTag("kulczynski"));
399 }else if (Estimators[i] == "kulczynskicody") {
400 cDisplays.push_back(new CollectDisplay(new KulczynskiCody(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("kulczynskicody"))));
401 outputNames.push_back(fileNameRoot+getOutputFileNameTag("kulczynskicody")); outputTypes["kulczynskicody"].push_back(fileNameRoot+getOutputFileNameTag("kulczynskicody"));
402 }else if (Estimators[i] == "lennon") {
403 cDisplays.push_back(new CollectDisplay(new Lennon(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("lennon"))));
404 outputNames.push_back(fileNameRoot+getOutputFileNameTag("lennon")); outputTypes["lennon"].push_back(fileNameRoot+getOutputFileNameTag("lennon"));
405 }else if (Estimators[i] == "morisitahorn") {
406 cDisplays.push_back(new CollectDisplay(new MorHorn(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("morisitahorn"))));
407 outputNames.push_back(fileNameRoot+getOutputFileNameTag("morisitahorn")); outputTypes["morisitahorn"].push_back(fileNameRoot+getOutputFileNameTag("morisitahorn"));
408 }else if (Estimators[i] == "braycurtis") {
409 cDisplays.push_back(new CollectDisplay(new BrayCurtis(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("braycurtis"))));
410 outputNames.push_back(fileNameRoot+getOutputFileNameTag("braycurtis")); outputTypes["braycurtis"].push_back(fileNameRoot+getOutputFileNameTag("braycurtis"));
411 }else if (Estimators[i] == "odum") {
412 cDisplays.push_back(new CollectDisplay(new Odum(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("odum"))));
413 outputNames.push_back(fileNameRoot+getOutputFileNameTag("odum")); outputTypes["odum"].push_back(fileNameRoot+getOutputFileNameTag("odum"));
414 }else if (Estimators[i] == "canberra") {
415 cDisplays.push_back(new CollectDisplay(new Canberra(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("canberra"))));
416 outputNames.push_back(fileNameRoot+getOutputFileNameTag("canberra")); outputTypes["canberra"].push_back(fileNameRoot+getOutputFileNameTag("canberra"));
417 }else if (Estimators[i] == "structeuclidean") {
418 cDisplays.push_back(new CollectDisplay(new StructEuclidean(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("structeuclidean"))));
419 outputNames.push_back(fileNameRoot+getOutputFileNameTag("structeuclidean")); outputTypes["structeuclidean"].push_back(fileNameRoot+getOutputFileNameTag("structeuclidean"));
420 }else if (Estimators[i] == "structchord") {
421 cDisplays.push_back(new CollectDisplay(new StructChord(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("structchord"))));
422 outputNames.push_back(fileNameRoot+getOutputFileNameTag("structchord")); outputTypes["structchord"].push_back(fileNameRoot+getOutputFileNameTag("structchord"));
423 }else if (Estimators[i] == "hellinger") {
424 cDisplays.push_back(new CollectDisplay(new Hellinger(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("hellinger"))));
425 outputNames.push_back(fileNameRoot+getOutputFileNameTag("hellinger")); outputTypes["hellinger"].push_back(fileNameRoot+getOutputFileNameTag("hellinger"));
426 }else if (Estimators[i] == "manhattan") {
427 cDisplays.push_back(new CollectDisplay(new Manhattan(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("manhattan"))));
428 outputNames.push_back(fileNameRoot+getOutputFileNameTag("manhattan")); outputTypes["manhattan"].push_back(fileNameRoot+getOutputFileNameTag("manhattan"));
429 }else if (Estimators[i] == "structpearson") {
430 cDisplays.push_back(new CollectDisplay(new StructPearson(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("structpearson"))));
431 outputNames.push_back(fileNameRoot+getOutputFileNameTag("structpearson")); outputTypes["structpearson"].push_back(fileNameRoot+getOutputFileNameTag("structpearson"));
432 }else if (Estimators[i] == "soergel") {
433 cDisplays.push_back(new CollectDisplay(new Soergel(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("soergel"))));
434 outputNames.push_back(fileNameRoot+getOutputFileNameTag("soergel")); outputTypes["soergel"].push_back(fileNameRoot+getOutputFileNameTag("soergel"));
435 }else if (Estimators[i] == "spearman") {
436 cDisplays.push_back(new CollectDisplay(new Spearman(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("spearman"))));
437 outputNames.push_back(fileNameRoot+getOutputFileNameTag("spearman")); outputTypes["spearman"].push_back(fileNameRoot+getOutputFileNameTag("spearman"));
438 }else if (Estimators[i] == "structkulczynski") {
439 cDisplays.push_back(new CollectDisplay(new StructKulczynski(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("structkulczynski"))));
440 outputNames.push_back(fileNameRoot+getOutputFileNameTag("structkulczynski")); outputTypes["structkulczynski"].push_back(fileNameRoot+getOutputFileNameTag("structkulczynski"));
441 }else if (Estimators[i] == "speciesprofile") {
442 cDisplays.push_back(new CollectDisplay(new SpeciesProfile(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("speciesprofile"))));
443 outputNames.push_back(fileNameRoot+getOutputFileNameTag("speciesprofile")); outputTypes["speciesprofile"].push_back(fileNameRoot+getOutputFileNameTag("speciesprofile"));
444 }else if (Estimators[i] == "hamming") {
445 cDisplays.push_back(new CollectDisplay(new Hamming(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("hamming"))));
446 outputNames.push_back(fileNameRoot+getOutputFileNameTag("hamming")); outputTypes["hamming"].push_back(fileNameRoot+getOutputFileNameTag("hamming"));
447 }else if (Estimators[i] == "structchi2") {
448 cDisplays.push_back(new CollectDisplay(new StructChi2(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("structchi2"))));
449 outputNames.push_back(fileNameRoot+getOutputFileNameTag("structchi2")); outputTypes["structchi2"].push_back(fileNameRoot+getOutputFileNameTag("structchi2"));
450 }else if (Estimators[i] == "gower") {
451 cDisplays.push_back(new CollectDisplay(new Gower(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("gower"))));
452 outputNames.push_back(fileNameRoot+getOutputFileNameTag("gower")); outputTypes["gower"].push_back(fileNameRoot+getOutputFileNameTag("gower"));
453 }else if (Estimators[i] == "memchi2") {
454 cDisplays.push_back(new CollectDisplay(new MemChi2(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("memchi2"))));
455 outputNames.push_back(fileNameRoot+getOutputFileNameTag("memchi2")); outputTypes["memchi2"].push_back(fileNameRoot+getOutputFileNameTag("memchi2"));
456 }else if (Estimators[i] == "memchord") {
457 cDisplays.push_back(new CollectDisplay(new MemChord(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("memchord"))));
458 outputNames.push_back(fileNameRoot+getOutputFileNameTag("memchord")); outputTypes["memchord"].push_back(fileNameRoot+getOutputFileNameTag("memchord"));
459 }else if (Estimators[i] == "memeuclidean") {
460 cDisplays.push_back(new CollectDisplay(new MemEuclidean(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("memeuclidean"))));
461 outputNames.push_back(fileNameRoot+getOutputFileNameTag("memeuclidean")); outputTypes["memeuclidean"].push_back(fileNameRoot+getOutputFileNameTag("memeuclidean"));
462 }else if (Estimators[i] == "mempearson") {
463 cDisplays.push_back(new CollectDisplay(new MemPearson(), new SharedOneColumnFile(fileNameRoot+getOutputFileNameTag("mempearson"))));
464 outputNames.push_back(fileNameRoot+getOutputFileNameTag("mempearson")); outputTypes["mempearson"].push_back(fileNameRoot+getOutputFileNameTag("mempearson"));
473 catch(exception& e) {
474 m->errorOut(e, "CollectSharedCommand", "CollectSharedCommand");
478 //**********************************************************************************************************************
479 CollectSharedCommand::~CollectSharedCommand(){}
480 //**********************************************************************************************************************
482 int CollectSharedCommand::execute(){
485 if (abort == true) { if (calledHelp) { return 0; } return 2; }
487 //if the users entered no valid calculators don't execute command
488 if (cDisplays.size() == 0) { return 0; }
489 for(int i=0;i<cDisplays.size();i++){ cDisplays[i]->setAll(all); }
491 input = new InputData(sharedfile, "sharedfile");
492 order = input->getSharedOrderVector();
493 string lastLabel = order->getLabel();
495 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
496 set<string> processedLabels;
497 set<string> userLabels = labels;
500 SharedUtil* util = new SharedUtil();
501 Groups = m->getGroups();
502 vector<string> allGroups = m->getAllGroups();
503 util->setGroups(Groups, allGroups, "collect");
504 m->setGroups(Groups);
505 m->setAllGroups(allGroups);
508 while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
509 if (m->control_pressed) {
510 for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear();
511 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
512 delete order; delete input;
517 if(allLines == 1 || labels.count(order->getLabel()) == 1){
519 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
520 //create collectors curve
521 cCurve = new Collect(order, cDisplays);
522 cCurve->getSharedCurve(freq);
525 processedLabels.insert(order->getLabel());
526 userLabels.erase(order->getLabel());
529 //you have a label the user want that is smaller than this label and the last label has not already been processed
530 if ((m->anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
531 string saveLabel = order->getLabel();
534 order = input->getSharedOrderVector(lastLabel);
536 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
537 //create collectors curve
538 cCurve = new Collect(order, cDisplays);
539 cCurve->getSharedCurve(freq);
542 processedLabels.insert(order->getLabel());
543 userLabels.erase(order->getLabel());
545 //restore real lastlabel to save below
546 order->setLabel(saveLabel);
550 lastLabel = order->getLabel();
552 //get next line to process
554 order = input->getSharedOrderVector();
557 if (m->control_pressed) {
558 for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear();
559 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
565 //output error messages about any remaining user labels
566 set<string>::iterator it;
567 bool needToRun = false;
568 for (it = userLabels.begin(); it != userLabels.end(); it++) {
569 m->mothurOut("Your file does not include the label " + *it);
570 if (processedLabels.count(lastLabel) != 1) {
571 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
574 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
578 //run last label if you need to
579 if (needToRun == true) {
580 if (order != NULL) { delete order; }
581 order = input->getSharedOrderVector(lastLabel);
583 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
584 cCurve = new Collect(order, cDisplays);
585 cCurve->getSharedCurve(freq);
588 if (m->control_pressed) {
589 for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear();
590 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
600 for(int i=0;i<cDisplays.size();i++){ delete cDisplays[i]; }
602 //reset groups parameter
606 m->mothurOutEndLine();
607 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
608 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
609 m->mothurOutEndLine();
614 catch(exception& e) {
615 m->errorOut(e, "CollectSharedCommand", "execute");
620 /***********************************************************/