]> git.donarmstrong.com Git - mothur.git/blob - errorchecking.cpp
working on libshuff
[mothur.git] / errorchecking.cpp
1 /*
2  *  errorchecking.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 "errorchecking.h"
11
12 /*******************************************************/
13
14 /******************************************************/
15
16 ErrorCheck::ErrorCheck() {
17         globaldata = GlobalData::getInstance();
18         validCommand = new ValidCommands();
19         validParameter = new ValidParameters();
20 }
21 /*******************************************************/
22
23 /******************************************************/
24
25 void ErrorCheck::refresh() {
26         columnfile = globaldata->getColumnFile();
27         phylipfile = globaldata->getPhylipFile();
28         listfile = globaldata->getListFile();
29         rabundfile = globaldata->getRabundFile();
30         sabundfile = globaldata->getSabundFile();
31         namefile = globaldata->getNameFile();
32         groupfile = globaldata->getGroupFile();
33         orderfile = globaldata->getOrderFile();
34         fastafile = globaldata->getFastaFile();
35         treefile = globaldata->getTreeFile();
36         cutoff = globaldata->getCutOff();
37         format = globaldata->getFormat();
38         method = globaldata->getMethod();
39         randomtree = globaldata->getRandomTree();
40         sharedfile = globaldata->getSharedFile();
41
42
43         
44 /*      string p[] = {
45                 "phylip",              //0
46                 "column",             //1
47                 "list",               //2
48                 "rabund",             //3
49                 "sabund",             //4
50                 "name",               //5
51                 "order",              //6
52                 "group",              //7
53                 "fasta",              //8
54                 "treefile",           //9
55                 "cutoff",             //10
56                 "precision",          //11
57                 "iters",              //12
58                 "jumble",             //13
59                 "freq",               //14
60                 "method",             //15
61                 "fileroot",           //16
62                 "line",               //17
63                 "label",              //18
64                 "single",             //19
65                 "rarefaction",        //20
66                 "shared",             //21
67                 "summary",            //22
68                 "sharedrarefaction",  //23
69                 "sharedsummary",      //24
70                 "groups",                         //25
71                 "abund",              //26
72                 };
73         
74         string c0[] = {p[0],p[5],p[10],p[11]};
75         string c1[] = {p[2],p[6],p[7]}; 
76         string c2[] = {p[10],p[11],p[15]}; 
77         string c3[] = {p[8]};  
78         string c4[] = {p[14],p[17],p[18],p[19],p[26]};
79         string c5[] = {p[13],p[14],p[17],p[18],p[21],p[25]};
80         string c6[] = {""}; 
81         string c7[] = {""}; 
82         string c8[] = {""}; 
83         string c9[] = {p[12],p[14],p[17],p[18],p[20],p[26]};
84         string c10[] = {p[12],p[13],p[17],p[18],p[23]};
85         string c11[] = {p[17],p[18],p[22],p[26]};   
86         string c12[] =  {p[13],p[17],p[18],p[24]}; 
87         string c13[] = {""};    
88         
89         vector<string> v0 (c0, c0+sizeof(c0)/sizeof(string)); 
90         vector<string> v1 (c1, c1+sizeof(c1)/sizeof(string));
91         vector<string> v2 (c2, c2+sizeof(c2)/sizeof(string));
92         vector<string> v3 (c3, c3+sizeof(c3)/sizeof(string));
93         vector<string> v4 (c4, c4+sizeof(c4)/sizeof(string));
94         vector<string> v5 (c5, c5+sizeof(c5)/sizeof(string));
95         vector<string> v6 (c6, c6+sizeof(c6)/sizeof(string));
96         vector<string> v7 (c7, c7+sizeof(c7)/sizeof(string));
97         vector<string> v8 (c8, c8+sizeof(c8)/sizeof(string));
98         vector<string> v9 (c9, c9+sizeof(c9)/sizeof(string));
99         vector<string> v10 (c10, c10+sizeof(c10)/sizeof(string));
100         vector<string> v11 (c11, c11+sizeof(c11)/sizeof(string));
101         vector<string> v12 (c12, c12+sizeof(c12)/sizeof(string));
102         vector<string> v13 (c13, c13+sizeof(c13)/sizeof(string));
103         
104         vector<vector<string> > allCommands;
105         allCommands.push_back(v0);
106         allCommands.push_back(v1);
107         allCommands.push_back(v2);
108         allCommands.push_back(v3);
109         allCommands.push_back(v4);
110         allCommands.push_back(v5);
111         allCommands.push_back(v6);
112         allCommands.push_back(v7);
113         allCommands.push_back(v8);
114         allCommands.push_back(v9);
115         allCommands.push_back(v10);
116         allCommands.push_back(v11);
117         allCommands.push_back(v12);
118         allCommands.push_back(v13);
119         
120         string commands[] = {
121         "read.dist",          //0
122         "read.otu",           //1
123         "cluster",            //2
124         "deconvolute",        //3
125         "collect.single",     //4
126         "collect.shared",     //5
127         "get.group",          //6
128         "get.label",          //7
129         "get.line",           //8
130         "rarefaction.single", //9
131         "rarefaction.shared", //10
132         "summary.single",     //11
133         "summary.shared",     //12
134         "quit"                //13
135         };
136         
137         for(int i = 0; i < allCommands.size(); i++)
138                 commandParameters[commands[i]] = allCommands.at(i);
139         
140          //{Lowerbound(piSent if no lowerbound), Upperbound(piSent if no upperbound), 1 if only the first 2 values, 0 if greater than, 0 if less than};
141         piSent = 3.14159;
142         double ip0[] = {10, piSent, 0, 1, 0};
143         double ip1[] = {10, piSent, 0, 1, 0};
144         double ip2[] = {0, 1, 1, 0, 0};
145         double ip3[] =  {1, piSent, 0, 0, 0};
146         double ip4[] = {1, piSent, 0, 1, 0};
147         double ip5[] = {5, piSent, 0, 1, 0};
148         
149         vector<double> ipv0 (ip0, ip0+sizeof(ip0)/sizeof(double)); 
150         vector<double> ipv1 (ip1, ip1+sizeof(ip1)/sizeof(double)); 
151         vector<double> ipv2 (ip2, ip2+sizeof(ip2)/sizeof(double)); 
152         vector<double> ipv3 (ip3, ip3+sizeof(ip3)/sizeof(double)); 
153         vector<double> ipv4 (ip4, ip4+sizeof(ip4)/sizeof(double)); 
154         vector<double> ipv5 (ip5, ip5+sizeof(ip5)/sizeof(double));
155
156         intParams[p[11]] = ipv0;
157         intParams[p[12]] = ipv1;
158         intParams[p[13]] = ipv2;
159         intParams[p[14]] = ipv3;
160         intParams[p[17]] = ipv4;
161         intParams[p[26]] = ipv5;   */
162         
163 }
164
165 /*******************************************************/
166
167 /******************************************************/
168
169 ErrorCheck::~ErrorCheck() {}
170
171 /*******************************************************/
172
173 /******************************************************/
174
175 bool ErrorCheck::checkInput(string input) {
176                 errorFree = true;
177                 clear();
178                 
179                 //refresh variable
180                 refresh();
181                 
182                 //get command name and parameters
183                 int openParen = input.find_first_of('(');
184                 int closeParen = input.find_last_of(')');
185
186                 if(openParen != -1 && closeParen != -1){                        
187                         commandName = input.substr(0, openParen);   //commandName contains everything before "("
188                         optionText = input.substr(openParen+1, closeParen-openParen-1); //optionString contains everything between "(" and ")".
189                 }else if (openParen == -1) { //there is no parenthesis
190                         cout << input << " is not a valid command. You are missing the ()." << endl;
191                         return false;
192                 }
193                 
194                 //is it a valid command
195                 if (validCommand->isValidCommand(commandName) != true) { return false; }
196                 
197                 string parameter, value;
198                 
199                 //reads in parameters and values
200                 if((optionText != "") && (commandName != "help")){
201                         while((optionText.find_first_of(',') != -1) && (errorFree)) {  //while there are parameters
202                                 splitAtComma(value, optionText);
203                                 splitAtEquals(parameter, value);
204                                 
205                                 //is it a valid parameter
206                                 if (validParameter->isValidParameter(parameter) != true) { return false; }
207                                 //if(!validCommandParameter(parameter,commandName)) { 
208                                 //      cout << "'" << parameter << "' is not a valid parameter for the " << commandName << " command.\n";
209                                 //      return false; 
210                                 //}
211                                 //if(!validParameterValue(value, parameter)) {
212                                 //      if(parameter.compare("precision") == 0)
213                                 //              cout << "The precision parameter can only take powers of 10 as a value (e.g. 10,1000,1000, etc.)\n";
214                                 //      else {
215                                 /*      vector<double> bounds = intParams[parameter];
216                                         double a = bounds.at(0);
217                                         double b = bounds.at(1);
218                                         double c = bounds.at(2);
219                                         double d = bounds.at(3);
220                                         double e = bounds.at(4);
221                                         cout << "The '" << parameter << "' parameter needs to be ";
222                                         if(c == 1)
223                                                         cout << "either '" << a << "' or '" << b << "'.\n";
224                                         else
225                                         {
226                                                 if(a != piSent)
227                                                 {
228                                                         cout << ">";
229                                                         if(d != 0)
230                                                                 cout << "=";
231                                                         cout << " '" << a << "'";
232                                                 }
233                                                 if(b == piSent)
234                                                         cout << ".\n";
235                                                 else if(a != piSent)
236                                                         cout << " and ";
237                                                 if(b != piSent)
238                                                 {
239                                                         cout << "<";
240                                                         if(e != 0)
241                                                                 cout << "=";
242                                                         cout << " '" << b << ".\n";
243                                                 }
244                                         }
245                                         }
246                                         return false;
247                                 } */
248
249                                 if (parameter == "phylip" )             { phylipfile = value; }
250                                 if (parameter == "column" )             { columnfile = value; }
251                                 if (parameter == "list" )               { listfile = value; }
252                                 if (parameter == "rabund" )             { rabundfile = value; }
253                                 if (parameter == "sabund" )             { sabundfile = value; }
254                                 if (parameter == "name" )               { namefile = value; }
255                                 if (parameter == "order" )              { orderfile = value; }
256                                 if (parameter == "fasta" )              { fastafile = value; }
257                                 if (parameter == "tree" )               { treefile = value; }
258                                 if (parameter == "group" )              { groupfile = value; }
259                                 if (parameter == "shared" )             { sharedfile = value; }
260                                 if (parameter == "cutoff" )                     { cutoff = value; }
261                                 if (parameter == "precision" )          { precision = value; }
262                                 if (parameter == "iters" )                      { iters = value; }
263                                 if (parameter == "jumble" )                     { jumble = value; }
264                                 if (parameter == "freq" )                       { freq = value; }
265                                 if (parameter == "method" )                     { method = value; }
266                                 if (parameter == "fileroot" )           { fileroot = value; }
267                                 if (parameter == "line" )                       { line = value; }
268                                 if (parameter == "label" )                      { label = value; }
269                                 if (parameter == "abund" )          { abund = value; }
270                                 if (parameter == "random" )                     { randomtree = value;   }
271                         }
272                         
273                         //gets the last parameter and value
274                         if (errorFree)  { //gets the last parameter and value
275                                 value = optionText;
276                                 splitAtEquals(parameter, value);
277                                 //is it a valid parameter
278                                 if (validParameter->isValidParameter(parameter) != true) { return false; }
279                         //      if(!validCommandParameter(parameter,commandName)) { 
280                         //              cout << "'" << parameter << "' is not a valid parameter for the " << commandName << " command.\n";
281                         //              return false; 
282                         //      }
283                         /*      if(!validParameterValue(value, parameter)) {
284                                         if(parameter.compare("precision") == 0)
285                                                 cout << "The precision parameter can only take powers of 10 as a value (e.g. 10,1000,1000, etc.)\n";
286                                         else {
287                                         vector<double> bounds = intParams[parameter];
288                                         double a = bounds.at(0);
289                                         double b = bounds.at(1);
290                                         double c = bounds.at(2);
291                                         double d = bounds.at(3);
292                                         double e = bounds.at(4);
293                                         cout << "The '" << parameter << "' parameter needs to be ";
294                                         if(c == 1)
295                                                         cout << "either '" << a << "' or '" << b << "'.\n";
296                                         else
297                                         {
298                                                 if(a != piSent)
299                                                 {
300                                                         cout << ">";
301                                                         if(d != 0)
302                                                                 cout << "=";
303                                                         cout << " '" << a << "'";
304                                                 }
305                                                 if(b == piSent)
306                                                         cout << ".\n";
307                                                 else if(a != piSent)
308                                                         cout << " and ";
309                                                 if(b != piSent)
310                                                 {
311                                                         cout << "<";
312                                                         if(e != 0)
313                                                                 cout << "=";
314                                                         cout << " '" << b << ".\n";
315                                                 }
316                                         }
317                                         }
318                                         return false;
319                                 }*/
320                                 if (parameter == "phylip" )             { phylipfile = value; }
321                                 if (parameter == "column" )             { columnfile = value; }                         
322                                 if (parameter == "list" )               { listfile = value; }
323                                 if (parameter == "rabund" )             { rabundfile = value; }
324                                 if (parameter == "sabund" )             { sabundfile = value; }
325                                 if (parameter == "name" )               { namefile = value; }
326                                 if (parameter == "order" )              { orderfile = value; }
327                                 if (parameter == "group" )              { groupfile = value; }
328                                 if (parameter == "shared" )             { sharedfile = value; }
329                                 if (parameter == "fasta" )              { fastafile = value; }
330                                 if (parameter == "tree" )               { treefile = value; }
331                                 if (parameter == "cutoff" )                     { cutoff = value; }
332                                 if (parameter == "precision" )          { precision = value; }
333                                 if (parameter == "iters" )                      { iters = value; }
334                                 if (parameter == "jumble" )                     { jumble = value; }
335                                 if (parameter == "freq" )                       { freq = value; }
336                                 if (parameter == "method" )                     { method = value; }
337                                 if (parameter == "fileroot" )           { fileroot = value; }
338                                 if (parameter == "line" )                       { line = value; }
339                                 if (parameter == "label" )                      { label = value; }
340                                 if (parameter == "random" )                     { randomtree = value;   }
341                                 if (parameter == "abund" )          { abund = value; }
342                         }
343                 }
344                 
345                 //make sure the user does not use both the line and label parameters
346                 if ((line != "") && (label != "")) { cout << "You may use either the line or label parameters, but not both." << endl; return false; }
347                 
348                 if (commandName == "read.dist") { 
349                         validateReadFiles();
350                         validateReadDist();
351                 }else if (commandName == "read.otu") { 
352                         //you want to do shared commands
353                         if ((listfile != "") && (groupfile != ""))      {
354                                 validateParseFiles(); //checks the listfile and groupfile parameters
355                         }else if (listfile != "") { //you want to do single commands
356                                 validateReadFiles();
357                                 validateReadPhil();
358                         }else if ((listfile == "") && (sharedfile == "")) {
359                                 cout << "You must enter either a listfile or a sharedfile with the read.otu command. " << endl; return false; 
360                         }else{//you are reading a shared file
361                                 validateReadFiles();
362                         }
363                 }else if (commandName == "read.tree") { 
364                         validateTreeFiles(); //checks the treefile and groupfile parameters
365                 }else if (commandName == "deconvolute") {
366                         if (fastafile == "") { cout << "You must enter a fastafile with the deconvolute() command." << endl; return false; }
367                         validateReadFiles();
368                 }
369                 
370                 //are you trying to cluster before you have read something                      
371                 if (((commandName == "cluster") && (globaldata->gSparseMatrix == NULL)) ||
372                         ((commandName == "cluster") && (globaldata->gListVector == NULL))) {
373                                 cout << "Before you use the cluster command, you first need to read in a distance matrix." << endl; 
374                                 errorFree = false;
375                 } 
376                 
377                 if ((commandName == "libshuff") && (globaldata->gMatrix == NULL)) {
378                          cout << "You must read in a matrix before you use the libshuff command. " << endl; return false; 
379                 }
380                 
381                 if (commandName == "parsimony") {
382                         //are you trying to use parsimony without reading a tree or saying you want random distribution
383                         if (randomtree == "")  {
384                                 if (globaldata->gTree.size() == 0) {
385                                         cout << "You must read a treefile and a groupfile or set the randomtree parameter to the output filename you wish, before you may execute the parsimony command." << endl; return false;  }
386                         }
387                 }
388                 
389                 if ((commandName == "unifrac.weighted") || (commandName == "unifrac.unweighted")) {
390                         if (globaldata->gTree.size() == 0) {//no trees were read
391                                 cout << "You must execute the read.tree command, before you may execute the unifrac.weighted or unifrac.unweighted command." << endl; return false;  }
392                 }
393                 
394                 //check for valid method
395                 if(commandName == "get.group") {
396                         if ((globaldata->getGroupFile() == "")) { cout << "You must read a group before you can use the get.group command." << endl; return false; }
397                 }
398                 if (commandName == "get.label" || commandName == "get.line") {
399                         if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { cout << "You must read a list, sabund or rabund before you can use the get.label or get.line command." << endl; return false; }
400                 }
401                 if (commandName == "cluster") {
402                         if ((method == "furthest") || (method == "nearest") || (method == "average")) { }
403                         else {cout << "Not a valid clustering method.  Valid clustering algorithms are furthest, nearest or average." << endl; return false; }
404                 }
405                 
406                 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single") ){ 
407                         if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { cout << "You must read a list, sabund or rabund before you can use the collect.single, rarefaction.single or summary.single commands." << endl; return false; }
408                 }
409                 
410                 if ((commandName == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") ){ 
411                         if (globaldata->getSharedFile() == "") {
412                                 if (globaldata->getListFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared or summary.shared commands." << endl; return false; }
413                                 else if (globaldata->getGroupFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared or summary.shared commands." << endl; return false; }
414                         }
415                 }
416
417                 return errorFree;
418 }
419
420 /*******************************************************/
421
422 /******************************************************/
423 //This function checks to make sure the user entered a file to 
424 // read and that the file exists and can be opened.
425 void ErrorCheck::validateReadFiles() {
426         try {
427                 //Validating files for read
428                 ifstream filehandle;
429                 int ableToOpen;
430         
431                 //are we reading a phylipfile
432                 if (phylipfile != "") {
433                         ableToOpen = openInputFile(phylipfile, filehandle);
434                         filehandle.close();
435                         //unable to open
436                         if (ableToOpen == 1) { errorFree = false; }
437                         else { globaldata->inputFileName = phylipfile; }
438                 //are we reading a columnfile
439                 }else if (columnfile != "") {
440                         ableToOpen = openInputFile(columnfile, filehandle);
441                         filehandle.close();
442                         //unable to open
443                         if (ableToOpen == 1) { errorFree = false; }
444                         else { globaldata->inputFileName = columnfile; }
445                 //are we reading a listfile
446                 }else if (listfile!= "") {
447                         ableToOpen = openInputFile(listfile, filehandle);
448                         filehandle.close();
449                         //unable to open
450                         if (ableToOpen == 1) {  errorFree = false; }
451                         else { globaldata->inputFileName = listfile; }
452                 //are we reading a rabundfile
453                 }else if (rabundfile != "") {
454                         ableToOpen = openInputFile(rabundfile, filehandle);
455                         filehandle.close();
456                         //unable to open
457                         if (ableToOpen == 1) {  errorFree = false; }
458                         else { globaldata->inputFileName = rabundfile; }
459                 //are we reading a sabundfile
460                 }else if (sabundfile != "") {
461                         ableToOpen = openInputFile(sabundfile, filehandle);
462                         filehandle.close();
463                         //unable to open
464                         if (ableToOpen == 1) {  errorFree = false; }
465                         else { globaldata->inputFileName = sabundfile; }
466                 }else if (fastafile != "") {
467                         ableToOpen = openInputFile(fastafile, filehandle);
468                         filehandle.close();
469                         //unable to open
470                         if (ableToOpen == 1) {  errorFree = false; }
471                         else { globaldata->inputFileName = fastafile; }
472                 }else if (sharedfile != "") {
473                         ableToOpen = openInputFile(sharedfile, filehandle);
474                         filehandle.close();
475                         //unable to open
476                         if (ableToOpen == 1) {  errorFree = false; }
477                         else { globaldata->inputFileName = sharedfile; }
478                 }else{ //no file given
479                         errorFree = false;
480                 }
481         }
482         catch(exception& e) {
483                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
484                 exit(1);
485         }
486         catch(...) {
487                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
488                 exit(1);
489         }
490         
491 }
492 /*******************************************************/
493
494 /******************************************************
495 //This function checks to see if the given paramter
496 //is a valid paramter for the given command.
497 bool ErrorCheck::validCommandParameter(string parameter, string commandName) {
498         try {
499                 for(int i = 0; i < commandParameters[commandName].size(); i++)
500                         if(parameter.compare(commandParameters[commandName][i]) == 0)
501                                 return true;
502                 return false;
503         }
504                 
505         catch(exception& e) {
506                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
507                 exit(1);
508         }
509         catch(...) {
510                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
511                 exit(1);
512         }
513 }
514 /*******************************************************/
515
516 /******************************************************
517 //This function checks to see if the given paramter value
518 //is convertable into an int if that parameter requires it.
519 bool ErrorCheck::validParameterValue(string value, string parameter) {
520         try {
521                 int pVal;
522                 if(intParams.count(parameter) == 1)
523                 {
524                         vector<double> bounds = intParams[parameter];
525                         bool valid = convertTest(value, pVal);
526                         if(!valid)
527                                 return false;
528                         if(parameter.compare("precision") == 0)
529                         {
530                                 double logNum = log10((double)pVal);
531                                 double diff = (double)((int)logNum - logNum);
532                                 if(diff != 0)
533                                         return false;
534                         }
535                         double a = bounds.at(0);
536                         double b = bounds.at(1);
537                         double c = bounds.at(2);
538                         double d = bounds.at(3);
539                         double e = bounds.at(4);
540                         bool a0 = pVal > a;
541                         bool a1 = pVal >= a;
542                         bool b0 = pVal < b;
543                         bool b1 = pVal <= b;
544                         
545                         if(c != 1)
546                         {
547                                 if(a == piSent && b == piSent)
548                                         return true;
549                                 if(a != piSent && b == piSent)
550                                 {
551                                         if(d == 0)
552                                                 return a0;
553                                         else
554                                                 return a1;
555                                 }
556                                 else if(a == piSent && b != piSent)
557                                 {
558                                         if(e == 0)
559                                                 return b0;
560                                         else
561                                                 return b1;
562                                 }
563                                 else
564                                 {
565                                         if(d == 0 && e == 0)
566                                                 return (a0 && b0);
567                                         else if(d == 0 && e == 1)
568                                                 return (a0 && b1);
569                                         else if(d == 1 && e == 0)
570                                                 return (a1 && b0);
571                                         else
572                                                 return (a1 && b1);
573                                 }
574                         }
575                         else
576                         {
577                                 if(a == piSent && b == piSent)
578                                         return true;
579                                 if(a != piSent && b == piSent)
580                                         return (pVal == a);
581                                 else if(a == piSent && b != piSent)
582                                         return (pVal == b);
583                                 else
584                                         return (pVal == a || pVal == b);
585                         }
586                 }
587                 return true;
588         }
589                 
590         catch(exception& e) {
591                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
592                 exit(1);
593         }
594         catch(...) {
595                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
596                 exit(1);
597         }
598 }               
599 /*******************************************************/
600
601 /******************************************************/
602 //This function checks to make sure the user entered appropriate
603 // format parameters on a distfile read
604 void ErrorCheck::validateReadDist() {
605         try {
606                 ifstream filehandle;
607                 int ableToOpen;
608                 
609                 if (groupfile != "") {
610                         ableToOpen = openInputFile(groupfile, filehandle);
611                         filehandle.close();
612                         //unable to open
613                         if (ableToOpen == 1) {  errorFree = false; }
614                 }
615                 
616                 if ((phylipfile == "") && (columnfile == "")) { cout << "When executing a read.dist you must enter a phylip or a column." << endl; errorFree = false; }
617                 else if ((phylipfile != "") && (columnfile != "")) { cout << "When executing a read.dist you must enter ONLY ONE of the following: phylip or column." << endl; errorFree = false; }
618                 
619                 if (columnfile != "") {
620                         if (namefile == "") {
621                                 cout << "You need to provide a namefile if you are going to use the column format." << endl;
622                                 errorFree = false; 
623                         }else {
624                                 ableToOpen = openInputFile(namefile, filehandle);
625                                 filehandle.close();
626                                 //unable to open
627                                 if (ableToOpen == 1) { errorFree = false; }
628                         }
629                 }
630         }
631         catch(exception& e) {
632                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadDist. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
633                 exit(1);
634         }
635         catch(...) {
636                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadDist. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
637                 exit(1);
638         }
639 }
640 /*******************************************************/
641
642 /******************************************************/
643 //This function checks to make sure the user entered appropriate
644 // format parameters on a parselistcommand
645 void ErrorCheck::validateParseFiles() {
646         try {
647                 ifstream filehandle;
648                 int ableToOpen;
649                 
650                 //checks for valid files
651         
652                 if (listfile == "") { cout << "When executing a read.otu for groups you must enter a list and a group." << endl; errorFree = false; }
653                 else if (groupfile == "") { cout << "When executing a read.otu for groups you must enter a list and a group." << endl; errorFree = false; }
654         
655                 //checks parameters on the read command
656                 if (listfile != "") {
657                         ableToOpen = openInputFile(listfile, filehandle);
658                         filehandle.close();
659                         if (ableToOpen == 1) { //unable to open
660                                 errorFree = false;
661                         }
662                         if (groupfile != "") {
663                                 ableToOpen = openInputFile(groupfile, filehandle);
664                                 filehandle.close();
665                                 if (ableToOpen == 1) { //unable to open
666                                         errorFree = false;;
667                                 }
668                         }
669                 }
670         }
671         catch(exception& e) {
672                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
673                 exit(1);
674         }
675         catch(...) {
676                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
677                 exit(1);
678         }
679 }
680 /*******************************************************/
681
682 /******************************************************/
683 //This function checks to make sure the user entered appropriate
684 // format parameters on a parselistcommand
685 void ErrorCheck::validateTreeFiles() {
686         try {
687                 ifstream filehandle;
688                 int ableToOpen;
689                 
690                 //checks for valid files
691         
692                 if (treefile == "") { cout << "When executing a read.tree you must enter a treefile and a groupfile." << endl; errorFree = false; }
693                 else if (groupfile == "") { cout << "When executing a read.tree you must enter a treefile and a groupfile." << endl; errorFree = false; }
694         
695                 //checks parameters on the read command
696                 if (treefile != "") {
697                         ableToOpen = openInputFile(treefile, filehandle);
698                         filehandle.close();
699                         if (ableToOpen == 1) { //unable to open
700                                 errorFree = false;
701                         }
702                         if (groupfile != "") {
703                                 ableToOpen = openInputFile(groupfile, filehandle);
704                                 filehandle.close();
705                                 if (ableToOpen == 1) { //unable to open
706                                         errorFree = false;;
707                                 }
708                         }
709                 }
710         }
711         catch(exception& e) {
712                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateTreeFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
713                 exit(1);
714         }
715         catch(...) {
716                 cout << "An unknown error has occurred in the ErrorCheck class function validateTreeFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
717                 exit(1);
718         }
719 }
720
721 /*******************************************************/
722
723 /******************************************************/
724 //This function checks to make sure the user entered appropriate
725 // format parameters on a distfile read
726 void ErrorCheck::validateReadPhil() {
727         try {
728                 ifstream filehandle;
729                 int ableToOpen;
730                 
731                 //checks to make sure only one file type is given
732                 if (listfile != "") { 
733                         if ((rabundfile != "") || (sabundfile != "")) { 
734                                 cout << "When executing a read.otu you must enter ONLY ONE of the following: list, rabund or sabund." << endl; errorFree = false; }
735                 }else if (rabundfile != "") { 
736                         if ((listfile != "") || (sabundfile != "")) { 
737                                 cout << "When executing a read.otu you must enter ONLY ONE of the following: list, rabund or sabund." << endl; errorFree = false; }
738                 }else if (sabundfile != "") { 
739                         if ((listfile != "") || (rabundfile != "")) { 
740                                 cout << "When executing a read.otu you must enter ONLY ONE of the following: list, rabund or sabund." << endl; errorFree = false; }
741                 }else if ((listfile == "") && (rabundfile == "") && (sabundfile == "")) {
742                             cout << "When executing a read.otu you must enter one of the following: list, rabund or sabund." << endl; errorFree = false; 
743                 }
744                 
745                 //checks parameters on the read command
746                 if (orderfile != "") {
747                         ableToOpen = openInputFile(orderfile, filehandle);
748                         filehandle.close();
749                         if (ableToOpen == 1) { //unable to open
750                                 errorFree = false;
751                         }
752                 }       
753         }
754         catch(exception& e) {
755                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
756                 exit(1);
757         }
758         catch(...) {
759                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
760                 exit(1);
761         }
762 }
763 /*******************************************************/
764
765 /******************************************************/
766
767 void ErrorCheck::clear() {
768         //option definitions should go here...
769         phylipfile              =       "";
770         columnfile              =       "";
771         listfile                =       "";
772         rabundfile              =       "";
773         sabundfile              =       "";
774         namefile                =       "";
775         groupfile               =       ""; 
776         orderfile               =       "";
777         sharedfile              =       "";
778         line                    =       "";
779         label                   =       "";
780         method                  =   "furthest";
781 }
782 /*******************************************************/
783
784 /******************************************************/
785