]> git.donarmstrong.com Git - mothur.git/blob - errorchecking.cpp
fixed bug in venn command
[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 == "ends" )                       { ends = value; }
120                                 if (parameter == "processors" )         { processors = value;   }
121
122                         }
123                         
124                         //gets the last parameter and value
125                         if (errorFree)  { //gets the last parameter and value
126                                 value = optionText;
127                                 splitAtEquals(parameter, value);
128                                 //is it a valid parameter
129                                 if (validParameter->isValidParameter(parameter, commandName, value) != true) { return false; }
130         
131                                 
132                                 if (parameter == "phylip" )             { phylipfile = value; }
133                                 if (parameter == "column" )             { columnfile = value; }                         
134                                 if (parameter == "list" )               { listfile = value; }
135                                 if (parameter == "rabund" )             { rabundfile = value; }
136                                 if (parameter == "sabund" )             { sabundfile = value; }
137                                 if (parameter == "name" )               { namefile = value; }
138                                 if (parameter == "order" )              { orderfile = value; }
139                                 if (parameter == "group" )              { groupfile = value; }
140                                 if (parameter == "shared" )             { sharedfile = value; }
141                                 if (parameter == "fasta" )              { fastafile = value; }
142                                 if (parameter == "nexus" )              { nexusfile = value; }
143                                 if (parameter == "clustal" )    { clustalfile = value; }
144                                 if (parameter == "tree" )               { treefile = value; }
145                                 if (parameter == "cutoff" )                     { cutoff = value; }
146                                 if (parameter == "precision" )          { precision = value; }
147                                 if (parameter == "iters" )                      { iters = value; }
148                                 if (parameter == "jumble" )                     { jumble = value; }
149                                 if (parameter == "freq" )                       { freq = value; }
150                                 if (parameter == "method" )                     { method = value; }
151                                 if (parameter == "fileroot" )           { fileroot = value; }
152                                 if (parameter == "line" )                       { line = value; }
153                                 if (parameter == "label" )                      { label = value; }
154                                 if (parameter == "random" )                     { randomtree = value;   }
155                                 if (parameter == "abund" )          { abund = value; }
156                                 if (parameter == "sorted" )                     { sorted = value;       }
157                                 if (parameter == "trump" )          { trump = value; }
158                                 if (parameter == "soft" )                       { soft = value; }
159                                 if (parameter == "filter" )         { filter = value; }
160                                 if (parameter == "scale" )                      { scale = value;        }
161                                 if (parameter == "ends" )                       { ends = value; }
162                                 if (parameter == "processors" )         { processors = value;   }
163
164                         }
165                 }
166                 
167                 //make sure the user does not use both the line and label parameters
168                 if ((line != "") && (label != "")) { cout << "You may use either the line or label parameters, but not both." << endl; return false; }
169                 
170                 //check for valid files 
171                 if (commandName == "read.dist") { 
172                         validateReadFiles();
173                         validateReadDist();
174                 }else if (commandName == "read.otu") { 
175                         //you want to do shared commands
176                         if ((listfile != "") && (groupfile != ""))      {
177                                 validateParseFiles(); //checks the listfile and groupfile parameters
178                         //you want to do single commands
179                         }else if ((listfile != "") || (rabundfile != "") || (sabundfile != "")){ 
180                                 validateReadFiles();
181                                 validateReadPhil();
182                         //you have not given a file
183                         }else if ((listfile == "") && (sharedfile == "") && (rabundfile == "") && (sabundfile == "")) {
184                                 cout << "You must enter either a listfile, rabundfile, sabundfile or a sharedfile with the read.otu command. " << endl; return false; 
185                         //you want to do shared commands with a shared file
186                         }else if (sharedfile != "") {//you are reading a shared file
187                                 validateReadFiles();
188                         }
189                 }else if (commandName == "read.tree") { 
190                         validateTreeFiles(); //checks the treefile and groupfile parameters
191                 }else if (commandName == "deconvolute") {
192                         if (fastafile == "") { cout << "You must enter a fastafile with the deconvolute() command." << endl; return false; }
193                         validateReadFiles();
194                 }
195                 
196                 //are you trying to cluster before you have read something      
197                 if (((commandName == "cluster") && (globaldata->gSparseMatrix == NULL)) ||
198                         ((commandName == "cluster") && (globaldata->gListVector == NULL))) {
199                                 cout << "Before you use the cluster command, you first need to read in a distance matrix." << endl; 
200                                 errorFree = false;
201                 } 
202                 
203                 if ((commandName == "libshuff") && ((globaldata->gMatrix == NULL) || (globaldata->gGroupmap == NULL))) {
204                          cout << "You must read in a matrix and groupfile using the read.dist command, before you use the libshuff command. " << endl; return false; 
205                 }
206                 
207                 if (commandName == "parsimony") {
208                         //are you trying to use parsimony without reading a tree or saying you want random distribution
209                         if (randomtree == "")  {
210                                 if (globaldata->gTree.size() == 0) {
211                                         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;  }
212                         }
213                 }
214                 
215                 if ((commandName == "unifrac.weighted") || (commandName == "unifrac.unweighted") || (commandName == "concensus")) {
216                         if (globaldata->gTree.size() == 0) {//no trees were read
217                                 cout << "You must execute the read.tree command, before you may execute the unifrac.weighted, unifrac.unweighted or concensus command." << endl; return false;  }
218                 }
219                 
220                 //check for valid method
221                 if(commandName == "get.group") {
222                         if ((globaldata->getGroupFile() == "")) { cout << "You must read a group before you can use the get.group command." << endl; return false; }
223                 }
224                 if (commandName == "get.label" || commandName == "get.line") {
225                         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; }
226                 }
227                 if (commandName == "cluster") {
228                         if ((method == "furthest") || (method == "nearest") || (method == "average")) { }
229                         else {cout << "Not a valid clustering method.  Valid clustering algorithms are furthest, nearest or average." << endl; return false; }
230                 }
231                 
232                 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single") ){ 
233                         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; }
234                 }
235                 
236                 if ((commandName == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") || (commandName == "tree.shared") || (commandName == "bootstrap.shared")){ 
237                         if (globaldata->getSharedFile() == "") {
238                                 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 or bootstrap.shared commands." << endl; return false; }
239                                 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 or bootstrap.shared commands." << endl; return false; }
240                         }
241                 }
242                 
243                 if ((commandName == "heatmap") || (commandName == "venn")) { 
244                         if ((globaldata->getListFile() == "") && (globaldata->getSharedFile() == "")) {
245                                  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; 
246                         }
247                 }
248                 
249                 if ((commandName == "filter.seqs") || (commandName == "dist.seqs")) { 
250                         if ((fastafile == "") && (nexusfile == "") && (clustalfile == "") && (phylipfile == "")) {
251                                  cout << "You must read either a fasta, nexus, clustal, or phylip file before you can use the filter.seqs command." << endl; return false; 
252                         }
253                         validateSeqsFiles();
254                 }
255                 
256                 if ((commandName == "bin.seqs")) { 
257                         if ((globaldata->getListFile() == "")) { cout << "You must read a list file before you can use the bin.seqs command." << endl; return false; }
258                         validateBinFiles();
259                 }
260                 
261                 if ((commandName == "get.oturep")) { 
262                         if ((globaldata->gSparseMatrix == NULL) || (globaldata->gListVector == NULL)) {
263                                 cout << "Before you use the get.oturep command, you first need to read in a distance matrix." << endl; 
264                                 errorFree = false;
265                         }
266                         if (listfile == "") { cout << "list is a required parameter for the get.oturep command." << endl; errorFree = false; }
267                         validateBinFiles();
268                 } 
269
270
271                 return errorFree;
272 }
273
274 /*******************************************************/
275
276 /******************************************************/
277 //This function checks to make sure the user entered a file to 
278 // read and that the file exists and can be opened.
279 void ErrorCheck::validateReadFiles() {
280         try {
281                 //Validating files for read
282                 ifstream filehandle;
283                 int ableToOpen;
284         
285                 //are we reading a phylipfile
286                 if (phylipfile != "") {
287                         ableToOpen = openInputFile(phylipfile, filehandle);
288                         filehandle.close();
289                         //unable to open
290                         if (ableToOpen == 1) { errorFree = false; }
291                         else { globaldata->inputFileName = phylipfile; }
292                 //are we reading a columnfile
293                 }else if (columnfile != "") {
294                         ableToOpen = openInputFile(columnfile, filehandle);
295                         filehandle.close();
296                         //unable to open
297                         if (ableToOpen == 1) { errorFree = false; }
298                         else { globaldata->inputFileName = columnfile; }
299                 //are we reading a listfile
300                 }else if (listfile!= "") {
301                         ableToOpen = openInputFile(listfile, filehandle);
302                         filehandle.close();
303                         //unable to open
304                         if (ableToOpen == 1) {  errorFree = false; }
305                         else { globaldata->inputFileName = listfile; }
306                 //are we reading a rabundfile
307                 }else if (rabundfile != "") {
308                         ableToOpen = openInputFile(rabundfile, filehandle);
309                         filehandle.close();
310                         //unable to open
311                         if (ableToOpen == 1) {  errorFree = false; }
312                         else { globaldata->inputFileName = rabundfile; }
313                 //are we reading a sabundfile
314                 }else if (sabundfile != "") {
315                         ableToOpen = openInputFile(sabundfile, filehandle);
316                         filehandle.close();
317                         //unable to open
318                         if (ableToOpen == 1) {  errorFree = false; }
319                         else { globaldata->inputFileName = sabundfile; }
320                 }else if (fastafile != "") {
321                         ableToOpen = openInputFile(fastafile, filehandle);
322                         filehandle.close();
323                         //unable to open
324                         if (ableToOpen == 1) {  errorFree = false; }
325                         else { globaldata->inputFileName = fastafile; }
326                 }else if (sharedfile != "") {
327                         ableToOpen = openInputFile(sharedfile, filehandle);
328                         filehandle.close();
329                         //unable to open
330                         if (ableToOpen == 1) {  errorFree = false; }
331                         else { globaldata->inputFileName = sharedfile; }
332                 }else{ //no file given
333                         errorFree = false;
334                 }
335         }
336         catch(exception& e) {
337                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
338                 exit(1);
339         }
340         catch(...) {
341                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
342                 exit(1);
343         }
344         
345 }
346 /*******************************************************/
347
348 /******************************************************/
349 //This function checks to make sure the user entered appropriate
350 // format parameters on a distfile read
351 void ErrorCheck::validateReadDist() {
352         try {
353                 ifstream filehandle;
354                 int ableToOpen;
355                 
356                 if (groupfile != "") {
357                         ableToOpen = openInputFile(groupfile, filehandle);
358                         filehandle.close();
359                         //unable to open
360                         if (ableToOpen == 1) {  errorFree = false; }
361                 }
362                 
363                 if ((phylipfile == "") && (columnfile == "")) { cout << "When executing a read.dist you must enter a phylip or a column." << endl; errorFree = false; }
364                 else if ((phylipfile != "") && (columnfile != "")) { cout << "When executing a read.dist you must enter ONLY ONE of the following: phylip or column." << endl; errorFree = false; }
365                 
366                 if (columnfile != "") {
367                         if (namefile == "") {
368                                 cout << "You need to provide a namefile if you are going to use the column format." << endl;
369                                 errorFree = false; 
370                         }else {
371                                 ableToOpen = openInputFile(namefile, filehandle);
372                                 filehandle.close();
373                                 //unable to open
374                                 if (ableToOpen == 1) { errorFree = false; }
375                         }
376                 }
377         }
378         catch(exception& e) {
379                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadDist. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
380                 exit(1);
381         }
382         catch(...) {
383                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadDist. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
384                 exit(1);
385         }
386 }
387 /*******************************************************/
388
389 /******************************************************/
390 //This function checks to make sure the user entered appropriate
391 // format parameters on a parselistcommand
392 void ErrorCheck::validateParseFiles() {
393         try {
394                 ifstream filehandle;
395                 int ableToOpen;
396                 
397                 //checks for valid files
398         
399                 if (listfile == "") { cout << "When executing a read.otu for groups you must enter a list and a group." << endl; errorFree = false; }
400                 else if (groupfile == "") { cout << "When executing a read.otu for groups you must enter a list and a group." << endl; errorFree = false; }
401         
402                 //checks parameters on the read command
403                 if (listfile != "") {
404                         ableToOpen = openInputFile(listfile, filehandle);
405                         filehandle.close();
406                         if (ableToOpen == 1) { //unable to open
407                                 errorFree = false;
408                         }
409                         if (groupfile != "") {
410                                 ableToOpen = openInputFile(groupfile, filehandle);
411                                 filehandle.close();
412                                 if (ableToOpen == 1) { //unable to open
413                                         errorFree = false;;
414                                 }
415                         }
416                 }
417         }
418         catch(exception& e) {
419                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadPhil. 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 validateReadPhil. 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::validateTreeFiles() {
433         try {
434                 ifstream filehandle;
435                 int ableToOpen;
436                 
437                 //checks for valid files
438         
439                 if (treefile == "") { cout << "When executing a read.tree you must enter a treefile and a groupfile." << endl; errorFree = false; }
440                 else if (groupfile == "") { cout << "When executing a read.tree you must enter a treefile and a groupfile." << endl; errorFree = false; }
441         
442                 //checks parameters on the read command
443                 if (treefile != "") {
444                         ableToOpen = openInputFile(treefile, 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 validateTreeFiles. 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 validateTreeFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
464                 exit(1);
465         }
466 }
467
468 /*******************************************************/
469
470 /******************************************************/
471 //This function checks to make sure the user entered appropriate
472 // format parameters on a distfile read
473 void ErrorCheck::validateReadPhil() {
474         try {
475                 ifstream filehandle;
476                 int ableToOpen;
477                 
478                 //checks to make sure only one file type is given
479                 if (listfile != "") { 
480                         if ((rabundfile != "") || (sabundfile != "")) { 
481                                 cout << "When executing a read.otu you must enter ONLY ONE of the following: list, rabund or sabund." << endl; errorFree = false; }
482                 }else if (rabundfile != "") { 
483                         if ((listfile != "") || (sabundfile != "")) { 
484                                 cout << "When executing a read.otu you must enter ONLY ONE of the following: list, rabund or sabund." << endl; errorFree = false; }
485                 }else if (sabundfile != "") { 
486                         if ((listfile != "") || (rabundfile != "")) { 
487                                 cout << "When executing a read.otu you must enter ONLY ONE of the following: list, rabund or sabund." << endl; errorFree = false; }
488                 }else if ((listfile == "") && (rabundfile == "") && (sabundfile == "") && (sharedfile == "")) {
489                             cout << "When executing a read.otu you must enter one of the following: list, rabund or sabund." << endl; errorFree = false; 
490                 }
491                 
492                 //checks parameters on the read command
493                 if (orderfile != "") {
494                         ableToOpen = openInputFile(orderfile, filehandle);
495                         filehandle.close();
496                         if (ableToOpen == 1) { //unable to open
497                                 errorFree = false;
498                         }
499                 }       
500         }
501         catch(exception& e) {
502                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
503                 exit(1);
504         }
505         catch(...) {
506                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
507                 exit(1);
508         }
509 }
510 /*******************************************************/
511
512 /******************************************************/
513 //This function checks to make sure the user entered appropriate
514 // format parameters on a distfile read
515 void ErrorCheck::validateSeqsFiles() {
516         try {
517                 ifstream filehandle;
518                 int ableToOpen;
519                 
520                 //checks to make sure only one file type is given
521                 if (phylipfile != "") { 
522                         if ((nexusfile != "") || (fastafile != "") || (clustalfile != "")) { 
523                                 cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; }
524                         else {
525                                 ableToOpen = openInputFile(phylipfile, filehandle);
526                                 filehandle.close();
527                                 if (ableToOpen == 1) { //unable to open
528                                         errorFree = false;
529                                 }
530                         }
531                 }else if (nexusfile != "") { 
532                         if ((phylipfile != "") || (fastafile != "") || (clustalfile != "")) { 
533                                 cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; }
534                         else {
535                                 ableToOpen = openInputFile(nexusfile, filehandle);
536                                 filehandle.close();
537                                 if (ableToOpen == 1) { //unable to open
538                                         errorFree = false;
539                                 }
540                         }
541                 }else if (fastafile != "") { 
542                         if ((phylipfile != "") || (nexusfile != "") || (clustalfile != "")) { 
543                                 cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; }
544                         else {
545                                 ableToOpen = openInputFile(fastafile, filehandle);
546                                 filehandle.close();
547                                 if (ableToOpen == 1) { //unable to open
548                                         errorFree = false;
549                                 }
550                         }
551                 }else if (clustalfile != "") { 
552                         if ((phylipfile != "") || (nexusfile != "") || (fastafile != "")) { 
553                                 cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; }
554                         else {
555                                 ableToOpen = openInputFile(clustalfile, filehandle);
556                                 filehandle.close();
557                                 if (ableToOpen == 1) { //unable to open
558                                         errorFree = false;
559                                 }
560                         }
561
562                 }
563                 
564         }
565         catch(exception& e) {
566                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateSeqsFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
567                 exit(1);
568         }
569         catch(...) {
570                 cout << "An unknown error has occurred in the ErrorCheck class function validateSeqsFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
571                 exit(1);
572         }
573 }
574
575 /*******************************************************/
576
577 /******************************************************/
578 //This function checks to make sure the user entered appropriate
579 // format parameters on a bin.seq command
580 void ErrorCheck::validateBinFiles() {
581         try {
582                 ifstream filehandle;
583                 int ableToOpen;
584                 
585                 if (fastafile == "") {
586                                 cout << "fasta is a required parameter for bin.seqs and get.oturep commands." << endl; errorFree = false; 
587                 }else if (fastafile != "") {
588                         //is it a valid filename'
589                         ableToOpen = openInputFile(fastafile, filehandle);
590                         filehandle.close();
591                         //unable to open
592                         if (ableToOpen == 1) {  errorFree = false; }
593                 }else if (listfile != "") {
594                         //is it a valid filename'
595                         ableToOpen = openInputFile(listfile, filehandle);
596                         filehandle.close();
597                         //unable to open
598                         if (ableToOpen == 1) {  errorFree = false; }
599                 }else if (globaldata->getNameFile() != "") {
600                         //is it a valid filename'
601                         ifstream filehandle;
602                         int ableToOpen = openInputFile(globaldata->getNameFile(), filehandle);
603                         filehandle.close();
604                         //unable to open
605                         if (ableToOpen == 1) {  errorFree = false; }
606                 }else if (namefile != "") {
607                         //is it a valid filename'
608                         ifstream filehandle;
609                         int ableToOpen = openInputFile(namefile, filehandle);
610                         filehandle.close();
611                         //unable to open
612                         if (ableToOpen == 1) {  errorFree = false; }
613                 }
614
615
616         }
617         catch(exception& e) {
618                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateBinFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
619                 exit(1);
620         }
621         catch(...) {
622                 cout << "An unknown error has occurred in the ErrorCheck class function validateBinFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
623                 exit(1);
624         }
625 }
626
627 /*******************************************************/
628
629 /******************************************************/
630
631 void ErrorCheck::clear() {
632         //option definitions should go here...
633         phylipfile              =       "";
634         columnfile              =       "";
635         listfile                =       "";
636         rabundfile              =       "";
637         sabundfile              =       "";
638         namefile                =       "";
639         groupfile               =       ""; 
640         orderfile               =       "";
641         sharedfile              =       "";
642         fastafile       =   "";
643         nexusfile       =   "";
644         clustalfile     =   "";
645         line                    =       "";
646         label                   =       "";
647         method                  =   "furthest";
648 }
649 /*******************************************************/
650
651 /******************************************************/
652