]> git.donarmstrong.com Git - mothur.git/blob - collectsharedcommand.cpp
Revert to previous commit
[mothur.git] / collectsharedcommand.cpp
1 /*
2  *  collectsharedcommand.cpp
3  *  Dotur
4  *
5  *  Created by Sarah Westcott on 1/2/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
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"
34 #include "odum.h"
35 #include "canberra.h"
36 #include "structeuclidean.h"
37 #include "structchord.h"
38 #include "hellinger.h"
39 #include "manhattan.h"
40 #include "structpearson.h"
41 #include "soergel.h"
42 #include "spearman.h"
43 #include "structkulczynski.h"
44 #include "structchi2.h"
45 #include "speciesprofile.h"
46 #include "hamming.h"
47 #include "gower.h"
48 #include "memchi2.h"
49 #include "memchord.h"
50 #include "memeuclidean.h"
51 #include "mempearson.h"
52
53
54 //**********************************************************************************************************************
55 vector<string> CollectSharedCommand::setParameters(){   
56         try {
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);
65                 
66                 vector<string> myArray;
67                 for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
68                 return myArray;
69         }
70         catch(exception& e) {
71                 m->errorOut(e, "CollectSharedCommand", "setParameters");
72                 exit(1);
73         }
74 }
75 //**********************************************************************************************************************
76 string CollectSharedCommand::getHelpString(){   
77         try {
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";
93                 return helpString;
94         }
95         catch(exception& e) {
96                 m->errorOut(e, "CollectSharedCommand", "getHelpString");
97                 exit(1);
98         }
99 }
100 //**********************************************************************************************************************
101 CollectSharedCommand::CollectSharedCommand(){   
102         try {
103                 abort = true; calledHelp = true; 
104                 setParameters();
105                 vector<string> tempOutNames;
106                 outputTypes["sharedchao"] = tempOutNames;
107                 outputTypes["sharedsobs"] = tempOutNames;
108                 outputTypes["sharedace"] = tempOutNames;
109                 outputTypes["jabund"] = tempOutNames;
110                 outputTypes["sorabund"] = tempOutNames;
111                 outputTypes["jclass"] = tempOutNames;
112                 outputTypes["sorclass"] = tempOutNames;
113                 outputTypes["jest"] = tempOutNames;
114                 outputTypes["sorest"] = tempOutNames;
115                 outputTypes["thetayc"] = tempOutNames;
116                 outputTypes["thetan"] = tempOutNames;
117                 outputTypes["kstest"] = tempOutNames;
118                 outputTypes["whittaker"] = tempOutNames;
119                 outputTypes["sharednseqs"] = tempOutNames;
120                 outputTypes["ochiai"] = tempOutNames;
121                 outputTypes["anderberg"] = tempOutNames;
122                 outputTypes["kulczynski"] = tempOutNames;
123                 outputTypes["kulczynskicody"] = tempOutNames;
124                 outputTypes["lennon"] = tempOutNames;
125                 outputTypes["morisitahorn"] = tempOutNames;
126                 outputTypes["braycurtis"] = tempOutNames;
127                 outputTypes["odum"] = tempOutNames;
128                 outputTypes["canberra"] = tempOutNames;
129                 outputTypes["structeuclidean"] = tempOutNames;
130                 outputTypes["structchord"] = tempOutNames;
131                 outputTypes["hellinger"] = tempOutNames;
132                 outputTypes["manhattan"] = tempOutNames;
133                 outputTypes["structpearson"] = tempOutNames;
134                 outputTypes["soergel"] = tempOutNames;
135                 outputTypes["spearman"] = tempOutNames;
136                 outputTypes["structkulczynski"] = tempOutNames;
137                 outputTypes["structchi2"] = tempOutNames;
138                 outputTypes["speciesprofile"] = tempOutNames;
139                 outputTypes["hamming"] = tempOutNames;
140                 outputTypes["gower"] = tempOutNames;
141                 outputTypes["memchi2"] = tempOutNames;
142                 outputTypes["memchord"] = tempOutNames;
143                 outputTypes["memeuclidean"] = tempOutNames;
144                 outputTypes["mempearson"] = tempOutNames;
145                 
146         }
147         catch(exception& e) {
148                 m->errorOut(e, "CollectSharedCommand", "CollectSharedCommand");
149                 exit(1);
150         }
151 }
152 //**********************************************************************************************************************
153 CollectSharedCommand::CollectSharedCommand(string option)  {
154         try {
155                 abort = false; calledHelp = false;   
156                 allLines = 1;
157                 
158                 //allow user to run help
159                 if(option == "help") { help(); abort = true; calledHelp = true; }
160                 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
161                 
162                 else {
163                         vector<string> myArray = setParameters();
164                         
165                         OptionParser parser(option);
166                         map<string,string> parameters=parser.getParameters();
167                         map<string,string>::iterator it;
168                         
169                         ValidParameters validParameter;
170                 
171                         //check to make sure all parameters are valid for command
172                         for (it = parameters.begin(); it != parameters.end(); it++) { 
173                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
174                         }
175         
176                         //initialize outputTypes
177                         vector<string> tempOutNames;
178                         outputTypes["sharedchao"] = tempOutNames;
179                         outputTypes["sharedsobs"] = tempOutNames;
180                         outputTypes["sharedace"] = tempOutNames;
181                         outputTypes["jabund"] = tempOutNames;
182                         outputTypes["sorabund"] = tempOutNames;
183                         outputTypes["jclass"] = tempOutNames;
184                         outputTypes["sorclass"] = tempOutNames;
185                         outputTypes["jest"] = tempOutNames;
186                         outputTypes["sorest"] = tempOutNames;
187                         outputTypes["thetayc"] = tempOutNames;
188                         outputTypes["thetan"] = tempOutNames;
189                         outputTypes["kstest"] = tempOutNames;
190                         outputTypes["whittaker"] = tempOutNames;
191                         outputTypes["sharednseqs"] = tempOutNames;
192                         outputTypes["ochiai"] = tempOutNames;
193                         outputTypes["anderberg"] = tempOutNames;
194                         outputTypes["kulczynski"] = tempOutNames;
195                         outputTypes["kulczynskicody"] = tempOutNames;
196                         outputTypes["lennon"] = tempOutNames;
197                         outputTypes["morisitahorn"] = tempOutNames;
198                         outputTypes["braycurtis"] = tempOutNames;
199                         outputTypes["odum"] = tempOutNames;
200                         outputTypes["canberra"] = tempOutNames;
201                         outputTypes["structeuclidean"] = tempOutNames;
202                         outputTypes["structchord"] = tempOutNames;
203                         outputTypes["hellinger"] = tempOutNames;
204                         outputTypes["manhattan"] = tempOutNames;
205                         outputTypes["structpearson"] = tempOutNames;
206                         outputTypes["soergel"] = tempOutNames;
207                         outputTypes["spearman"] = tempOutNames;
208                         outputTypes["structkulczynski"] = tempOutNames;
209                         outputTypes["speciesprofile"] = tempOutNames;
210                         outputTypes["structchi2"] = tempOutNames;
211                         outputTypes["hamming"] = tempOutNames;
212                         outputTypes["gower"] = tempOutNames;
213                         outputTypes["memchi2"] = tempOutNames;
214                         outputTypes["memchord"] = tempOutNames;
215                         outputTypes["memeuclidean"] = tempOutNames;
216                         outputTypes["mempearson"] = tempOutNames;
217                         
218                         
219                         //if the user changes the input directory command factory will send this info to us in the output parameter 
220                         string inputDir = validParameter.validFile(parameters, "inputdir", false);              
221                         if (inputDir == "not found"){   inputDir = "";          }
222                         else {
223                                 string path;
224                                 it = parameters.find("shared");
225                                 //user has given a template file
226                                 if(it != parameters.end()){ 
227                                         path = m->hasPath(it->second);
228                                         //if the user has not given a path then, add inputdir. else leave path alone.
229                                         if (path == "") {       parameters["shared"] = inputDir + it->second;           }
230                                 }
231                         }
232                         
233                         //get shared file
234                         sharedfile = validParameter.validFile(parameters, "shared", true);
235                         if (sharedfile == "not open") { sharedfile = ""; abort = true; }        
236                         else if (sharedfile == "not found") { 
237                                 //if there is a current shared file, use it
238                                 sharedfile = m->getSharedFile(); 
239                                 if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
240                                 else {  m->mothurOut("You have no current sharedfile and the shared parameter is required."); m->mothurOutEndLine(); abort = true; }
241                         }else { m->setSharedFile(sharedfile); }
242                         
243                         
244                         //if the user changes the output directory command factory will send this info to us in the output parameter 
245                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = m->hasPath(sharedfile);             }
246                         
247                         //check for optional parameter and set defaults
248                         // ...at some point should added some additional type checking..
249                         label = validParameter.validFile(parameters, "label", false);                   
250                         if (label == "not found") { label = ""; }
251                         else { 
252                                 if(label != "all") {  m->splitAtDash(label, labels);  allLines = 0;  }
253                                 else { allLines = 1;  }
254                         }
255                         
256                         calc = validParameter.validFile(parameters, "calc", false);                     
257                         if (calc == "not found") { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan";  }
258                         else { 
259                                  if (calc == "default")  {  calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan";  }
260                         }
261                         m->splitAtDash(calc, Estimators);
262                         if (m->inUsersGroups("citation", Estimators)) { 
263                                 ValidCalculators validCalc; validCalc.printCitations(Estimators); 
264                                 //remove citation from list of calcs
265                                 for (int i = 0; i < Estimators.size(); i++) { if (Estimators[i] == "citation") {  Estimators.erase(Estimators.begin()+i); break; } }
266                         }
267                         
268                         groups = validParameter.validFile(parameters, "groups", false);                 
269                         if (groups == "not found") { groups = ""; }
270                         else { 
271                                 m->splitAtDash(groups, Groups);
272                         }
273                         m->setGroups(Groups);
274                         
275                         string temp;
276                         temp = validParameter.validFile(parameters, "freq", false);                     if (temp == "not found") { temp = "100"; }
277                         m->mothurConvert(temp, freq); 
278                         
279                         temp = validParameter.validFile(parameters, "all", false);                              if (temp == "not found") { temp = "false"; }
280                         all = m->isTrue(temp);
281                                                 
282                         if (abort == false) {
283                                 
284                                 string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(sharedfile));
285                                 
286                                 ValidCalculators validCalculator;
287                                 
288                                 for (int i=0; i<Estimators.size(); i++) {
289                                         if (validCalculator.isValidCalculator("shared", Estimators[i]) == true) { 
290                                                 if (Estimators[i] == "sharedchao") { 
291                                                         cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao")));
292                                                         outputNames.push_back(fileNameRoot+"shared.chao"); outputTypes["sharedchao"].push_back(fileNameRoot+"shared.chao");
293                                                 }else if (Estimators[i] == "sharedsobs") { 
294                                                         cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs")));
295                                                         outputNames.push_back(fileNameRoot+"shared.sobs"); outputTypes["sharedsobs"].push_back(fileNameRoot+"shared.sobs");
296                                                 }else if (Estimators[i] == "sharedace") { 
297                                                         cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace")));
298                                                         outputNames.push_back(fileNameRoot+"shared.ace"); outputTypes["sharedace"].push_back(fileNameRoot+"shared.ace");
299                                                 }else if (Estimators[i] == "jabund") {  
300                                                         cDisplays.push_back(new CollectDisplay(new JAbund(), new SharedOneColumnFile(fileNameRoot+"jabund")));
301                                                         outputNames.push_back(fileNameRoot+"jabund"); outputTypes["jabund"].push_back(fileNameRoot+"jabund");
302                                                 }else if (Estimators[i] == "sorabund") { 
303                                                         cDisplays.push_back(new CollectDisplay(new SorAbund(), new SharedOneColumnFile(fileNameRoot+"sorabund")));
304                                                         outputNames.push_back(fileNameRoot+"sorabund"); outputTypes["sorabund"].push_back(fileNameRoot+"sorabund");
305                                                 }else if (Estimators[i] == "jclass") { 
306                                                         cDisplays.push_back(new CollectDisplay(new Jclass(), new SharedOneColumnFile(fileNameRoot+"jclass")));
307                                                         outputNames.push_back(fileNameRoot+"jclass"); outputTypes["jclass"].push_back(fileNameRoot+"jclass");
308                                                 }else if (Estimators[i] == "sorclass") { 
309                                                         cDisplays.push_back(new CollectDisplay(new SorClass(), new SharedOneColumnFile(fileNameRoot+"sorclass")));
310                                                         outputNames.push_back(fileNameRoot+"sorclass"); outputTypes["sorclass"].push_back(fileNameRoot+"sorclass");
311                                                 }else if (Estimators[i] == "jest") { 
312                                                         cDisplays.push_back(new CollectDisplay(new Jest(), new SharedOneColumnFile(fileNameRoot+"jest")));
313                                                         outputNames.push_back(fileNameRoot+"jest"); outputTypes["jest"].push_back(fileNameRoot+"jest");
314                                                 }else if (Estimators[i] == "sorest") { 
315                                                         cDisplays.push_back(new CollectDisplay(new SorEst(), new SharedOneColumnFile(fileNameRoot+"sorest")));
316                                                         outputNames.push_back(fileNameRoot+"sorest"); outputTypes["sorest"].push_back(fileNameRoot+"sorest");
317                                                 }else if (Estimators[i] == "thetayc") { 
318                                                         cDisplays.push_back(new CollectDisplay(new ThetaYC(), new SharedOneColumnFile(fileNameRoot+"thetayc")));
319                                                         outputNames.push_back(fileNameRoot+"thetayc"); outputTypes["thetayc"].push_back(fileNameRoot+"thetayc");
320                                                 }else if (Estimators[i] == "thetan") { 
321                                                         cDisplays.push_back(new CollectDisplay(new ThetaN(), new SharedOneColumnFile(fileNameRoot+"thetan")));
322                                                         outputNames.push_back(fileNameRoot+"thetan"); outputTypes["thetan"].push_back(fileNameRoot+"thetan");
323                                                 }else if (Estimators[i] == "kstest") { 
324                                                         cDisplays.push_back(new CollectDisplay(new KSTest(), new SharedOneColumnFile(fileNameRoot+"kstest")));
325                                                         outputNames.push_back(fileNameRoot+"kstest"); outputTypes["kstest"].push_back(fileNameRoot+"kstest");
326                                                 }else if (Estimators[i] == "whittaker") { 
327                                                         cDisplays.push_back(new CollectDisplay(new Whittaker(), new SharedOneColumnFile(fileNameRoot+"whittaker")));
328                                                         outputNames.push_back(fileNameRoot+"whittaker"); outputTypes["whittaker"].push_back(fileNameRoot+"whittaker");
329                                                 }else if (Estimators[i] == "sharednseqs") { 
330                                                         cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(fileNameRoot+"shared.nseqs")));
331                                                         outputNames.push_back(fileNameRoot+"shared.nseqs"); outputTypes["shared.nseqs"].push_back(fileNameRoot+"shared.nseqs");
332                                                 }else if (Estimators[i] == "ochiai") { 
333                                                         cDisplays.push_back(new CollectDisplay(new Ochiai(), new SharedOneColumnFile(fileNameRoot+"ochiai")));
334                                                         outputNames.push_back(fileNameRoot+"ochiai"); outputTypes["ochiai"].push_back(fileNameRoot+"ochiai");
335                                                 }else if (Estimators[i] == "anderberg") { 
336                                                         cDisplays.push_back(new CollectDisplay(new Anderberg(), new SharedOneColumnFile(fileNameRoot+"anderberg")));
337                                                         outputNames.push_back(fileNameRoot+"anderberg"); outputTypes["anderberg"].push_back(fileNameRoot+"anderberg");
338                                                 }else if (Estimators[i] == "kulczynski") { 
339                                                         cDisplays.push_back(new CollectDisplay(new Kulczynski(), new SharedOneColumnFile(fileNameRoot+"kulczynski")));
340                                                         outputNames.push_back(fileNameRoot+"kulczynski"); outputTypes["kulczynski"].push_back(fileNameRoot+"kulczynski");
341                                                 }else if (Estimators[i] == "kulczynskicody") { 
342                                                         cDisplays.push_back(new CollectDisplay(new KulczynskiCody(), new SharedOneColumnFile(fileNameRoot+"kulczynskicody")));
343                                                         outputNames.push_back(fileNameRoot+"kulczynskicody"); outputTypes["kulczynskicody"].push_back(fileNameRoot+"kulczynskicody");
344                                                 }else if (Estimators[i] == "lennon") { 
345                                                         cDisplays.push_back(new CollectDisplay(new Lennon(), new SharedOneColumnFile(fileNameRoot+"lennon")));
346                                                         outputNames.push_back(fileNameRoot+"lennon"); outputTypes["lennon"].push_back(fileNameRoot+"lennon");
347                                                 }else if (Estimators[i] == "morisitahorn") { 
348                                                         cDisplays.push_back(new CollectDisplay(new MorHorn(), new SharedOneColumnFile(fileNameRoot+"morisitahorn")));
349                                                         outputNames.push_back(fileNameRoot+"morisitahorn"); outputTypes["morisitahorn"].push_back(fileNameRoot+"morisitahorn");
350                                                 }else if (Estimators[i] == "braycurtis") { 
351                                                         cDisplays.push_back(new CollectDisplay(new BrayCurtis(), new SharedOneColumnFile(fileNameRoot+"braycurtis")));
352                                                         outputNames.push_back(fileNameRoot+"braycurtis"); outputTypes["braycurtis"].push_back(fileNameRoot+"braycurtis");
353                                                 }else if (Estimators[i] == "odum") { 
354                                                         cDisplays.push_back(new CollectDisplay(new Odum(), new SharedOneColumnFile(fileNameRoot+"odum")));
355                                                         outputNames.push_back(fileNameRoot+"odum"); outputTypes["odum"].push_back(fileNameRoot+"odum");
356                                                 }else if (Estimators[i] == "canberra") { 
357                                                         cDisplays.push_back(new CollectDisplay(new Canberra(), new SharedOneColumnFile(fileNameRoot+"canberra")));
358                                                         outputNames.push_back(fileNameRoot+"canberra"); outputTypes["canberra"].push_back(fileNameRoot+"canberra");
359                                                 }else if (Estimators[i] == "structeuclidean") { 
360                                                         cDisplays.push_back(new CollectDisplay(new StructEuclidean(), new SharedOneColumnFile(fileNameRoot+"structeuclidean")));
361                                                         outputNames.push_back(fileNameRoot+"structeuclidean"); outputTypes["structeuclidean"].push_back(fileNameRoot+"structeuclidean");
362                                                 }else if (Estimators[i] == "structchord") { 
363                                                         cDisplays.push_back(new CollectDisplay(new StructChord(), new SharedOneColumnFile(fileNameRoot+"structchord")));
364                                                         outputNames.push_back(fileNameRoot+"structchord"); outputTypes["structchord"].push_back(fileNameRoot+"structchord");
365                                                 }else if (Estimators[i] == "hellinger") { 
366                                                         cDisplays.push_back(new CollectDisplay(new Hellinger(), new SharedOneColumnFile(fileNameRoot+"hellinger")));
367                                                         outputNames.push_back(fileNameRoot+"hellinger"); outputTypes["hellinger"].push_back(fileNameRoot+"hellinger");
368                                                 }else if (Estimators[i] == "manhattan") { 
369                                                         cDisplays.push_back(new CollectDisplay(new Manhattan(), new SharedOneColumnFile(fileNameRoot+"manhattan")));
370                                                         outputNames.push_back(fileNameRoot+"manhattan"); outputTypes["manhattan"].push_back(fileNameRoot+"manhattan");
371                                                 }else if (Estimators[i] == "structpearson") { 
372                                                         cDisplays.push_back(new CollectDisplay(new StructPearson(), new SharedOneColumnFile(fileNameRoot+"structpearson")));
373                                                         outputNames.push_back(fileNameRoot+"structpearson"); outputTypes["structpearson"].push_back(fileNameRoot+"structpearson");
374                                                 }else if (Estimators[i] == "soergel") { 
375                                                         cDisplays.push_back(new CollectDisplay(new Soergel(), new SharedOneColumnFile(fileNameRoot+"soergel")));
376                                                         outputNames.push_back(fileNameRoot+"soergel"); outputTypes["soergel"].push_back(fileNameRoot+"soergel");
377                                                 }else if (Estimators[i] == "spearman") { 
378                                                         cDisplays.push_back(new CollectDisplay(new Spearman(), new SharedOneColumnFile(fileNameRoot+"spearman")));
379                                                         outputNames.push_back(fileNameRoot+"spearman"); outputTypes["spearman"].push_back(fileNameRoot+"spearman");
380                                                 }else if (Estimators[i] == "structkulczynski") { 
381                                                         cDisplays.push_back(new CollectDisplay(new StructKulczynski(), new SharedOneColumnFile(fileNameRoot+"structkulczynski")));
382                                                         outputNames.push_back(fileNameRoot+"structkulczynski"); outputTypes["structkulczynski"].push_back(fileNameRoot+"structkulczynski");
383                                                 }else if (Estimators[i] == "speciesprofile") { 
384                                                         cDisplays.push_back(new CollectDisplay(new SpeciesProfile(), new SharedOneColumnFile(fileNameRoot+"speciesprofile")));
385                                                         outputNames.push_back(fileNameRoot+"speciesprofile"); outputTypes["speciesprofile"].push_back(fileNameRoot+"speciesprofile");
386                                                 }else if (Estimators[i] == "hamming") { 
387                                                         cDisplays.push_back(new CollectDisplay(new Hamming(), new SharedOneColumnFile(fileNameRoot+"hamming")));
388                                                         outputNames.push_back(fileNameRoot+"hamming"); outputTypes["hamming"].push_back(fileNameRoot+"hamming");
389                                                 }else if (Estimators[i] == "structchi2") { 
390                                                         cDisplays.push_back(new CollectDisplay(new StructChi2(), new SharedOneColumnFile(fileNameRoot+"structchi2")));
391                                                         outputNames.push_back(fileNameRoot+"structchi2"); outputTypes["structchi2"].push_back(fileNameRoot+"structchi2");
392                                                 }else if (Estimators[i] == "gower") { 
393                                                         cDisplays.push_back(new CollectDisplay(new Gower(), new SharedOneColumnFile(fileNameRoot+"gower")));
394                                                         outputNames.push_back(fileNameRoot+"gower"); outputTypes["gower"].push_back(fileNameRoot+"gower");
395                                                 }else if (Estimators[i] == "memchi2") { 
396                                                         cDisplays.push_back(new CollectDisplay(new MemChi2(), new SharedOneColumnFile(fileNameRoot+"memchi2")));
397                                                         outputNames.push_back(fileNameRoot+"memchi2"); outputTypes["memchi2"].push_back(fileNameRoot+"memchi2");
398                                                 }else if (Estimators[i] == "memchord") { 
399                                                         cDisplays.push_back(new CollectDisplay(new MemChord(), new SharedOneColumnFile(fileNameRoot+"memchord")));
400                                                         outputNames.push_back(fileNameRoot+"memchord"); outputTypes["memchord"].push_back(fileNameRoot+"memchord");
401                                                 }else if (Estimators[i] == "memeuclidean") { 
402                                                         cDisplays.push_back(new CollectDisplay(new MemEuclidean(), new SharedOneColumnFile(fileNameRoot+"memeuclidean")));
403                                                         outputNames.push_back(fileNameRoot+"memeuclidean"); outputTypes["memeuclidean"].push_back(fileNameRoot+"memeuclidean");
404                                                 }else if (Estimators[i] == "mempearson") { 
405                                                         cDisplays.push_back(new CollectDisplay(new MemPearson(), new SharedOneColumnFile(fileNameRoot+"mempearson")));
406                                                         outputNames.push_back(fileNameRoot+"mempearson"); outputTypes["mempearson"].push_back(fileNameRoot+"mempearson");
407                                                 }
408                                                 
409                                         }
410                                 }       
411                         }
412                 }
413
414         }
415         catch(exception& e) {
416                 m->errorOut(e, "CollectSharedCommand", "CollectSharedCommand");
417                 exit(1);
418         }
419 }
420 //**********************************************************************************************************************
421 CollectSharedCommand::~CollectSharedCommand(){}
422 //**********************************************************************************************************************
423
424 int CollectSharedCommand::execute(){
425         try {
426                 
427                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
428                 
429                 //if the users entered no valid calculators don't execute command
430                 if (cDisplays.size() == 0) { return 0; }
431                 for(int i=0;i<cDisplays.size();i++){    cDisplays[i]->setAll(all);      }       
432         
433                 input = new InputData(sharedfile, "sharedfile");
434                 order = input->getSharedOrderVector();
435                 string lastLabel = order->getLabel();
436                 
437                 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
438                 set<string> processedLabels;
439                 set<string> userLabels = labels;
440                         
441                 //set users groups
442                 SharedUtil* util = new SharedUtil();
443                 Groups = m->getGroups();
444                 vector<string> allGroups = m->getAllGroups();
445                 util->setGroups(Groups, allGroups, "collect");
446                 m->setGroups(Groups);
447                 m->setAllGroups(allGroups);
448                 delete util;
449
450                 while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
451                         if (m->control_pressed) { 
452                                         for (int i = 0; i < outputNames.size(); i++) {  m->mothurRemove(outputNames[i]);        }  outputTypes.clear();
453                                         for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
454                                         delete order; delete input;
455                                         m->clearGroups();
456                                         return 0;
457                         }
458
459                         if(allLines == 1 || labels.count(order->getLabel()) == 1){
460                         
461                                 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
462                                 //create collectors curve
463                                 cCurve = new Collect(order, cDisplays);
464                                 cCurve->getSharedCurve(freq);
465                                 delete cCurve;
466                         
467                                 processedLabels.insert(order->getLabel());
468                                 userLabels.erase(order->getLabel());
469                         }
470                         
471                         //you have a label the user want that is smaller than this label and the last label has not already been processed
472                         if ((m->anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
473                                 string saveLabel = order->getLabel();
474                                 
475                                 delete order;
476                                 order = input->getSharedOrderVector(lastLabel);
477                                 
478                                 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
479                                 //create collectors curve
480                                 cCurve = new Collect(order, cDisplays);
481                                 cCurve->getSharedCurve(freq);
482                                 delete cCurve;
483                                 
484                                 processedLabels.insert(order->getLabel());
485                                 userLabels.erase(order->getLabel());
486                                 
487                                 //restore real lastlabel to save below
488                                 order->setLabel(saveLabel);
489                         }
490                         
491                         
492                         lastLabel = order->getLabel();                  
493                         
494                         //get next line to process
495                         delete order;
496                         order = input->getSharedOrderVector();
497                 }
498                 
499                 if (m->control_pressed) { 
500                                         for (int i = 0; i < outputNames.size(); i++) {  m->mothurRemove(outputNames[i]);        }   outputTypes.clear();
501                                         for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
502                                         m->clearGroups();
503                                         delete input;
504                                         return 0;
505                 }
506                 
507                 //output error messages about any remaining user labels
508                 set<string>::iterator it;
509                 bool needToRun = false;
510                 for (it = userLabels.begin(); it != userLabels.end(); it++) {  
511                         m->mothurOut("Your file does not include the label " + *it); 
512                         if (processedLabels.count(lastLabel) != 1) {
513                                 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
514                                 needToRun = true;
515                         }else {
516                                 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
517                         }
518                 }
519                 
520                 //run last label if you need to
521                 if (needToRun == true)  {
522                         if (order != NULL) {  delete order;  }
523                         order = input->getSharedOrderVector(lastLabel);
524                         
525                         m->mothurOut(order->getLabel()); m->mothurOutEndLine();
526                         cCurve = new Collect(order, cDisplays);
527                         cCurve->getSharedCurve(freq);
528                         delete cCurve;
529                         
530                         if (m->control_pressed) { 
531                                 for (int i = 0; i < outputNames.size(); i++) {  m->mothurRemove(outputNames[i]);        }  outputTypes.clear();
532                                 for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
533                                 delete order; 
534                                 delete input;
535                                 m->clearGroups();
536                                 return 0;
537                         }
538
539                         delete order;
540                 }
541                 
542                 for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }       
543                 
544                 //reset groups parameter
545                 m->clearGroups(); 
546                 delete input;
547                 
548                 m->mothurOutEndLine();
549                 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
550                 for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
551                 m->mothurOutEndLine();
552
553                 
554                 return 0;
555         }
556         catch(exception& e) {
557                 m->errorOut(e, "CollectSharedCommand", "execute");
558                 exit(1);
559         }
560 }
561
562 /***********************************************************/