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