]> git.donarmstrong.com Git - mothur.git/blob - errorchecking.cpp
e4c1877907e272c89a0be023ec21ad6bf2947f50
[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
27         //columnfile = globaldata->getColumnFile();
28         //phylipfile = globaldata->getPhylipFile();
29         //listfile = globaldata->getListFile();
30         //rabundfile = globaldata->getRabundFile();
31         //sabundfile = globaldata->getSabundFile();
32         //namefile = globaldata->getNameFile();
33         //groupfile = globaldata->getGroupFile();
34         //orderfile = globaldata->getOrderFile();
35         //fastafile = globaldata->getFastaFile();
36         //treefile = globaldata->getTreeFile();
37         //cutoff = globaldata->getCutOff();
38         //format = globaldata->getFormat();
39         //method = globaldata->getMethod();
40         //randomtree = globaldata->getRandomTree();
41         //sharedfile = globaldata->getSharedFile();
42
43 }
44
45 /*******************************************************/
46
47 /******************************************************/
48
49 ErrorCheck::~ErrorCheck() {
50         delete validCommand;
51         delete validParameter;
52 }
53
54 /*******************************************************/
55
56 /******************************************************/
57
58 bool ErrorCheck::checkInput(string input) {
59                 errorFree = true;
60                 clear();
61                 
62                 //refresh variable
63                 refresh();
64                 
65                 //get command name and parameters
66                 int openParen = input.find_first_of('(');
67                 int closeParen = input.find_last_of(')');
68
69                 if(openParen != -1 && closeParen != -1){                        
70                         commandName = input.substr(0, openParen);   //commandName contains everything before "("
71                         optionText = input.substr(openParen+1, closeParen-openParen-1); //optionString contains everything between "(" and ")".
72                 }else if (openParen == -1) { //there is no parenthesis
73                         cout << input << " is not a valid command. You are missing the ()." << endl;
74                         return false;
75                 }
76                 
77                 //is it a valid command
78                 if (validCommand->isValidCommand(commandName) != true) { return false; }
79                 string parameter, value;
80                 
81                 //reads in parameters and values
82                 if((optionText != "") && (commandName != "help")){
83                         while((optionText.find_first_of(',') != -1) && (errorFree)) {  //while there are parameters
84                                 splitAtComma(value, optionText);
85                                 splitAtEquals(parameter, value);
86                                 
87                                 //is it a valid parameter
88                                 if (validParameter->isValidParameter(parameter, commandName, value) != true) { return false; }
89                                 
90                                 if (parameter == "phylip" )             { phylipfile = value; }
91                                 if (parameter == "column" )             { columnfile = value; }
92                                 if (parameter == "list" )               { listfile = value; }
93                                 if (parameter == "rabund" )             { rabundfile = value; }
94                                 if (parameter == "sabund" )             { sabundfile = value; }
95                                 if (parameter == "name" )               { namefile = value; }
96                                 if (parameter == "order" )              { orderfile = value; }
97                                 if (parameter == "fasta" )              { fastafile = value; }
98                                 if (parameter == "nexus" )              { nexusfile = value; }
99                                 if (parameter == "clustal" )    { clustalfile = value; }
100                                 if (parameter == "tree" )               { treefile = value; }
101                                 if (parameter == "group" )                      { groupfile = value; }
102                                 if (parameter == "shared" )                     { sharedfile = value; }
103                                 if (parameter == "cutoff" )                     { cutoff = value; }
104                                 if (parameter == "precision" )          { precision = value; }
105                                 if (parameter == "iters" )                      { iters = value; }
106                                 if (parameter == "jumble" )                     { jumble = value; }
107                                 if (parameter == "freq" )                       { freq = value; }
108                                 if (parameter == "method" )                     { method = value; }
109                                 if (parameter == "fileroot" )           { fileroot = value; }
110                                 if (parameter == "line" )                       { line = value; }
111                                 if (parameter == "label" )                      { label = value; }
112                                 if (parameter == "abund" )          { abund = value; }
113                                 if (parameter == "random" )                     { randomtree = value; }
114                                 if (parameter == "sorted" )                     { sorted = value; }
115                                 if (parameter == "trump" )          { trump = value; }
116                                 if (parameter == "soft" )                       { soft = value; }
117                                 if (parameter == "filter" )         { filter = value; }
118                                 if (parameter == "scale" )                      { scale = value;        }
119                                 if (parameter == "countends" )          { countends = value; }
120                                 if (parameter == "processors" )         { processors = value;   }
121                                 if (parameter == "size" )                       { size = value; }
122                                 if (parameter == "candidate")           { candidatefile = value;        }
123                                 if (parameter == "search")                      { search = value;               }
124                                 if (parameter == "ksize")                       { ksize = value;                }
125                                 if (parameter == "align")                   { align = value;            }
126                                 if (parameter == "match")                       { match = value;                }
127                                 if (parameter == "mismatch")            { mismatch = value;         }
128                                 if (parameter == "gapopen")                     { gapopen = value;              }
129                                 if (parameter == "gapextend" )          { gapextend = value;    }
130                         }
131                         
132                         //gets the last parameter and value
133                         if (errorFree)  { //gets the last parameter and value
134                                 value = optionText;
135                                 splitAtEquals(parameter, value);
136                                 //is it a valid parameter
137                                 if (validParameter->isValidParameter(parameter, commandName, value) != true) { return false; }
138         
139                                 
140                                 if (parameter == "phylip" )             { phylipfile = value; }
141                                 if (parameter == "column" )             { columnfile = value; }                         
142                                 if (parameter == "list" )               { listfile = value; }
143                                 if (parameter == "rabund" )             { rabundfile = value; }
144                                 if (parameter == "sabund" )             { sabundfile = value; }
145                                 if (parameter == "name" )               { namefile = value; }
146                                 if (parameter == "order" )              { orderfile = value; }
147                                 if (parameter == "group" )              { groupfile = value; }
148                                 if (parameter == "shared" )             { sharedfile = value; }
149                                 if (parameter == "fasta" )              { fastafile = value; }
150                                 if (parameter == "nexus" )              { nexusfile = value; }
151                                 if (parameter == "clustal" )    { clustalfile = value; }
152                                 if (parameter == "tree" )               { treefile = value; }
153                                 if (parameter == "cutoff" )                     { cutoff = value; }
154                                 if (parameter == "precision" )          { precision = value; }
155                                 if (parameter == "iters" )                      { iters = value; }
156                                 if (parameter == "jumble" )                     { jumble = value; }
157                                 if (parameter == "freq" )                       { freq = value; }
158                                 if (parameter == "method" )                     { method = value; }
159                                 if (parameter == "fileroot" )           { fileroot = value; }
160                                 if (parameter == "line" )                       { line = value; }
161                                 if (parameter == "label" )                      { label = value; }
162                                 if (parameter == "random" )                     { randomtree = value;   }
163                                 if (parameter == "abund" )          { abund = value; }
164                                 if (parameter == "sorted" )                     { sorted = value;       }
165                                 if (parameter == "trump" )          { trump = value; }
166                                 if (parameter == "soft" )                       { soft = value; }
167                                 if (parameter == "filter" )         { filter = value; }
168                                 if (parameter == "scale" )                      { scale = value;        }
169                                 if (parameter == "countends" )          { countends = value; }
170                                 if (parameter == "processors" )         { processors = value;   }
171                                 if (parameter == "size" )                       { size = value; }
172                                 if (parameter == "candidate")           { candidatefile = value;        }
173                                 if (parameter == "search")                      { search = value;               }
174                                 if (parameter == "ksize")                       { ksize = value;                }
175                                 if (parameter == "align")                   { align = value;            }
176                                 if (parameter == "match")                       { match = value;                }
177                                 if (parameter == "mismatch")            { mismatch = value;         }
178                                 if (parameter == "gapopen")                     { gapopen = value;              }
179                                 if (parameter == "gapextend" )          { gapextend = value;    }
180                                 
181                         }
182                 }
183                 
184                 //make sure the user does not use both the line and label parameters
185                 if ((line != "") && (label != "")) { cout << "You may use either the line or label parameters, but not both." << endl; return false; }
186                 
187                 //check for valid files 
188                 if (commandName == "read.dist") { 
189                         validateReadFiles();
190                         validateReadDist();
191                 }else if (commandName == "read.otu") { 
192                         //you want to do shared commands
193                         if ((listfile != "") && (groupfile != ""))      {
194                                 validateParseFiles(); //checks the listfile and groupfile parameters
195                         //you want to do single commands
196                         }else if ((listfile != "") || (rabundfile != "") || (sabundfile != "")){ 
197                                 validateReadFiles();
198                                 validateReadPhil();
199                         //you have not given a file
200                         }else if ((listfile == "") && (sharedfile == "") && (rabundfile == "") && (sabundfile == "")) {
201                                 cout << "You must enter either a listfile, rabundfile, sabundfile or a sharedfile with the read.otu command. " << endl; return false; 
202                         //you want to do shared commands with a shared file
203                         }else if (sharedfile != "") {//you are reading a shared file
204                                 validateReadFiles();
205                         }
206                 }else if (commandName == "read.tree") { 
207                         validateTreeFiles(); //checks the treefile and groupfile parameters
208                 }else if (commandName == "deconvolute") {
209                         if (fastafile == "") { cout << "You must enter a fastafile with the deconvolute() command." << endl; return false; }
210                         validateReadFiles();
211                 }
212                 
213                 //are you trying to cluster before you have read something      
214                 if (((commandName == "cluster") && (globaldata->gSparseMatrix == NULL)) ||
215                         ((commandName == "cluster") && (globaldata->gListVector == NULL))) {
216                                 cout << "Before you use the cluster command, you first need to read in a distance matrix." << endl; 
217                                 errorFree = false;
218                 } 
219                 
220                 if ((commandName == "libshuff") && ((globaldata->gMatrix == NULL) || (globaldata->gGroupmap == NULL))) {
221                          cout << "You must read in a matrix and groupfile using the read.dist command, before you use the libshuff command. " << endl; return false; 
222                 }
223                 
224                 if (commandName == "parsimony") {
225                         //are you trying to use parsimony without reading a tree or saying you want random distribution
226                         if (randomtree == "")  {
227                                 if (globaldata->gTree.size() == 0) {
228                                         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;  }
229                         }
230                 }
231                 
232                 if ((commandName == "unifrac.weighted") || (commandName == "unifrac.unweighted") || (commandName == "concensus")) {
233                         if (globaldata->gTree.size() == 0) {//no trees were read
234                                 cout << "You must execute the read.tree command, before you may execute the unifrac.weighted, unifrac.unweighted or concensus command." << endl; return false;  }
235                 }
236                 
237                 //check for valid method
238                 if(commandName == "get.group") {
239                         if ((globaldata->getSharedFile() == "")) { cout << "You must read a groupfile or a sharedfile before you can use the get.group command." << endl; return false; }
240                 }
241                 if (commandName == "get.label" || commandName == "get.line") {
242                         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; }
243                 }
244                 if (commandName == "cluster") {
245                         if ((method == "furthest") || (method == "nearest") || (method == "average")) { }
246                         else {cout << "Not a valid clustering method.  Valid clustering algorithms are furthest, nearest or average." << endl; return false; }
247                 }
248                 
249                 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single") ){ 
250                         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; }
251                 }
252                 
253                 if ((commandName == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") || (commandName == "bootstrap.shared") || (commandName == "dist.shared")){ 
254                         if (globaldata->getSharedFile() == "") {
255                                 if (globaldata->getListFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared, summary.shared, tree.shared, bootstrap.shared or dist.shared commands." << endl; return false; }
256                                 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, summary.shared, tree.shared, bootstrap.shared or dist.shared commands." << endl; return false; }
257                         }
258                 }
259                 
260                 if  (commandName == "tree.shared")  {
261                         //given no files                        
262                         if ((globaldata->getSharedFile() == "") && ((phylipfile == "") && (columnfile == "")))  { cout << "You must run the read.otu command or provide a distance file before running the tree.shared command." << endl; return false; }
263                         //you want to do single commands
264                         else if ((globaldata->getSharedFile() == "") && ((phylipfile != "") || (columnfile != ""))) {
265                                 validateReadDist();
266                         }
267                 }
268                 
269                 if ((commandName == "heatmap") || (commandName == "venn")) { 
270                         if ((globaldata->getListFile() == "") && (globaldata->getSharedFile() == "")) {
271                                  cout << "You must read a list, or a list and a group, or a shared before you can use the heatmap or venn commands." << endl; return false; 
272                         }
273                 }
274                 
275                 if ((commandName == "filter.seqs") || (commandName == "dist.seqs")) { 
276                         if ((fastafile == "") && (nexusfile == "") && (clustalfile == "") && (phylipfile == "")) {
277                                  cout << "You must enter either a fasta, nexus, clustal, or phylip file before you can use the filter.seqs or dist.seqs command." << endl; return false; 
278                         }
279                         validateSeqsFiles();
280                 }
281                 
282                 if (commandName == "align.seqs") {
283                         if ((fastafile == "") || (candidatefile == "")) {
284                                 cout << "You must enter fasta and a candidate file to use the align.seqs command." << endl; return false; 
285                         }
286                         validateSeqsFiles();
287                 }
288                 
289                 if ((commandName == "bin.seqs")) { 
290                         if ((globaldata->getListFile() == "")) { cout << "You must read a list file before you can use the bin.seqs commands." << endl; return false; }
291                         validateBinFiles();
292                 }
293                 
294                 
295                 if ((commandName == "get.oturep")) { 
296                         if ((globaldata->gSparseMatrix == NULL) || (globaldata->gListVector == NULL)) {
297                                 cout << "Before you use the get.oturep command, you first need to read in a distance matrix." << endl; 
298                                 errorFree = false;
299                         }
300                         if (listfile == "") { cout << "list is a required parameter for the get.oturep command." << endl; errorFree = false; }
301                         validateBinFiles();
302                 } 
303
304
305                 return errorFree;
306 }
307
308 /*******************************************************/
309
310 /******************************************************/
311 //This function checks to make sure the user entered a file to 
312 // read and that the file exists and can be opened.
313 void ErrorCheck::validateReadFiles() {
314         try {
315                 //Validating files for read
316                 ifstream filehandle;
317                 int ableToOpen;
318         
319                 //are we reading a phylipfile
320                 if (phylipfile != "") {
321                         ableToOpen = openInputFile(phylipfile, filehandle);
322                         filehandle.close();
323                         //unable to open
324                         if (ableToOpen == 1) { errorFree = false; }
325                         else { globaldata->inputFileName = phylipfile; }
326                 //are we reading a columnfile
327                 }else if (columnfile != "") {
328                         ableToOpen = openInputFile(columnfile, filehandle);
329                         filehandle.close();
330                         //unable to open
331                         if (ableToOpen == 1) { errorFree = false; }
332                         else { globaldata->inputFileName = columnfile; }
333                 //are we reading a listfile
334                 }else if (listfile!= "") {
335                         ableToOpen = openInputFile(listfile, filehandle);
336                         filehandle.close();
337                         //unable to open
338                         if (ableToOpen == 1) {  errorFree = false; }
339                         else { globaldata->inputFileName = listfile; }
340                 //are we reading a rabundfile
341                 }else if (rabundfile != "") {
342                         ableToOpen = openInputFile(rabundfile, filehandle);
343                         filehandle.close();
344                         //unable to open
345                         if (ableToOpen == 1) {  errorFree = false; }
346                         else { globaldata->inputFileName = rabundfile; }
347                 //are we reading a sabundfile
348                 }else if (sabundfile != "") {
349                         ableToOpen = openInputFile(sabundfile, filehandle);
350                         filehandle.close();
351                         //unable to open
352                         if (ableToOpen == 1) {  errorFree = false; }
353                         else { globaldata->inputFileName = sabundfile; }
354                 }else if (fastafile != "") {
355                         ableToOpen = openInputFile(fastafile, filehandle);
356                         filehandle.close();
357                         //unable to open
358                         if (ableToOpen == 1) {  errorFree = false; }
359                         else { globaldata->inputFileName = fastafile; }
360                 }else if (sharedfile != "") {
361                         ableToOpen = openInputFile(sharedfile, filehandle);
362                         filehandle.close();
363                         //unable to open
364                         if (ableToOpen == 1) {  errorFree = false; }
365                         else { globaldata->inputFileName = sharedfile; }
366                 }else if (groupfile != "") {
367                         ableToOpen = openInputFile(groupfile, filehandle);
368                         filehandle.close();
369                         if (ableToOpen == 1) { //unable to open
370                                 errorFree = false;
371                         }
372                 }else{ //no file given
373                         errorFree = false;
374                 }
375         }
376         catch(exception& e) {
377                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
378                 exit(1);
379         }
380         catch(...) {
381                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
382                 exit(1);
383         }
384         
385 }
386 /*******************************************************/
387
388 /******************************************************/
389 //This function checks to make sure the user entered appropriate
390 // format parameters on a distfile read
391 void ErrorCheck::validateReadDist() {
392         try {
393                 ifstream filehandle;
394                 int ableToOpen;
395                 
396                 if (groupfile != "") {
397                         ableToOpen = openInputFile(groupfile, filehandle);
398                         filehandle.close();
399                         //unable to open
400                         if (ableToOpen == 1) {  errorFree = false; }
401                 }
402                 
403                 if ((phylipfile == "") && (columnfile == "")) { cout << "When executing a read.dist or a tree.shared command with a distance file you must enter a phylip or a column." << endl; errorFree = false; }
404                 else if ((phylipfile != "") && (columnfile != "")) { cout << "When executing a read.dist or a tree.shared command with a distance file you must enter ONLY ONE of the following: phylip or column." << endl; errorFree = false; }
405                 
406                 if (columnfile != "") {
407                         if (namefile == "") {
408                                 cout << "You need to provide a namefile if you are going to use the column format." << endl;
409                                 errorFree = false; 
410                         }else {
411                                 ableToOpen = openInputFile(namefile, filehandle);
412                                 filehandle.close();
413                                 //unable to open
414                                 if (ableToOpen == 1) { errorFree = false; }
415                         }
416                 }
417         }
418         catch(exception& e) {
419                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadDist. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
420                 exit(1);
421         }
422         catch(...) {
423                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadDist. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
424                 exit(1);
425         }
426 }
427 /*******************************************************/
428
429 /******************************************************/
430 //This function checks to make sure the user entered appropriate
431 // format parameters on a parselistcommand
432 void ErrorCheck::validateParseFiles() {
433         try {
434                 ifstream filehandle;
435                 int ableToOpen;
436                 
437                 //checks for valid files
438         
439                 if (listfile == "") { cout << "When executing a read.otu for groups you must enter a list and a group." << endl; errorFree = false; }
440                 else if (groupfile == "") { cout << "When executing a read.otu for groups you must enter a list and a group." << endl; errorFree = false; }
441         
442                 //checks parameters on the read command
443                 if (listfile != "") {
444                         ableToOpen = openInputFile(listfile, filehandle);
445                         filehandle.close();
446                         if (ableToOpen == 1) { //unable to open
447                                 errorFree = false;
448                         }
449                         if (groupfile != "") {
450                                 ableToOpen = openInputFile(groupfile, filehandle);
451                                 filehandle.close();
452                                 if (ableToOpen == 1) { //unable to open
453                                         errorFree = false;
454                                 }
455                         }
456                 }
457         }
458         catch(exception& e) {
459                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
460                 exit(1);
461         }
462         catch(...) {
463                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
464                 exit(1);
465         }
466 }
467 /*******************************************************/
468
469 /******************************************************/
470 //This function checks to make sure the user entered appropriate
471 // format parameters on a parselistcommand
472 void ErrorCheck::validateTreeFiles() {
473         try {
474                 ifstream filehandle;
475                 int ableToOpen;
476                 
477                 //checks for valid files
478         
479                 if (treefile == "") { cout << "When executing a read.tree you must enter a treefile and a groupfile." << endl; errorFree = false; }
480                 else if (groupfile == "") { cout << "When executing a read.tree you must enter a treefile and a groupfile." << endl; errorFree = false; }
481         
482                 //checks parameters on the read command
483                 if (treefile != "") {
484                         ableToOpen = openInputFile(treefile, filehandle);
485                         filehandle.close();
486                         if (ableToOpen == 1) { //unable to open
487                                 errorFree = false;
488                         }
489                         if (groupfile != "") {
490                                 ableToOpen = openInputFile(groupfile, filehandle);
491                                 filehandle.close();
492                                 if (ableToOpen == 1) { //unable to open
493                                         errorFree = false;;
494                                 }
495                         }
496                 }
497         }
498         catch(exception& e) {
499                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateTreeFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
500                 exit(1);
501         }
502         catch(...) {
503                 cout << "An unknown error has occurred in the ErrorCheck class function validateTreeFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
504                 exit(1);
505         }
506 }
507
508 /*******************************************************/
509
510 /******************************************************/
511 //This function checks to make sure the user entered appropriate
512 // format parameters on a distfile read
513 void ErrorCheck::validateReadPhil() {
514         try {
515                 ifstream filehandle;
516                 int ableToOpen;
517                 
518                 //checks to make sure only one file type is given
519                 if (listfile != "") { 
520                         if ((rabundfile != "") || (sabundfile != "")) { 
521                                 cout << "When executing a read.otu you must enter ONLY ONE of the following: list, rabund or sabund." << endl; errorFree = false; }
522                 }else if (rabundfile != "") { 
523                         if ((listfile != "") || (sabundfile != "")) { 
524                                 cout << "When executing a read.otu you must enter ONLY ONE of the following: list, rabund or sabund." << endl; errorFree = false; }
525                 }else if (sabundfile != "") { 
526                         if ((listfile != "") || (rabundfile != "")) { 
527                                 cout << "When executing a read.otu you must enter ONLY ONE of the following: list, rabund or sabund." << endl; errorFree = false; }
528                 }else if ((listfile == "") && (rabundfile == "") && (sabundfile == "") && (sharedfile == "")) {
529                             cout << "When executing a read.otu you must enter one of the following: list, rabund or sabund." << endl; errorFree = false; 
530                 }
531                 
532                 //checks parameters on the read command
533                 if (orderfile != "") {
534                         ableToOpen = openInputFile(orderfile, filehandle);
535                         filehandle.close();
536                         if (ableToOpen == 1) { //unable to open
537                                 errorFree = false;
538                         }
539                 }       
540         }
541         catch(exception& e) {
542                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
543                 exit(1);
544         }
545         catch(...) {
546                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
547                 exit(1);
548         }
549 }
550 /*******************************************************/
551
552 /******************************************************/
553 //This function checks to make sure the user entered appropriate
554 // format parameters on a distfile read
555 void ErrorCheck::validateSeqsFiles() {
556         try {
557                 ifstream filehandle;
558                 int ableToOpen;
559                 
560                 //checks to make sure only one file type is given
561                 if (phylipfile != "") { 
562                         if ((nexusfile != "") || (fastafile != "") || (clustalfile != "")) { 
563                                 cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; }
564                         else {
565                                 ableToOpen = openInputFile(phylipfile, filehandle);
566                                 filehandle.close();
567                                 if (ableToOpen == 1) { //unable to open
568                                         errorFree = false;
569                                 }
570                         }
571                 }else if (nexusfile != "") { 
572                         if ((phylipfile != "") || (fastafile != "") || (clustalfile != "")) { 
573                                 cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; }
574                         else {
575                                 ableToOpen = openInputFile(nexusfile, filehandle);
576                                 filehandle.close();
577                                 if (ableToOpen == 1) { //unable to open
578                                         errorFree = false;
579                                 }
580                         }
581                 }else if (fastafile != "") { 
582                         if ((phylipfile != "") || (nexusfile != "") || (clustalfile != "")) { 
583                                 cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; }
584                         else {
585                                 ableToOpen = openInputFile(fastafile, filehandle);
586                                 filehandle.close();
587                                 if (ableToOpen == 1) { //unable to open
588                                         errorFree = false;
589                                 }
590                         }
591                 }else if (clustalfile != "") { 
592                         if ((phylipfile != "") || (nexusfile != "") || (fastafile != "")) { 
593                                 cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; }
594                         else {
595                                 ableToOpen = openInputFile(clustalfile, filehandle);
596                                 filehandle.close();
597                                 if (ableToOpen == 1) { //unable to open
598                                         errorFree = false;
599                                 }
600                         }
601                 }else if (candidatefile != "") {
602                         ableToOpen = openInputFile(candidatefile, filehandle);
603                         filehandle.close();
604                         if (ableToOpen == 1) { //unable to open
605                                 errorFree = false;
606                         }
607                 }
608                 
609                 
610         }
611         catch(exception& e) {
612                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateSeqsFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
613                 exit(1);
614         }
615         catch(...) {
616                 cout << "An unknown error has occurred in the ErrorCheck class function validateSeqsFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
617                 exit(1);
618         }
619 }
620
621 /*******************************************************/
622
623 /******************************************************/
624 //This function checks to make sure the user entered appropriate
625 // format parameters on a bin.seq command
626 void ErrorCheck::validateBinFiles() {
627         try {
628                 ifstream filehandle;
629                 int ableToOpen;
630                 
631                 if (fastafile == "") {
632                                 cout << "fasta is a required parameter for bin.seqs, get.oturep and get.repseqs commands." << endl; errorFree = false; 
633                 }else if (fastafile != "") {
634                         //is it a valid filename'
635                         ableToOpen = openInputFile(fastafile, filehandle);
636                         filehandle.close();
637                         //unable to open
638                         if (ableToOpen == 1) {  errorFree = false; }
639                 }else if (listfile != "") {
640                         //is it a valid filename'
641                         ableToOpen = openInputFile(listfile, filehandle);
642                         filehandle.close();
643                         //unable to open
644                         if (ableToOpen == 1) {  errorFree = false; }
645                 }else if (globaldata->getNameFile() != "") {
646                         //is it a valid filename'
647                         ifstream filehandle;
648                         int ableToOpen = openInputFile(globaldata->getNameFile(), filehandle);
649                         filehandle.close();
650                         //unable to open
651                         if (ableToOpen == 1) {  errorFree = false; }
652                 }else if (namefile != "") {
653                         //is it a valid filename'
654                         ifstream filehandle;
655                         int ableToOpen = openInputFile(namefile, filehandle);
656                         filehandle.close();
657                         //unable to open
658                         if (ableToOpen == 1) {  errorFree = false; }
659                 }else if (groupfile != "") {
660                         //is it a valid filename'
661                         ifstream filehandle;
662                         int ableToOpen = openInputFile(groupfile, filehandle);
663                         filehandle.close();
664                         //unable to open
665                         if (ableToOpen == 1) {  errorFree = false; }
666                 }
667
668
669
670         }
671         catch(exception& e) {
672                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateBinFiles. 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 validateBinFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
677                 exit(1);
678         }
679 }
680
681 /*******************************************************/
682
683 /******************************************************/
684
685 void ErrorCheck::clear() {
686         //option definitions should go here...
687         phylipfile              =       "";
688         columnfile              =       "";
689         listfile                =       "";
690         rabundfile              =       "";
691         sabundfile              =       "";
692         namefile                =       "";
693         groupfile               =       ""; 
694         orderfile               =       "";
695         sharedfile              =       "";
696         fastafile       =   "";
697         nexusfile       =   "";
698         clustalfile     =   "";
699         candidatefile   =       "";
700         line                    =       "";
701         label                   =       "";
702         method                  =   "furthest";
703 }
704 /*******************************************************/
705
706 /******************************************************/
707