]> git.donarmstrong.com Git - mothur.git/blob - errorchecking.cpp
added get.repseqs command, started matrix output command
[mothur.git] / errorchecking.cpp
1 /*
2  *  errorchecking.cpp
3  *  Dotur
4  *
5  *  Created by Sarah Westcott on 1/2/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "errorchecking.h"
11
12 /*******************************************************/
13
14 /******************************************************/
15
16 ErrorCheck::ErrorCheck() {
17         globaldata = GlobalData::getInstance();
18         validCommand = new ValidCommands();
19         validParameter = new ValidParameters();
20 }
21 /*******************************************************/
22
23 /******************************************************/
24
25 void ErrorCheck::refresh() {
26
27         //columnfile = globaldata->getColumnFile();
28         //phylipfile = globaldata->getPhylipFile();
29         //listfile = globaldata->getListFile();
30         //rabundfile = globaldata->getRabundFile();
31         //sabundfile = globaldata->getSabundFile();
32         //namefile = globaldata->getNameFile();
33         //groupfile = globaldata->getGroupFile();
34         //orderfile = globaldata->getOrderFile();
35         //fastafile = globaldata->getFastaFile();
36         //treefile = globaldata->getTreeFile();
37         //cutoff = globaldata->getCutOff();
38         //format = globaldata->getFormat();
39         //method = globaldata->getMethod();
40         //randomtree = globaldata->getRandomTree();
41         //sharedfile = globaldata->getSharedFile();
42
43 }
44
45 /*******************************************************/
46
47 /******************************************************/
48
49 ErrorCheck::~ErrorCheck() {
50         delete validCommand;
51         delete validParameter;
52 }
53
54 /*******************************************************/
55
56 /******************************************************/
57
58 bool ErrorCheck::checkInput(string input) {
59                 errorFree = true;
60                 clear();
61                 
62                 //refresh variable
63                 refresh();
64                 
65                 //get command name and parameters
66                 int openParen = input.find_first_of('(');
67                 int closeParen = input.find_last_of(')');
68
69                 if(openParen != -1 && closeParen != -1){                        
70                         commandName = input.substr(0, openParen);   //commandName contains everything before "("
71                         optionText = input.substr(openParen+1, closeParen-openParen-1); //optionString contains everything between "(" and ")".
72                 }else if (openParen == -1) { //there is no parenthesis
73                         cout << input << " is not a valid command. You are missing the ()." << endl;
74                         return false;
75                 }
76                 
77                 //is it a valid command
78                 if (validCommand->isValidCommand(commandName) != true) { return false; }
79                 string parameter, value;
80                 
81                 //reads in parameters and values
82                 if((optionText != "") && (commandName != "help")){
83                         while((optionText.find_first_of(',') != -1) && (errorFree)) {  //while there are parameters
84                                 splitAtComma(value, optionText);
85                                 splitAtEquals(parameter, value);
86                                 
87                                 //is it a valid parameter
88                                 if (validParameter->isValidParameter(parameter, commandName, value) != true) { return false; }
89                                 
90                                 if (parameter == "phylip" )             { phylipfile = value; }
91                                 if (parameter == "column" )             { columnfile = value; }
92                                 if (parameter == "list" )               { listfile = value; }
93                                 if (parameter == "rabund" )             { rabundfile = value; }
94                                 if (parameter == "sabund" )             { sabundfile = value; }
95                                 if (parameter == "name" )               { namefile = value; }
96                                 if (parameter == "order" )              { orderfile = value; }
97                                 if (parameter == "fasta" )              { fastafile = value; }
98                                 if (parameter == "nexus" )              { nexusfile = value; }
99                                 if (parameter == "clustal" )    { clustalfile = value; }
100                                 if (parameter == "tree" )               { treefile = value; }
101                                 if (parameter == "group" )                      { groupfile = value; }
102                                 if (parameter == "shared" )                     { sharedfile = value; }
103                                 if (parameter == "cutoff" )                     { cutoff = value; }
104                                 if (parameter == "precision" )          { precision = value; }
105                                 if (parameter == "iters" )                      { iters = value; }
106                                 if (parameter == "jumble" )                     { jumble = value; }
107                                 if (parameter == "freq" )                       { freq = value; }
108                                 if (parameter == "method" )                     { method = value; }
109                                 if (parameter == "fileroot" )           { fileroot = value; }
110                                 if (parameter == "line" )                       { line = value; }
111                                 if (parameter == "label" )                      { label = value; }
112                                 if (parameter == "abund" )          { abund = value; }
113                                 if (parameter == "random" )                     { randomtree = value; }
114                                 if (parameter == "sorted" )                     { sorted = value; }
115                                 if (parameter == "trump" )          { trump = value; }
116                                 if (parameter == "soft" )                       { soft = value; }
117                                 if (parameter == "filter" )         { filter = value; }
118                                 if (parameter == "scale" )                      { scale = value;        }
119                                 if (parameter == "ends" )                       { ends = value; }
120                                 if (parameter == "processors" )         { processors = value;   }
121                                 if (parameter == "size" )                       { size = value; }
122                                 if (parameter == "template")            { templatefile = 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 == "ends" )                       { ends = value; }
170                                 if (parameter == "processors" )         { processors = value;   }
171                                 if (parameter == "size" )                       { size = value; }
172                                 if (parameter == "template")            { templatefile = 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->getGroupFile() == "")) { cout << "You must read a group before you can use the get.group command." << endl; return false; }
240                 }
241                 if (commandName == "get.label" || commandName == "get.line") {
242                         if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { cout << "You must read a list, sabund or rabund before you can use the get.label or get.line command." << endl; return false; }
243                 }
244                 if (commandName == "cluster") {
245                         if ((method == "furthest") || (method == "nearest") || (method == "average")) { }
246                         else {cout << "Not a valid clustering method.  Valid clustering algorithms are furthest, nearest or average." << endl; return false; }
247                 }
248                 
249                 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single") ){ 
250                         if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { cout << "You must read a list, sabund or rabund before you can use the collect.single, rarefaction.single or summary.single commands." << endl; return false; }
251                 }
252                 
253                 if ((commandName == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") || (commandName == "tree.shared") || (commandName == "bootstrap.shared")){ 
254                         if (globaldata->getSharedFile() == "") {
255                                 if (globaldata->getListFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared, summary.shared, tree.shared or bootstrap.shared commands." << endl; return false; }
256                                 else if (globaldata->getGroupFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared, summary.shared, tree.shared or bootstrap.shared commands." << endl; return false; }
257                         }
258                 }
259                 
260                 if ((commandName == "heatmap") || (commandName == "venn")) { 
261                         if ((globaldata->getListFile() == "") && (globaldata->getSharedFile() == "")) {
262                                  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; 
263                         }
264                 }
265                 
266                 if ((commandName == "filter.seqs") || (commandName == "dist.seqs") || (commandName == "align.seqs")) { 
267                         if ((fastafile == "") && (nexusfile == "") && (clustalfile == "") && (phylipfile == "")) {
268                                  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; 
269                         }else if ((commandName == "align.seqs") && (templatefile == "")) {
270                                 cout << "You must enter a template to use the align.seqs command." << endl; return false; 
271                         }
272                         validateSeqsFiles();
273                 }
274                 
275                 if ((commandName == "bin.seqs")) { 
276                         if ((globaldata->getListFile() == "")) { cout << "You must read a list file before you can use the bin.seqs command." << endl; return false; }
277                         validateBinFiles();
278                 }
279                 
280                 if ((commandName == "get.repseqs")) { 
281                         if ((globaldata->getListFile() == "")) { cout << "You must read a list file before you can use the get.repseqs command." << endl; return false; }
282                         else if (groupfile == "") { cout << "You must provide a groupfile before you can use the get.repseqs command." << endl; return false; }
283                         validateBinFiles();
284                 }
285
286                 
287                 if ((commandName == "get.oturep")) { 
288                         if ((globaldata->gSparseMatrix == NULL) || (globaldata->gListVector == NULL)) {
289                                 cout << "Before you use the get.oturep command, you first need to read in a distance matrix." << endl; 
290                                 errorFree = false;
291                         }
292                         if (listfile == "") { cout << "list is a required parameter for the get.oturep command." << endl; errorFree = false; }
293                         validateBinFiles();
294                 } 
295
296
297                 return errorFree;
298 }
299
300 /*******************************************************/
301
302 /******************************************************/
303 //This function checks to make sure the user entered a file to 
304 // read and that the file exists and can be opened.
305 void ErrorCheck::validateReadFiles() {
306         try {
307                 //Validating files for read
308                 ifstream filehandle;
309                 int ableToOpen;
310         
311                 //are we reading a phylipfile
312                 if (phylipfile != "") {
313                         ableToOpen = openInputFile(phylipfile, filehandle);
314                         filehandle.close();
315                         //unable to open
316                         if (ableToOpen == 1) { errorFree = false; }
317                         else { globaldata->inputFileName = phylipfile; }
318                 //are we reading a columnfile
319                 }else if (columnfile != "") {
320                         ableToOpen = openInputFile(columnfile, filehandle);
321                         filehandle.close();
322                         //unable to open
323                         if (ableToOpen == 1) { errorFree = false; }
324                         else { globaldata->inputFileName = columnfile; }
325                 //are we reading a listfile
326                 }else if (listfile!= "") {
327                         ableToOpen = openInputFile(listfile, filehandle);
328                         filehandle.close();
329                         //unable to open
330                         if (ableToOpen == 1) {  errorFree = false; }
331                         else { globaldata->inputFileName = listfile; }
332                 //are we reading a rabundfile
333                 }else if (rabundfile != "") {
334                         ableToOpen = openInputFile(rabundfile, filehandle);
335                         filehandle.close();
336                         //unable to open
337                         if (ableToOpen == 1) {  errorFree = false; }
338                         else { globaldata->inputFileName = rabundfile; }
339                 //are we reading a sabundfile
340                 }else if (sabundfile != "") {
341                         ableToOpen = openInputFile(sabundfile, filehandle);
342                         filehandle.close();
343                         //unable to open
344                         if (ableToOpen == 1) {  errorFree = false; }
345                         else { globaldata->inputFileName = sabundfile; }
346                 }else if (fastafile != "") {
347                         ableToOpen = openInputFile(fastafile, filehandle);
348                         filehandle.close();
349                         //unable to open
350                         if (ableToOpen == 1) {  errorFree = false; }
351                         else { globaldata->inputFileName = fastafile; }
352                 }else if (sharedfile != "") {
353                         ableToOpen = openInputFile(sharedfile, filehandle);
354                         filehandle.close();
355                         //unable to open
356                         if (ableToOpen == 1) {  errorFree = false; }
357                         else { globaldata->inputFileName = sharedfile; }
358                 }else{ //no file given
359                         errorFree = false;
360                 }
361         }
362         catch(exception& e) {
363                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
364                 exit(1);
365         }
366         catch(...) {
367                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
368                 exit(1);
369         }
370         
371 }
372 /*******************************************************/
373
374 /******************************************************/
375 //This function checks to make sure the user entered appropriate
376 // format parameters on a distfile read
377 void ErrorCheck::validateReadDist() {
378         try {
379                 ifstream filehandle;
380                 int ableToOpen;
381                 
382                 if (groupfile != "") {
383                         ableToOpen = openInputFile(groupfile, filehandle);
384                         filehandle.close();
385                         //unable to open
386                         if (ableToOpen == 1) {  errorFree = false; }
387                 }
388                 
389                 if ((phylipfile == "") && (columnfile == "")) { cout << "When executing a read.dist you must enter a phylip or a column." << endl; errorFree = false; }
390                 else if ((phylipfile != "") && (columnfile != "")) { cout << "When executing a read.dist you must enter ONLY ONE of the following: phylip or column." << endl; errorFree = false; }
391                 
392                 if (columnfile != "") {
393                         if (namefile == "") {
394                                 cout << "You need to provide a namefile if you are going to use the column format." << endl;
395                                 errorFree = false; 
396                         }else {
397                                 ableToOpen = openInputFile(namefile, filehandle);
398                                 filehandle.close();
399                                 //unable to open
400                                 if (ableToOpen == 1) { errorFree = false; }
401                         }
402                 }
403         }
404         catch(exception& e) {
405                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadDist. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
406                 exit(1);
407         }
408         catch(...) {
409                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadDist. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
410                 exit(1);
411         }
412 }
413 /*******************************************************/
414
415 /******************************************************/
416 //This function checks to make sure the user entered appropriate
417 // format parameters on a parselistcommand
418 void ErrorCheck::validateParseFiles() {
419         try {
420                 ifstream filehandle;
421                 int ableToOpen;
422                 
423                 //checks for valid files
424         
425                 if (listfile == "") { cout << "When executing a read.otu for groups you must enter a list and a group." << endl; errorFree = false; }
426                 else if (groupfile == "") { cout << "When executing a read.otu for groups you must enter a list and a group." << endl; errorFree = false; }
427         
428                 //checks parameters on the read command
429                 if (listfile != "") {
430                         ableToOpen = openInputFile(listfile, filehandle);
431                         filehandle.close();
432                         if (ableToOpen == 1) { //unable to open
433                                 errorFree = false;
434                         }
435                         if (groupfile != "") {
436                                 ableToOpen = openInputFile(groupfile, filehandle);
437                                 filehandle.close();
438                                 if (ableToOpen == 1) { //unable to open
439                                         errorFree = false;;
440                                 }
441                         }
442                 }
443         }
444         catch(exception& e) {
445                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
446                 exit(1);
447         }
448         catch(...) {
449                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
450                 exit(1);
451         }
452 }
453 /*******************************************************/
454
455 /******************************************************/
456 //This function checks to make sure the user entered appropriate
457 // format parameters on a parselistcommand
458 void ErrorCheck::validateTreeFiles() {
459         try {
460                 ifstream filehandle;
461                 int ableToOpen;
462                 
463                 //checks for valid files
464         
465                 if (treefile == "") { cout << "When executing a read.tree you must enter a treefile and a groupfile." << endl; errorFree = false; }
466                 else if (groupfile == "") { cout << "When executing a read.tree you must enter a treefile and a groupfile." << endl; errorFree = false; }
467         
468                 //checks parameters on the read command
469                 if (treefile != "") {
470                         ableToOpen = openInputFile(treefile, filehandle);
471                         filehandle.close();
472                         if (ableToOpen == 1) { //unable to open
473                                 errorFree = false;
474                         }
475                         if (groupfile != "") {
476                                 ableToOpen = openInputFile(groupfile, filehandle);
477                                 filehandle.close();
478                                 if (ableToOpen == 1) { //unable to open
479                                         errorFree = false;;
480                                 }
481                         }
482                 }
483         }
484         catch(exception& e) {
485                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateTreeFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
486                 exit(1);
487         }
488         catch(...) {
489                 cout << "An unknown error has occurred in the ErrorCheck class function validateTreeFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
490                 exit(1);
491         }
492 }
493
494 /*******************************************************/
495
496 /******************************************************/
497 //This function checks to make sure the user entered appropriate
498 // format parameters on a distfile read
499 void ErrorCheck::validateReadPhil() {
500         try {
501                 ifstream filehandle;
502                 int ableToOpen;
503                 
504                 //checks to make sure only one file type is given
505                 if (listfile != "") { 
506                         if ((rabundfile != "") || (sabundfile != "")) { 
507                                 cout << "When executing a read.otu you must enter ONLY ONE of the following: list, rabund or sabund." << endl; errorFree = false; }
508                 }else if (rabundfile != "") { 
509                         if ((listfile != "") || (sabundfile != "")) { 
510                                 cout << "When executing a read.otu you must enter ONLY ONE of the following: list, rabund or sabund." << endl; errorFree = false; }
511                 }else if (sabundfile != "") { 
512                         if ((listfile != "") || (rabundfile != "")) { 
513                                 cout << "When executing a read.otu you must enter ONLY ONE of the following: list, rabund or sabund." << endl; errorFree = false; }
514                 }else if ((listfile == "") && (rabundfile == "") && (sabundfile == "") && (sharedfile == "")) {
515                             cout << "When executing a read.otu you must enter one of the following: list, rabund or sabund." << endl; errorFree = false; 
516                 }
517                 
518                 //checks parameters on the read command
519                 if (orderfile != "") {
520                         ableToOpen = openInputFile(orderfile, filehandle);
521                         filehandle.close();
522                         if (ableToOpen == 1) { //unable to open
523                                 errorFree = false;
524                         }
525                 }       
526         }
527         catch(exception& e) {
528                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
529                 exit(1);
530         }
531         catch(...) {
532                 cout << "An unknown error has occurred in the ErrorCheck class function validateReadPhil. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
533                 exit(1);
534         }
535 }
536 /*******************************************************/
537
538 /******************************************************/
539 //This function checks to make sure the user entered appropriate
540 // format parameters on a distfile read
541 void ErrorCheck::validateSeqsFiles() {
542         try {
543                 ifstream filehandle;
544                 int ableToOpen;
545                 
546                 //checks to make sure only one file type is given
547                 if (phylipfile != "") { 
548                         if ((nexusfile != "") || (fastafile != "") || (clustalfile != "")) { 
549                                 cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; }
550                         else {
551                                 ableToOpen = openInputFile(phylipfile, filehandle);
552                                 filehandle.close();
553                                 if (ableToOpen == 1) { //unable to open
554                                         errorFree = false;
555                                 }
556                         }
557                 }else if (nexusfile != "") { 
558                         if ((phylipfile != "") || (fastafile != "") || (clustalfile != "")) { 
559                                 cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; }
560                         else {
561                                 ableToOpen = openInputFile(nexusfile, filehandle);
562                                 filehandle.close();
563                                 if (ableToOpen == 1) { //unable to open
564                                         errorFree = false;
565                                 }
566                         }
567                 }else if (fastafile != "") { 
568                         if ((phylipfile != "") || (nexusfile != "") || (clustalfile != "")) { 
569                                 cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; }
570                         else {
571                                 ableToOpen = openInputFile(fastafile, filehandle);
572                                 filehandle.close();
573                                 if (ableToOpen == 1) { //unable to open
574                                         errorFree = false;
575                                 }
576                         }
577                 }else if (clustalfile != "") { 
578                         if ((phylipfile != "") || (nexusfile != "") || (fastafile != "")) { 
579                                 cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; }
580                         else {
581                                 ableToOpen = openInputFile(clustalfile, filehandle);
582                                 filehandle.close();
583                                 if (ableToOpen == 1) { //unable to open
584                                         errorFree = false;
585                                 }
586                         }
587                 }else if (templatefile != "") {
588                         ableToOpen = openInputFile(templatefile, filehandle);
589                         filehandle.close();
590                         if (ableToOpen == 1) { //unable to open
591                                 errorFree = false;
592                         }
593                 }
594                 
595                 
596         }
597         catch(exception& e) {
598                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateSeqsFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
599                 exit(1);
600         }
601         catch(...) {
602                 cout << "An unknown error has occurred in the ErrorCheck class function validateSeqsFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
603                 exit(1);
604         }
605 }
606
607 /*******************************************************/
608
609 /******************************************************/
610 //This function checks to make sure the user entered appropriate
611 // format parameters on a bin.seq command
612 void ErrorCheck::validateBinFiles() {
613         try {
614                 ifstream filehandle;
615                 int ableToOpen;
616                 
617                 if (fastafile == "") {
618                                 cout << "fasta is a required parameter for bin.seqs, get.oturep and get.repseqs commands." << endl; errorFree = false; 
619                 }else if (fastafile != "") {
620                         //is it a valid filename'
621                         ableToOpen = openInputFile(fastafile, filehandle);
622                         filehandle.close();
623                         //unable to open
624                         if (ableToOpen == 1) {  errorFree = false; }
625                 }else if (listfile != "") {
626                         //is it a valid filename'
627                         ableToOpen = openInputFile(listfile, filehandle);
628                         filehandle.close();
629                         //unable to open
630                         if (ableToOpen == 1) {  errorFree = false; }
631                 }else if (globaldata->getNameFile() != "") {
632                         //is it a valid filename'
633                         ifstream filehandle;
634                         int ableToOpen = openInputFile(globaldata->getNameFile(), filehandle);
635                         filehandle.close();
636                         //unable to open
637                         if (ableToOpen == 1) {  errorFree = false; }
638                 }else if (namefile != "") {
639                         //is it a valid filename'
640                         ifstream filehandle;
641                         int ableToOpen = openInputFile(namefile, filehandle);
642                         filehandle.close();
643                         //unable to open
644                         if (ableToOpen == 1) {  errorFree = false; }
645                 }else if (groupfile != "") {
646                         //is it a valid filename'
647                         ifstream filehandle;
648                         int ableToOpen = openInputFile(groupfile, filehandle);
649                         filehandle.close();
650                         //unable to open
651                         if (ableToOpen == 1) {  errorFree = false; }
652                 }
653
654
655
656         }
657         catch(exception& e) {
658                 cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateBinFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
659                 exit(1);
660         }
661         catch(...) {
662                 cout << "An unknown error has occurred in the ErrorCheck class function validateBinFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
663                 exit(1);
664         }
665 }
666
667 /*******************************************************/
668
669 /******************************************************/
670
671 void ErrorCheck::clear() {
672         //option definitions should go here...
673         phylipfile              =       "";
674         columnfile              =       "";
675         listfile                =       "";
676         rabundfile              =       "";
677         sabundfile              =       "";
678         namefile                =       "";
679         groupfile               =       ""; 
680         orderfile               =       "";
681         sharedfile              =       "";
682         fastafile       =   "";
683         nexusfile       =   "";
684         clustalfile     =   "";
685         templatefile    =       "";
686         line                    =       "";
687         label                   =       "";
688         method                  =   "furthest";
689 }
690 /*******************************************************/
691
692 /******************************************************/
693