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