]> git.donarmstrong.com Git - mothur.git/blob - errorchecking.cpp
added get.rabund and get.sabund command and fixed bug introduced by line by line...
[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 == "get.rabund") {
254                         if (globaldata->getListFile() == "") { cout << "You must read a listfile before you can use the get.rabund command." << endl; return false; }
255                 }
256                 
257                 if (commandName == "get.sabund") {
258                         if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "")) { cout << "You must read a list or rabund before you can use the get.sabund command." << endl; return false; }
259                 }
260                 
261                 if ((commandName == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") || (commandName == "bootstrap.shared") || (commandName == "dist.shared")){ 
262                         if (globaldata->getSharedFile() == "") {
263                                 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; }
264                                 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; }
265                         }
266                 }
267                 
268                 if  (commandName == "tree.shared")  {
269                         //given no files                        
270                         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; }
271                         //you want to do single commands
272                         else if ((globaldata->getSharedFile() == "") && ((phylipfile != "") || (columnfile != ""))) {
273                                 validateReadDist();
274                         }
275                 }
276                 
277                 if ((commandName == "heatmap") || (commandName == "venn")) { 
278                         if ((globaldata->getListFile() == "") && (globaldata->getSharedFile() == "")) {
279                                  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; 
280                         }
281                 }
282                 
283                 if ((commandName == "filter.seqs") || (commandName == "dist.seqs")) { 
284                         if ((fastafile == "") && (nexusfile == "") && (clustalfile == "") && (phylipfile == "")) {
285                                  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; 
286                         }
287                         validateSeqsFiles();
288                 }
289                 
290                 if (commandName == "align.seqs") {
291                         if ((fastafile == "") || (candidatefile == "")) {
292                                 cout << "You must enter fasta and a candidate file to use the align.seqs command." << endl; return false; 
293                         }
294                         validateSeqsFiles();
295                 }
296                 
297                 if ((commandName == "bin.seqs")) { 
298                         if ((globaldata->getListFile() == "")) { cout << "You must read a list file before you can use the bin.seqs commands." << endl; return false; }
299                         validateBinFiles();
300                 }
301                 
302                 
303                 if ((commandName == "get.oturep")) { 
304                         if ((globaldata->gSparseMatrix == NULL) || (globaldata->gListVector == NULL)) {
305                                 cout << "Before you use the get.oturep command, you first need to read in a distance matrix." << endl; 
306                                 errorFree = false;
307                         }
308                         if (listfile == "") { cout << "list is a required parameter for the get.oturep command." << endl; errorFree = false; }
309                         if (fastafile == "") { cout << "fasta is a required parameter for the get.oturep command." << endl; errorFree = false; }
310                         validateBinFiles();
311                 } 
312
313
314                 return errorFree;
315 }
316
317 /*******************************************************/
318
319 /******************************************************/
320 //This function checks to make sure the user entered a file to 
321 // read and that the file exists and can be opened.
322 void ErrorCheck::validateReadFiles() {
323         try {
324                 //Validating files for read
325                 ifstream filehandle;
326                 int ableToOpen;
327         
328                 //are we reading a phylipfile
329                 if (phylipfile != "") {
330                         ableToOpen = openInputFile(phylipfile, filehandle);
331                         filehandle.close();
332                         //unable to open
333                         if (ableToOpen == 1) { errorFree = false; }
334                         else { globaldata->inputFileName = phylipfile; }
335                 //are we reading a columnfile
336                 }else if (columnfile != "") {
337                         ableToOpen = openInputFile(columnfile, filehandle);
338                         filehandle.close();
339                         //unable to open
340                         if (ableToOpen == 1) { errorFree = false; }
341                         else { globaldata->inputFileName = columnfile; }
342                 //are we reading a listfile
343                 }else if (listfile!= "") {
344                         ableToOpen = openInputFile(listfile, filehandle);
345                         filehandle.close();
346                         //unable to open
347                         if (ableToOpen == 1) {  errorFree = false; }
348                         else { globaldata->inputFileName = listfile; }
349                 //are we reading a rabundfile
350                 }else if (rabundfile != "") {
351                         ableToOpen = openInputFile(rabundfile, filehandle);
352                         filehandle.close();
353                         //unable to open
354                         if (ableToOpen == 1) {  errorFree = false; }
355                         else { globaldata->inputFileName = rabundfile; }
356                 //are we reading a sabundfile
357                 }else if (sabundfile != "") {
358                         ableToOpen = openInputFile(sabundfile, filehandle);
359                         filehandle.close();
360                         //unable to open
361                         if (ableToOpen == 1) {  errorFree = false; }
362                         else { globaldata->inputFileName = sabundfile; }
363                 }else if (fastafile != "") {
364                         ableToOpen = openInputFile(fastafile, filehandle);
365                         filehandle.close();
366                         //unable to open
367                         if (ableToOpen == 1) {  errorFree = false; }
368                         else { globaldata->inputFileName = fastafile; }
369                 }else if (sharedfile != "") {
370                         ableToOpen = openInputFile(sharedfile, filehandle);
371                         filehandle.close();
372                         //unable to open
373                         if (ableToOpen == 1) {  errorFree = false; }
374                         else { globaldata->inputFileName = sharedfile; }
375                 }else if (groupfile != "") {
376                         ableToOpen = openInputFile(groupfile, filehandle);
377                         filehandle.close();
378                         if (ableToOpen == 1) { //unable to open
379                                 errorFree = false;
380                         }
381                 }else{ //no file given
382                         errorFree = false;
383                 }
384         }
385         catch(exception& e) {
386                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
387                 exit(1);
388         }
389         catch(...) {
390                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
391                 exit(1);
392         }
393         
394 }
395 /*******************************************************/
396
397 /******************************************************/
398 //This function checks to make sure the user entered appropriate
399 // format parameters on a distfile read
400 void ErrorCheck::validateReadDist() {
401         try {
402                 ifstream filehandle;
403                 int ableToOpen;
404                 
405                 if (groupfile != "") {
406                         ableToOpen = openInputFile(groupfile, filehandle);
407                         filehandle.close();
408                         //unable to open
409                         if (ableToOpen == 1) {  errorFree = false; }
410                 }
411                 
412                 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; }
413                 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; }
414                 
415                 if (columnfile != "") {
416                         if (namefile == "") {
417                                 cout << "You need to provide a namefile if you are going to use the column format." << endl;
418                                 errorFree = false; 
419                         }else {
420                                 ableToOpen = openInputFile(namefile, filehandle);
421                                 filehandle.close();
422                                 //unable to open
423                                 if (ableToOpen == 1) { errorFree = false; }
424                         }
425                 }
426         }
427         catch(exception& e) {
428                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadDist. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
429                 exit(1);
430         }
431         catch(...) {
432                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadDist. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
433                 exit(1);
434         }
435 }
436 /*******************************************************/
437
438 /******************************************************/
439 //This function checks to make sure the user entered appropriate
440 // format parameters on a parselistcommand
441 void ErrorCheck::validateParseFiles() {
442         try {
443                 ifstream filehandle;
444                 int ableToOpen;
445                 
446                 //checks for valid files
447         
448                 if (listfile == "") { cout << "When executing a read.otu for groups you must enter a list and a group." << endl; errorFree = false; }
449                 else if (groupfile == "") { cout << "When executing a read.otu for groups you must enter a list and a group." << endl; errorFree = false; }
450         
451                 //checks parameters on the read command
452                 if (listfile != "") {
453                         ableToOpen = openInputFile(listfile, filehandle);
454                         filehandle.close();
455                         if (ableToOpen == 1) { //unable to open
456                                 errorFree = false;
457                         }
458                         if (groupfile != "") {
459                                 ableToOpen = openInputFile(groupfile, filehandle);
460                                 filehandle.close();
461                                 if (ableToOpen == 1) { //unable to open
462                                         errorFree = false;
463                                 }
464                         }
465                 }
466         }
467         catch(exception& e) {
468                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
469                 exit(1);
470         }
471         catch(...) {
472                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
473                 exit(1);
474         }
475 }
476 /*******************************************************/
477
478 /******************************************************/
479 //This function checks to make sure the user entered appropriate
480 // format parameters on a parselistcommand
481 void ErrorCheck::validateTreeFiles() {
482         try {
483                 ifstream filehandle;
484                 int ableToOpen;
485                 
486                 //checks for valid files
487         
488                 if (treefile == "") { cout << "When executing a read.tree you must enter a treefile and a groupfile." << endl; errorFree = false; }
489                 else if (groupfile == "") { cout << "When executing a read.tree you must enter a treefile and a groupfile." << endl; errorFree = false; }
490         
491                 //checks parameters on the read command
492                 if (treefile != "") {
493                         ableToOpen = openInputFile(treefile, filehandle);
494                         filehandle.close();
495                         if (ableToOpen == 1) { //unable to open
496                                 errorFree = false;
497                         }
498                         if (groupfile != "") {
499                                 ableToOpen = openInputFile(groupfile, filehandle);
500                                 filehandle.close();
501                                 if (ableToOpen == 1) { //unable to open
502                                         errorFree = false;;
503                                 }
504                         }
505                 }
506         }
507         catch(exception& e) {
508                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateTreeFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
509                 exit(1);
510         }
511         catch(...) {
512                 cout << "An unknown error has occurred in the ErrorCheck class function validateTreeFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
513                 exit(1);
514         }
515 }
516
517 /*******************************************************/
518
519 /******************************************************/
520 //This function checks to make sure the user entered appropriate
521 // format parameters on a distfile read
522 void ErrorCheck::validateReadPhil() {
523         try {
524                 ifstream filehandle;
525                 int ableToOpen;
526                 
527                 //checks to make sure only one file type is given
528                 if (listfile != "") { 
529                         if ((rabundfile != "") || (sabundfile != "")) { 
530                                 cout << "When executing a read.otu you must enter ONLY ONE of the following: list, rabund or sabund." << endl; errorFree = false; }
531                 }else if (rabundfile != "") { 
532                         if ((listfile != "") || (sabundfile != "")) { 
533                                 cout << "When executing a read.otu you must enter ONLY ONE of the following: list, rabund or sabund." << endl; errorFree = false; }
534                 }else if (sabundfile != "") { 
535                         if ((listfile != "") || (rabundfile != "")) { 
536                                 cout << "When executing a read.otu you must enter ONLY ONE of the following: list, rabund or sabund." << endl; errorFree = false; }
537                 }else if ((listfile == "") && (rabundfile == "") && (sabundfile == "") && (sharedfile == "")) {
538                             cout << "When executing a read.otu you must enter one of the following: list, rabund or sabund." << endl; errorFree = false; 
539                 }
540                 
541                 //checks parameters on the read command
542                 if (orderfile != "") {
543                         ableToOpen = openInputFile(orderfile, filehandle);
544                         filehandle.close();
545                         if (ableToOpen == 1) { //unable to open
546                                 errorFree = false;
547                         }
548                 }       
549         }
550         catch(exception& e) {
551                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
552                 exit(1);
553         }
554         catch(...) {
555                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
556                 exit(1);
557         }
558 }
559 /*******************************************************/
560
561 /******************************************************/
562 //This function checks to make sure the user entered appropriate
563 // format parameters on a distfile read
564 void ErrorCheck::validateSeqsFiles() {
565         try {
566                 ifstream filehandle;
567                 int ableToOpen;
568                 
569                 //checks to make sure only one file type is given
570                 if (phylipfile != "") { 
571                         if ((nexusfile != "") || (fastafile != "") || (clustalfile != "")) { 
572                                 cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; }
573                         else {
574                                 ableToOpen = openInputFile(phylipfile, filehandle);
575                                 filehandle.close();
576                                 if (ableToOpen == 1) { //unable to open
577                                         errorFree = false;
578                                 }
579                         }
580                 }else if (nexusfile != "") { 
581                         if ((phylipfile != "") || (fastafile != "") || (clustalfile != "")) { 
582                                 cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; }
583                         else {
584                                 ableToOpen = openInputFile(nexusfile, filehandle);
585                                 filehandle.close();
586                                 if (ableToOpen == 1) { //unable to open
587                                         errorFree = false;
588                                 }
589                         }
590                 }else if (fastafile != "") { 
591                         if ((phylipfile != "") || (nexusfile != "") || (clustalfile != "")) { 
592                                 cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; }
593                         else {
594                                 ableToOpen = openInputFile(fastafile, filehandle);
595                                 filehandle.close();
596                                 if (ableToOpen == 1) { //unable to open
597                                         errorFree = false;
598                                 }
599                         }
600                 }else if (clustalfile != "") { 
601                         if ((phylipfile != "") || (nexusfile != "") || (fastafile != "")) { 
602                                 cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; }
603                         else {
604                                 ableToOpen = openInputFile(clustalfile, filehandle);
605                                 filehandle.close();
606                                 if (ableToOpen == 1) { //unable to open
607                                         errorFree = false;
608                                 }
609                         }
610                 }else if (candidatefile != "") {
611                         ableToOpen = openInputFile(candidatefile, filehandle);
612                         filehandle.close();
613                         if (ableToOpen == 1) { //unable to open
614                                 errorFree = false;
615                         }
616                 }
617                 
618                 
619         }
620         catch(exception& e) {
621                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateSeqsFiles. 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 validateSeqsFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
626                 exit(1);
627         }
628 }
629
630 /*******************************************************/
631
632 /******************************************************/
633 //This function checks to make sure the user entered appropriate
634 // format parameters on a bin.seq command
635 void ErrorCheck::validateBinFiles() {
636         try {
637                 ifstream filehandle;
638                 int ableToOpen;
639                 
640                 if (fastafile == "") {
641                                 cout << "fasta is a required parameter for bin.seqs, get.oturep and get.repseqs commands." << endl; errorFree = false; 
642                 }else if (fastafile != "") {
643                         //is it a valid filename'
644                         ableToOpen = openInputFile(fastafile, filehandle);
645                         filehandle.close();
646                         //unable to open
647                         if (ableToOpen == 1) {  errorFree = false; }
648                 }else if (listfile != "") {
649                         //is it a valid filename'
650                         ableToOpen = openInputFile(listfile, filehandle);
651                         filehandle.close();
652                         //unable to open
653                         if (ableToOpen == 1) {  errorFree = false; }
654                 }else if (globaldata->getNameFile() != "") {
655                         //is it a valid filename'
656                         ifstream filehandle;
657                         int ableToOpen = openInputFile(globaldata->getNameFile(), filehandle);
658                         filehandle.close();
659                         //unable to open
660                         if (ableToOpen == 1) {  errorFree = false; }
661                 }else if (namefile != "") {
662                         //is it a valid filename'
663                         ifstream filehandle;
664                         int ableToOpen = openInputFile(namefile, filehandle);
665                         filehandle.close();
666                         //unable to open
667                         if (ableToOpen == 1) {  errorFree = false; }
668                 }else if (groupfile != "") {
669                         //is it a valid filename'
670                         ifstream filehandle;
671                         int ableToOpen = openInputFile(groupfile, filehandle);
672                         filehandle.close();
673                         //unable to open
674                         if (ableToOpen == 1) {  errorFree = false; }
675                 }
676
677
678
679         }
680         catch(exception& e) {
681                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateBinFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
682                 exit(1);
683         }
684         catch(...) {
685                 cout << "An unknown error has occurred in the ErrorCheck class function validateBinFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
686                 exit(1);
687         }
688 }
689
690 /*******************************************************/
691
692 /******************************************************/
693
694 void ErrorCheck::clear() {
695         //option definitions should go here...
696         phylipfile              =       "";
697         columnfile              =       "";
698         listfile                =       "";
699         rabundfile              =       "";
700         sabundfile              =       "";
701         namefile                =       "";
702         groupfile               =       ""; 
703         orderfile               =       "";
704         sharedfile              =       "";
705         fastafile       =   "";
706         nexusfile       =   "";
707         clustalfile     =   "";
708         candidatefile   =       "";
709         line                    =       "";
710         label                   =       "";
711         method                  =   "furthest";
712 }
713 /*******************************************************/
714
715 /******************************************************/
716