]> git.donarmstrong.com Git - mothur.git/blob - mothurout.cpp
added unix to ifdefs. minor changes while testing 1.24.0.
[mothur.git] / mothurout.cpp
1 /*
2  *  mothurOut.cpp
3  *  Mothur
4  *
5  *  Created by westcott on 2/25/10.
6  *  Copyright 2010 Schloss Lab. All rights reserved.
7  *
8  */
9
10 #include "mothurout.h"
11
12
13 /******************************************************/
14 MothurOut* MothurOut::getInstance() {
15         if( _uniqueInstance == 0) {
16                 _uniqueInstance = new MothurOut();
17         }
18         return _uniqueInstance;
19 }
20 /*********************************************************************************************/
21 void MothurOut::printCurrentFiles()  {
22         try {
23                 if (accnosfile != "")           {  mothurOut("accnos=" + accnosfile); mothurOutEndLine();                       }
24                 if (columnfile != "")           {  mothurOut("column=" + columnfile); mothurOutEndLine();                       }
25                 if (designfile != "")           {  mothurOut("design=" + designfile); mothurOutEndLine();                       }
26                 if (fastafile != "")            {  mothurOut("fasta=" + fastafile); mothurOutEndLine();                         }
27                 if (groupfile != "")            {  mothurOut("group=" + groupfile); mothurOutEndLine();                         }
28                 if (listfile != "")                     {  mothurOut("list=" + listfile); mothurOutEndLine();                           }
29                 if (namefile != "")                     {  mothurOut("name=" + namefile); mothurOutEndLine();                           }
30                 if (oligosfile != "")           {  mothurOut("oligos=" + oligosfile); mothurOutEndLine();                       }
31                 if (orderfile != "")            {  mothurOut("order=" + orderfile); mothurOutEndLine();                         }
32                 if (ordergroupfile != "")       {  mothurOut("ordergroup=" + ordergroupfile); mothurOutEndLine();       }
33                 if (phylipfile != "")           {  mothurOut("phylip=" + phylipfile); mothurOutEndLine();                       }
34                 if (qualfile != "")                     {  mothurOut("qfile=" + qualfile); mothurOutEndLine();                          }
35                 if (rabundfile != "")           {  mothurOut("rabund=" + rabundfile); mothurOutEndLine();                       }
36                 if (relabundfile != "")         {  mothurOut("relabund=" + relabundfile); mothurOutEndLine();           }
37                 if (sabundfile != "")           {  mothurOut("sabund=" + sabundfile); mothurOutEndLine();                       }
38                 if (sfffile != "")                      {  mothurOut("sff=" + sfffile); mothurOutEndLine();                                     }
39                 if (sharedfile != "")           {  mothurOut("shared=" + sharedfile); mothurOutEndLine();                       }
40                 if (taxonomyfile != "")         {  mothurOut("taxonomy=" + taxonomyfile); mothurOutEndLine();           }
41                 if (treefile != "")                     {  mothurOut("tree=" + treefile); mothurOutEndLine();                           }
42                 if (flowfile != "")                     {  mothurOut("flow=" + flowfile); mothurOutEndLine();                           }
43                 if (processors != "1")          {  mothurOut("processors=" + processors); mothurOutEndLine();           }
44                 
45         }
46         catch(exception& e) {
47                 errorOut(e, "MothurOut", "printCurrentFiles");
48                 exit(1);
49         }
50 }
51 /*********************************************************************************************/
52 bool MothurOut::hasCurrentFiles()  {
53         try {
54                 bool hasCurrent = false;
55                 
56                 if (accnosfile != "")           {  return true;                 }
57                 if (columnfile != "")           {  return true;                 }
58                 if (designfile != "")           {  return true;                 }
59                 if (fastafile != "")            {  return true;                 }
60                 if (groupfile != "")            {  return true;                 }
61                 if (listfile != "")                     {  return true;                 }
62                 if (namefile != "")                     {  return true;                 }
63                 if (oligosfile != "")           {  return true;                 }
64                 if (orderfile != "")            {  return true;                 }
65                 if (ordergroupfile != "")       {  return true;                 }
66                 if (phylipfile != "")           {  return true;                 }
67                 if (qualfile != "")                     {  return true;                 }
68                 if (rabundfile != "")           {  return true;                 }
69                 if (relabundfile != "")         {  return true;                 }
70                 if (sabundfile != "")           {  return true;                 }
71                 if (sfffile != "")                      {  return true;                 }
72                 if (sharedfile != "")           {  return true;                 }
73                 if (taxonomyfile != "")         {  return true;                 }
74                 if (treefile != "")                     {  return true;                 }
75                 if (flowfile != "")                     {  return true;                 }
76                 if (processors != "1")          {  return true;                 }
77                 
78                 return hasCurrent;
79                 
80         }
81         catch(exception& e) {
82                 errorOut(e, "MothurOut", "hasCurrentFiles");
83                 exit(1);
84         }
85 }
86
87 /*********************************************************************************************/
88 void MothurOut::clearCurrentFiles()  {
89         try {
90                 phylipfile = "";
91                 columnfile = "";
92                 listfile = "";
93                 rabundfile = "";
94                 sabundfile = "";
95                 namefile = "";
96                 groupfile = "";
97                 designfile = "";
98                 orderfile = "";
99                 treefile = "";
100                 sharedfile = "";
101                 ordergroupfile = "";
102                 relabundfile = "";
103                 fastafile = "";
104                 qualfile = "";
105                 sfffile = "";
106                 oligosfile = "";
107                 accnosfile = "";
108                 taxonomyfile = "";      
109                 flowfile = "";
110                 processors = "1";
111         }
112         catch(exception& e) {
113                 errorOut(e, "MothurOut", "clearCurrentFiles");
114                 exit(1);
115         }
116 }
117 /*********************************************************************************************/
118 void MothurOut::setFileName(string filename)  {
119         try {
120                 logFileName = filename;
121                 
122                 #ifdef USE_MPI
123                         int pid;
124                         MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
125                                         
126                         if (pid == 0) { //only one process should output to screen
127                 #endif
128                 
129                 openOutputFile(filename, out);
130                 
131                 #ifdef USE_MPI
132                         }
133                 #endif
134         }
135         catch(exception& e) {
136                 errorOut(e, "MothurOut", "setFileName");
137                 exit(1);
138         }
139 }
140 /*********************************************************************************************/
141 void MothurOut::setDefaultPath(string pathname)  {
142         try {
143         
144                 //add / to name if needed
145                 string lastChar = pathname.substr(pathname.length()-1);
146                 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
147                         if (lastChar != "/") { pathname += "/"; }
148                 #else
149                         if (lastChar != "\\") { pathname += "\\"; }     
150                 #endif
151                 
152                 defaultPath = pathname;
153                 
154         }
155         catch(exception& e) {
156                 errorOut(e, "MothurOut", "setDefaultPath");
157                 exit(1);
158         }
159 }
160 /*********************************************************************************************/
161 void MothurOut::setOutputDir(string pathname)  {
162         try {
163                 outputDir = pathname;
164         }
165         catch(exception& e) {
166                 errorOut(e, "MothurOut", "setOutputDir");
167                 exit(1);
168         }
169 }
170 /*********************************************************************************************/
171 void MothurOut::closeLog()  {
172         try {
173                 
174                 #ifdef USE_MPI
175                         int pid;
176                         MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
177                                         
178                         if (pid == 0) { //only one process should output to screen
179                 #endif
180                 
181                 out.close();
182                 
183                 #ifdef USE_MPI
184                         }
185                 #endif
186         }
187         catch(exception& e) {
188                 errorOut(e, "MothurOut", "closeLog");
189                 exit(1);
190         }
191 }
192
193 /*********************************************************************************************/
194 MothurOut::~MothurOut() {
195         try {
196                 _uniqueInstance = 0;
197                 
198         }
199         catch(exception& e) {
200                 errorOut(e, "MothurOut", "MothurOut");
201                 exit(1);
202         }
203 }
204 /*********************************************************************************************/
205 void MothurOut::mothurOut(string output) {
206         try {
207                 
208                 #ifdef USE_MPI
209                         int pid;
210                         MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
211                                         
212                         if (pid == 0) { //only one process should output to screen
213                 #endif
214                 
215                 out << output;
216         logger() << output;
217                 
218                 #ifdef USE_MPI
219                         }
220                 #endif
221         }
222         catch(exception& e) {
223                 errorOut(e, "MothurOut", "MothurOut");
224                 exit(1);
225         }
226 }
227 /*********************************************************************************************/
228 void MothurOut::mothurOutEndLine() {
229         try {
230                 #ifdef USE_MPI
231                         int pid;
232                         MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
233                                         
234                         if (pid == 0) { //only one process should output to screen
235                 #endif
236                 
237                 out << endl;
238         logger() << endl;
239                 
240                 #ifdef USE_MPI
241                         }
242                 #endif
243         }
244         catch(exception& e) {
245                 errorOut(e, "MothurOut", "MothurOutEndLine");
246                 exit(1);
247         }
248 }
249 /*********************************************************************************************/
250 void MothurOut::mothurOut(string output, ofstream& outputFile) {
251         try {
252                 
253 #ifdef USE_MPI
254                 int pid;
255                 MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
256                 
257                 if (pid == 0) { //only one process should output to screen
258 #endif
259                         
260                         
261                         out << output;
262                         outputFile << output;
263             logger() << output;
264                         
265 #ifdef USE_MPI
266                 }
267 #endif
268         
269         }
270         catch(exception& e) {
271                 errorOut(e, "MothurOut", "MothurOut");
272                 exit(1);
273         }
274 }
275 /*********************************************************************************************/
276 void MothurOut::mothurOutEndLine(ofstream& outputFile) {
277         try {
278 #ifdef USE_MPI
279                 int pid;
280                 MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
281                 
282                 if (pid == 0) { //only one process should output to screen
283 #endif
284                         
285                         out << endl;
286                         outputFile << endl;
287             logger() << endl;
288                         
289 #ifdef USE_MPI
290                 }
291 #endif
292         }
293         catch(exception& e) {
294                 errorOut(e, "MothurOut", "MothurOutEndLine");
295                 exit(1);
296         }
297 }
298 /*********************************************************************************************/
299 void MothurOut::mothurOutJustToLog(string output) {
300         try {
301                 #ifdef USE_MPI
302                         int pid;
303                         MPI_Comm_rank(MPI_COMM_WORLD, &pid); 
304                                         
305                         if (pid == 0) { //only one process should output to screen
306                 #endif
307                 
308                 out << output;
309                 
310                 #ifdef USE_MPI
311                         }
312                 #endif
313         }
314         catch(exception& e) {
315                 errorOut(e, "MothurOut", "MothurOutJustToLog");
316                 exit(1);
317         }
318 }
319 /*********************************************************************************************/
320 void MothurOut::errorOut(exception& e, string object, string function) {
321         //double vm, rss;
322         //mem_usage(vm, rss);
323         
324         mothurOut("[ERROR]: ");
325         mothurOut(toString(e.what()));
326         mothurOut(" has occurred in the " + object + " class function " + function + ". Please contact Pat Schloss at mothur.bugs@gmail.com, and be sure to include the mothur.logFile with your inquiry.");
327         mothurOutEndLine();
328 }
329 /*********************************************************************************************/
330 //The following was originally from http://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-run-time-in-c 
331 // process_mem_usage(double &, double &) - takes two doubles by reference,
332 // attempts to read the system-dependent data for a process' virtual memory
333 // size and resident set size, and return the results in KB.
334 //
335 // On failure, returns 0.0, 0.0
336 int MothurOut::mem_usage(double& vm_usage, double& resident_set) {
337   #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
338   
339            vm_usage     = 0.0;
340            resident_set = 0.0;
341
342            // 'file' stat seems to give the most reliable results
343            //
344            ifstream stat_stream("/proc/self/stat",ios_base::in);
345
346            // dummy vars for leading entries in stat that we don't care about
347            //
348            string pid, comm, state, ppid, pgrp, session, tty_nr;
349            string tpgid, flags, minflt, cminflt, majflt, cmajflt;
350            string utime, stime, cutime, cstime, priority, nice;
351            string O, itrealvalue, starttime;
352
353            // the two fields we want
354            //
355            unsigned long vsize;
356            long rss;
357
358            stat_stream >> pid >> comm >> state >> ppid >> pgrp >> session >> tty_nr
359                                    >> tpgid >> flags >> minflt >> cminflt >> majflt >> cmajflt
360                                    >> utime >> stime >> cutime >> cstime >> priority >> nice
361                                    >> O >> itrealvalue >> starttime >> vsize >> rss; // don't care about the rest
362
363            long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // in case x86-64 is configured to use 2MB pages
364            vm_usage     = vsize / 1024.0;
365            resident_set = rss * page_size_kb;
366            
367            mothurOut("Memory Usage: vm = " + toString(vm_usage) + " rss = " + toString(resident_set) + "\n");
368                 return 0;
369
370         #else
371 /*              //windows memory usage
372                 // Get the list of process identifiers.
373                 DWORD aProcesses[1024], cbNeeded, cProcesses;
374                 
375                 if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ){ return 1; }
376
377                 // Calculate how many process identifiers were returned.
378                 cProcesses = cbNeeded / sizeof(DWORD);
379
380                 // Print the memory usage for each process
381                 for (int i = 0; i < cProcesses; i++ ) {
382                         DWORD processID = aProcesses[i];
383                         
384                         PROCESS_MEMORY_COUNTERS pmc;
385
386                         HANDLE hProcess = OpenProcess((PROCESS_QUERY_INFORMATION | PROCESS_VM_READ), FALSE, processID);
387
388                         // Print the process identifier.
389                         printf( "\nProcess ID: %u\n", processID);
390                         
391                         if (NULL != hProcess) {
392
393                                 if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) ) {
394                                         printf( "\tPageFaultCount: 0x%08X\n", pmc.PageFaultCount );
395                                         printf( "\tPeakWorkingSetSize: 0x%08X\n", pmc.PeakWorkingSetSize );
396                                         printf( "\tWorkingSetSize: 0x%08X\n", pmc.WorkingSetSize );
397                                         printf( "\tQuotaPeakPagedPoolUsage: 0x%08X\n", pmc.QuotaPeakPagedPoolUsage );
398                                         printf( "\tQuotaPagedPoolUsage: 0x%08X\n", pmc.QuotaPagedPoolUsage );
399                                         printf( "\tQuotaPeakNonPagedPoolUsage: 0x%08X\n", pmc.QuotaPeakNonPagedPoolUsage );
400                                         printf( "\tQuotaNonPagedPoolUsage: 0x%08X\n", pmc.QuotaNonPagedPoolUsage );
401                                         printf( "\tPagefileUsage: 0x%08X\n", pmc.PagefileUsage ); 
402                                         printf( "\tPeakPagefileUsage: 0x%08X\n", pmc.PeakPagefileUsage );
403                                 }
404                                 CloseHandle(hProcess);
405                         }
406                 }
407 */
408                         return 0;
409
410         #endif
411 }
412
413
414 /***********************************************************************/
415 int MothurOut::openOutputFileAppend(string fileName, ofstream& fileHandle){
416         try {
417                 fileName = getFullPathName(fileName);
418                 
419                 fileHandle.open(fileName.c_str(), ios::app);
420                 if(!fileHandle) {
421                         mothurOut("[ERROR]: Could not open " + fileName); mothurOutEndLine();
422                         return 1;
423                 }
424                 else {
425                         return 0;
426                 }
427         }
428         catch(exception& e) {
429                 errorOut(e, "MothurOut", "openOutputFileAppend");
430                 exit(1);
431         }
432 }
433 /***********************************************************************/
434 void MothurOut::gobble(istream& f){
435         try {
436                 
437                 char d;
438                 while(isspace(d=f.get()))               { ;}
439                 if(!f.eof()) { f.putback(d); }
440         }
441         catch(exception& e) {
442                 errorOut(e, "MothurOut", "gobble");
443                 exit(1);
444         }
445 }
446 /***********************************************************************/
447 void MothurOut::gobble(istringstream& f){
448         try {
449                 char d;
450                 while(isspace(d=f.get()))               {;}
451                 if(!f.eof()) { f.putback(d); }
452         }
453         catch(exception& e) {
454                 errorOut(e, "MothurOut", "gobble");
455                 exit(1);
456         }
457 }
458
459 /***********************************************************************/
460
461 string MothurOut::getline(istringstream& fileHandle) {
462         try {
463         
464                 string line = "";
465                 
466                 while (!fileHandle.eof())       {
467                         //get next character
468                         char c = fileHandle.get(); 
469                         
470                         //are you at the end of the line
471                         if ((c == '\n') || (c == '\r') || (c == '\f')){  break; }       
472                         else {          line += c;              }
473                 }
474                 
475                 return line;
476                 
477         }
478         catch(exception& e) {
479                 errorOut(e, "MothurOut", "getline");
480                 exit(1);
481         }
482 }
483 /***********************************************************************/
484
485 string MothurOut::getline(ifstream& fileHandle) {
486         try {
487         
488                 string line = "";
489                 
490                 while (fileHandle)      {
491                         //get next character
492                         char c = fileHandle.get(); 
493                         
494                         //are you at the end of the line
495                         if ((c == '\n') || (c == '\r') || (c == '\f') || (c == EOF)){  break;   }       
496                         else {          line += c;              }
497                 }
498                 
499                 return line;
500                 
501         }
502         catch(exception& e) {
503                 errorOut(e, "MothurOut", "getline");
504                 exit(1);
505         }
506 }
507 /***********************************************************************/
508
509 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
510 #ifdef USE_COMPRESSION
511 inline bool endsWith(string s, const char * suffix){
512   size_t suffixLength = strlen(suffix);
513   return s.size() >= suffixLength && s.substr(s.size() - suffixLength, suffixLength).compare(suffix) == 0;
514 }
515 #endif
516 #endif
517
518 string MothurOut::getRootName(string longName){
519         try {
520         
521                 string rootName = longName;
522
523 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
524 #ifdef USE_COMPRESSION
525     if (endsWith(rootName, ".gz") || endsWith(rootName, ".bz2")) {
526       int pos = rootName.find_last_of('.');
527       rootName = rootName.substr(0, pos);
528       cerr << "shortening " << longName << " to " << rootName << "\n";
529     }
530 #endif
531 #endif
532                 if(rootName.find_last_of(".") != rootName.npos){
533                         int pos = rootName.find_last_of('.')+1;
534                         rootName = rootName.substr(0, pos);
535                 }
536
537                 return rootName;
538         }
539         catch(exception& e) {
540                 errorOut(e, "MothurOut", "getRootName");
541                 exit(1);
542         }
543 }
544 /***********************************************************************/
545
546 string MothurOut::getSimpleName(string longName){
547         try {
548                 string simpleName = longName;
549                 
550                 size_t found;
551                 found=longName.find_last_of("/\\");
552
553                 if(found != longName.npos){
554                         simpleName = longName.substr(found+1);
555                 }
556                 
557                 return simpleName;
558         }
559         catch(exception& e) {
560                 errorOut(e, "MothurOut", "getSimpleName");
561                 exit(1);
562         }
563 }
564
565 /***********************************************************************/
566
567 int MothurOut::getRandomIndex(int highest){
568         try {
569                 
570                 int random = (int) ((float)(highest+1) * (float)(rand()) / ((float)RAND_MAX+1.0));
571                 
572                 return random;
573         }
574         catch(exception& e) {
575                 errorOut(e, "MothurOut", "getRandomIndex");
576                 exit(1);
577         }       
578         
579 }
580 /**********************************************************************/
581
582 string MothurOut::getPathName(string longName){
583         try {
584                 string rootPathName = longName;
585                 
586                 if(longName.find_last_of("/\\") != longName.npos){
587                         int pos = longName.find_last_of("/\\")+1;
588                         rootPathName = longName.substr(0, pos);
589                 }
590                 
591                 return rootPathName;
592         }
593         catch(exception& e) {
594                 errorOut(e, "MothurOut", "getPathName");
595                 exit(1);
596         }       
597
598 }
599 /***********************************************************************/
600
601 string MothurOut::hasPath(string longName){
602         try {
603                 string path = "";
604                 
605                 size_t found;
606                 found=longName.find_last_of("~/\\");
607
608                 if(found != longName.npos){
609                         path = longName.substr(0, found+1);
610                 }
611                 
612                 return path;
613         }
614         catch(exception& e) {
615                 errorOut(e, "MothurOut", "hasPath");
616                 exit(1);
617         }       
618 }
619
620 /***********************************************************************/
621
622 string MothurOut::getExtension(string longName){
623         try {
624                 string extension = longName;
625                 
626                 if(longName.find_last_of('.') != longName.npos){
627                         int pos = longName.find_last_of('.');
628                         extension = longName.substr(pos, longName.length());
629                 }
630                 
631                 return extension;
632         }
633         catch(exception& e) {
634                 errorOut(e, "MothurOut", "getExtension");
635                 exit(1);
636         }       
637 }
638 /***********************************************************************/
639 bool MothurOut::isBlank(string fileName){
640         try {
641                 
642                 fileName = getFullPathName(fileName);
643                 
644                 ifstream fileHandle;
645                 fileHandle.open(fileName.c_str());
646                 if(!fileHandle) {
647                         mothurOut("[ERROR]: Could not open " + fileName); mothurOutEndLine();
648                         return false;
649                 }else {
650                         //check for blank file
651                         gobble(fileHandle);
652                         if (fileHandle.eof()) { fileHandle.close(); return true;  }
653                         fileHandle.close();
654                 }
655                 return false;
656         }
657         catch(exception& e) {
658                 errorOut(e, "MothurOut", "isBlank");
659                 exit(1);
660         }       
661 }
662 /***********************************************************************/
663
664 string MothurOut::getFullPathName(string fileName){
665         try{
666         
667         string path = hasPath(fileName);
668         string newFileName;
669         int pos;
670         
671         if (path == "") { return fileName; } //its a simple name
672         else { //we need to complete the pathname
673                 // ex. ../../../filename 
674                 // cwd = /user/work/desktop
675                                 
676                 string cwd;
677                 //get current working directory 
678                 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)  
679                         
680                         if (path.find("~") != -1) { //go to home directory
681                                 string homeDir;
682                         
683                                 char *homepath = NULL;
684                                 homepath = getenv ("HOME");
685                                 if ( homepath != NULL) { homeDir = homepath; }
686                                 else { homeDir = "";  }
687
688                                 newFileName = homeDir + fileName.substr(fileName.find("~")+1);
689                                 return newFileName;
690                         }else { //find path
691                                 if (path.rfind("./") == string::npos) { return fileName; } //already complete name
692                                 else { newFileName = fileName.substr(fileName.rfind("./")+2); } //save the complete part of the name
693                                 
694                                 //char* cwdpath = new char[1024];
695                                 //size_t size;
696                                 //cwdpath=getcwd(cwdpath,size);
697                                 //cwd = cwdpath;
698                                 
699                                 char *cwdpath = NULL;
700                                 cwdpath = getcwd(NULL, 0); // or _getcwd
701                                 if ( cwdpath != NULL) { cwd = cwdpath; }
702                                 else { cwd = "";  }
703
704                                 
705                                 //rip off first '/'
706                                 string simpleCWD;
707                                 if (cwd.length() > 0) { simpleCWD = cwd.substr(1); }
708                                 
709                                 //break apart the current working directory
710                                 vector<string> dirs;
711                                 while (simpleCWD.find_first_of('/') != string::npos) {
712                                         string dir = simpleCWD.substr(0,simpleCWD.find_first_of('/'));
713                                         simpleCWD = simpleCWD.substr(simpleCWD.find_first_of('/')+1, simpleCWD.length());
714                                         dirs.push_back(dir);
715                                 }
716                                 //get last one              // ex. ../../../filename = /user/work/desktop/filename
717                                 dirs.push_back(simpleCWD);  //ex. dirs[0] = user, dirs[1] = work, dirs[2] = desktop
718                                 
719                         
720                                 int index = dirs.size()-1;
721                 
722                                 while((pos = path.rfind("./")) != string::npos) { //while you don't have a complete path
723                                         if (pos == 0) { break;  //you are at the end
724                                         }else if (path[(pos-1)] == '.') { //you want your parent directory ../
725                                                 path = path.substr(0, pos-1);
726                                                 index--;
727                                                 if (index == 0) {  break; }
728                                         }else if (path[(pos-1)] == '/') { //you want the current working dir ./
729                                                 path = path.substr(0, pos);
730                                         }else if (pos == 1) { break;  //you are at the end
731                                         }else { mothurOut("cannot resolve path for " +  fileName + "\n"); return fileName; }
732                                 }
733                         
734                                 for (int i = index; i >= 0; i--) {
735                                         newFileName = dirs[i] +  "/" + newFileName;             
736                                 }
737                                 
738                                 newFileName =  "/" +  newFileName;
739                                 return newFileName;
740                         }       
741                 #else
742                         if (path.find("~") != string::npos) { //go to home directory
743                                 string homeDir = getenv ("HOMEPATH");
744                                 newFileName = homeDir + fileName.substr(fileName.find("~")+1);
745                                 return newFileName;
746                         }else { //find path
747                                 if (path.rfind(".\\") == string::npos) { return fileName; } //already complete name
748                                 else { newFileName = fileName.substr(fileName.rfind(".\\")+2); } //save the complete part of the name
749                                                         
750                                 char *cwdpath = NULL;
751                                 cwdpath = getcwd(NULL, 0); // or _getcwd
752                                 if ( cwdpath != NULL) { cwd = cwdpath; }
753                                 else { cwd = "";  }
754                                 
755                                 //break apart the current working directory
756                                 vector<string> dirs;
757                                 while (cwd.find_first_of('\\') != -1) {
758                                         string dir = cwd.substr(0,cwd.find_first_of('\\'));
759                                         cwd = cwd.substr(cwd.find_first_of('\\')+1, cwd.length());
760                                         dirs.push_back(dir);
761                 
762                                 }
763                                 //get last one
764                                 dirs.push_back(cwd);  //ex. dirs[0] = user, dirs[1] = work, dirs[2] = desktop
765                                         
766                                 int index = dirs.size()-1;
767                                         
768                                 while((pos = path.rfind(".\\")) != string::npos) { //while you don't have a complete path
769                                         if (pos == 0) { break;  //you are at the end
770                                         }else if (path[(pos-1)] == '.') { //you want your parent directory ../
771                                                 path = path.substr(0, pos-1);
772                                                 index--;
773                                                 if (index == 0) {  break; }
774                                         }else if (path[(pos-1)] == '\\') { //you want the current working dir ./
775                                                 path = path.substr(0, pos);
776                                         }else if (pos == 1) { break;  //you are at the end
777                                         }else { mothurOut("cannot resolve path for " +  fileName + "\n"); return fileName; }
778                                 }
779                         
780                                 for (int i = index; i >= 0; i--) {
781                                         newFileName = dirs[i] +  "\\" + newFileName;            
782                                 }
783                                 
784                                 return newFileName;
785                         }
786                         
787                 #endif
788         }
789         }
790         catch(exception& e) {
791                 errorOut(e, "MothurOut", "getFullPathName");
792                 exit(1);
793         }       
794 }
795 /***********************************************************************/
796
797 int MothurOut::openInputFile(string fileName, ifstream& fileHandle, string m){
798         try {
799                         //get full path name
800                         string completeFileName = getFullPathName(fileName);
801 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
802 #ifdef USE_COMPRESSION
803       // check for gzipped or bzipped file
804       if (endsWith(completeFileName, ".gz") || endsWith(completeFileName, ".bz2")) {
805         string tempName = string(tmpnam(0));
806         mkfifo(tempName.c_str(), 0666);
807         int fork_result = fork();
808         if (fork_result < 0) {
809           cerr << "Error forking.\n";
810           exit(1);
811         } else if (fork_result == 0) {
812           string command = (endsWith(completeFileName, ".gz") ? "zcat " : "bzcat ") + completeFileName + string(" > ") + tempName;
813           cerr << "Decompressing " << completeFileName << " via temporary named pipe " << tempName << "\n";
814           system(command.c_str());
815           cerr << "Done decompressing " << completeFileName << "\n";
816           mothurRemove(tempName);
817           exit(EXIT_SUCCESS);
818         } else {
819           cerr << "waiting on child process " << fork_result << "\n";
820           completeFileName = tempName;
821         }
822       }
823 #endif
824 #endif
825                         fileHandle.open(completeFileName.c_str());
826                         if(!fileHandle) {
827                                 //mothurOut("[ERROR]: Could not open " + completeFileName); mothurOutEndLine();
828                                 return 1;
829                         }else {
830                                 //check for blank file
831                                 gobble(fileHandle);
832                                 return 0;
833                         }
834         }
835         catch(exception& e) {
836                 errorOut(e, "MothurOut", "openInputFile - no Error");
837                 exit(1);
838         }
839 }
840 /***********************************************************************/
841
842 int MothurOut::openInputFile(string fileName, ifstream& fileHandle){
843         try {
844
845                 //get full path name
846                 string completeFileName = getFullPathName(fileName);
847 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
848 #ifdef USE_COMPRESSION
849   // check for gzipped or bzipped file
850   if (endsWith(completeFileName, ".gz") || endsWith(completeFileName, ".bz2")) {
851     string tempName = string(tmpnam(0));
852     mkfifo(tempName.c_str(), 0666);
853     int fork_result = fork();
854     if (fork_result < 0) {
855       cerr << "Error forking.\n";
856       exit(1);
857     } else if (fork_result == 0) {
858       string command = (endsWith(completeFileName, ".gz") ? "zcat " : "bzcat ") + completeFileName + string(" > ") + tempName;
859       cerr << "Decompressing " << completeFileName << " via temporary named pipe " << tempName << "\n";
860       system(command.c_str());
861       cerr << "Done decompressing " << completeFileName << "\n";
862       mothurRemove(tempName);
863       exit(EXIT_SUCCESS);
864     } else {
865       cerr << "waiting on child process " << fork_result << "\n";
866       completeFileName = tempName;
867     }
868   }
869 #endif
870 #endif
871
872                 fileHandle.open(completeFileName.c_str());
873                 if(!fileHandle) {
874                         mothurOut("[ERROR]: Could not open " + completeFileName); mothurOutEndLine();
875                         return 1;
876                 }
877                 else {
878                         //check for blank file
879                         gobble(fileHandle);
880                         if (fileHandle.eof()) { mothurOut("[ERROR]: " + completeFileName + " is blank. Please correct."); mothurOutEndLine();  }
881                         
882                         return 0;
883                 }
884         }
885         catch(exception& e) {
886                 errorOut(e, "MothurOut", "openInputFile");
887                 exit(1);
888         }       
889 }
890 /***********************************************************************/
891
892 int MothurOut::renameFile(string oldName, string newName){
893         try {
894                 ifstream inTest;
895                 int exist = openInputFile(newName, inTest, "");
896                 inTest.close();
897                 
898         #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)          
899                 if (exist == 0) { //you could open it so you want to delete it
900                         string command = "rm " + newName;
901                         system(command.c_str());
902                 }
903                                 
904                 string command = "mv " + oldName + " " + newName;
905                 system(command.c_str());
906         #else
907                 mothurRemove(newName);
908                 int renameOk = rename(oldName.c_str(), newName.c_str());
909         #endif
910                 return 0;
911                 
912         }
913         catch(exception& e) {
914                 errorOut(e, "MothurOut", "renameFile");
915                 exit(1);
916         }       
917 }
918
919 /***********************************************************************/
920
921 int MothurOut::openOutputFile(string fileName, ofstream& fileHandle){
922         try { 
923         
924                 string completeFileName = getFullPathName(fileName);
925 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
926 #ifdef USE_COMPRESSION
927     // check for gzipped file
928     if (endsWith(completeFileName, ".gz") || endsWith(completeFileName, ".bz2")) {
929       string tempName = string(tmpnam(0));
930       mkfifo(tempName.c_str(), 0666);
931       cerr << "Compressing " << completeFileName << " via temporary named pipe " << tempName << "\n";
932       int fork_result = fork();
933       if (fork_result < 0) {
934         cerr << "Error forking.\n";
935         exit(1);
936       } else if (fork_result == 0) {
937         string command = string(endsWith(completeFileName, ".gz") ?  "gzip" : "bzip2") + " -v > " + completeFileName + string(" < ") + tempName;
938         system(command.c_str());
939         exit(0);
940       } else {
941         completeFileName = tempName;
942       }
943     }
944 #endif
945 #endif
946                 fileHandle.open(completeFileName.c_str(), ios::trunc);
947                 if(!fileHandle) {
948                         mothurOut("[ERROR]: Could not open " + completeFileName); mothurOutEndLine();
949                         return 1;
950                 }
951                 else {
952                         return 0;
953                 }
954         }
955         catch(exception& e) {
956                 errorOut(e, "MothurOut", "openOutputFile");
957                 exit(1);
958         }       
959
960 }
961
962 /**************************************************************************************************/
963 int MothurOut::appendFiles(string temp, string filename) {
964         try{
965                 ofstream output;
966                 ifstream input;
967         
968                 //open output file in append mode
969                 openOutputFileAppend(filename, output);
970                 int ableToOpen = openInputFile(temp, input, "no error");
971                 //int ableToOpen = openInputFile(temp, input);
972                 
973                 int numLines = 0;
974                 if (ableToOpen == 0) { //you opened it
975                         while(char c = input.get()){
976                                 if(input.eof())         {       break;                  }
977                                 else                            {       output << c;    if (c == '\n') {numLines++;} }
978                         }
979                         input.close();
980                 }
981                 
982                 output.close();
983                 
984                 return numLines;
985         }
986         catch(exception& e) {
987                 errorOut(e, "MothurOut", "appendFiles");
988                 exit(1);
989         }       
990 }
991
992 /**************************************************************************************************/
993 string MothurOut::sortFile(string distFile, string outputDir){
994         try {   
995         
996                 //if (outputDir == "") {  outputDir += hasPath(distFile);  }
997                 string outfile = getRootName(distFile) + "sorted.dist";
998
999                 
1000                 //if you can, use the unix sort since its been optimized for years
1001                 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
1002                         string command = "sort -n -k +3 " + distFile + " -o " + outfile;
1003                         system(command.c_str());
1004                 #else //you are stuck with my best attempt...
1005                         //windows sort does not have a way to specify a column, only a character in the line
1006                         //since we cannot assume that the distance will always be at the the same character location on each line
1007                         //due to variable sequence name lengths, I chose to force the distance into first position, then sort and then put it back.
1008                 
1009                         //read in file line by file and put distance first
1010                         string tempDistFile = distFile + ".temp";
1011                         ifstream input;
1012                         ofstream output;
1013                         openInputFile(distFile, input);
1014                         openOutputFile(tempDistFile, output);
1015
1016                         string firstName, secondName;
1017                         float dist;
1018                         while (input) {
1019                                 input >> firstName >> secondName >> dist;
1020                                 output << dist << '\t' << firstName << '\t' << secondName << endl;
1021                                 gobble(input);
1022                         }
1023                         input.close();
1024                         output.close();
1025                 
1026         
1027                         //sort using windows sort
1028                         string tempOutfile = outfile + ".temp";
1029                         string command = "sort " + tempDistFile + " /O " + tempOutfile;
1030                         system(command.c_str());
1031                 
1032                         //read in sorted file and put distance at end again
1033                         ifstream input2;
1034                         openInputFile(tempOutfile, input2);
1035                         openOutputFile(outfile, output);
1036                 
1037                         while (input2) {
1038                                 input2 >> dist >> firstName >> secondName;
1039                                 output << firstName << '\t' << secondName << '\t' << dist << endl;
1040                                 gobble(input2);
1041                         }
1042                         input2.close();
1043                         output.close();
1044                 
1045                         //remove temp files
1046                         mothurRemove(tempDistFile);
1047                         mothurRemove(tempOutfile);
1048                 #endif
1049                 
1050                 return outfile;
1051         }
1052         catch(exception& e) {
1053                 errorOut(e, "MothurOut", "sortFile");
1054                 exit(1);
1055         }       
1056 }
1057 /**************************************************************************************************/
1058 vector<unsigned long long> MothurOut::setFilePosFasta(string filename, int& num) {
1059         try {
1060                         vector<unsigned long long> positions;
1061                         ifstream inFASTA;
1062                         //openInputFile(filename, inFASTA);
1063                         inFASTA.open(filename.c_str(), ios::binary);
1064                                                 
1065                         string input;
1066                         unsigned long long count = 0;
1067                         while(!inFASTA.eof()){
1068                                 //input = getline(inFASTA); 
1069                                 //cout << input << '\t' << inFASTA.tellg() << endl;
1070                                 //if (input.length() != 0) {
1071                                 //      if(input[0] == '>'){    unsigned long int pos = inFASTA.tellg(); positions.push_back(pos - input.length() - 1);  cout << (pos - input.length() - 1) << endl; }
1072                                 //}
1073                                 //gobble(inFASTA); //has to be here since windows line endings are 2 characters and mess up the positions
1074                                 char c = inFASTA.get(); count++;
1075                                 if (c == '>') {
1076                                         positions.push_back(count-1);
1077                                         //cout << count << endl;
1078                                 }
1079                         }
1080                         inFASTA.close();
1081                 
1082                         num = positions.size();
1083                 
1084                         /*FILE * pFile;
1085                         long size;
1086                 
1087                         //get num bytes in file
1088                         pFile = fopen (filename.c_str(),"rb");
1089                         if (pFile==NULL) perror ("Error opening file");
1090                         else{
1091                                 fseek (pFile, 0, SEEK_END);
1092                                 size=ftell (pFile);
1093                                 fclose (pFile);
1094                         }*/
1095                         
1096                         unsigned long long size = positions[(positions.size()-1)];
1097                         ifstream in;
1098                         openInputFile(filename, in);
1099                         
1100                         in.seekg(size);
1101                 
1102                         while(in.get()){
1103                                 if(in.eof())            {       break;  }
1104                                 else                            {       size++; }
1105                         }
1106                         in.close();
1107                 
1108                         positions.push_back(size);
1109                         positions[0] = 0;
1110                 
1111                         return positions;
1112         }
1113         catch(exception& e) {
1114                 errorOut(e, "MothurOut", "setFilePosFasta");
1115                 exit(1);
1116         }
1117 }
1118 /**************************************************************************************************/
1119 vector<unsigned long long> MothurOut::setFilePosEachLine(string filename, int& num) {
1120         try {
1121                         filename = getFullPathName(filename);
1122                         
1123                         vector<unsigned long long> positions;
1124                         ifstream in;
1125                         //openInputFile(filename, in);
1126                         in.open(filename.c_str(), ios::binary);
1127                 
1128                         string input;
1129                         unsigned long long count = 0;
1130                         positions.push_back(0);
1131                 
1132                         while(!in.eof()){
1133                                 //unsigned long long lastpos = in.tellg();
1134                                 //input = getline(in); 
1135                                 //if (input.length() != 0) {
1136                                         //unsigned long long pos = in.tellg(); 
1137                                         //if (pos != -1) { positions.push_back(pos - input.length() - 1);       }
1138                                         //else {  positions.push_back(lastpos);  }
1139                                 //}
1140                                 //gobble(in); //has to be here since windows line endings are 2 characters and mess up the positions
1141                                 
1142                                 
1143                                 //getline counting reads
1144                                 char d = in.get(); count++;
1145                                 while ((d != '\n') && (d != '\r') && (d != '\f') && (d != in.eof()))    {
1146                                         //get next character
1147                                         d = in.get(); 
1148                                         count++;
1149                                 }
1150                                 
1151                                 if (!in.eof()) {
1152                                         d=in.get(); count++;
1153                                         while(isspace(d) && (d != in.eof()))            { d=in.get(); count++;}
1154                                 }
1155                                 positions.push_back(count-1);
1156                                 //cout << count-1 << endl;
1157                         }
1158                         in.close();
1159                 
1160                         num = positions.size()-1;
1161                 
1162                         FILE * pFile;
1163                         unsigned long long size;
1164                         
1165                         //get num bytes in file
1166                         pFile = fopen (filename.c_str(),"rb");
1167                         if (pFile==NULL) perror ("Error opening file");
1168                         else{
1169                                 fseek (pFile, 0, SEEK_END);
1170                                 size=ftell (pFile);
1171                                 fclose (pFile);
1172                         }
1173                 
1174                         positions[(positions.size()-1)] = size;
1175                 
1176                         return positions;
1177         }
1178         catch(exception& e) {
1179                 errorOut(e, "MothurOut", "setFilePosEachLine");
1180                 exit(1);
1181         }
1182 }
1183 /**************************************************************************************************/
1184
1185 vector<unsigned long long> MothurOut::divideFile(string filename, int& proc) {
1186         try{
1187                 vector<unsigned long long> filePos;
1188                 filePos.push_back(0);
1189                 
1190                 FILE * pFile;
1191                 unsigned long long size;
1192                 
1193                 filename = getFullPathName(filename);
1194         
1195                 //get num bytes in file
1196                 pFile = fopen (filename.c_str(),"rb");
1197                 if (pFile==NULL) perror ("Error opening file");
1198                 else{
1199                         fseek (pFile, 0, SEEK_END);
1200                         size=ftell (pFile);
1201                         fclose (pFile);
1202                 }
1203                 
1204         #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
1205                                 
1206                 //estimate file breaks
1207                 unsigned long long chunkSize = 0;
1208                 chunkSize = size / proc;
1209
1210                 //file to small to divide by processors
1211                 if (chunkSize == 0)  {  proc = 1;       filePos.push_back(size); return filePos;        }
1212         
1213                 //for each process seekg to closest file break and search for next '>' char. make that the filebreak
1214                 for (int i = 0; i < proc; i++) {
1215                         unsigned long long spot = (i+1) * chunkSize;
1216                         
1217                         ifstream in;
1218                         openInputFile(filename, in);
1219                         in.seekg(spot);
1220                         
1221                         //look for next '>'
1222                         unsigned long long newSpot = spot;
1223                         while (!in.eof()) {
1224                            char c = in.get();
1225                                 
1226                            if (c == '>') {   in.putback(c); newSpot = in.tellg(); break;  }
1227                            else if (int(c) == -1) { break; }
1228                                 
1229                         }
1230                 
1231                         //there was not another sequence before the end of the file
1232                         unsigned long long sanityPos = in.tellg();
1233
1234                         if (sanityPos == -1) {  break;  }
1235                         else {  filePos.push_back(newSpot);  }
1236                         
1237                         in.close();
1238                 }
1239                 
1240                 //save end pos
1241                 filePos.push_back(size);
1242                 
1243                 //sanity check filePos
1244                 for (int i = 0; i < (filePos.size()-1); i++) {
1245                         if (filePos[(i+1)] <= filePos[i]) {  filePos.erase(filePos.begin()+(i+1)); i--; }
1246                 }
1247
1248                 proc = (filePos.size() - 1);
1249 #else
1250                 mothurOut("[ERROR]: Windows version should not be calling the divideFile function."); mothurOutEndLine();
1251                 proc=1;
1252                 filePos.push_back(size);
1253 #endif
1254                 return filePos;
1255         }
1256         catch(exception& e) {
1257                 errorOut(e, "MothurOut", "divideFile");
1258                 exit(1);
1259         }
1260 }
1261 /**************************************************************************************************/
1262 int MothurOut::divideFile(string filename, int& proc, vector<string>& files) {
1263         try{
1264                 
1265                 vector<unsigned long long> filePos = divideFile(filename, proc);
1266                 
1267                 for (int i = 0; i < (filePos.size()-1); i++) {
1268                         
1269                         //read file chunk
1270                         ifstream in;
1271                         openInputFile(filename, in);
1272                         in.seekg(filePos[i]);
1273                         unsigned long long size = filePos[(i+1)] - filePos[i];
1274                         char* chunk = new char[size];
1275                         in.read(chunk, size);
1276                         in.close();
1277                         
1278                         //open new file
1279                         string fileChunkName = filename + "." + toString(i) + ".tmp";
1280                         ofstream out; 
1281                         openOutputFile(fileChunkName, out);
1282                         
1283                         out << chunk << endl;
1284                         out.close();
1285                         delete[] chunk;
1286                         
1287                         //save name
1288                         files.push_back(fileChunkName);
1289                 }
1290                                 
1291                 return 0;
1292         }
1293         catch(exception& e) {
1294                 errorOut(e, "MothurOut", "divideFile");
1295                 exit(1);
1296         }
1297 }
1298 /***********************************************************************/
1299
1300 bool MothurOut::isTrue(string f){
1301         try {
1302                 
1303                 for (int i = 0; i < f.length(); i++) { f[i] = toupper(f[i]); }
1304                 
1305                 if ((f == "TRUE") || (f == "T")) {      return true;    }
1306                 else {  return false;  }
1307         }
1308         catch(exception& e) {
1309                 errorOut(e, "MothurOut", "isTrue");
1310                 exit(1);
1311         }
1312 }
1313
1314 /***********************************************************************/
1315
1316 float MothurOut::roundDist(float dist, int precision){
1317         try {
1318                 return int(dist * precision + 0.5)/float(precision);
1319         }
1320         catch(exception& e) {
1321                 errorOut(e, "MothurOut", "roundDist");
1322                 exit(1);
1323         }
1324 }
1325 /***********************************************************************/
1326
1327 float MothurOut::ceilDist(float dist, int precision){
1328         try {
1329                 return int(ceil(dist * precision))/float(precision);
1330         }
1331         catch(exception& e) {
1332                 errorOut(e, "MothurOut", "ceilDist");
1333                 exit(1);
1334         }
1335 }
1336 /**********************************************************************************************************************/
1337 int MothurOut::readNames(string namefile, map<string, string>& nameMap) { 
1338         try {
1339                 
1340                 //open input file
1341                 ifstream in;
1342                 openInputFile(namefile, in);
1343                 
1344                 while (!in.eof()) {
1345                         if (control_pressed) { break; }
1346                         
1347                         string firstCol, secondCol;
1348                         in >> firstCol >> secondCol; gobble(in);
1349                         
1350                         nameMap[firstCol] = secondCol;
1351                 }
1352                 in.close();
1353                 
1354                 return 0;
1355                 
1356         }
1357         catch(exception& e) {
1358                 errorOut(e, "MothurOut", "readNames");
1359                 exit(1);
1360         }
1361 }
1362 /**********************************************************************************************************************/
1363 int MothurOut::readNames(string namefile, map<string, vector<string> >& nameMap) { 
1364         try {
1365                 
1366                 //open input file
1367                 ifstream in;
1368                 openInputFile(namefile, in);
1369                 
1370                 while (!in.eof()) {
1371                         if (control_pressed) { break; }
1372                         
1373                         string firstCol, secondCol;
1374                         in >> firstCol >> secondCol; gobble(in);
1375                         
1376                         vector<string> temp;
1377                         splitAtComma(secondCol, temp);
1378                         
1379                         nameMap[firstCol] = temp;
1380                 }
1381                 in.close();
1382                 
1383                 return 0;
1384                 
1385         }
1386         catch(exception& e) {
1387                 errorOut(e, "MothurOut", "readNames");
1388                 exit(1);
1389         }
1390 }
1391 /**********************************************************************************************************************/
1392 map<string, int> MothurOut::readNames(string namefile) { 
1393         try {
1394                 
1395                 map<string, int> nameMap;
1396                 
1397                 //open input file
1398                 ifstream in;
1399                 openInputFile(namefile, in);
1400                 
1401                 while (!in.eof()) {
1402                         if (control_pressed) { break; }
1403                         
1404                         string firstCol, secondCol;
1405                         in >> firstCol >> secondCol; gobble(in);
1406                         
1407                         int num = getNumNames(secondCol);
1408                         
1409                         nameMap[firstCol] = num;
1410                 }
1411                 in.close();
1412                 
1413                 return nameMap;
1414                 
1415         }
1416         catch(exception& e) {
1417                 errorOut(e, "MothurOut", "readNames");
1418                 exit(1);
1419         }
1420 }
1421 /**********************************************************************************************************************/
1422 int MothurOut::readNames(string namefile, vector<seqPriorityNode>& nameVector, map<string, string>& fastamap) { 
1423         try {
1424                 int error = 0;
1425                 
1426                 //open input file
1427                 ifstream in;
1428                 openInputFile(namefile, in);
1429                 
1430                 while (!in.eof()) {
1431                         if (control_pressed) { break; }
1432                         
1433                         string firstCol, secondCol;
1434                         in >> firstCol >> secondCol; gobble(in);
1435                         
1436                         int num = getNumNames(secondCol);
1437                         
1438                         map<string, string>::iterator it = fastamap.find(firstCol);
1439                         if (it == fastamap.end()) {
1440                                 error = 1;
1441                                 mothurOut("[ERROR]: " + firstCol + " is not in your fastafile, but is in your namesfile, please correct."); mothurOutEndLine();
1442                         }else {
1443                                 seqPriorityNode temp(num, it->second, firstCol);
1444                                 nameVector.push_back(temp);
1445                         }
1446                 }
1447                 in.close();
1448                 
1449                 return error;
1450                 
1451         }
1452         catch(exception& e) {
1453                 errorOut(e, "MothurOut", "readNames");
1454                 exit(1);
1455         }
1456 }
1457
1458 /***********************************************************************/
1459
1460 int MothurOut::getNumNames(string names){
1461         try {
1462                 int count = 0;
1463                 
1464                 if(names != ""){
1465                         count = 1;
1466                         for(int i=0;i<names.size();i++){
1467                                 if(names[i] == ','){
1468                                         count++;
1469                                 }
1470                         }
1471                 }
1472                 
1473                 return count;
1474         }
1475         catch(exception& e) {
1476                 errorOut(e, "MothurOut", "getNumNames");
1477                 exit(1);
1478         }
1479 }
1480 /***********************************************************************/
1481
1482 int MothurOut::getNumChar(string line, char c){
1483         try {
1484                 int count = 0;
1485                 
1486                 if(line != ""){
1487                         for(int i=0;i<line.size();i++){
1488                                 if(line[i] == c){
1489                                         count++;
1490                                 }
1491                         }
1492                 }
1493                 
1494                 return count;
1495         }
1496         catch(exception& e) {
1497                 errorOut(e, "MothurOut", "getNumChar");
1498                 exit(1);
1499         }
1500 }
1501 /***********************************************************************/
1502 int MothurOut::mothurRemove(string filename){
1503         try {
1504                 filename = getFullPathName(filename);
1505                 int error = remove(filename.c_str());
1506                 //if (error != 0) { 
1507                 //      if (errno != ENOENT) { //ENOENT == file does not exist
1508                 //              string message = "Error deleting file " + filename;
1509                 //              perror(message.c_str()); 
1510                 //      }
1511                 //}
1512                 return error;
1513         }
1514         catch(exception& e) {
1515                 errorOut(e, "MothurOut", "mothurRemove");
1516                 exit(1);
1517         }
1518 }
1519 /***********************************************************************/
1520 bool MothurOut::mothurConvert(string item, int& num){
1521         try {
1522                 bool error = false;
1523                 
1524                 if (isNumeric1(item)) {
1525                         convert(item, num);
1526                 }else {
1527                         num = 0;
1528                         error = true;
1529                         mothurOut("[ERROR]: cannot convert " + item + " to an integer."); mothurOutEndLine();
1530                         commandInputsConvertError = true;
1531                 }
1532                 
1533                 return error;
1534         }
1535         catch(exception& e) {
1536                 errorOut(e, "MothurOut", "mothurConvert");
1537                 exit(1);
1538         }
1539 }
1540 /***********************************************************************/
1541 bool MothurOut::isNumeric1(string stringToCheck){
1542         try {
1543                 bool numeric = false;
1544                 
1545                 if(stringToCheck.find_first_not_of("0123456789.-") == string::npos) { numeric = true; }
1546                         
1547                 return numeric;
1548         }
1549         catch(exception& e) {
1550                 errorOut(e, "MothurOut", "isNumeric1");
1551                 exit(1);
1552         }
1553         
1554 }
1555 /***********************************************************************/
1556 bool MothurOut::mothurConvert(string item, float& num){
1557         try {
1558                 bool error = false;
1559                 
1560                 if (isNumeric1(item)) {
1561                         convert(item, num);
1562                 }else {
1563                         num = 0;
1564                         error = true;
1565                         mothurOut("[ERROR]: cannot convert " + item + " to a float."); mothurOutEndLine();
1566                         commandInputsConvertError = true;
1567                 }
1568                 
1569                 return error;
1570         }
1571         catch(exception& e) {
1572                 errorOut(e, "MothurOut", "mothurConvert");
1573                 exit(1);
1574         }
1575 }
1576 /***********************************************************************/
1577 bool MothurOut::mothurConvert(string item, double& num){
1578         try {
1579                 bool error = false;
1580                 
1581                 if (isNumeric1(item)) {
1582                         convert(item, num);
1583                 }else {
1584                         num = 0;
1585                         error = true;
1586                         mothurOut("[ERROR]: cannot convert " + item + " to a double."); mothurOutEndLine();
1587                         commandInputsConvertError = true;
1588                 }
1589                 
1590                 return error;
1591         }
1592         catch(exception& e) {
1593                 errorOut(e, "MothurOut", "mothurConvert");
1594                 exit(1);
1595         }
1596 }
1597 /**************************************************************************************************/
1598
1599 vector<vector<double> > MothurOut::binomial(int maxOrder){
1600         try {
1601         vector<vector<double> > binomial(maxOrder+1);
1602         
1603     for(int i=0;i<=maxOrder;i++){
1604                 binomial[i].resize(maxOrder+1);
1605                 binomial[i][0]=1;
1606                 binomial[0][i]=0;
1607     }
1608     binomial[0][0]=1;
1609         
1610     binomial[1][0]=1;
1611     binomial[1][1]=1;
1612         
1613     for(int i=2;i<=maxOrder;i++){
1614                 binomial[1][i]=0;
1615     }
1616         
1617     for(int i=2;i<=maxOrder;i++){
1618                 for(int j=1;j<=maxOrder;j++){
1619                         if(i==j){       binomial[i][j]=1;                                                                       }
1620                         if(j>i) {       binomial[i][j]=0;                                                                       }
1621                         else    {       binomial[i][j]=binomial[i-1][j-1]+binomial[i-1][j];     }
1622                 }
1623     }
1624         
1625         return binomial;
1626         
1627         }
1628         catch(exception& e) {
1629                 errorOut(e, "MothurOut", "binomial");
1630                 exit(1);
1631         }
1632 }
1633 /**************************************************************************************************/
1634 unsigned int MothurOut::fromBase36(string base36){
1635         try {
1636                 unsigned int num = 0;
1637                 
1638                 map<char, int> converts;
1639                 converts['A'] = 0;
1640                 converts['a'] = 0;
1641                 converts['B'] = 1;
1642                 converts['b'] = 1;
1643                 converts['C'] = 2;
1644                 converts['c'] = 2;
1645                 converts['D'] = 3;
1646                 converts['d'] = 3;
1647                 converts['E'] = 4;
1648                 converts['e'] = 4;
1649                 converts['F'] = 5;
1650                 converts['f'] = 5;
1651                 converts['G'] = 6;
1652                 converts['g'] = 6;
1653                 converts['H'] = 7;
1654                 converts['h'] = 7;
1655                 converts['I'] = 8;
1656                 converts['i'] = 8;
1657                 converts['J'] = 9;
1658                 converts['j'] = 9;
1659                 converts['K'] = 10;
1660                 converts['k'] = 10;
1661                 converts['L'] = 11;
1662                 converts['l'] = 11;
1663                 converts['M'] = 12;
1664                 converts['m'] = 12;
1665                 converts['N'] = 13;
1666                 converts['n'] = 13;
1667                 converts['O'] = 14;
1668                 converts['o'] = 14;
1669                 converts['P'] = 15;
1670                 converts['p'] = 15;
1671                 converts['Q'] = 16;
1672                 converts['q'] = 16;
1673                 converts['R'] = 17;
1674                 converts['r'] = 17;
1675                 converts['S'] = 18;
1676                 converts['s'] = 18;
1677                 converts['T'] = 19;
1678                 converts['t'] = 19;
1679                 converts['U'] = 20;
1680                 converts['u'] = 20;
1681                 converts['V'] = 21;
1682                 converts['v'] = 21;
1683                 converts['W'] = 22;
1684                 converts['w'] = 22;
1685                 converts['X'] = 23;
1686                 converts['x'] = 23;
1687                 converts['Y'] = 24;
1688                 converts['y'] = 24;
1689                 converts['Z'] = 25;
1690                 converts['z'] = 25;
1691                 converts['0'] = 26;
1692                 converts['1'] = 27;
1693                 converts['2'] = 28;
1694                 converts['3'] = 29;
1695                 converts['4'] = 30;
1696                 converts['5'] = 31;
1697                 converts['6'] = 32;
1698                 converts['7'] = 33;
1699                 converts['8'] = 34;
1700                 converts['9'] = 35;             
1701                 
1702                 int i = 0;
1703                 while (i < base36.length()) {
1704                         char c = base36[i];
1705                         num = 36 * num + converts[c];
1706                         i++;
1707                 }
1708                 
1709                 return num;
1710                 
1711         }
1712         catch(exception& e) {
1713                 errorOut(e, "MothurOut", "fromBase36");
1714                 exit(1);
1715         }
1716 }
1717 /***********************************************************************/
1718
1719 int MothurOut::factorial(int num){
1720         try {
1721                 int total = 1;
1722                 
1723                 for (int i = 1; i <= num; i++) {
1724                         total *= i;
1725                 }
1726                 
1727                 return total;
1728         }
1729         catch(exception& e) {
1730                 errorOut(e, "MothurOut", "factorial");
1731                 exit(1);
1732         }
1733 }
1734 /***********************************************************************/
1735
1736 int MothurOut::getNumSeqs(ifstream& file){
1737         try {
1738                 int numSeqs = count(istreambuf_iterator<char>(file),istreambuf_iterator<char>(), '>');
1739                 file.seekg(0);
1740                 return numSeqs;
1741         }
1742         catch(exception& e) {
1743                 errorOut(e, "MothurOut", "getNumSeqs");
1744                 exit(1);
1745         }       
1746 }
1747 /***********************************************************************/
1748 void MothurOut::getNumSeqs(ifstream& file, int& numSeqs){
1749         try {
1750                 string input;
1751                 numSeqs = 0;
1752                 while(!file.eof()){
1753                         input = getline(file);
1754                         if (input.length() != 0) {
1755                                 if(input[0] == '>'){ numSeqs++; }
1756                         }
1757                 }
1758         }
1759         catch(exception& e) {
1760                 errorOut(e, "MothurOut", "getNumSeqs");
1761                 exit(1);
1762         }       
1763 }
1764 /***********************************************************************/
1765
1766 //This function parses the estimator options and puts them in a vector
1767 void MothurOut::splitAtChar(string& estim, vector<string>& container, char symbol) {
1768         try {
1769                 string individual = "";
1770                 int estimLength = estim.size();
1771                 for(int i=0;i<estimLength;i++){
1772                         if(estim[i] == symbol){
1773                                 container.push_back(individual);
1774                                 individual = "";                                
1775                         }
1776                         else{
1777                                 individual += estim[i];
1778                         }
1779                 }
1780                 container.push_back(individual);
1781
1782         }
1783         catch(exception& e) {
1784                 errorOut(e, "MothurOut", "splitAtChar");
1785                 exit(1);
1786         }       
1787 }
1788
1789 /***********************************************************************/
1790
1791 //This function parses the estimator options and puts them in a vector
1792 void MothurOut::splitAtDash(string& estim, vector<string>& container) {
1793         try {
1794                 string individual = "";
1795                 int estimLength = estim.size();
1796                 for(int i=0;i<estimLength;i++){
1797                         if(estim[i] == '-'){
1798                                 container.push_back(individual);
1799                                 individual = "";                                
1800                         }
1801                         else{
1802                                 individual += estim[i];
1803                         }
1804                 }
1805                 container.push_back(individual);
1806
1807         
1808         /*      string individual;
1809                 
1810                 while (estim.find_first_of('-') != -1) {
1811                         individual = estim.substr(0,estim.find_first_of('-'));
1812                         if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
1813                                 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
1814                                 container.push_back(individual);
1815                         }
1816                 }
1817                 //get last one
1818                 container.push_back(estim); */
1819         }
1820         catch(exception& e) {
1821                 errorOut(e, "MothurOut", "splitAtDash");
1822                 exit(1);
1823         }       
1824 }
1825
1826 /***********************************************************************/
1827 //This function parses the label options and puts them in a set
1828 void MothurOut::splitAtDash(string& estim, set<string>& container) {
1829         try {
1830                 string individual = "";
1831                 int estimLength = estim.size();
1832                 for(int i=0;i<estimLength;i++){
1833                         if(estim[i] == '-'){
1834                                 container.insert(individual);
1835                                 individual = "";                                
1836                         }
1837                         else{
1838                                 individual += estim[i];
1839                         }
1840                 }
1841                 container.insert(individual);
1842
1843         //      string individual;
1844                 
1845         //      while (estim.find_first_of('-') != -1) {
1846         //              individual = estim.substr(0,estim.find_first_of('-'));
1847         //              if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
1848         //                      estim = estim.substr(estim.find_first_of('-')+1, estim.length());
1849         //                      container.insert(individual);
1850         //              }
1851         //      }
1852                 //get last one
1853         //      container.insert(estim);
1854         
1855         }
1856         catch(exception& e) {
1857                 errorOut(e, "MothurOut", "splitAtDash");
1858                 exit(1);
1859         }       
1860 }
1861 /***********************************************************************/
1862 //This function parses the line options and puts them in a set
1863 void MothurOut::splitAtDash(string& estim, set<int>& container) {
1864         try {
1865                 string individual;
1866                 int lineNum;
1867                 
1868                 while (estim.find_first_of('-') != -1) {
1869                         individual = estim.substr(0,estim.find_first_of('-'));
1870                         if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
1871                                 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
1872                                 convert(individual, lineNum); //convert the string to int
1873                                 container.insert(lineNum);
1874                         }
1875                 }
1876                 //get last one
1877                 convert(estim, lineNum); //convert the string to int
1878                 container.insert(lineNum);
1879         }
1880         catch(exception& e) {
1881                 errorOut(e, "MothurOut", "splitAtDash");
1882                 exit(1);
1883         }       
1884 }
1885 /***********************************************************************/
1886 //This function parses the a string and puts peices in a vector
1887 void MothurOut::splitAtComma(string& estim, vector<string>& container) {
1888         try {
1889                 string individual = "";
1890                 int estimLength = estim.size();
1891                 for(int i=0;i<estimLength;i++){
1892                         if(estim[i] == ','){
1893                                 container.push_back(individual);
1894                                 individual = "";                                
1895                         }
1896                         else{
1897                                 individual += estim[i];
1898                         }
1899                 }
1900                 container.push_back(individual);
1901                 
1902                 
1903                 
1904                 
1905 //              string individual;
1906 //              
1907 //              while (estim.find_first_of(',') != -1) {
1908 //                      individual = estim.substr(0,estim.find_first_of(','));
1909 //                      if ((estim.find_first_of(',')+1) <= estim.length()) { //checks to make sure you don't have comma at end of string
1910 //                              estim = estim.substr(estim.find_first_of(',')+1, estim.length());
1911 //                              container.push_back(individual);
1912 //                      }
1913 //              }
1914 //              //get last one
1915 //              container.push_back(estim);
1916         }
1917         catch(exception& e) {
1918                 errorOut(e, "MothurOut", "splitAtComma");
1919                 exit(1);
1920         }       
1921 }
1922 /***********************************************************************/
1923
1924 //This function splits up the various option parameters
1925 void MothurOut::splitAtComma(string& prefix, string& suffix){
1926         try {
1927                 prefix = suffix.substr(0,suffix.find_first_of(','));
1928                 if ((suffix.find_first_of(',')+2) <= suffix.length()) {  //checks to make sure you don't have comma at end of string
1929                         suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length());
1930                         string space = " ";
1931                         while(suffix.at(0) == ' ')
1932                                 suffix = suffix.substr(1, suffix.length());
1933                 }
1934
1935         }
1936         catch(exception& e) {
1937                 errorOut(e, "MothurOut", "splitAtComma");
1938                 exit(1);
1939         }       
1940 }
1941 /***********************************************************************/
1942
1943 //This function separates the key value from the option value i.e. dist=96_...
1944 void MothurOut::splitAtEquals(string& key, string& value){              
1945         try {
1946                 if(value.find_first_of('=') != -1){
1947                         key = value.substr(0,value.find_first_of('='));
1948                         if ((value.find_first_of('=')+1) <= value.length()) {
1949                                 value = value.substr(value.find_first_of('=')+1, value.length());
1950                         }
1951                 }else{
1952                         key = value;
1953                         value = 1;
1954                 }
1955         }
1956         catch(exception& e) {
1957                 errorOut(e, "MothurOut", "splitAtEquals");
1958                 exit(1);
1959         }       
1960 }
1961
1962 /**************************************************************************************************/
1963
1964 bool MothurOut::inUsersGroups(string groupname, vector<string> Groups) {
1965         try {
1966                 for (int i = 0; i < Groups.size(); i++) {
1967                         if (groupname == Groups[i]) { return true; }
1968                 }
1969                 return false;
1970         }
1971         catch(exception& e) {
1972                 errorOut(e, "MothurOut", "inUsersGroups");
1973                 exit(1);
1974         }       
1975 }
1976 /**************************************************************************************************/
1977 //returns true if any of the strings in first vector are in second vector
1978 bool MothurOut::inUsersGroups(vector<string> groupnames, vector<string> Groups) {
1979         try {
1980                 
1981                 for (int i = 0; i < groupnames.size(); i++) {
1982                         if (inUsersGroups(groupnames[i], Groups)) { return true; }
1983                 }
1984                 return false;
1985         }
1986         catch(exception& e) {
1987                 errorOut(e, "MothurOut", "inUsersGroups");
1988                 exit(1);
1989         }       
1990 }
1991 /***********************************************************************/
1992 //this function determines if the user has given us labels that are smaller than the given label.
1993 //if so then it returns true so that the calling function can run the previous valid distance.
1994 //it's a "smart" distance function.  It also checks for invalid labels.
1995 bool MothurOut::anyLabelsToProcess(string label, set<string>& userLabels, string errorOff) {
1996         try {
1997                 
1998                 set<string>::iterator it;
1999                 vector<float> orderFloat;
2000                 map<string, float> userMap;  //the conversion process removes trailing 0's which we need to put back
2001                 map<string, float>::iterator it2;
2002                 float labelFloat;
2003                 bool smaller = false;
2004                 
2005                 //unique is the smallest line
2006                 if (label == "unique") {  return false;  }
2007                 else { 
2008                         if (convertTestFloat(label, labelFloat)) {
2009                                 convert(label, labelFloat); 
2010                         }else { //cant convert 
2011                                 return false;
2012                         }
2013                 }
2014                 
2015                 //go through users set and make them floats
2016                 for(it = userLabels.begin(); it != userLabels.end();) {
2017                         
2018                         float temp;
2019                         if ((*it != "unique") && (convertTestFloat(*it, temp) == true)){
2020                                 convert(*it, temp);
2021                                 orderFloat.push_back(temp);
2022                                 userMap[*it] = temp;
2023                                 it++;
2024                         }else if (*it == "unique") { 
2025                                 orderFloat.push_back(-1.0);
2026                                 userMap["unique"] = -1.0;
2027                                 it++;
2028                         }else {
2029                                 if (errorOff == "") {  mothurOut(*it + " is not a valid label."); mothurOutEndLine();  }
2030                                 userLabels.erase(it++); 
2031                         }
2032                 }
2033                 
2034                 //sort order
2035                 sort(orderFloat.begin(), orderFloat.end());
2036                 
2037                 /*************************************************/
2038                 //is this label bigger than any of the users labels
2039                 /*************************************************/
2040                                 
2041                 //loop through order until you find a label greater than label
2042                 for (int i = 0; i < orderFloat.size(); i++) {
2043                         if (orderFloat[i] < labelFloat) {
2044                                 smaller = true;
2045                                 if (orderFloat[i] == -1) { 
2046                                         if (errorOff == "") { mothurOut("Your file does not include the label unique."); mothurOutEndLine(); }
2047                                         userLabels.erase("unique");
2048                                 }
2049                                 else {  
2050                                         if (errorOff == "") { mothurOut("Your file does not include the label "); mothurOutEndLine(); }
2051                                         string s = "";
2052                                         for (it2 = userMap.begin(); it2!= userMap.end(); it2++) {  
2053                                                 if (it2->second == orderFloat[i]) {  
2054                                                         s = it2->first;  
2055                                                         //remove small labels
2056                                                         userLabels.erase(s);
2057                                                         break;
2058                                                 }
2059                                         }
2060                                         if (errorOff == "") {mothurOut( s +  ". I will use the next smallest distance. "); mothurOutEndLine(); }
2061                                 }
2062                         //since they are sorted once you find a bigger one stop looking
2063                         }else { break; }
2064                 }
2065                 
2066                 return smaller;
2067                                                 
2068         }
2069         catch(exception& e) {
2070                 errorOut(e, "MothurOut", "anyLabelsToProcess");
2071                 exit(1);
2072         }       
2073 }
2074
2075 /**************************************************************************************************/
2076 bool MothurOut::checkReleaseVersion(ifstream& file, string version) {
2077         try {
2078                 
2079                 bool good = true;
2080                 
2081                 string line = getline(file);  
2082
2083                 //before we added this check
2084                 if (line[0] != '#') {  good = false;  }
2085                 else {
2086                         //rip off #
2087                         line = line.substr(1);
2088                         
2089                         vector<string> versionVector;
2090                         splitAtChar(version, versionVector, '.');
2091                         
2092                         //check file version
2093                         vector<string> linesVector;
2094                         splitAtChar(line, linesVector, '.');
2095                         
2096                         if (versionVector.size() != linesVector.size()) { good = false; }
2097                         else {
2098                                 for (int j = 0; j < versionVector.size(); j++) {
2099                                         int num1, num2;
2100                                         convert(versionVector[j], num1);
2101                                         convert(linesVector[j], num2);
2102                                         
2103                                         //if mothurs version is newer than this files version, then we want to remake it
2104                                         if (num1 > num2) {  good = false; break;  }
2105                                 }
2106                         }
2107                         
2108                 }
2109                 
2110                 if (!good) {  file.close();  }
2111                 else { file.seekg(0);  }
2112                 
2113                 return good;
2114         }
2115         catch(exception& e) {
2116                 errorOut(e, "MothurOut", "checkReleaseVersion");                
2117                 exit(1);
2118         }
2119 }
2120 /**************************************************************************************************/
2121 bool MothurOut::isContainingOnlyDigits(string input) {
2122         try{
2123                 
2124                 //are you a digit in ascii code
2125                 for (int i = 0;i < input.length(); i++){
2126                         if( input[i]>47 && input[i]<58){}
2127                         else { return false; }
2128                 }
2129                 
2130                 return true;
2131         }
2132         catch(exception& e) {
2133                 errorOut(e, "MothurOut", "isContainingOnlyDigits");             
2134                 exit(1);
2135         }
2136 }
2137 /**************************************************************************************************/
2138 int MothurOut::removeConfidences(string& tax) {
2139         try {
2140                 
2141                 string taxon;
2142                 string newTax = "";
2143                 
2144                 while (tax.find_first_of(';') != -1) {
2145                         
2146                         if (control_pressed) { return 0; }
2147                         
2148                         //get taxon
2149                         taxon = tax.substr(0,tax.find_first_of(';'));
2150         
2151                         int pos = taxon.find_last_of('(');
2152                         if (pos != -1) {
2153                                 //is it a number?
2154                                 int pos2 = taxon.find_last_of(')');
2155                                 if (pos2 != -1) {
2156                                         string confidenceScore = taxon.substr(pos+1, (pos2-(pos+1)));
2157                                         if (isNumeric1(confidenceScore)) {
2158                                                 taxon = taxon.substr(0, pos); //rip off confidence 
2159                                         }
2160                                 }
2161                         }
2162                         taxon += ";";
2163                         
2164                         tax = tax.substr(tax.find_first_of(';')+1, tax.length());
2165                         newTax += taxon;
2166                 }
2167                 
2168                 tax = newTax;
2169                 
2170                 return 0;
2171         }
2172         catch(exception& e) {
2173                 errorOut(e, "MothurOut", "removeConfidences");
2174                 exit(1);
2175         }
2176 }
2177 /**************************************************************************************************/
2178
2179
2180
2181
2182