]> git.donarmstrong.com Git - mothur.git/blob - collectsharedcommand.cpp
added citation function to commands
[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-skulczynski-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["skulczynski"] = 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["skulczynski"] = 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                         }
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                         
263                         groups = validParameter.validFile(parameters, "groups", false);                 
264                         if (groups == "not found") { groups = ""; }
265                         else { 
266                                 m->splitAtDash(groups, Groups);
267                         }
268                         m->Groups = Groups;
269                         
270                         string temp;
271                         temp = validParameter.validFile(parameters, "freq", false);                     if (temp == "not found") { temp = "100"; }
272                         convert(temp, freq); 
273                         
274                         temp = validParameter.validFile(parameters, "all", false);                              if (temp == "not found") { temp = "false"; }
275                         all = m->isTrue(temp);
276                                                 
277                         if (abort == false) {
278                                 
279                                 string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(sharedfile));
280                                 
281                                 ValidCalculators validCalculator;
282                                 
283                                 for (int i=0; i<Estimators.size(); i++) {
284                                         if (validCalculator.isValidCalculator("shared", Estimators[i]) == true) { 
285                                                 if (Estimators[i] == "sharedchao") { 
286                                                         cDisplays.push_back(new CollectDisplay(new SharedChao1(), new SharedOneColumnFile(fileNameRoot+"shared.chao")));
287                                                         outputNames.push_back(fileNameRoot+"shared.chao"); outputTypes["sharedchao"].push_back(fileNameRoot+"shared.chao");
288                                                 }else if (Estimators[i] == "sharedsobs") { 
289                                                         cDisplays.push_back(new CollectDisplay(new SharedSobsCS(), new SharedOneColumnFile(fileNameRoot+"shared.sobs")));
290                                                         outputNames.push_back(fileNameRoot+"shared.sobs"); outputTypes["sharedsobs"].push_back(fileNameRoot+"shared.sobs");
291                                                 }else if (Estimators[i] == "sharedace") { 
292                                                         cDisplays.push_back(new CollectDisplay(new SharedAce(), new SharedOneColumnFile(fileNameRoot+"shared.ace")));
293                                                         outputNames.push_back(fileNameRoot+"shared.ace"); outputTypes["sharedace"].push_back(fileNameRoot+"shared.ace");
294                                                 }else if (Estimators[i] == "jabund") {  
295                                                         cDisplays.push_back(new CollectDisplay(new JAbund(), new SharedOneColumnFile(fileNameRoot+"jabund")));
296                                                         outputNames.push_back(fileNameRoot+"jabund"); outputTypes["jabund"].push_back(fileNameRoot+"jabund");
297                                                 }else if (Estimators[i] == "sorabund") { 
298                                                         cDisplays.push_back(new CollectDisplay(new SorAbund(), new SharedOneColumnFile(fileNameRoot+"sorabund")));
299                                                         outputNames.push_back(fileNameRoot+"sorabund"); outputTypes["sorabund"].push_back(fileNameRoot+"sorabund");
300                                                 }else if (Estimators[i] == "jclass") { 
301                                                         cDisplays.push_back(new CollectDisplay(new Jclass(), new SharedOneColumnFile(fileNameRoot+"jclass")));
302                                                         outputNames.push_back(fileNameRoot+"jclass"); outputTypes["jclass"].push_back(fileNameRoot+"jclass");
303                                                 }else if (Estimators[i] == "sorclass") { 
304                                                         cDisplays.push_back(new CollectDisplay(new SorClass(), new SharedOneColumnFile(fileNameRoot+"sorclass")));
305                                                         outputNames.push_back(fileNameRoot+"sorclass"); outputTypes["sorclass"].push_back(fileNameRoot+"sorclass");
306                                                 }else if (Estimators[i] == "jest") { 
307                                                         cDisplays.push_back(new CollectDisplay(new Jest(), new SharedOneColumnFile(fileNameRoot+"jest")));
308                                                         outputNames.push_back(fileNameRoot+"jest"); outputTypes["jest"].push_back(fileNameRoot+"jest");
309                                                 }else if (Estimators[i] == "sorest") { 
310                                                         cDisplays.push_back(new CollectDisplay(new SorEst(), new SharedOneColumnFile(fileNameRoot+"sorest")));
311                                                         outputNames.push_back(fileNameRoot+"sorest"); outputTypes["sorest"].push_back(fileNameRoot+"sorest");
312                                                 }else if (Estimators[i] == "thetayc") { 
313                                                         cDisplays.push_back(new CollectDisplay(new ThetaYC(), new SharedOneColumnFile(fileNameRoot+"thetayc")));
314                                                         outputNames.push_back(fileNameRoot+"thetayc"); outputTypes["thetayc"].push_back(fileNameRoot+"thetayc");
315                                                 }else if (Estimators[i] == "thetan") { 
316                                                         cDisplays.push_back(new CollectDisplay(new ThetaN(), new SharedOneColumnFile(fileNameRoot+"thetan")));
317                                                         outputNames.push_back(fileNameRoot+"thetan"); outputTypes["thetan"].push_back(fileNameRoot+"thetan");
318                                                 }else if (Estimators[i] == "kstest") { 
319                                                         cDisplays.push_back(new CollectDisplay(new KSTest(), new SharedOneColumnFile(fileNameRoot+"kstest")));
320                                                         outputNames.push_back(fileNameRoot+"kstest"); outputTypes["kstest"].push_back(fileNameRoot+"kstest");
321                                                 }else if (Estimators[i] == "whittaker") { 
322                                                         cDisplays.push_back(new CollectDisplay(new Whittaker(), new SharedOneColumnFile(fileNameRoot+"whittaker")));
323                                                         outputNames.push_back(fileNameRoot+"whittaker"); outputTypes["whittaker"].push_back(fileNameRoot+"whittaker");
324                                                 }else if (Estimators[i] == "sharednseqs") { 
325                                                         cDisplays.push_back(new CollectDisplay(new SharedNSeqs(), new SharedOneColumnFile(fileNameRoot+"shared.nseqs")));
326                                                         outputNames.push_back(fileNameRoot+"shared.nseqs"); outputTypes["shared.nseqs"].push_back(fileNameRoot+"shared.nseqs");
327                                                 }else if (Estimators[i] == "ochiai") { 
328                                                         cDisplays.push_back(new CollectDisplay(new Ochiai(), new SharedOneColumnFile(fileNameRoot+"ochiai")));
329                                                         outputNames.push_back(fileNameRoot+"ochiai"); outputTypes["ochiai"].push_back(fileNameRoot+"ochiai");
330                                                 }else if (Estimators[i] == "anderberg") { 
331                                                         cDisplays.push_back(new CollectDisplay(new Anderberg(), new SharedOneColumnFile(fileNameRoot+"anderberg")));
332                                                         outputNames.push_back(fileNameRoot+"anderberg"); outputTypes["anderberg"].push_back(fileNameRoot+"anderberg");
333                                                 }else if (Estimators[i] == "skulczynski") { 
334                                                         cDisplays.push_back(new CollectDisplay(new Kulczynski(), new SharedOneColumnFile(fileNameRoot+"kulczynski")));
335                                                         outputNames.push_back(fileNameRoot+"kulczynski"); outputTypes["kulczynski"].push_back(fileNameRoot+"kulczynski");
336                                                 }else if (Estimators[i] == "kulczynskicody") { 
337                                                         cDisplays.push_back(new CollectDisplay(new KulczynskiCody(), new SharedOneColumnFile(fileNameRoot+"kulczynskicody")));
338                                                         outputNames.push_back(fileNameRoot+"kulczynskicody"); outputTypes["kulczynskicody"].push_back(fileNameRoot+"kulczynskicody");
339                                                 }else if (Estimators[i] == "lennon") { 
340                                                         cDisplays.push_back(new CollectDisplay(new Lennon(), new SharedOneColumnFile(fileNameRoot+"lennon")));
341                                                         outputNames.push_back(fileNameRoot+"lennon"); outputTypes["lennon"].push_back(fileNameRoot+"lennon");
342                                                 }else if (Estimators[i] == "morisitahorn") { 
343                                                         cDisplays.push_back(new CollectDisplay(new MorHorn(), new SharedOneColumnFile(fileNameRoot+"morisitahorn")));
344                                                         outputNames.push_back(fileNameRoot+"morisitahorn"); outputTypes["morisitahorn"].push_back(fileNameRoot+"morisitahorn");
345                                                 }else if (Estimators[i] == "braycurtis") { 
346                                                         cDisplays.push_back(new CollectDisplay(new BrayCurtis(), new SharedOneColumnFile(fileNameRoot+"braycurtis")));
347                                                         outputNames.push_back(fileNameRoot+"braycurtis"); outputTypes["braycurtis"].push_back(fileNameRoot+"braycurtis");
348                                                 }else if (Estimators[i] == "odum") { 
349                                                         cDisplays.push_back(new CollectDisplay(new Odum(), new SharedOneColumnFile(fileNameRoot+"odum")));
350                                                         outputNames.push_back(fileNameRoot+"odum"); outputTypes["odum"].push_back(fileNameRoot+"odum");
351                                                 }else if (Estimators[i] == "canberra") { 
352                                                         cDisplays.push_back(new CollectDisplay(new Canberra(), new SharedOneColumnFile(fileNameRoot+"canberra")));
353                                                         outputNames.push_back(fileNameRoot+"canberra"); outputTypes["canberra"].push_back(fileNameRoot+"canberra");
354                                                 }else if (Estimators[i] == "structeuclidean") { 
355                                                         cDisplays.push_back(new CollectDisplay(new StructEuclidean(), new SharedOneColumnFile(fileNameRoot+"structeuclidean")));
356                                                         outputNames.push_back(fileNameRoot+"structeuclidean"); outputTypes["structeuclidean"].push_back(fileNameRoot+"structeuclidean");
357                                                 }else if (Estimators[i] == "structchord") { 
358                                                         cDisplays.push_back(new CollectDisplay(new StructChord(), new SharedOneColumnFile(fileNameRoot+"structchord")));
359                                                         outputNames.push_back(fileNameRoot+"structchord"); outputTypes["structchord"].push_back(fileNameRoot+"structchord");
360                                                 }else if (Estimators[i] == "hellinger") { 
361                                                         cDisplays.push_back(new CollectDisplay(new Hellinger(), new SharedOneColumnFile(fileNameRoot+"hellinger")));
362                                                         outputNames.push_back(fileNameRoot+"hellinger"); outputTypes["hellinger"].push_back(fileNameRoot+"hellinger");
363                                                 }else if (Estimators[i] == "manhattan") { 
364                                                         cDisplays.push_back(new CollectDisplay(new Manhattan(), new SharedOneColumnFile(fileNameRoot+"manhattan")));
365                                                         outputNames.push_back(fileNameRoot+"manhattan"); outputTypes["manhattan"].push_back(fileNameRoot+"manhattan");
366                                                 }else if (Estimators[i] == "structpearson") { 
367                                                         cDisplays.push_back(new CollectDisplay(new StructPearson(), new SharedOneColumnFile(fileNameRoot+"structpearson")));
368                                                         outputNames.push_back(fileNameRoot+"structpearson"); outputTypes["structpearson"].push_back(fileNameRoot+"structpearson");
369                                                 }else if (Estimators[i] == "soergel") { 
370                                                         cDisplays.push_back(new CollectDisplay(new Soergel(), new SharedOneColumnFile(fileNameRoot+"soergel")));
371                                                         outputNames.push_back(fileNameRoot+"soergel"); outputTypes["soergel"].push_back(fileNameRoot+"soergel");
372                                                 }else if (Estimators[i] == "spearman") { 
373                                                         cDisplays.push_back(new CollectDisplay(new Spearman(), new SharedOneColumnFile(fileNameRoot+"spearman")));
374                                                         outputNames.push_back(fileNameRoot+"spearman"); outputTypes["spearman"].push_back(fileNameRoot+"spearman");
375                                                 }else if (Estimators[i] == "structkulczynski") { 
376                                                         cDisplays.push_back(new CollectDisplay(new StructKulczynski(), new SharedOneColumnFile(fileNameRoot+"structkulczynski")));
377                                                         outputNames.push_back(fileNameRoot+"structkulczynski"); outputTypes["structkulczynski"].push_back(fileNameRoot+"structkulczynski");
378                                                 }else if (Estimators[i] == "speciesprofile") { 
379                                                         cDisplays.push_back(new CollectDisplay(new SpeciesProfile(), new SharedOneColumnFile(fileNameRoot+"speciesprofile")));
380                                                         outputNames.push_back(fileNameRoot+"speciesprofile"); outputTypes["speciesprofile"].push_back(fileNameRoot+"speciesprofile");
381                                                 }else if (Estimators[i] == "hamming") { 
382                                                         cDisplays.push_back(new CollectDisplay(new Hamming(), new SharedOneColumnFile(fileNameRoot+"hamming")));
383                                                         outputNames.push_back(fileNameRoot+"hamming"); outputTypes["hamming"].push_back(fileNameRoot+"hamming");
384                                                 }else if (Estimators[i] == "structchi2") { 
385                                                         cDisplays.push_back(new CollectDisplay(new StructChi2(), new SharedOneColumnFile(fileNameRoot+"structchi2")));
386                                                         outputNames.push_back(fileNameRoot+"structchi2"); outputTypes["structchi2"].push_back(fileNameRoot+"structchi2");
387                                                 }else if (Estimators[i] == "gower") { 
388                                                         cDisplays.push_back(new CollectDisplay(new Gower(), new SharedOneColumnFile(fileNameRoot+"gower")));
389                                                         outputNames.push_back(fileNameRoot+"gower"); outputTypes["gower"].push_back(fileNameRoot+"gower");
390                                                 }else if (Estimators[i] == "memchi2") { 
391                                                         cDisplays.push_back(new CollectDisplay(new MemChi2(), new SharedOneColumnFile(fileNameRoot+"memchi2")));
392                                                         outputNames.push_back(fileNameRoot+"memchi2"); outputTypes["memchi2"].push_back(fileNameRoot+"memchi2");
393                                                 }else if (Estimators[i] == "memchord") { 
394                                                         cDisplays.push_back(new CollectDisplay(new MemChord(), new SharedOneColumnFile(fileNameRoot+"memchord")));
395                                                         outputNames.push_back(fileNameRoot+"memchord"); outputTypes["memchord"].push_back(fileNameRoot+"memchord");
396                                                 }else if (Estimators[i] == "memeuclidean") { 
397                                                         cDisplays.push_back(new CollectDisplay(new MemEuclidean(), new SharedOneColumnFile(fileNameRoot+"memeuclidean")));
398                                                         outputNames.push_back(fileNameRoot+"memeuclidean"); outputTypes["memeuclidean"].push_back(fileNameRoot+"memeuclidean");
399                                                 }else if (Estimators[i] == "mempearson") { 
400                                                         cDisplays.push_back(new CollectDisplay(new MemPearson(), new SharedOneColumnFile(fileNameRoot+"mempearson")));
401                                                         outputNames.push_back(fileNameRoot+"mempearson"); outputTypes["mempearson"].push_back(fileNameRoot+"mempearson");
402                                                 }
403                                                 
404                                         }
405                                 }       
406                         }
407                 }
408
409         }
410         catch(exception& e) {
411                 m->errorOut(e, "CollectSharedCommand", "CollectSharedCommand");
412                 exit(1);
413         }
414 }
415 //**********************************************************************************************************************
416 CollectSharedCommand::~CollectSharedCommand(){}
417 //**********************************************************************************************************************
418
419 int CollectSharedCommand::execute(){
420         try {
421                 
422                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
423                 
424                 //if the users entered no valid calculators don't execute command
425                 if (cDisplays.size() == 0) { return 0; }
426                 for(int i=0;i<cDisplays.size();i++){    cDisplays[i]->setAll(all);      }       
427         
428                 input = new InputData(sharedfile, "sharedfile");
429                 order = input->getSharedOrderVector();
430                 string lastLabel = order->getLabel();
431                 
432                 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
433                 set<string> processedLabels;
434                 set<string> userLabels = labels;
435                         
436                 //set users groups
437                 SharedUtil* util = new SharedUtil();
438                 util->setGroups(m->Groups, m->namesOfGroups, "collect");
439                 delete util;
440
441                 while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
442                         if (m->control_pressed) { 
443                                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }  outputTypes.clear();
444                                         for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
445                                         delete order; delete input;
446                                         m->Groups.clear();
447                                         return 0;
448                         }
449
450                         if(allLines == 1 || labels.count(order->getLabel()) == 1){
451                         
452                                 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
453                                 //create collectors curve
454                                 cCurve = new Collect(order, cDisplays);
455                                 cCurve->getSharedCurve(freq);
456                                 delete cCurve;
457                         
458                                 processedLabels.insert(order->getLabel());
459                                 userLabels.erase(order->getLabel());
460                         }
461                         
462                         //you have a label the user want that is smaller than this label and the last label has not already been processed
463                         if ((m->anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
464                                 string saveLabel = order->getLabel();
465                                 
466                                 delete order;
467                                 order = input->getSharedOrderVector(lastLabel);
468                                 
469                                 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
470                                 //create collectors curve
471                                 cCurve = new Collect(order, cDisplays);
472                                 cCurve->getSharedCurve(freq);
473                                 delete cCurve;
474                                 
475                                 processedLabels.insert(order->getLabel());
476                                 userLabels.erase(order->getLabel());
477                                 
478                                 //restore real lastlabel to save below
479                                 order->setLabel(saveLabel);
480                         }
481                         
482                         
483                         lastLabel = order->getLabel();                  
484                         
485                         //get next line to process
486                         delete order;
487                         order = input->getSharedOrderVector();
488                 }
489                 
490                 if (m->control_pressed) { 
491                                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }   outputTypes.clear();
492                                         for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
493                                         m->Groups.clear();
494                                         delete input;
495                                         return 0;
496                 }
497                 
498                 //output error messages about any remaining user labels
499                 set<string>::iterator it;
500                 bool needToRun = false;
501                 for (it = userLabels.begin(); it != userLabels.end(); it++) {  
502                         m->mothurOut("Your file does not include the label " + *it); 
503                         if (processedLabels.count(lastLabel) != 1) {
504                                 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
505                                 needToRun = true;
506                         }else {
507                                 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
508                         }
509                 }
510                 
511                 //run last label if you need to
512                 if (needToRun == true)  {
513                         if (order != NULL) {  delete order;  }
514                         order = input->getSharedOrderVector(lastLabel);
515                         
516                         m->mothurOut(order->getLabel()); m->mothurOutEndLine();
517                         cCurve = new Collect(order, cDisplays);
518                         cCurve->getSharedCurve(freq);
519                         delete cCurve;
520                         
521                         if (m->control_pressed) { 
522                                 for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }  outputTypes.clear();
523                                 for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
524                                 delete order; 
525                                 delete input;
526                                 m->Groups.clear();
527                                 return 0;
528                         }
529
530                         delete order;
531                 }
532                 
533                 for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }       
534                 
535                 //reset groups parameter
536                 m->Groups.clear(); 
537                 delete input;
538                 
539                 m->mothurOutEndLine();
540                 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
541                 for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
542                 m->mothurOutEndLine();
543
544                 
545                 return 0;
546         }
547         catch(exception& e) {
548                 m->errorOut(e, "CollectSharedCommand", "execute");
549                 exit(1);
550         }
551 }
552
553 /***********************************************************/