]> git.donarmstrong.com Git - mothur.git/blob - collectcommand.cpp
added getCommandInfoCommand for gui
[mothur.git] / collectcommand.cpp
1 /*
2  *  collectcommand.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 "collectcommand.h"
11 #include "ace.h"
12 #include "sobs.h"
13 #include "nseqs.h"
14 #include "chao1.h"
15 #include "bootstrap.h"
16 #include "simpson.h"
17 #include "simpsoneven.h"
18 #include "invsimpson.h"
19 #include "npshannon.h"
20 #include "shannon.h"
21 #include "smithwilson.h"
22 #include "heip.h"
23 #include "shannoneven.h"
24 #include "jackknife.h"
25 #include "geom.h"
26 #include "qstat.h"
27 #include "logsd.h"
28 #include "bergerparker.h"
29 #include "bstick.h"
30 #include "goodscoverage.h"
31 #include "efron.h"
32 #include "boneh.h"
33 #include "solow.h"
34 #include "shen.h"
35 #include "coverage.h"
36
37
38 //**********************************************************************************************************************
39 vector<string> CollectCommand::setParameters(){ 
40         try {
41                 CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(plist);
42                 CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prabund);
43                 CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(psabund);
44                 CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared);
45                 CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel);
46                 CommandParameter pfreq("freq", "Number", "", "100", "", "", "",false,false); parameters.push_back(pfreq);
47                 CommandParameter pcalc("calc", "Multiple", "sobs-chao-nseqs-coverage-ace-jack-shannon-shannoneven-np_shannon-heip-smithwilson-simpson-simpsoneven-invsimpson-bootstrap-geometric-qstat-logseries-bergerparker-bstick-goodscoverage-efron-boneh-solow-shen", "sobs-chao-ace-jack-shannon-npshannon-simpson", "", "", "",true,false); parameters.push_back(pcalc);
48                 CommandParameter pabund("abund", "Number", "", "10", "", "", "",false,false); parameters.push_back(pabund);
49                 CommandParameter psize("size", "Number", "", "0", "", "", "",false,false); parameters.push_back(psize);
50                 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
51                 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
52                 
53                 vector<string> myArray;
54                 for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
55                 return myArray;
56         }
57         catch(exception& e) {
58                 m->errorOut(e, "CollectCommand", "setParameters");
59                 exit(1);
60         }
61 }
62 //**********************************************************************************************************************
63 string CollectCommand::getHelpString(){ 
64         try {
65                 string helpString = "";
66                 ValidCalculators validCalculator;
67                 helpString += "The collect.single command parameters are list, sabund, rabund, shared, label, freq, calc and abund.  list, sabund, rabund or shared is required unless you have a valid current file. \n";
68                 helpString += "The collect.single command should be in the following format: \n";
69                 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";
70                 helpString += "collect.single(label=yourLabel, iters=yourIters, freq=yourFreq, calc=yourEstimators).\n";
71                 helpString += "Example collect(label=unique-.01-.03, iters=10000, freq=10, calc=sobs-chao-ace-jack).\n";
72                 helpString += "The default values for freq is 100, and calc are sobs-chao-ace-jack-shannon-npshannon-simpson.\n";
73                 helpString += validCalculator.printCalc("single");
74                 helpString += "The label parameter is used to analyze specific labels in your input.\n";
75                 helpString += "Note: No spaces between parameter labels (i.e. freq), '=' and parameters (i.e.yourFreq).\n";
76                 return helpString;
77         }
78         catch(exception& e) {
79                 m->errorOut(e, "CollectCommand", "getHelpString");
80                 exit(1);
81         }
82 }
83 //**********************************************************************************************************************
84 CollectCommand::CollectCommand(){       
85         try {
86                 abort = true; calledHelp = true; 
87                 setParameters();
88                 vector<string> tempOutNames;
89                 outputTypes["sobs"] = tempOutNames;
90                 outputTypes["chao"] = tempOutNames;
91                 outputTypes["nseqs"] = tempOutNames;
92                 outputTypes["coverage"] = tempOutNames;
93                 outputTypes["ace"] = tempOutNames;
94                 outputTypes["jack"] = tempOutNames;
95                 outputTypes["shannon"] = tempOutNames;
96                 outputTypes["shannoneven"] = tempOutNames;
97                 outputTypes["np_shannon"] = tempOutNames;
98                 outputTypes["heip"] = tempOutNames;
99                 outputTypes["smithwilson"] = tempOutNames;
100                 outputTypes["simpson"] = tempOutNames;
101                 outputTypes["simpsoneven"] = tempOutNames;
102                 outputTypes["invsimpson"] = tempOutNames;
103                 outputTypes["bootstrap"] = tempOutNames;
104                 outputTypes["geometric"] = tempOutNames;
105                 outputTypes["qstat"] = tempOutNames;
106                 outputTypes["logseries"] = tempOutNames;
107                 outputTypes["bergerparker"] = tempOutNames;
108                 outputTypes["bstick"] = tempOutNames;
109                 outputTypes["goodscoverage"] = tempOutNames;
110                 outputTypes["efron"] = tempOutNames;
111                 outputTypes["boneh"] = tempOutNames;
112                 outputTypes["solow"] = tempOutNames;
113                 outputTypes["shen"] = tempOutNames;
114         }
115         catch(exception& e) {
116                 m->errorOut(e, "CollectCommand", "CollectCommand");
117                 exit(1);
118         }
119 }
120 //**********************************************************************************************************************
121 CollectCommand::CollectCommand(string option)  {
122         try {
123                 abort = false; calledHelp = false;   
124                 allLines = 1;
125                 
126                 //allow user to run help
127                 if(option == "help") { help(); abort = true; }
128                 
129                 else {
130                         vector<string> myArray = setParameters();
131                         
132                         OptionParser parser(option);
133                         map<string,string> parameters = parser.getParameters();
134                         map<string,string>::iterator it;
135                         
136                         ValidParameters validParameter;
137                 
138                         //check to make sure all parameters are valid for command
139                         for (it = parameters.begin(); it != parameters.end(); it++) { 
140                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
141                         }
142
143                         //initialize outputTypes
144                         vector<string> tempOutNames;
145                         outputTypes["sobs"] = tempOutNames;
146                         outputTypes["chao"] = tempOutNames;
147                         outputTypes["nseqs"] = tempOutNames;
148                         outputTypes["coverage"] = tempOutNames;
149                         outputTypes["ace"] = tempOutNames;
150                         outputTypes["jack"] = tempOutNames;
151                         outputTypes["shannon"] = tempOutNames;
152                         outputTypes["shannoneven"] = tempOutNames;
153                         outputTypes["np_shannon"] = tempOutNames;
154                         outputTypes["heip"] = tempOutNames;
155                         outputTypes["smithwilson"] = tempOutNames;
156                         outputTypes["simpson"] = tempOutNames;
157                         outputTypes["simpsoneven"] = tempOutNames;
158                         outputTypes["invsimpson"] = tempOutNames;
159                         outputTypes["bootstrap"] = tempOutNames;
160                         outputTypes["geometric"] = tempOutNames;
161                         outputTypes["qstat"] = tempOutNames;
162                         outputTypes["logseries"] = tempOutNames;
163                         outputTypes["bergerparker"] = tempOutNames;
164                         outputTypes["bstick"] = tempOutNames;
165                         outputTypes["goodscoverage"] = tempOutNames;
166                         outputTypes["efron"] = tempOutNames;
167                         outputTypes["boneh"] = tempOutNames;
168                         outputTypes["solow"] = tempOutNames;
169                         outputTypes["shen"] = tempOutNames;
170                         
171                         //if the user changes the input directory command factory will send this info to us in the output parameter 
172                         string inputDir = validParameter.validFile(parameters, "inputdir", false);              
173                         if (inputDir == "not found"){   inputDir = "";          }
174                         else {
175                                 string path;
176                                 it = parameters.find("shared");
177                                 //user has given a template file
178                                 if(it != parameters.end()){ 
179                                         path = m->hasPath(it->second);
180                                         //if the user has not given a path then, add inputdir. else leave path alone.
181                                         if (path == "") {       parameters["shared"] = inputDir + it->second;           }
182                                 }
183                                 
184                                 it = parameters.find("rabund");
185                                 //user has given a template file
186                                 if(it != parameters.end()){ 
187                                         path = m->hasPath(it->second);
188                                         //if the user has not given a path then, add inputdir. else leave path alone.
189                                         if (path == "") {       parameters["rabund"] = inputDir + it->second;           }
190                                 }
191                                 
192                                 it = parameters.find("sabund");
193                                 //user has given a template file
194                                 if(it != parameters.end()){ 
195                                         path = m->hasPath(it->second);
196                                         //if the user has not given a path then, add inputdir. else leave path alone.
197                                         if (path == "") {       parameters["sabund"] = inputDir + it->second;           }
198                                 }
199                                 
200                                 it = parameters.find("list");
201                                 //user has given a template file
202                                 if(it != parameters.end()){ 
203                                         path = m->hasPath(it->second);
204                                         //if the user has not given a path then, add inputdir. else leave path alone.
205                                         if (path == "") {       parameters["list"] = inputDir + it->second;             }
206                                 }
207                         }
208                         
209                         //check for required parameters
210                         listfile = validParameter.validFile(parameters, "list", true);
211                         if (listfile == "not open") { listfile = ""; abort = true; }
212                         else if (listfile == "not found") { listfile = ""; }
213                         else {  format = "list"; inputfile = listfile; }
214                         
215                         sabundfile = validParameter.validFile(parameters, "sabund", true);
216                         if (sabundfile == "not open") { sabundfile = ""; abort = true; }        
217                         else if (sabundfile == "not found") { sabundfile = ""; }
218                         else {  format = "sabund"; inputfile = sabundfile; }
219                         
220                         rabundfile = validParameter.validFile(parameters, "rabund", true);
221                         if (rabundfile == "not open") { rabundfile = ""; abort = true; }        
222                         else if (rabundfile == "not found") { rabundfile = ""; }
223                         else {  format = "rabund"; inputfile = rabundfile; }
224                         
225                         sharedfile = validParameter.validFile(parameters, "shared", true);
226                         if (sharedfile == "not open") { sharedfile = ""; abort = true; }        
227                         else if (sharedfile == "not found") { sharedfile = ""; }
228                         else {  format = "sharedfile"; inputfile = sharedfile; }
229                         
230                         
231                         //if the user changes the output directory command factory will send this info to us in the output parameter 
232                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
233                         
234                         if ((sharedfile == "") && (listfile == "") && (rabundfile == "") && (sabundfile == "")) { 
235                                 //is there are current file available for any of these?
236                                 //give priority to shared, then list, then rabund, then sabund
237                                 //if there is a current shared file, use it
238                                 sharedfile = m->getSharedFile(); 
239                                 if (sharedfile != "") { inputfile = sharedfile; format = "sharedfile"; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
240                                 else { 
241                                         listfile = m->getListFile(); 
242                                         if (listfile != "") { inputfile = listfile; format = "list"; m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); }
243                                         else { 
244                                                 rabundfile = m->getRabundFile(); 
245                                                 if (rabundfile != "") { inputfile = rabundfile; format = "rabund"; m->mothurOut("Using " + rabundfile + " as input file for the rabund parameter."); m->mothurOutEndLine(); }
246                                                 else { 
247                                                         sabundfile = m->getSabundFile(); 
248                                                         if (sabundfile != "") { inputfile = sabundfile; format = "sabund"; m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); }
249                                                         else { 
250                                                                 m->mothurOut("No valid current files. You must provide a list, sabund, rabund or shared file before you can use the collect.single command."); m->mothurOutEndLine(); 
251                                                                 abort = true;
252                                                         }
253                                                 }
254                                         }
255                                 }
256                         }
257                         
258                         //check for optional parameter and set defaults
259                         // ...at some point should added some additional type checking...
260                         label = validParameter.validFile(parameters, "label", false);                   
261                         if (label == "not found") { label = ""; }
262                         else { 
263                                 if(label != "all") {  m->splitAtDash(label, labels);  allLines = 0;  }
264                                 else { allLines = 1;  }
265                         }
266                         
267                         //NOTE: if you add new calc options, don't forget to add them to the parameter initialize in setParameters or the gui won't be able to use them
268                         calc = validParameter.validFile(parameters, "calc", false);                     
269                         if (calc == "not found") { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson";  }
270                         else { 
271                                  if (calc == "default")  {  calc = "sobs-chao-ace-jack-shannon-npshannon-simpson";  }
272                         }
273                         m->splitAtDash(calc, Estimators);
274
275                         string temp;
276                         temp = validParameter.validFile(parameters, "freq", false);                     if (temp == "not found") { temp = "100"; }
277                         convert(temp, freq); 
278                         
279                         temp = validParameter.validFile(parameters, "abund", false);            if (temp == "not found") { temp = "10"; }
280                         convert(temp, abund); 
281                         
282                         temp = validParameter.validFile(parameters, "size", false);                     if (temp == "not found") { temp = "0"; }
283                         convert(temp, size); 
284                 }
285                 
286         }
287         catch(exception& e) {
288                 m->errorOut(e, "CollectCommand", "CollectCommand");
289                 exit(1);
290         }                       
291 }
292 //**********************************************************************************************************************
293
294 int CollectCommand::execute(){
295         try {
296                 
297                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
298         
299                 if ((format != "sharedfile")) { inputFileNames.push_back(inputfile);  }
300                 else {  inputFileNames = parseSharedFile(sharedfile);  format = "rabund"; }
301         
302                 for (int p = 0; p < inputFileNames.size(); p++) {
303                         
304                         if (m->control_pressed) {  outputTypes.clear(); for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         }  m->Groups.clear();  return 0; }
305                         
306                         if (outputDir == "") { outputDir += m->hasPath(inputFileNames[p]); }
307                         string fileNameRoot = outputDir + m->getRootName(m->getSimpleName(inputFileNames[p]));
308                         //globaldata->inputFileName = inputFileNames[p];
309                 
310                         if (inputFileNames.size() > 1) {
311                                 m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine();
312                         }
313                 
314                         ValidCalculators validCalculator;
315                         
316                         for (int i=0; i<Estimators.size(); i++) {
317                                 if (validCalculator.isValidCalculator("single", Estimators[i]) == true) { 
318                                         if (Estimators[i] == "sobs") { 
319                                                 cDisplays.push_back(new CollectDisplay(new Sobs(), new OneColumnFile(fileNameRoot+"sobs")));
320                                                 outputNames.push_back(fileNameRoot+"sobs"); outputTypes["sobs"].push_back(fileNameRoot+"sobs");
321                                         }else if (Estimators[i] == "chao") { 
322                                                 cDisplays.push_back(new CollectDisplay(new Chao1(), new ThreeColumnFile(fileNameRoot+"chao")));
323                                                 outputNames.push_back(fileNameRoot+"chao"); outputTypes["chao"].push_back(fileNameRoot+"chao");
324                                         }else if (Estimators[i] == "nseqs") { 
325                                                 cDisplays.push_back(new CollectDisplay(new NSeqs(), new OneColumnFile(fileNameRoot+"nseqs")));
326                                                 outputNames.push_back(fileNameRoot+"nseqs"); outputTypes["nseqs"].push_back(fileNameRoot+"nseqs");
327                                         }else if (Estimators[i] == "coverage") { 
328                                                 cDisplays.push_back(new CollectDisplay(new Coverage(), new OneColumnFile(fileNameRoot+"coverage")));
329                                                 outputNames.push_back(fileNameRoot+"coverage"); outputTypes["coverage"].push_back(fileNameRoot+"coverage");
330                                         }else if (Estimators[i] == "ace") { 
331                                                 cDisplays.push_back(new CollectDisplay(new Ace(abund), new ThreeColumnFile(fileNameRoot+"ace")));
332                                                 outputNames.push_back(fileNameRoot+"ace"); outputTypes["ace"].push_back(fileNameRoot+"ace");
333                                         }else if (Estimators[i] == "jack") { 
334                                                 cDisplays.push_back(new CollectDisplay(new Jackknife(), new ThreeColumnFile(fileNameRoot+"jack")));
335                                                 outputNames.push_back(fileNameRoot+"jack"); outputTypes["jack"].push_back(fileNameRoot+"jack");
336                                         }else if (Estimators[i] == "shannon") { 
337                                                 cDisplays.push_back(new CollectDisplay(new Shannon(), new ThreeColumnFile(fileNameRoot+"shannon")));
338                                                 outputNames.push_back(fileNameRoot+"shannon"); outputTypes["shannon"].push_back(fileNameRoot+"shannon");
339                                         }else if (Estimators[i] == "shannoneven") { 
340                                                 cDisplays.push_back(new CollectDisplay(new ShannonEven(), new OneColumnFile(fileNameRoot+"shannoneven")));
341                                                 outputNames.push_back(fileNameRoot+"shannoneven"); outputTypes["shannoneven"].push_back(fileNameRoot+"shannoneven");
342                                         }else if (Estimators[i] == "npshannon") { 
343                                                 cDisplays.push_back(new CollectDisplay(new NPShannon(), new OneColumnFile(fileNameRoot+"np_shannon")));
344                                                 outputNames.push_back(fileNameRoot+"np_shannon"); outputTypes["np_shannon"].push_back(fileNameRoot+"np_shannon");
345                                         }else if (Estimators[i] == "heip") { 
346                                                 cDisplays.push_back(new CollectDisplay(new Heip(), new OneColumnFile(fileNameRoot+"heip")));
347                                                 outputNames.push_back(fileNameRoot+"heip"); outputTypes["heip"].push_back(fileNameRoot+"heip");
348                                         }else if (Estimators[i] == "smithwilson") { 
349                                                 cDisplays.push_back(new CollectDisplay(new SmithWilson(), new OneColumnFile(fileNameRoot+"smithwilson")));
350                                                 outputNames.push_back(fileNameRoot+"smithwilson"); outputTypes["smithwilson"].push_back(fileNameRoot+"smithwilson");
351                                         }else if (Estimators[i] == "simpson") { 
352                                                 cDisplays.push_back(new CollectDisplay(new Simpson(), new ThreeColumnFile(fileNameRoot+"simpson")));
353                                                 outputNames.push_back(fileNameRoot+"simpson"); outputTypes["simpson"].push_back(fileNameRoot+"simpson");
354                                         }else if (Estimators[i] == "simpsoneven") { 
355                                                 cDisplays.push_back(new CollectDisplay(new SimpsonEven(), new OneColumnFile(fileNameRoot+"simpsoneven")));
356                                                 outputNames.push_back(fileNameRoot+"simpsoneven"); outputTypes["simpsoneven"].push_back(fileNameRoot+"simpsoneven");
357                                         }else if (Estimators[i] == "invsimpson") { 
358                                                 cDisplays.push_back(new CollectDisplay(new InvSimpson(), new ThreeColumnFile(fileNameRoot+"invsimpson")));
359                                                 outputNames.push_back(fileNameRoot+"invsimpson"); outputTypes["invsimpson"].push_back(fileNameRoot+"invsimpson");
360                                         }else if (Estimators[i] == "bootstrap") { 
361                                                 cDisplays.push_back(new CollectDisplay(new Bootstrap(), new OneColumnFile(fileNameRoot+"bootstrap")));
362                                                 outputNames.push_back(fileNameRoot+"bootstrap"); outputTypes["bootstrap"].push_back(fileNameRoot+"bootstrap");
363                                         }else if (Estimators[i] == "geometric") { 
364                                                 cDisplays.push_back(new CollectDisplay(new Geom(), new OneColumnFile(fileNameRoot+"geometric")));
365                                                 outputNames.push_back(fileNameRoot+"geometric"); outputTypes["geometric"].push_back(fileNameRoot+"geometric");
366                                         }else if (Estimators[i] == "qstat") { 
367                                                 cDisplays.push_back(new CollectDisplay(new QStat(), new OneColumnFile(fileNameRoot+"qstat")));
368                                                 outputNames.push_back(fileNameRoot+"qstat"); outputTypes["qstat"].push_back(fileNameRoot+"qstat");
369                                         }else if (Estimators[i] == "logseries") { 
370                                                 cDisplays.push_back(new CollectDisplay(new LogSD(), new OneColumnFile(fileNameRoot+"logseries")));
371                                                 outputNames.push_back(fileNameRoot+"logseries"); outputTypes["logseries"].push_back(fileNameRoot+"logseries");
372                                         }else if (Estimators[i] == "bergerparker") { 
373                                                 cDisplays.push_back(new CollectDisplay(new BergerParker(), new OneColumnFile(fileNameRoot+"bergerparker")));
374                                                 outputNames.push_back(fileNameRoot+"bergerparker"); outputTypes["bergerparker"].push_back(fileNameRoot+"bergerparker");
375                                         }else if (Estimators[i] == "bstick") { 
376                                                 cDisplays.push_back(new CollectDisplay(new BStick(), new ThreeColumnFile(fileNameRoot+"bstick")));
377                                                 outputNames.push_back(fileNameRoot+"bstick"); outputTypes["bstick"].push_back(fileNameRoot+"bstick");
378                                         }else if (Estimators[i] == "goodscoverage") { 
379                                                 cDisplays.push_back(new CollectDisplay(new GoodsCoverage(), new OneColumnFile(fileNameRoot+"goodscoverage")));
380                                                 outputNames.push_back(fileNameRoot+"goodscoverage"); outputTypes["goodscoverage"].push_back(fileNameRoot+"goodscoverage");
381                                         }else if (Estimators[i] == "efron") {
382                                                 cDisplays.push_back(new CollectDisplay(new Efron(size), new OneColumnFile(fileNameRoot+"efron")));
383                                                 outputNames.push_back(fileNameRoot+"efron"); outputTypes["efron"].push_back(fileNameRoot+"efron");
384                                         }else if (Estimators[i] == "boneh") {
385                                                 cDisplays.push_back(new CollectDisplay(new Boneh(size), new OneColumnFile(fileNameRoot+"boneh")));
386                                                 outputNames.push_back(fileNameRoot+"boneh"); outputTypes["boneh"].push_back(fileNameRoot+"boneh");
387                                         }else if (Estimators[i] == "solow") {
388                                                 cDisplays.push_back(new CollectDisplay(new Solow(size), new OneColumnFile(fileNameRoot+"solow")));
389                                                 outputNames.push_back(fileNameRoot+"solow"); outputTypes["solow"].push_back(fileNameRoot+"solow");
390                                         }else if (Estimators[i] == "shen") {
391                                                 cDisplays.push_back(new CollectDisplay(new Shen(size, abund), new OneColumnFile(fileNameRoot+"shen")));
392                                                 outputNames.push_back(fileNameRoot+"shen"); outputTypes["shen"].push_back(fileNameRoot+"shen");
393                                         }
394                                 }
395                         }
396                 
397                         //if the users entered no valid calculators don't execute command
398                         if (cDisplays.size() == 0) { return 0; }
399                         
400                         input = new InputData(inputFileNames[p], format);
401                         order = input->getOrderVector();
402                         string lastLabel = order->getLabel();
403                         
404                         //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
405                         set<string> processedLabels;
406                         set<string> userLabels = labels;
407                         
408                         if (m->control_pressed) {  
409                                 for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
410                                 for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         } outputTypes.clear(); 
411                                 delete input;  
412                                 delete order; 
413                                 m->Groups.clear();
414                                 return 0;
415                         }
416
417
418                         while((order != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
419                         
420                                 if (m->control_pressed) { 
421                                         for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
422                                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         } outputTypes.clear(); 
423                                         delete input;  
424                                         delete order; 
425                                         m->Groups.clear();
426                                         return 0;
427                                 }
428
429                                 
430                                 if(allLines == 1 || labels.count(order->getLabel()) == 1){
431                                 
432                                         m->mothurOut(order->getLabel()); m->mothurOutEndLine();
433                                         cCurve = new Collect(order, cDisplays);
434                                         cCurve->getCurve(freq);
435                                         delete cCurve;
436                                         
437                                         processedLabels.insert(order->getLabel());
438                                         userLabels.erase(order->getLabel());
439                                         
440                                         
441                                 }
442                                 //you have a label the user want that is smaller than this label and the last label has not already been processed 
443                                 if ((m->anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
444                                         string saveLabel = order->getLabel();
445                                         
446                                         delete order;
447                                         order = (input->getOrderVector(lastLabel));
448                                         
449                                         m->mothurOut(order->getLabel()); m->mothurOutEndLine();
450                                         cCurve = new Collect(order, cDisplays);
451                                         cCurve->getCurve(freq);
452                                         delete cCurve;
453                                         
454                                         
455                                         processedLabels.insert(order->getLabel());
456                                         userLabels.erase(order->getLabel());
457                                         
458                                         //restore real lastlabel to save below
459                                         order->setLabel(saveLabel);
460                                 }
461                                 
462                                 lastLabel = order->getLabel();  
463                                 
464                                 delete order;           
465                                 order = (input->getOrderVector());
466                         }
467                         
468                         
469                         if (m->control_pressed) { 
470                                         for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
471                                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         } outputTypes.clear(); 
472                                         delete input;  
473                                         m->Groups.clear();
474                                         return 0;
475                         }
476                                 
477                         //output error messages about any remaining user labels
478                         set<string>::iterator it;
479                         bool needToRun = false;
480                         for (it = userLabels.begin(); it != userLabels.end(); it++) {  
481                                 m->mothurOut("Your file does not include the label " + *it); 
482                                 if (processedLabels.count(lastLabel) != 1) {
483                                         m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
484                                         needToRun = true;
485                                 }else {
486                                         m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
487                                 }
488                         }
489                         
490                         //run last label if you need to
491                         if (needToRun == true)  {
492                                 if (order != NULL) {    delete order;   }
493                                 order = (input->getOrderVector(lastLabel));
494                                 
495                                 m->mothurOut(order->getLabel()); m->mothurOutEndLine();
496                                 
497                                 cCurve = new Collect(order, cDisplays);
498                                 cCurve->getCurve(freq);
499                                 delete cCurve;
500                                 
501                                 if (m->control_pressed) { 
502                                         for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
503                                         for (int i = 0; i < outputNames.size(); i++) {  remove(outputNames[i].c_str());         } outputTypes.clear(); 
504                                         delete input;  
505                                         delete order;
506                                         m->Groups.clear();
507                                         return 0;
508                                 }
509                                 delete order;
510                         }
511                         
512                         for(int i=0;i<cDisplays.size();i++){    delete cDisplays[i];    }
513                         cDisplays.clear();
514                         delete input;  
515                 }
516                 
517                 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        remove(outputNames[i].c_str());         } return 0; }
518                                 
519                 m->mothurOutEndLine();
520                 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
521                 for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
522                 m->mothurOutEndLine();
523
524                 
525                 return 0;
526         }
527         catch(exception& e) {
528                 m->errorOut(e, "CollectCommand", "execute");
529                 exit(1);
530         }
531 }
532
533 //**********************************************************************************************************************
534 vector<string> CollectCommand::parseSharedFile(string filename) {
535         try {
536                 vector<string> filenames;
537                 
538                 map<string, ofstream*> filehandles;
539                 map<string, ofstream*>::iterator it3;
540                                         
541                 input = new InputData(filename, "sharedfile");
542                 vector<SharedRAbundVector*> lookup = input->getSharedRAbundVectors();
543                 
544                 string sharedFileRoot = m->getRootName(filename);
545                 
546                 //clears file before we start to write to it below
547                 for (int i=0; i<lookup.size(); i++) {
548                         remove((sharedFileRoot + lookup[i]->getGroup() + ".rabund").c_str());
549                         filenames.push_back((sharedFileRoot + lookup[i]->getGroup() + ".rabund"));
550                 }
551                 
552                 ofstream* temp;
553                 for (int i=0; i<lookup.size(); i++) {
554                         temp = new ofstream;
555                         filehandles[lookup[i]->getGroup()] = temp;
556                         groups.push_back(lookup[i]->getGroup());
557                 }
558
559                 while(lookup[0] != NULL) {
560                 
561                         for (int i = 0; i < lookup.size(); i++) {
562                                 RAbundVector rav = lookup[i]->getRAbundVector();
563                                 m->openOutputFileAppend(sharedFileRoot + lookup[i]->getGroup() + ".rabund", *(filehandles[lookup[i]->getGroup()]));
564                                 rav.print(*(filehandles[lookup[i]->getGroup()]));
565                                 (*(filehandles[lookup[i]->getGroup()])).close();
566                         }
567                 
568                         for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
569                         lookup = input->getSharedRAbundVectors();
570                 }
571                 
572                 //free memory
573                 for (it3 = filehandles.begin(); it3 != filehandles.end(); it3++) {
574                         delete it3->second;
575                 }
576                 
577                 delete input;
578
579                 return filenames;
580         }
581         catch(exception& e) {
582                 m->errorOut(e, "CollectCommand", "parseSharedFile");
583                 exit(1);
584         }
585 }
586 //**********************************************************************************************************************
587