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