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