5 * Created by westcott on 2/25/10.
6 * Copyright 2010 Schloss Lab. All rights reserved.
10 #include "mothurout.h"
13 /******************************************************/
14 MothurOut* MothurOut::getInstance() {
15 if( _uniqueInstance == 0) {
16 _uniqueInstance = new MothurOut();
18 return _uniqueInstance;
20 /*********************************************************************************************/
21 void MothurOut::printCurrentFiles() {
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(); }
47 errorOut(e, "MothurOut", "printCurrentFiles");
51 /*********************************************************************************************/
52 bool MothurOut::hasCurrentFiles() {
54 bool hasCurrent = false;
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; }
82 errorOut(e, "MothurOut", "hasCurrentFiles");
87 /*********************************************************************************************/
88 void MothurOut::clearCurrentFiles() {
112 catch(exception& e) {
113 errorOut(e, "MothurOut", "clearCurrentFiles");
117 /*********************************************************************************************/
118 void MothurOut::setFileName(string filename) {
120 logFileName = filename;
124 MPI_Comm_rank(MPI_COMM_WORLD, &pid);
126 if (pid == 0) { //only one process should output to screen
129 openOutputFile(filename, out);
135 catch(exception& e) {
136 errorOut(e, "MothurOut", "setFileName");
140 /*********************************************************************************************/
141 void MothurOut::setDefaultPath(string pathname) {
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 += "/"; }
149 if (lastChar != "\\") { pathname += "\\"; }
152 defaultPath = pathname;
155 catch(exception& e) {
156 errorOut(e, "MothurOut", "setDefaultPath");
160 /*********************************************************************************************/
161 void MothurOut::setOutputDir(string pathname) {
163 outputDir = pathname;
165 catch(exception& e) {
166 errorOut(e, "MothurOut", "setOutputDir");
170 /*********************************************************************************************/
171 void MothurOut::closeLog() {
176 MPI_Comm_rank(MPI_COMM_WORLD, &pid);
178 if (pid == 0) { //only one process should output to screen
187 catch(exception& e) {
188 errorOut(e, "MothurOut", "closeLog");
193 /*********************************************************************************************/
194 MothurOut::~MothurOut() {
199 catch(exception& e) {
200 errorOut(e, "MothurOut", "MothurOut");
204 /*********************************************************************************************/
205 void MothurOut::mothurOut(string output) {
210 MPI_Comm_rank(MPI_COMM_WORLD, &pid);
212 if (pid == 0) { //only one process should output to screen
222 catch(exception& e) {
223 errorOut(e, "MothurOut", "MothurOut");
227 /*********************************************************************************************/
228 void MothurOut::mothurOutEndLine() {
232 MPI_Comm_rank(MPI_COMM_WORLD, &pid);
234 if (pid == 0) { //only one process should output to screen
244 catch(exception& e) {
245 errorOut(e, "MothurOut", "MothurOutEndLine");
249 /*********************************************************************************************/
250 void MothurOut::mothurOut(string output, ofstream& outputFile) {
255 MPI_Comm_rank(MPI_COMM_WORLD, &pid);
257 if (pid == 0) { //only one process should output to screen
262 outputFile << output;
270 catch(exception& e) {
271 errorOut(e, "MothurOut", "MothurOut");
275 /*********************************************************************************************/
276 void MothurOut::mothurOutEndLine(ofstream& outputFile) {
280 MPI_Comm_rank(MPI_COMM_WORLD, &pid);
282 if (pid == 0) { //only one process should output to screen
293 catch(exception& e) {
294 errorOut(e, "MothurOut", "MothurOutEndLine");
298 /*********************************************************************************************/
299 void MothurOut::mothurOutJustToLog(string output) {
303 MPI_Comm_rank(MPI_COMM_WORLD, &pid);
305 if (pid == 0) { //only one process should output to screen
314 catch(exception& e) {
315 errorOut(e, "MothurOut", "MothurOutJustToLog");
319 /*********************************************************************************************/
320 void MothurOut::errorOut(exception& e, string object, string function) {
322 //mem_usage(vm, rss);
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.");
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.
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)
342 // 'file' stat seems to give the most reliable results
344 ifstream stat_stream("/proc/self/stat",ios_base::in);
346 // dummy vars for leading entries in stat that we don't care about
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;
353 // the two fields we want
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
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;
367 mothurOut("Memory Usage: vm = " + toString(vm_usage) + " rss = " + toString(resident_set) + "\n");
371 /* //windows memory usage
372 // Get the list of process identifiers.
373 DWORD aProcesses[1024], cbNeeded, cProcesses;
375 if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ){ return 1; }
377 // Calculate how many process identifiers were returned.
378 cProcesses = cbNeeded / sizeof(DWORD);
380 // Print the memory usage for each process
381 for (int i = 0; i < cProcesses; i++ ) {
382 DWORD processID = aProcesses[i];
384 PROCESS_MEMORY_COUNTERS pmc;
386 HANDLE hProcess = OpenProcess((PROCESS_QUERY_INFORMATION | PROCESS_VM_READ), FALSE, processID);
388 // Print the process identifier.
389 printf( "\nProcess ID: %u\n", processID);
391 if (NULL != hProcess) {
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 );
404 CloseHandle(hProcess);
414 /***********************************************************************/
415 int MothurOut::openOutputFileAppend(string fileName, ofstream& fileHandle){
417 fileName = getFullPathName(fileName);
419 fileHandle.open(fileName.c_str(), ios::app);
421 mothurOut("[ERROR]: Could not open " + fileName); mothurOutEndLine();
428 catch(exception& e) {
429 errorOut(e, "MothurOut", "openOutputFileAppend");
433 /***********************************************************************/
434 void MothurOut::gobble(istream& f){
438 while(isspace(d=f.get())) { ;}
439 if(!f.eof()) { f.putback(d); }
441 catch(exception& e) {
442 errorOut(e, "MothurOut", "gobble");
446 /***********************************************************************/
447 void MothurOut::gobble(istringstream& f){
450 while(isspace(d=f.get())) {;}
451 if(!f.eof()) { f.putback(d); }
453 catch(exception& e) {
454 errorOut(e, "MothurOut", "gobble");
459 /***********************************************************************/
461 string MothurOut::getline(istringstream& fileHandle) {
466 while (!fileHandle.eof()) {
468 char c = fileHandle.get();
470 //are you at the end of the line
471 if ((c == '\n') || (c == '\r') || (c == '\f')){ break; }
478 catch(exception& e) {
479 errorOut(e, "MothurOut", "getline");
483 /***********************************************************************/
485 string MothurOut::getline(ifstream& fileHandle) {
492 char c = fileHandle.get();
494 //are you at the end of the line
495 if ((c == '\n') || (c == '\r') || (c == '\f') || (c == EOF)){ break; }
502 catch(exception& e) {
503 errorOut(e, "MothurOut", "getline");
507 /***********************************************************************/
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;
518 string MothurOut::getRootName(string longName){
521 string rootName = longName;
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";
532 if(rootName.find_last_of(".") != rootName.npos){
533 int pos = rootName.find_last_of('.')+1;
534 rootName = rootName.substr(0, pos);
539 catch(exception& e) {
540 errorOut(e, "MothurOut", "getRootName");
544 /***********************************************************************/
546 string MothurOut::getSimpleName(string longName){
548 string simpleName = longName;
551 found=longName.find_last_of("/\\");
553 if(found != longName.npos){
554 simpleName = longName.substr(found+1);
559 catch(exception& e) {
560 errorOut(e, "MothurOut", "getSimpleName");
565 /***********************************************************************/
567 int MothurOut::getRandomIndex(int highest){
570 int random = (int) ((float)(highest+1) * (float)(rand()) / ((float)RAND_MAX+1.0));
574 catch(exception& e) {
575 errorOut(e, "MothurOut", "getRandomIndex");
580 /**********************************************************************/
582 string MothurOut::getPathName(string longName){
584 string rootPathName = longName;
586 if(longName.find_last_of("/\\") != longName.npos){
587 int pos = longName.find_last_of("/\\")+1;
588 rootPathName = longName.substr(0, pos);
593 catch(exception& e) {
594 errorOut(e, "MothurOut", "getPathName");
599 /***********************************************************************/
601 string MothurOut::hasPath(string longName){
606 found=longName.find_last_of("~/\\");
608 if(found != longName.npos){
609 path = longName.substr(0, found+1);
614 catch(exception& e) {
615 errorOut(e, "MothurOut", "hasPath");
620 /***********************************************************************/
622 string MothurOut::getExtension(string longName){
624 string extension = "";
626 if(longName.find_last_of('.') != longName.npos){
627 int pos = longName.find_last_of('.');
628 extension = longName.substr(pos, longName.length());
633 catch(exception& e) {
634 errorOut(e, "MothurOut", "getExtension");
638 /***********************************************************************/
639 bool MothurOut::isBlank(string fileName){
642 fileName = getFullPathName(fileName);
645 fileHandle.open(fileName.c_str());
647 mothurOut("[ERROR]: Could not open " + fileName); mothurOutEndLine();
650 //check for blank file
652 if (fileHandle.eof()) { fileHandle.close(); return true; }
657 catch(exception& e) {
658 errorOut(e, "MothurOut", "isBlank");
662 /***********************************************************************/
664 string MothurOut::getFullPathName(string fileName){
667 string path = hasPath(fileName);
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
677 //get current working directory
678 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
680 if (path.find("~") != -1) { //go to home directory
683 char *homepath = NULL;
684 homepath = getenv ("HOME");
685 if ( homepath != NULL) { homeDir = homepath; }
686 else { homeDir = ""; }
688 newFileName = homeDir + fileName.substr(fileName.find("~")+1);
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
694 //char* cwdpath = new char[1024];
696 //cwdpath=getcwd(cwdpath,size);
699 char *cwdpath = NULL;
700 cwdpath = getcwd(NULL, 0); // or _getcwd
701 if ( cwdpath != NULL) { cwd = cwdpath; }
707 if (cwd.length() > 0) { simpleCWD = cwd.substr(1); }
709 //break apart the current working directory
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());
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
720 int index = dirs.size()-1;
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);
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; }
734 for (int i = index; i >= 0; i--) {
735 newFileName = dirs[i] + "/" + newFileName;
738 newFileName = "/" + newFileName;
742 if (path.find("~") != string::npos) { //go to home directory
743 string homeDir = getenv ("HOMEPATH");
744 newFileName = homeDir + fileName.substr(fileName.find("~")+1);
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
750 char *cwdpath = NULL;
751 cwdpath = getcwd(NULL, 0); // or _getcwd
752 if ( cwdpath != NULL) { cwd = cwdpath; }
755 //break apart the current working directory
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());
764 dirs.push_back(cwd); //ex. dirs[0] = user, dirs[1] = work, dirs[2] = desktop
766 int index = dirs.size()-1;
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);
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; }
780 for (int i = index; i >= 0; i--) {
781 newFileName = dirs[i] + "\\" + newFileName;
790 catch(exception& e) {
791 errorOut(e, "MothurOut", "getFullPathName");
795 /***********************************************************************/
797 int MothurOut::openInputFile(string fileName, ifstream& fileHandle, string m){
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";
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);
819 cerr << "waiting on child process " << fork_result << "\n";
820 completeFileName = tempName;
825 fileHandle.open(completeFileName.c_str());
827 //mothurOut("[ERROR]: Could not open " + completeFileName); mothurOutEndLine();
830 //check for blank file
835 catch(exception& e) {
836 errorOut(e, "MothurOut", "openInputFile - no Error");
840 /***********************************************************************/
842 int MothurOut::openInputFile(string fileName, ifstream& fileHandle){
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";
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);
865 cerr << "waiting on child process " << fork_result << "\n";
866 completeFileName = tempName;
872 fileHandle.open(completeFileName.c_str());
874 mothurOut("[ERROR]: Could not open " + completeFileName); mothurOutEndLine();
878 //check for blank file
880 if (fileHandle.eof()) { mothurOut("[ERROR]: " + completeFileName + " is blank. Please correct."); mothurOutEndLine(); }
885 catch(exception& e) {
886 errorOut(e, "MothurOut", "openInputFile");
890 /***********************************************************************/
892 int MothurOut::renameFile(string oldName, string newName){
895 int exist = openInputFile(newName, inTest, "");
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());
904 string command = "mv " + oldName + " " + newName;
905 system(command.c_str());
907 mothurRemove(newName);
908 int renameOk = rename(oldName.c_str(), newName.c_str());
913 catch(exception& e) {
914 errorOut(e, "MothurOut", "renameFile");
919 /***********************************************************************/
921 int MothurOut::openOutputFile(string fileName, ofstream& fileHandle){
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";
936 } else if (fork_result == 0) {
937 string command = string(endsWith(completeFileName, ".gz") ? "gzip" : "bzip2") + " -v > " + completeFileName + string(" < ") + tempName;
938 system(command.c_str());
941 completeFileName = tempName;
946 fileHandle.open(completeFileName.c_str(), ios::trunc);
948 mothurOut("[ERROR]: Could not open " + completeFileName); mothurOutEndLine();
955 catch(exception& e) {
956 errorOut(e, "MothurOut", "openOutputFile");
962 /**************************************************************************************************/
963 int MothurOut::appendFiles(string temp, string filename) {
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);
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++;} }
986 catch(exception& e) {
987 errorOut(e, "MothurOut", "appendFiles");
992 /**************************************************************************************************/
993 string MothurOut::sortFile(string distFile, string outputDir){
996 //if (outputDir == "") { outputDir += hasPath(distFile); }
997 string outfile = getRootName(distFile) + "sorted.dist";
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.
1009 //read in file line by file and put distance first
1010 string tempDistFile = distFile + ".temp";
1013 openInputFile(distFile, input);
1014 openOutputFile(tempDistFile, output);
1016 string firstName, secondName;
1019 input >> firstName >> secondName >> dist;
1020 output << dist << '\t' << firstName << '\t' << secondName << endl;
1027 //sort using windows sort
1028 string tempOutfile = outfile + ".temp";
1029 string command = "sort " + tempDistFile + " /O " + tempOutfile;
1030 system(command.c_str());
1032 //read in sorted file and put distance at end again
1034 openInputFile(tempOutfile, input2);
1035 openOutputFile(outfile, output);
1038 input2 >> dist >> firstName >> secondName;
1039 output << firstName << '\t' << secondName << '\t' << dist << endl;
1046 mothurRemove(tempDistFile);
1047 mothurRemove(tempOutfile);
1052 catch(exception& e) {
1053 errorOut(e, "MothurOut", "sortFile");
1057 /**************************************************************************************************/
1058 vector<unsigned long long> MothurOut::setFilePosFasta(string filename, int& num) {
1060 vector<unsigned long long> positions;
1062 //openInputFile(filename, inFASTA);
1063 inFASTA.open(filename.c_str(), ios::binary);
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; }
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++;
1076 positions.push_back(count-1);
1077 //cout << count << endl;
1082 num = positions.size();
1087 //get num bytes in file
1088 pFile = fopen (filename.c_str(),"rb");
1089 if (pFile==NULL) perror ("Error opening file");
1091 fseek (pFile, 0, SEEK_END);
1096 unsigned long long size = positions[(positions.size()-1)];
1098 openInputFile(filename, in);
1103 if(in.eof()) { break; }
1108 positions.push_back(size);
1113 catch(exception& e) {
1114 errorOut(e, "MothurOut", "setFilePosFasta");
1118 /**************************************************************************************************/
1119 vector<unsigned long long> MothurOut::setFilePosEachLine(string filename, int& num) {
1121 filename = getFullPathName(filename);
1123 vector<unsigned long long> positions;
1125 //openInputFile(filename, in);
1126 in.open(filename.c_str(), ios::binary);
1129 unsigned long long count = 0;
1130 positions.push_back(0);
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); }
1140 //gobble(in); //has to be here since windows line endings are 2 characters and mess up the positions
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
1152 d=in.get(); count++;
1153 while(isspace(d) && (d != in.eof())) { d=in.get(); count++;}
1155 positions.push_back(count-1);
1156 //cout << count-1 << endl;
1160 num = positions.size()-1;
1163 unsigned long long size;
1165 //get num bytes in file
1166 pFile = fopen (filename.c_str(),"rb");
1167 if (pFile==NULL) perror ("Error opening file");
1169 fseek (pFile, 0, SEEK_END);
1174 positions[(positions.size()-1)] = size;
1178 catch(exception& e) {
1179 errorOut(e, "MothurOut", "setFilePosEachLine");
1183 /**************************************************************************************************/
1185 vector<unsigned long long> MothurOut::divideFile(string filename, int& proc) {
1187 vector<unsigned long long> filePos;
1188 filePos.push_back(0);
1191 unsigned long long size;
1193 filename = getFullPathName(filename);
1195 //get num bytes in file
1196 pFile = fopen (filename.c_str(),"rb");
1197 if (pFile==NULL) perror ("Error opening file");
1199 fseek (pFile, 0, SEEK_END);
1204 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
1206 //estimate file breaks
1207 unsigned long long chunkSize = 0;
1208 chunkSize = size / proc;
1210 //file to small to divide by processors
1211 if (chunkSize == 0) { proc = 1; filePos.push_back(size); return filePos; }
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;
1218 openInputFile(filename, in);
1222 unsigned long long newSpot = spot;
1226 if (c == '>') { in.putback(c); newSpot = in.tellg(); break; }
1227 else if (int(c) == -1) { break; }
1231 //there was not another sequence before the end of the file
1232 unsigned long long sanityPos = in.tellg();
1234 if (sanityPos == -1) { break; }
1235 else { filePos.push_back(newSpot); }
1241 filePos.push_back(size);
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--; }
1248 proc = (filePos.size() - 1);
1250 mothurOut("[ERROR]: Windows version should not be calling the divideFile function."); mothurOutEndLine();
1252 filePos.push_back(size);
1256 catch(exception& e) {
1257 errorOut(e, "MothurOut", "divideFile");
1261 /**************************************************************************************************/
1262 int MothurOut::divideFile(string filename, int& proc, vector<string>& files) {
1265 vector<unsigned long long> filePos = divideFile(filename, proc);
1267 for (int i = 0; i < (filePos.size()-1); i++) {
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);
1279 string fileChunkName = filename + "." + toString(i) + ".tmp";
1281 openOutputFile(fileChunkName, out);
1283 out << chunk << endl;
1288 files.push_back(fileChunkName);
1293 catch(exception& e) {
1294 errorOut(e, "MothurOut", "divideFile");
1298 /***********************************************************************/
1300 bool MothurOut::isTrue(string f){
1303 for (int i = 0; i < f.length(); i++) { f[i] = toupper(f[i]); }
1305 if ((f == "TRUE") || (f == "T")) { return true; }
1306 else { return false; }
1308 catch(exception& e) {
1309 errorOut(e, "MothurOut", "isTrue");
1314 /***********************************************************************/
1316 float MothurOut::roundDist(float dist, int precision){
1318 return int(dist * precision + 0.5)/float(precision);
1320 catch(exception& e) {
1321 errorOut(e, "MothurOut", "roundDist");
1325 /***********************************************************************/
1327 float MothurOut::ceilDist(float dist, int precision){
1329 return int(ceil(dist * precision))/float(precision);
1331 catch(exception& e) {
1332 errorOut(e, "MothurOut", "ceilDist");
1336 /**********************************************************************************************************************/
1337 int MothurOut::readNames(string namefile, map<string, string>& nameMap) {
1342 openInputFile(namefile, in);
1345 if (control_pressed) { break; }
1347 string firstCol, secondCol;
1348 in >> firstCol >> secondCol; gobble(in);
1350 nameMap[firstCol] = secondCol;
1354 return nameMap.size();
1357 catch(exception& e) {
1358 errorOut(e, "MothurOut", "readNames");
1362 /**********************************************************************************************************************/
1363 int MothurOut::readNames(string namefile, map<string, vector<string> >& nameMap) {
1368 openInputFile(namefile, in);
1371 if (control_pressed) { break; }
1373 string firstCol, secondCol;
1374 in >> firstCol >> secondCol; gobble(in);
1376 vector<string> temp;
1377 splitAtComma(secondCol, temp);
1379 nameMap[firstCol] = temp;
1383 return nameMap.size();
1386 catch(exception& e) {
1387 errorOut(e, "MothurOut", "readNames");
1391 /**********************************************************************************************************************/
1392 map<string, int> MothurOut::readNames(string namefile) {
1395 map<string, int> nameMap;
1399 openInputFile(namefile, in);
1402 if (control_pressed) { break; }
1404 string firstCol, secondCol;
1405 in >> firstCol >> secondCol; gobble(in);
1407 int num = getNumNames(secondCol);
1409 nameMap[firstCol] = num;
1416 catch(exception& e) {
1417 errorOut(e, "MothurOut", "readNames");
1421 /**********************************************************************************************************************/
1422 int MothurOut::readNames(string namefile, vector<seqPriorityNode>& nameVector, map<string, string>& fastamap) {
1428 openInputFile(namefile, in);
1431 if (control_pressed) { break; }
1433 string firstCol, secondCol;
1434 in >> firstCol >> secondCol; gobble(in);
1436 int num = getNumNames(secondCol);
1438 map<string, string>::iterator it = fastamap.find(firstCol);
1439 if (it == fastamap.end()) {
1441 mothurOut("[ERROR]: " + firstCol + " is not in your fastafile, but is in your namesfile, please correct."); mothurOutEndLine();
1443 seqPriorityNode temp(num, it->second, firstCol);
1444 nameVector.push_back(temp);
1452 catch(exception& e) {
1453 errorOut(e, "MothurOut", "readNames");
1458 /***********************************************************************/
1460 int MothurOut::getNumNames(string names){
1466 for(int i=0;i<names.size();i++){
1467 if(names[i] == ','){
1475 catch(exception& e) {
1476 errorOut(e, "MothurOut", "getNumNames");
1480 /***********************************************************************/
1482 int MothurOut::getNumChar(string line, char c){
1487 for(int i=0;i<line.size();i++){
1496 catch(exception& e) {
1497 errorOut(e, "MothurOut", "getNumChar");
1501 /***********************************************************************/
1502 int MothurOut::mothurRemove(string filename){
1504 filename = getFullPathName(filename);
1505 int error = remove(filename.c_str());
1507 // if (errno != ENOENT) { //ENOENT == file does not exist
1508 // string message = "Error deleting file " + filename;
1509 // perror(message.c_str());
1514 catch(exception& e) {
1515 errorOut(e, "MothurOut", "mothurRemove");
1519 /***********************************************************************/
1520 bool MothurOut::mothurConvert(string item, int& num){
1524 if (isNumeric1(item)) {
1529 mothurOut("[ERROR]: cannot convert " + item + " to an integer."); mothurOutEndLine();
1530 commandInputsConvertError = true;
1535 catch(exception& e) {
1536 errorOut(e, "MothurOut", "mothurConvert");
1540 /***********************************************************************/
1541 bool MothurOut::isNumeric1(string stringToCheck){
1543 bool numeric = false;
1545 if(stringToCheck.find_first_not_of("0123456789.-") == string::npos) { numeric = true; }
1549 catch(exception& e) {
1550 errorOut(e, "MothurOut", "isNumeric1");
1555 /***********************************************************************/
1556 bool MothurOut::mothurConvert(string item, float& num){
1560 if (isNumeric1(item)) {
1565 mothurOut("[ERROR]: cannot convert " + item + " to a float."); mothurOutEndLine();
1566 commandInputsConvertError = true;
1571 catch(exception& e) {
1572 errorOut(e, "MothurOut", "mothurConvert");
1576 /***********************************************************************/
1577 bool MothurOut::mothurConvert(string item, double& num){
1581 if (isNumeric1(item)) {
1586 mothurOut("[ERROR]: cannot convert " + item + " to a double."); mothurOutEndLine();
1587 commandInputsConvertError = true;
1592 catch(exception& e) {
1593 errorOut(e, "MothurOut", "mothurConvert");
1597 /**************************************************************************************************/
1599 vector<vector<double> > MothurOut::binomial(int maxOrder){
1601 vector<vector<double> > binomial(maxOrder+1);
1603 for(int i=0;i<=maxOrder;i++){
1604 binomial[i].resize(maxOrder+1);
1613 for(int i=2;i<=maxOrder;i++){
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]; }
1628 catch(exception& e) {
1629 errorOut(e, "MothurOut", "binomial");
1633 /**************************************************************************************************/
1634 unsigned int MothurOut::fromBase36(string base36){
1636 unsigned int num = 0;
1638 map<char, int> converts;
1703 while (i < base36.length()) {
1705 num = 36 * num + converts[c];
1712 catch(exception& e) {
1713 errorOut(e, "MothurOut", "fromBase36");
1717 /***********************************************************************/
1719 int MothurOut::factorial(int num){
1723 for (int i = 1; i <= num; i++) {
1729 catch(exception& e) {
1730 errorOut(e, "MothurOut", "factorial");
1734 /***********************************************************************/
1736 int MothurOut::getNumSeqs(ifstream& file){
1738 int numSeqs = count(istreambuf_iterator<char>(file),istreambuf_iterator<char>(), '>');
1742 catch(exception& e) {
1743 errorOut(e, "MothurOut", "getNumSeqs");
1747 /***********************************************************************/
1748 void MothurOut::getNumSeqs(ifstream& file, int& numSeqs){
1753 input = getline(file);
1754 if (input.length() != 0) {
1755 if(input[0] == '>'){ numSeqs++; }
1759 catch(exception& e) {
1760 errorOut(e, "MothurOut", "getNumSeqs");
1764 /***********************************************************************/
1766 //This function parses the estimator options and puts them in a vector
1767 void MothurOut::splitAtChar(string& estim, vector<string>& container, char symbol) {
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);
1777 individual += estim[i];
1780 container.push_back(individual);
1783 catch(exception& e) {
1784 errorOut(e, "MothurOut", "splitAtChar");
1789 /***********************************************************************/
1791 //This function parses the estimator options and puts them in a vector
1792 void MothurOut::splitAtDash(string& estim, vector<string>& container) {
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);
1802 individual += estim[i];
1805 container.push_back(individual);
1808 /* string individual;
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);
1818 container.push_back(estim); */
1820 catch(exception& e) {
1821 errorOut(e, "MothurOut", "splitAtDash");
1826 /***********************************************************************/
1827 //This function parses the label options and puts them in a set
1828 void MothurOut::splitAtDash(string& estim, set<string>& container) {
1830 string individual = "";
1831 int estimLength = estim.size();
1832 for(int i=0;i<estimLength;i++){
1833 if(estim[i] == '-'){
1834 container.insert(individual);
1838 individual += estim[i];
1841 container.insert(individual);
1843 // string individual;
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);
1853 // container.insert(estim);
1856 catch(exception& e) {
1857 errorOut(e, "MothurOut", "splitAtDash");
1861 /***********************************************************************/
1862 //This function parses the line options and puts them in a set
1863 void MothurOut::splitAtDash(string& estim, set<int>& container) {
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);
1877 convert(estim, lineNum); //convert the string to int
1878 container.insert(lineNum);
1880 catch(exception& e) {
1881 errorOut(e, "MothurOut", "splitAtDash");
1885 /***********************************************************************/
1886 //This function parses the a string and puts peices in a vector
1887 void MothurOut::splitAtComma(string& estim, vector<string>& container) {
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);
1897 individual += estim[i];
1900 container.push_back(individual);
1905 // string individual;
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);
1915 // container.push_back(estim);
1917 catch(exception& e) {
1918 errorOut(e, "MothurOut", "splitAtComma");
1922 /***********************************************************************/
1924 //This function splits up the various option parameters
1925 void MothurOut::splitAtComma(string& prefix, string& suffix){
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());
1931 while(suffix.at(0) == ' ')
1932 suffix = suffix.substr(1, suffix.length());
1936 catch(exception& e) {
1937 errorOut(e, "MothurOut", "splitAtComma");
1941 /***********************************************************************/
1943 //This function separates the key value from the option value i.e. dist=96_...
1944 void MothurOut::splitAtEquals(string& key, string& value){
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());
1956 catch(exception& e) {
1957 errorOut(e, "MothurOut", "splitAtEquals");
1962 /**************************************************************************************************/
1964 bool MothurOut::inUsersGroups(string groupname, vector<string> Groups) {
1966 for (int i = 0; i < Groups.size(); i++) {
1967 if (groupname == Groups[i]) { return true; }
1971 catch(exception& e) {
1972 errorOut(e, "MothurOut", "inUsersGroups");
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) {
1981 for (int i = 0; i < groupnames.size(); i++) {
1982 if (inUsersGroups(groupnames[i], Groups)) { return true; }
1986 catch(exception& e) {
1987 errorOut(e, "MothurOut", "inUsersGroups");
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) {
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;
2003 bool smaller = false;
2005 //unique is the smallest line
2006 if (label == "unique") { return false; }
2008 if (convertTestFloat(label, labelFloat)) {
2009 convert(label, labelFloat);
2010 }else { //cant convert
2015 //go through users set and make them floats
2016 for(it = userLabels.begin(); it != userLabels.end();) {
2019 if ((*it != "unique") && (convertTestFloat(*it, temp) == true)){
2021 orderFloat.push_back(temp);
2022 userMap[*it] = temp;
2024 }else if (*it == "unique") {
2025 orderFloat.push_back(-1.0);
2026 userMap["unique"] = -1.0;
2029 if (errorOff == "") { mothurOut(*it + " is not a valid label."); mothurOutEndLine(); }
2030 userLabels.erase(it++);
2035 sort(orderFloat.begin(), orderFloat.end());
2037 /*************************************************/
2038 //is this label bigger than any of the users labels
2039 /*************************************************/
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) {
2045 if (orderFloat[i] == -1) {
2046 if (errorOff == "") { mothurOut("Your file does not include the label unique."); mothurOutEndLine(); }
2047 userLabels.erase("unique");
2050 if (errorOff == "") { mothurOut("Your file does not include the label "); mothurOutEndLine(); }
2052 for (it2 = userMap.begin(); it2!= userMap.end(); it2++) {
2053 if (it2->second == orderFloat[i]) {
2055 //remove small labels
2056 userLabels.erase(s);
2060 if (errorOff == "") {mothurOut( s + ". I will use the next smallest distance. "); mothurOutEndLine(); }
2062 //since they are sorted once you find a bigger one stop looking
2069 catch(exception& e) {
2070 errorOut(e, "MothurOut", "anyLabelsToProcess");
2075 /**************************************************************************************************/
2076 bool MothurOut::checkReleaseVersion(ifstream& file, string version) {
2081 string line = getline(file);
2083 //before we added this check
2084 if (line[0] != '#') { good = false; }
2087 line = line.substr(1);
2089 vector<string> versionVector;
2090 splitAtChar(version, versionVector, '.');
2092 //check file version
2093 vector<string> linesVector;
2094 splitAtChar(line, linesVector, '.');
2096 if (versionVector.size() != linesVector.size()) { good = false; }
2098 for (int j = 0; j < versionVector.size(); j++) {
2100 convert(versionVector[j], num1);
2101 convert(linesVector[j], num2);
2103 //if mothurs version is newer than this files version, then we want to remake it
2104 if (num1 > num2) { good = false; break; }
2110 if (!good) { file.close(); }
2111 else { file.seekg(0); }
2115 catch(exception& e) {
2116 errorOut(e, "MothurOut", "checkReleaseVersion");
2120 /**************************************************************************************************/
2121 bool MothurOut::isContainingOnlyDigits(string input) {
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; }
2132 catch(exception& e) {
2133 errorOut(e, "MothurOut", "isContainingOnlyDigits");
2137 /**************************************************************************************************/
2138 int MothurOut::removeConfidences(string& tax) {
2144 while (tax.find_first_of(';') != -1) {
2146 if (control_pressed) { return 0; }
2149 taxon = tax.substr(0,tax.find_first_of(';'));
2151 int pos = taxon.find_last_of('(');
2154 int pos2 = taxon.find_last_of(')');
2156 string confidenceScore = taxon.substr(pos+1, (pos2-(pos+1)));
2157 if (isNumeric1(confidenceScore)) {
2158 taxon = taxon.substr(0, pos); //rip off confidence
2164 tax = tax.substr(tax.find_first_of(';')+1, tax.length());
2172 catch(exception& e) {
2173 errorOut(e, "MothurOut", "removeConfidences");
2177 /**************************************************************************************************/