]> git.donarmstrong.com Git - mothur.git/blob - globaldata.cpp
removed readseqs, readfasta, readnexus, readclustal, readseqsphylip and updated seque...
[mothur.git] / globaldata.cpp
1 #include "globaldata.hpp"
2 #include "tree.h"
3 #include "sparsematrix.hpp"
4
5 /*******************************************************/
6
7 /******************************************************/
8 GlobalData* GlobalData::getInstance() {
9         if( _uniqueInstance == 0 ) {
10                 _uniqueInstance = new GlobalData();
11         }
12         return _uniqueInstance;
13 }
14 /*******************************************************/
15
16 /******************************************************/
17 //This function parses through the option string of the command to remove its parameters
18 void GlobalData::parseGlobalData(string commandString, string optionText){
19         try {
20                 commandName = commandString; //save command name to be used by other classes
21                 
22                 //set all non filename paramters to default
23                 reset();
24                 
25                 //clears out data from previous read
26                 if ((commandName == "read.dist") || (commandName == "read.otu") || (commandName == "read.tree")) { 
27                         clear();
28                         gGroupmap = NULL;
29                         gListVector = NULL;
30                         gSparseMatrix = NULL;
31                         gTree.clear();
32                         Treenames.clear();
33                         labels.clear(); lines.clear(); Groups.clear();
34                         allLines = 1;
35                 }
36                 
37                 //saves help request
38                 if (commandName =="help") {
39                         helpRequest = optionText;
40                 }
41                 
42                 if (commandName == "libshuff") {
43                         iters = "10000";
44                         cutoff = "1.0";
45                 }
46                 
47                 //set default value for cutoff
48                 if (commandName == "dist.seqs") {       cutoff = "1.0";         }
49
50                 string key, value;              
51                 //reads in parameters and values
52                 if((optionText != "") && (commandName != "help")){
53                         while((optionText.find_first_of(',') != -1)) {  //while there are parameters
54                                 splitAtComma(value, optionText);
55                                 splitAtEquals(key, value);
56                                 
57                                 if (key == "phylip" )   { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip";       }
58                                 if (key == "column" )   { columnfile = value; inputFileName = value; fileroot = value; format = "column";       }
59                                 if (key == "list" )             { listfile = value; inputFileName = value; fileroot = value; format = "list";           }
60                                 if (key == "rabund" )   { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund";       }
61                                 if (key == "sabund" )   { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund";       } 
62                                 if (key == "fasta" )    { fastafile = value; inputFileName = value; fileroot = value; format = "fasta";         }
63                                 if (key == "tree" )             { treefile = value; inputFileName = value; fileroot = value; format = "tree";           }
64                                 if (key == "shared" )   { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile";   }
65                                 if (key == "name" )             { namefile = value;             }
66                                 if (key == "order" )    { orderfile = value;    }
67                                 if (key == "group" )    { groupfile = value;    }
68                                 if (key == "cutoff" )           { cutoff = value;               }
69                                 if (key == "precision" )        { precision = value;    }
70                                 if (key == "iters" )            { iters = value;                }
71                                 if (key == "jumble" )           { jumble = value;               }
72                                 if (key == "freq" )                     { freq = value;                 }
73                                 if (key == "method" )           { method = value;               }
74                                 if (key == "fileroot" )         { fileroot = value;             }
75                                 if (key == "abund" )        { abund = value;        }
76                                 if (key == "random" )           { randomtree = value;   }
77                                 if (key == "calc")                      { calc = value;                 }
78                                 if (key == "step")                      { step = value;                 }
79                                 if (key == "form")                      { form = value;                 }
80                                 if (key == "sorted")            { sorted = value;               }
81                                 if (key == "vertical")          { vertical = value;             }
82                                 if (key == "trump")                 { trump = value;            }
83                                 if (key == "hard")                      { hard = value;         }
84                                 if (key == "soft")                  { soft = value;                 }
85                                 if (key == "scale")                     { scale = value;                }
86                                 if (key == "countends" )        { countends = value;    }
87                                 if (key == "processors" )       { processors = value;   }
88                                 if (key == "size" )         { size = value;         }
89                                 if (key == "candidate")         { candidatefile = value;        }
90                                 if (key == "search")            { search = value;               }
91                                 if (key == "ksize")                     { ksize = value;                }
92                                 if (key == "align")                 { align = value;            }
93                                 if (key == "match")                     { match = value;                }
94                                 if (key == "mismatch")          { mismatch = value;         }
95                                 if (key == "gapopen")           { gapopen = value;              }
96                                 if (key == "gapextend" )        { gapextend = value;    }
97                                 if (key == "start" )            { startPos = value;     }
98                                 if (key == "end" )                      { endPos = value;       }
99                                 if (key == "maxambig" )         { maxAmbig = value;     }
100                                 if (key == "maxhomop" )         { maxHomoPolymer = value;       }
101                                 if (key == "minlength" )        { minLength = value;    }
102                                 if (key == "maxlength" )        { maxLength = value;    }
103                                 
104                                 if (key == "line") {//stores lines to be used in a vector
105                                         lines.clear();
106                                         labels.clear();
107                                         line = value;
108                                         label = "";
109                                         if (line != "all") {  splitAtDash(value, lines);  allLines = 0;  }
110                                         else { allLines = 1;  }
111                                 }
112                         
113                                 if (key == "label") {//stores lines to be used in a vector
114                                         labels.clear();
115                                         lines.clear();
116                                         label = value;
117                                         line = "";
118                                         if (label != "all") {  splitAtDash(value, labels);  allLines = 0;  }
119                                         else { allLines = 1;  }
120                                 }
121
122                                 if (key == "groups") {//stores groups to be used in a vector
123                                         Groups.clear();
124                                         groups = value;
125                                         splitAtDash(value, Groups);
126                                 }
127
128                         }
129                         
130                         //saves the last parameter
131                         value = optionText;
132                         splitAtEquals(key, value);
133                         if (key == "phylip" )   { phylipfile = value; inputFileName = value; fileroot = value; format = "phylip";       }
134                         if (key == "column" )   { columnfile = value; inputFileName = value; fileroot = value; format = "column";       }
135                         if (key == "list" )             { listfile = value; inputFileName = value; fileroot = value; format = "list";           }
136                         if (key == "rabund" )   { rabundfile = value; inputFileName = value; fileroot = value; format = "rabund";       }
137                         if (key == "sabund" )   { sabundfile = value; inputFileName = value; fileroot = value; format = "sabund";       }
138                         if (key == "fasta" )    { fastafile = value; inputFileName = value; fileroot = value; format = "fasta";         }
139                         if (key == "tree" )             { treefile = value; inputFileName = value; fileroot = value; format = "tree";           } 
140                         if (key == "shared" )   { sharedfile = value; inputFileName = value; fileroot = value; format = "sharedfile";   }
141                         if (key == "name" )             { namefile = value;             }
142                         if (key == "order" )    { orderfile = value;    }
143                         if (key == "group" )    { groupfile = value;    }
144                         if (key == "cutoff" )           { cutoff = value;               }
145                         if (key == "precision" )        { precision = value;    }
146                         if (key == "iters" )            { iters = value;                }
147                         if (key == "jumble" )           { jumble = value;               }
148                         if (key == "freq" )                     { freq = value;                 }
149                         if (key == "method" )           { method = value;               }
150                         if (key == "fileroot" )         { fileroot = value;             }
151                         if (key == "abund" )        { abund = value;        }
152                         if (key == "random" )           { randomtree = value;   }
153                         if (key == "calc")                      { calc = value;                 }
154                         if (key == "step")                      { step = value;                 }
155                         if (key == "form")                      { form = value;                 }
156                         if (key == "sorted")            { sorted = value;               }
157                         if (key == "vertical")          { vertical = value;             }
158                         if (key == "trump")                 { trump = value;            }
159                         if (key == "hard")                      { hard = value;         }
160                         if (key == "soft")                  { soft = value;                 }
161                         if (key == "scale")                     { scale = value;                }
162                         if (key == "countends" )        { countends = value;    }
163                         if (key == "processors" )       { processors = value;   }
164                         if (key == "size" )         { size = value;         }
165                         if (key == "candidate")         { candidatefile = value;        }
166                         if (key == "search")            { search = value;               }
167                         if (key == "ksize")                     { ksize = value;                }
168                         if (key == "align")                 { align = value;            }
169                         if (key == "match")                     { match = value;                }
170                         if (key == "mismatch")          { mismatch = value;         }
171                         if (key == "gapopen")           { gapopen = value;              }
172                         if (key == "gapextend" )        { gapextend = value;    }
173                         if (key == "start" )            { startPos = value;     }
174                         if (key == "end" )                      { endPos = value;       }
175                         if (key == "maxambig" )         { maxAmbig = value;     }
176                         if (key == "maxhomop" )         { maxHomoPolymer = value;       }
177                         if (key == "minlength" )        { minLength = value;    }
178                         if (key == "maxlength" )        { maxLength = value;    }
179
180
181                         if (key == "line") {//stores lines to be used in a vector
182                                 lines.clear();
183                                 labels.clear();
184                                 line = value;
185                                 label = "";
186                                 if (line != "all") {  splitAtDash(value, lines);  allLines = 0;  }
187                                 else { allLines = 1;  }
188                         }
189                         
190                         if (key == "label") {//stores lines to be used in a vector
191                                 labels.clear();
192                                 lines.clear();
193                                 label = value;
194                                 line = "";
195                                 if (label != "all") {  splitAtDash(value, labels);  allLines = 0;  }
196                                 else { allLines = 1;  }
197                         }
198                         
199                         if (key == "groups") {//stores groups to be used in a vector
200                                         Groups.clear();
201                                         groups = value;
202                                         splitAtDash(value, Groups);
203                         }
204                 }
205                 
206                 //set format for shared
207                 if ((listfile != "") && (groupfile != "")) { format = "shared"; }
208                 if ((phylipfile != "") && (groupfile != "")) { format = "matrix"; }
209                                 
210                 //input defaults for calculators
211                 if (commandName == "collect.single") {
212
213                         if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson"; }
214                         Estimators.clear();
215                         splitAtDash(calc, Estimators); 
216                 }
217                 if (commandName == "rarefaction.single") {
218                         if ((calc == "default") || (calc == "")) { calc = "sobs"; }
219                         Estimators.clear();
220                         splitAtDash(calc, Estimators); 
221                 }
222                 if (commandName == "collect.shared") {
223                         if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
224                         Estimators.clear();
225                         splitAtDash(calc, Estimators); 
226                 }
227                 if (commandName == "summary.single") {
228                         if ((calc == "default") || (calc == "")) { calc = "sobs-chao-ace-jack-shannon-npshannon-simpson"; }
229                         Estimators.clear();
230                         splitAtDash(calc, Estimators); 
231                 }
232                 if (commandName == "summary.shared") {
233                         if ((calc == "default") || (calc == "")) { calc = "sharedsobs-sharedchao-sharedace-jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan"; }
234                         Estimators.clear();
235                         splitAtDash(calc, Estimators); 
236                 }
237                 if (commandName == "rarefaction.shared") {
238                         if ((calc == "default") || (calc == "")) { calc = "sharedobserved"; }
239                         Estimators.clear();
240                         splitAtDash(calc, Estimators); 
241                 }
242                 if (commandName == "dist.seqs") {
243                         if ((calc == "default") || (calc == "")) {  calc = "onegap";    }
244                         if (countends == "")    { countends = "T"; }
245                         Estimators.clear();
246                         splitAtDash(calc, Estimators); 
247                 }
248                 if (commandName == "venn") {
249                         if ((calc == "default") || (calc == "")) { 
250                                 if (format == "list") { calc = "sobs"; }
251                                 else { calc = "sharedsobs"; }
252                         }
253                         Estimators.clear();
254                         splitAtDash(calc, Estimators); 
255                 }
256                 if ((commandName == "tree.shared") || (commandName == "bootstrap.shared") || (commandName == "dist.shared")) {
257                         if ((calc == "default") || (calc == "")) { 
258                                 calc = "jclass-thetayc";
259                         }
260                         Estimators.clear();
261                         splitAtDash(calc, Estimators); 
262                 }
263                 
264                 if(commandName == "filter.seqs"){
265                         if(trump == "" && vertical == "" && hard == "" && soft == ""){
266                                 trump = '.';
267                         }
268
269                 }
270
271                 //if you have done a read.otu with a groupfile but don't want to use it anymore because you want to do single commands
272                 if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")) {
273                         if (listfile != "") { format = "list"; }
274                         else if (sabundfile != "") { format = "sabund"; }
275                         else if (rabundfile != "") { format = "rabund"; }
276                 }
277         }
278         catch(exception& e) {
279                 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
280                 exit(1);
281         }
282         catch(...) {
283                 cout << "An unknown error has occurred in the GlobalData class function parseGlobalData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
284                 exit(1);
285         }
286 }
287 /*******************************************************/
288
289 /******************************************************/
290 // These functions give you the option parameters of the commands
291 string GlobalData::getPhylipFile()              {       return phylipfile;      }
292 string GlobalData::getColumnFile()              {       return columnfile;      }
293 string GlobalData::getListFile()                {       return listfile;        }
294 string GlobalData::getRabundFile()              {       return rabundfile;      }
295 string GlobalData::getSabundFile()              {       return sabundfile;      }
296 string GlobalData::getNameFile()                {       return namefile;        }
297 string GlobalData::getGroupFile()               {       return groupfile;       }
298 string GlobalData::getOrderFile()               {       return orderfile;       }
299 string GlobalData::getTreeFile()                {       return treefile;        }
300 string GlobalData::getSharedFile()              {       return sharedfile;      }
301 string GlobalData::getFastaFile()               {       return fastafile;       }
302 string GlobalData::getCutOff()                  {       return cutoff;          }
303 string GlobalData::getFormat()                  {       return format;          }
304 string GlobalData::getPrecision()               {       return precision;       }
305 string GlobalData::getMethod()                  {       return method;          }
306 string GlobalData::getFileRoot()                {       return fileroot;        }
307 string GlobalData::getIters()                   {       return iters;           }
308 string GlobalData::getJumble()                  {       return jumble;          }
309 string GlobalData::getFreq()                    {       return freq;            }
310 string GlobalData::getAbund()           {   return abund;       }
311 string GlobalData::getRandomTree()              {       return randomtree;      }
312 string GlobalData::getGroups()                  {       return groups;          }
313 string GlobalData::getStep()                    {       return step;            }
314 string GlobalData::getForm()                    {       return form;            }
315 string GlobalData::getSorted()                  {       return sorted;          }
316 string GlobalData::getVertical()                {   return vertical;    }
317 string GlobalData::getTrump()                   {   return trump;       }
318 string GlobalData::getSoft()                    {   return soft;                }
319 string GlobalData::getHard()                    {   return hard;                }
320 string GlobalData::getScale()                   {       return scale;           }
321 string GlobalData::getCountEnds()               {   return countends;   }
322 string GlobalData::getProcessors()              {       return processors;      }
323 string GlobalData::getSize()            {   return size;        }
324 string GlobalData::getCandidateFile()   {       return candidatefile;}
325 string GlobalData::getSearch()                  {       return search;          }
326 string GlobalData::getKSize()                   {       return ksize;           }
327 string GlobalData::getAlign()                   {       return align;           }
328 string GlobalData::getMatch()                   {       return match;           }
329 string GlobalData::getMismatch()                {       return mismatch;        }
330 string GlobalData::getGapopen()                 {       return gapopen;         }
331 string GlobalData::getGapextend()               {       return gapextend;       }
332 string GlobalData::getStartPos()                {       return startPos;        }
333 string GlobalData::getEndPos()                  {       return endPos;          }
334 string GlobalData::getMaxAmbig()                {       return maxAmbig;        }
335 string GlobalData::getMaxHomoPolymer()  {       return maxHomoPolymer;  }
336 string GlobalData::getMinLength()               {       return minLength;       }
337 string GlobalData::getMaxLength()               {       return maxLength;       }
338
339
340 void GlobalData::setListFile(string file)               {       listfile = file;        inputFileName = file;                                   }
341 void GlobalData::setRabundFile(string file)             {       rabundfile = file;      inputFileName = file;                                   }
342 void GlobalData::setSabundFile(string file)             {       sabundfile = file;      inputFileName = file;                                   }
343 void GlobalData::setPhylipFile(string file)             {       phylipfile = file;    inputFileName = file;                                     }
344 void GlobalData::setColumnFile(string file)             {       columnfile = file;    inputFileName = file;                                     }
345 void GlobalData::setGroupFile(string file)              {       groupfile = file;                                                                                       }
346 void GlobalData::setSharedFile(string file)             {       sharedfile = file;      inputFileName = file; fileroot = file;  }
347 void GlobalData::setNameFile(string file)               {       namefile = file;                }
348 void GlobalData::setFormat(string Format)               {       format = Format;                }
349 void GlobalData::setRandomTree(string Random)   {       randomtree = Random;    }
350 void GlobalData::setGroups(string g)                    {       groups = g;                             }
351 void GlobalData::setCalc(string Calc)                   {       calc = Calc;                    }
352 void GlobalData::setCountEnds(string e)                 {   countends = e;                      }
353 void GlobalData::setProcessors(string p)                {       processors = p;                 }
354
355
356 /*******************************************************/
357
358 /******************************************************/
359 GlobalData::GlobalData() {
360         //option definitions should go here...
361         helpRequest = "";
362         clear();
363         gListVector = NULL;             
364         gSparseMatrix = NULL;   
365 }
366 /*******************************************************/
367
368 /******************************************************/
369 void GlobalData::clear() {
370         //option definitions should go here...
371         phylipfile              =       "";
372         columnfile              =       "";
373         listfile                =       "";
374         rabundfile              =       "";
375         sabundfile              =       "";
376         namefile                =       "";
377         groupfile               =       ""; 
378         orderfile               =       "";
379         fastafile               =   "";
380         treefile                =       "";
381         sharedfile              =       "";
382         candidatefile   =       "";
383         cutoff                  =       "10.00";
384         format                  =       "";
385         precision               =       "100";
386         iters                   =       "1000"; 
387         line                    =   "";
388         label                   =       "";
389         groups                  =       "";
390         jumble                  =       "1";    //0 means don't jumble, 1 means jumble.
391         randomtree              =       "";  //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
392         freq                    =       "100";
393         method                  =       "furthest";
394         fileroot                =       "";
395         abund           =   "10";
396         step                    =       "0.01";
397         form                    =       "integral";
398         sorted                  =       "T";  //F means don't sort, T means sort.
399         vertical        =   "F";                
400         trump           =       "";             
401         hard                    =   "";         
402         soft            =   ""; 
403         scale                   =       "log10";
404         countends               =   "T";  //yes
405         processors              =       "1";
406         size            =   "0";
407         search                  =       "kmer";
408         ksize                   =       "8";
409         align                   =       "needleman";
410         match                   =       "1.0";
411         mismatch                =       "-1.0";
412         gapopen                 =       "-1.0";
413         gapextend               =       "-2.0";
414         startPos                =       "-1";
415         endPos                  =       "-1";
416         maxAmbig                =       "-1";
417         maxHomoPolymer  =       "-1";
418         minLength               =       "-1";
419         maxLength               =       "-1";
420         
421 }
422
423 //*******************************************************/
424
425 /******************************************************/
426 void GlobalData::reset() {
427         cutoff                  =       "10.00";
428         precision               =       "100";
429         iters                   =       "1000"; 
430         groups                  =       "";
431         jumble                  =       "1";    //0 means don't jumble, 1 means jumble.
432         sorted                  =       "T";  //F means don't sort, T means sort.
433         randomtree              =       "";  //"" means user will enter some user trees, "outputfile" means they just want the random tree distribution to be outputted to outputfile.
434         freq                    =       "100";
435         method                  =       "furthest";
436         calc                    =       "";
437         abund                   =   "10";
438         step                    =       "0.01";
439         form                    =       "integral";
440         countends               =   "T";
441         processors              =       "1";
442         size            =   "0";
443         search                  =       "kmer";
444         ksize                   =       "8";
445         align                   =       "needleman";
446         match                   =       "1.0";
447         mismatch                =       "-1.0";
448         gapopen                 =       "-1.0";
449         gapextend               =       "-2.0";
450         vertical        =   "";         
451         trump           =   "";         
452         hard                    =   "";         
453         soft            =   ""; 
454         startPos                =       "-1";
455         endPos                  =       "-1";
456         maxAmbig                =       "-1";
457         maxHomoPolymer  =       "-1";
458         minLength               =       "-1";
459         maxLength               =       "-1";
460         
461 }
462 /*******************************************************/
463
464 /******************************************************/
465 GlobalData::~GlobalData() {
466         _uniqueInstance = 0;
467         if(gListVector != NULL)         {       delete gListVector;             }
468         if(gSparseMatrix != NULL)       {       delete gSparseMatrix;   }
469         if(gorder != NULL)                      {       delete gorder;          }
470 }
471 /*******************************************************/
472
473 /*******************************************************/
474 void GlobalData::parseTreeFile() {
475         //Why is THIS in GlobalData??? - PDS
476         
477         //only takes names from the first tree and assumes that all trees use the same names.
478         try {
479                 string filename = treefile;
480                 ifstream filehandle;
481                 openInputFile(filename, filehandle);
482                 int c, comment;
483                 comment = 0;
484                 
485                 //if you are not a nexus file 
486                 if ((c = filehandle.peek()) != '#') {  
487                         while((c = filehandle.peek()) != ';') { 
488                                 while ((c = filehandle.peek()) != ';') {
489                                         // get past comments
490                                         if(c == '[') {
491                                                 comment = 1;
492                                         }
493                                         if(c == ']'){
494                                                 comment = 0;
495                                         }
496                                         if((c == '(') && (comment != 1)){ break; }
497                                         filehandle.get();
498                                 }
499
500                                 readTreeString(filehandle); 
501                         }
502                 //if you are a nexus file
503                 }else if ((c = filehandle.peek()) == '#') {
504                         string holder = "";
505                                         
506                         // get past comments
507                         while(holder != "translate" && holder != "Translate"){  
508                                 if(holder == "[" || holder == "[!"){
509                                         comment = 1;
510                                 }
511                                 if(holder == "]"){
512                                         comment = 0;
513                                 }
514                                 filehandle >> holder; 
515         
516                                 //if there is no translate then you must read tree string otherwise use translate to get names
517                                 if(holder == "tree" && comment != 1){   
518                                         //pass over the "tree rep.6878900 = "
519                                         while (((c = filehandle.get()) != '(') && ((c = filehandle.peek()) != EOF) ) {;}
520
521                                         if (c == EOF ) { break; }
522                                         filehandle.putback(c);  //put back first ( of tree.
523                                         readTreeString(filehandle);     
524                                         break;
525                                 }
526                         }
527                         
528                         //use nexus translation rather than parsing tree to save time
529                         if ((holder == "translate") || (holder == "Translate")) {
530
531                                 string number, name, h;
532                                 h = ""; // so it enters the loop the first time
533                                 while((h != ";") && (number != ";")) { 
534                                         filehandle >> number;
535                                         filehandle >> name;
536         
537                                         //c = , until done with translation then c = ;
538                                         h = name.substr(name.length()-1, name.length()); 
539                                         name.erase(name.end()-1);  //erase the comma
540                                         Treenames.push_back(number);
541                                 }
542                                 if (number == ";") { Treenames.pop_back(); }  //in case ';' from translation is on next line instead of next to last name
543                         }
544                 }
545                 
546         }
547         catch(exception& e) {
548                 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
549                 exit(1);
550         }
551         catch(...) {
552                 cout << "An unknown error has occurred in the GlobalData class function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
553                 exit(1);
554         }               
555 }
556 /*******************************************************/
557
558 /*******************************************************/
559 void GlobalData::readTreeString(ifstream& filehandle)   {
560         try {
561                 int c;
562                 string name; //k
563                 
564                 while((c = filehandle.peek()) != ';') { 
565                                 //if you are a name
566                         if ((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != '\t') && (c != 32)) { //32 is space
567                                 name = "";
568                                 c = filehandle.get();
569         //              k = c;
570 //cout << k << endl;
571                                 while ((c != '(') && (c != ')') && (c != ',') && (c != ':') && (c != '\n') && (c != 32) && (c != '\t')) {                       
572                                         name += c;
573                                         c = filehandle.get();
574                 //      k = c;
575 //cout << " in name while " << k << endl;
576                                 }
577                                 
578 //cout << "name = " << name << endl;
579                                 Treenames.push_back(name);
580                                 filehandle.putback(c);
581 //k = c;
582 //cout << " after putback" <<  k << endl;
583                         } 
584                         
585                         if (c  == ':') { //read until you reach the end of the branch length
586                                 while ((c != '(') && (c != ')') && (c != ',') && (c != ';') && (c != '\n') && (c != '\t') && (c != 32)) {
587                                         c = filehandle.get();
588                                 //      k = c;
589         //cout << " in branch while " << k << endl;
590                                 }
591                                 filehandle.putback(c);
592                         }
593                         c = filehandle.get();
594                         if (c == ';') { break; }
595                 //      k = c;
596 //cout << k << endl;
597
598                 }
599         }
600         catch(exception& e) {
601                 cout << "Standard Error: " << e.what() << " has occurred in the GlobalData class Function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
602                 exit(1);
603         }
604         catch(...) {
605                 cout << "An unknown error has occurred in the GlobalData class function parseTreeFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
606                 exit(1);
607         }               
608 }       
609
610 /*******************************************************/
611
612 /*******************************************************/
613
614