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 bool MothurOut::dirCheck(string& dirName){
607 MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
612 //add / to name if needed
613 string lastChar = dirName.substr(dirName.length()-1);
614 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
615 if (lastChar != "/") { dirName += "/"; }
617 if (lastChar != "\\") { dirName += "\\"; }
620 //test to make sure directory exists
621 dirName = getFullPathName(dirName);
622 string outTemp = dirName + tag + "temp";
624 out.open(outTemp.c_str(), ios::trunc);
626 mothurOut(dirName + " directory does not exist or is not writable."); mothurOutEndLine();
629 mothurRemove(outTemp);
635 catch(exception& e) {
636 errorOut(e, "MothurOut", "dirCheck");
641 /***********************************************************************/
643 string MothurOut::hasPath(string longName){
648 found=longName.find_last_of("~/\\");
650 if(found != longName.npos){
651 path = longName.substr(0, found+1);
656 catch(exception& e) {
657 errorOut(e, "MothurOut", "hasPath");
662 /***********************************************************************/
664 string MothurOut::getExtension(string longName){
666 string extension = "";
668 if(longName.find_last_of('.') != longName.npos){
669 int pos = longName.find_last_of('.');
670 extension = longName.substr(pos, longName.length());
675 catch(exception& e) {
676 errorOut(e, "MothurOut", "getExtension");
680 /***********************************************************************/
681 bool MothurOut::isBlank(string fileName){
684 fileName = getFullPathName(fileName);
687 fileHandle.open(fileName.c_str());
689 mothurOut("[ERROR]: Could not open " + fileName); mothurOutEndLine();
692 //check for blank file
694 if (fileHandle.eof()) { fileHandle.close(); return true; }
699 catch(exception& e) {
700 errorOut(e, "MothurOut", "isBlank");
704 /***********************************************************************/
706 string MothurOut::getFullPathName(string fileName){
709 string path = hasPath(fileName);
713 if (path == "") { return fileName; } //its a simple name
714 else { //we need to complete the pathname
715 // ex. ../../../filename
716 // cwd = /user/work/desktop
719 //get current working directory
720 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
722 if (path.find("~") != -1) { //go to home directory
725 char *homepath = NULL;
726 homepath = getenv ("HOME");
727 if ( homepath != NULL) { homeDir = homepath; }
728 else { homeDir = ""; }
730 newFileName = homeDir + fileName.substr(fileName.find("~")+1);
733 if (path.rfind("./") == string::npos) { return fileName; } //already complete name
734 else { newFileName = fileName.substr(fileName.rfind("./")+2); } //save the complete part of the name
736 //char* cwdpath = new char[1024];
738 //cwdpath=getcwd(cwdpath,size);
741 char *cwdpath = NULL;
742 cwdpath = getcwd(NULL, 0); // or _getcwd
743 if ( cwdpath != NULL) { cwd = cwdpath; }
749 if (cwd.length() > 0) { simpleCWD = cwd.substr(1); }
751 //break apart the current working directory
753 while (simpleCWD.find_first_of('/') != string::npos) {
754 string dir = simpleCWD.substr(0,simpleCWD.find_first_of('/'));
755 simpleCWD = simpleCWD.substr(simpleCWD.find_first_of('/')+1, simpleCWD.length());
758 //get last one // ex. ../../../filename = /user/work/desktop/filename
759 dirs.push_back(simpleCWD); //ex. dirs[0] = user, dirs[1] = work, dirs[2] = desktop
762 int index = dirs.size()-1;
764 while((pos = path.rfind("./")) != string::npos) { //while you don't have a complete path
765 if (pos == 0) { break; //you are at the end
766 }else if (path[(pos-1)] == '.') { //you want your parent directory ../
767 path = path.substr(0, pos-1);
769 if (index == 0) { break; }
770 }else if (path[(pos-1)] == '/') { //you want the current working dir ./
771 path = path.substr(0, pos);
772 }else if (pos == 1) { break; //you are at the end
773 }else { mothurOut("cannot resolve path for " + fileName + "\n"); return fileName; }
776 for (int i = index; i >= 0; i--) {
777 newFileName = dirs[i] + "/" + newFileName;
780 newFileName = "/" + newFileName;
784 if (path.find("~") != string::npos) { //go to home directory
785 string homeDir = getenv ("HOMEPATH");
786 newFileName = homeDir + fileName.substr(fileName.find("~")+1);
789 if (path.rfind(".\\") == string::npos) { return fileName; } //already complete name
790 else { newFileName = fileName.substr(fileName.rfind(".\\")+2); } //save the complete part of the name
792 char *cwdpath = NULL;
793 cwdpath = getcwd(NULL, 0); // or _getcwd
794 if ( cwdpath != NULL) { cwd = cwdpath; }
797 //break apart the current working directory
799 while (cwd.find_first_of('\\') != -1) {
800 string dir = cwd.substr(0,cwd.find_first_of('\\'));
801 cwd = cwd.substr(cwd.find_first_of('\\')+1, cwd.length());
806 dirs.push_back(cwd); //ex. dirs[0] = user, dirs[1] = work, dirs[2] = desktop
808 int index = dirs.size()-1;
810 while((pos = path.rfind(".\\")) != string::npos) { //while you don't have a complete path
811 if (pos == 0) { break; //you are at the end
812 }else if (path[(pos-1)] == '.') { //you want your parent directory ../
813 path = path.substr(0, pos-1);
815 if (index == 0) { break; }
816 }else if (path[(pos-1)] == '\\') { //you want the current working dir ./
817 path = path.substr(0, pos);
818 }else if (pos == 1) { break; //you are at the end
819 }else { mothurOut("cannot resolve path for " + fileName + "\n"); return fileName; }
822 for (int i = index; i >= 0; i--) {
823 newFileName = dirs[i] + "\\" + newFileName;
832 catch(exception& e) {
833 errorOut(e, "MothurOut", "getFullPathName");
837 /***********************************************************************/
839 int MothurOut::openInputFile(string fileName, ifstream& fileHandle, string m){
842 string completeFileName = getFullPathName(fileName);
843 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
844 #ifdef USE_COMPRESSION
845 // check for gzipped or bzipped file
846 if (endsWith(completeFileName, ".gz") || endsWith(completeFileName, ".bz2")) {
847 string tempName = string(tmpnam(0));
848 mkfifo(tempName.c_str(), 0666);
849 int fork_result = fork();
850 if (fork_result < 0) {
851 cerr << "Error forking.\n";
853 } else if (fork_result == 0) {
854 string command = (endsWith(completeFileName, ".gz") ? "zcat " : "bzcat ") + completeFileName + string(" > ") + tempName;
855 cerr << "Decompressing " << completeFileName << " via temporary named pipe " << tempName << "\n";
856 system(command.c_str());
857 cerr << "Done decompressing " << completeFileName << "\n";
858 mothurRemove(tempName);
861 cerr << "waiting on child process " << fork_result << "\n";
862 completeFileName = tempName;
867 fileHandle.open(completeFileName.c_str());
869 //mothurOut("[ERROR]: Could not open " + completeFileName); mothurOutEndLine();
872 //check for blank file
877 catch(exception& e) {
878 errorOut(e, "MothurOut", "openInputFile - no Error");
882 /***********************************************************************/
884 int MothurOut::openInputFile(string fileName, ifstream& fileHandle){
888 string completeFileName = getFullPathName(fileName);
889 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
890 #ifdef USE_COMPRESSION
891 // check for gzipped or bzipped file
892 if (endsWith(completeFileName, ".gz") || endsWith(completeFileName, ".bz2")) {
893 string tempName = string(tmpnam(0));
894 mkfifo(tempName.c_str(), 0666);
895 int fork_result = fork();
896 if (fork_result < 0) {
897 cerr << "Error forking.\n";
899 } else if (fork_result == 0) {
900 string command = (endsWith(completeFileName, ".gz") ? "zcat " : "bzcat ") + completeFileName + string(" > ") + tempName;
901 cerr << "Decompressing " << completeFileName << " via temporary named pipe " << tempName << "\n";
902 system(command.c_str());
903 cerr << "Done decompressing " << completeFileName << "\n";
904 mothurRemove(tempName);
907 cerr << "waiting on child process " << fork_result << "\n";
908 completeFileName = tempName;
914 fileHandle.open(completeFileName.c_str());
916 mothurOut("[ERROR]: Could not open " + completeFileName); mothurOutEndLine();
920 //check for blank file
922 if (fileHandle.eof()) { mothurOut("[ERROR]: " + completeFileName + " is blank. Please correct."); mothurOutEndLine(); }
927 catch(exception& e) {
928 errorOut(e, "MothurOut", "openInputFile");
932 /***********************************************************************/
934 int MothurOut::renameFile(string oldName, string newName){
937 int exist = openInputFile(newName, inTest, "");
940 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
941 if (exist == 0) { //you could open it so you want to delete it
942 string command = "rm " + newName;
943 system(command.c_str());
946 string command = "mv " + oldName + " " + newName;
947 system(command.c_str());
949 mothurRemove(newName);
950 int renameOk = rename(oldName.c_str(), newName.c_str());
955 catch(exception& e) {
956 errorOut(e, "MothurOut", "renameFile");
961 /***********************************************************************/
963 int MothurOut::openOutputFile(string fileName, ofstream& fileHandle){
966 string completeFileName = getFullPathName(fileName);
967 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
968 #ifdef USE_COMPRESSION
969 // check for gzipped file
970 if (endsWith(completeFileName, ".gz") || endsWith(completeFileName, ".bz2")) {
971 string tempName = string(tmpnam(0));
972 mkfifo(tempName.c_str(), 0666);
973 cerr << "Compressing " << completeFileName << " via temporary named pipe " << tempName << "\n";
974 int fork_result = fork();
975 if (fork_result < 0) {
976 cerr << "Error forking.\n";
978 } else if (fork_result == 0) {
979 string command = string(endsWith(completeFileName, ".gz") ? "gzip" : "bzip2") + " -v > " + completeFileName + string(" < ") + tempName;
980 system(command.c_str());
983 completeFileName = tempName;
988 fileHandle.open(completeFileName.c_str(), ios::trunc);
990 mothurOut("[ERROR]: Could not open " + completeFileName); mothurOutEndLine();
997 catch(exception& e) {
998 errorOut(e, "MothurOut", "openOutputFile");
1004 /**************************************************************************************************/
1005 int MothurOut::appendFiles(string temp, string filename) {
1010 //open output file in append mode
1011 openOutputFileAppend(filename, output);
1012 int ableToOpen = openInputFile(temp, input, "no error");
1013 //int ableToOpen = openInputFile(temp, input);
1016 if (ableToOpen == 0) { //you opened it
1017 while(!input.eof()){
1018 char c = input.get();
1019 if(input.eof()) { break; }
1020 else { output << c; if (c == '\n') {numLines++;} }
1029 catch(exception& e) {
1030 errorOut(e, "MothurOut", "appendFiles");
1035 /**************************************************************************************************/
1036 string MothurOut::sortFile(string distFile, string outputDir){
1039 //if (outputDir == "") { outputDir += hasPath(distFile); }
1040 string outfile = getRootName(distFile) + "sorted.dist";
1043 //if you can, use the unix sort since its been optimized for years
1044 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
1045 string command = "sort -n -k +3 " + distFile + " -o " + outfile;
1046 system(command.c_str());
1047 #else //you are stuck with my best attempt...
1048 //windows sort does not have a way to specify a column, only a character in the line
1049 //since we cannot assume that the distance will always be at the the same character location on each line
1050 //due to variable sequence name lengths, I chose to force the distance into first position, then sort and then put it back.
1052 //read in file line by file and put distance first
1053 string tempDistFile = distFile + ".temp";
1056 openInputFile(distFile, input);
1057 openOutputFile(tempDistFile, output);
1059 string firstName, secondName;
1062 input >> firstName >> secondName >> dist;
1063 output << dist << '\t' << firstName << '\t' << secondName << endl;
1070 //sort using windows sort
1071 string tempOutfile = outfile + ".temp";
1072 string command = "sort " + tempDistFile + " /O " + tempOutfile;
1073 system(command.c_str());
1075 //read in sorted file and put distance at end again
1077 openInputFile(tempOutfile, input2);
1078 openOutputFile(outfile, output);
1081 input2 >> dist >> firstName >> secondName;
1082 output << firstName << '\t' << secondName << '\t' << dist << endl;
1089 mothurRemove(tempDistFile);
1090 mothurRemove(tempOutfile);
1095 catch(exception& e) {
1096 errorOut(e, "MothurOut", "sortFile");
1100 /**************************************************************************************************/
1101 vector<unsigned long long> MothurOut::setFilePosFasta(string filename, int& num) {
1103 vector<unsigned long long> positions;
1105 //openInputFile(filename, inFASTA);
1106 inFASTA.open(filename.c_str(), ios::binary);
1109 unsigned long long count = 0;
1110 while(!inFASTA.eof()){
1111 //input = getline(inFASTA);
1112 //cout << input << '\t' << inFASTA.tellg() << endl;
1113 //if (input.length() != 0) {
1114 // if(input[0] == '>'){ unsigned long int pos = inFASTA.tellg(); positions.push_back(pos - input.length() - 1); cout << (pos - input.length() - 1) << endl; }
1116 //gobble(inFASTA); //has to be here since windows line endings are 2 characters and mess up the positions
1117 char c = inFASTA.get(); count++;
1119 positions.push_back(count-1);
1120 //cout << count << endl;
1125 num = positions.size();
1130 //get num bytes in file
1131 pFile = fopen (filename.c_str(),"rb");
1132 if (pFile==NULL) perror ("Error opening file");
1134 fseek (pFile, 0, SEEK_END);
1139 unsigned long long size = positions[(positions.size()-1)];
1141 openInputFile(filename, in);
1146 if(in.eof()) { break; }
1151 positions.push_back(size);
1156 catch(exception& e) {
1157 errorOut(e, "MothurOut", "setFilePosFasta");
1161 /**************************************************************************************************/
1162 vector<unsigned long long> MothurOut::setFilePosEachLine(string filename, int& num) {
1164 filename = getFullPathName(filename);
1166 vector<unsigned long long> positions;
1168 //openInputFile(filename, in);
1169 in.open(filename.c_str(), ios::binary);
1172 unsigned long long count = 0;
1173 positions.push_back(0);
1176 //unsigned long long lastpos = in.tellg();
1177 //input = getline(in);
1178 //if (input.length() != 0) {
1179 //unsigned long long pos = in.tellg();
1180 //if (pos != -1) { positions.push_back(pos - input.length() - 1); }
1181 //else { positions.push_back(lastpos); }
1183 //gobble(in); //has to be here since windows line endings are 2 characters and mess up the positions
1186 //getline counting reads
1187 char d = in.get(); count++;
1188 while ((d != '\n') && (d != '\r') && (d != '\f') && (d != in.eof())) {
1189 //get next character
1195 d=in.get(); count++;
1196 while(isspace(d) && (d != in.eof())) { d=in.get(); count++;}
1198 positions.push_back(count-1);
1199 //cout << count-1 << endl;
1203 num = positions.size()-1;
1206 unsigned long long size;
1208 //get num bytes in file
1209 pFile = fopen (filename.c_str(),"rb");
1210 if (pFile==NULL) perror ("Error opening file");
1212 fseek (pFile, 0, SEEK_END);
1217 positions[(positions.size()-1)] = size;
1221 catch(exception& e) {
1222 errorOut(e, "MothurOut", "setFilePosEachLine");
1226 /**************************************************************************************************/
1228 vector<unsigned long long> MothurOut::divideFile(string filename, int& proc) {
1230 vector<unsigned long long> filePos;
1231 filePos.push_back(0);
1234 unsigned long long size;
1236 filename = getFullPathName(filename);
1238 //get num bytes in file
1239 pFile = fopen (filename.c_str(),"rb");
1240 if (pFile==NULL) perror ("Error opening file");
1242 fseek (pFile, 0, SEEK_END);
1247 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
1249 //estimate file breaks
1250 unsigned long long chunkSize = 0;
1251 chunkSize = size / proc;
1253 //file to small to divide by processors
1254 if (chunkSize == 0) { proc = 1; filePos.push_back(size); return filePos; }
1256 //for each process seekg to closest file break and search for next '>' char. make that the filebreak
1257 for (int i = 0; i < proc; i++) {
1258 unsigned long long spot = (i+1) * chunkSize;
1261 openInputFile(filename, in);
1265 unsigned long long newSpot = spot;
1269 if (c == '>') { in.putback(c); newSpot = in.tellg(); break; }
1270 else if (int(c) == -1) { break; }
1274 //there was not another sequence before the end of the file
1275 unsigned long long sanityPos = in.tellg();
1277 if (sanityPos == -1) { break; }
1278 else { filePos.push_back(newSpot); }
1284 filePos.push_back(size);
1286 //sanity check filePos
1287 for (int i = 0; i < (filePos.size()-1); i++) {
1288 if (filePos[(i+1)] <= filePos[i]) { filePos.erase(filePos.begin()+(i+1)); i--; }
1291 proc = (filePos.size() - 1);
1293 mothurOut("[ERROR]: Windows version should not be calling the divideFile function."); mothurOutEndLine();
1295 filePos.push_back(size);
1299 catch(exception& e) {
1300 errorOut(e, "MothurOut", "divideFile");
1304 /**************************************************************************************************/
1305 int MothurOut::divideFile(string filename, int& proc, vector<string>& files) {
1308 vector<unsigned long long> filePos = divideFile(filename, proc);
1310 for (int i = 0; i < (filePos.size()-1); i++) {
1314 openInputFile(filename, in);
1315 in.seekg(filePos[i]);
1316 unsigned long long size = filePos[(i+1)] - filePos[i];
1317 char* chunk = new char[size];
1318 in.read(chunk, size);
1322 string fileChunkName = filename + "." + toString(i) + ".tmp";
1324 openOutputFile(fileChunkName, out);
1326 out << chunk << endl;
1331 files.push_back(fileChunkName);
1336 catch(exception& e) {
1337 errorOut(e, "MothurOut", "divideFile");
1341 /***********************************************************************/
1343 bool MothurOut::isTrue(string f){
1346 for (int i = 0; i < f.length(); i++) { f[i] = toupper(f[i]); }
1348 if ((f == "TRUE") || (f == "T")) { return true; }
1349 else { return false; }
1351 catch(exception& e) {
1352 errorOut(e, "MothurOut", "isTrue");
1357 /***********************************************************************/
1359 float MothurOut::roundDist(float dist, int precision){
1361 return int(dist * precision + 0.5)/float(precision);
1363 catch(exception& e) {
1364 errorOut(e, "MothurOut", "roundDist");
1368 /***********************************************************************/
1370 float MothurOut::ceilDist(float dist, int precision){
1372 return int(ceil(dist * precision))/float(precision);
1374 catch(exception& e) {
1375 errorOut(e, "MothurOut", "ceilDist");
1379 /**********************************************************************************************************************/
1380 int MothurOut::readNames(string namefile, map<string, string>& nameMap) {
1385 openInputFile(namefile, in);
1388 if (control_pressed) { break; }
1390 string firstCol, secondCol;
1391 in >> firstCol >> secondCol; gobble(in);
1393 nameMap[firstCol] = secondCol;
1397 return nameMap.size();
1400 catch(exception& e) {
1401 errorOut(e, "MothurOut", "readNames");
1405 /**********************************************************************************************************************/
1406 int MothurOut::readNames(string namefile, map<string, vector<string> >& nameMap) {
1411 openInputFile(namefile, in);
1414 if (control_pressed) { break; }
1416 string firstCol, secondCol;
1417 in >> firstCol >> secondCol; gobble(in);
1419 vector<string> temp;
1420 splitAtComma(secondCol, temp);
1422 nameMap[firstCol] = temp;
1426 return nameMap.size();
1429 catch(exception& e) {
1430 errorOut(e, "MothurOut", "readNames");
1434 /**********************************************************************************************************************/
1435 map<string, int> MothurOut::readNames(string namefile) {
1438 map<string, int> nameMap;
1442 openInputFile(namefile, in);
1445 if (control_pressed) { break; }
1447 string firstCol, secondCol;
1448 in >> firstCol >> secondCol; gobble(in);
1450 int num = getNumNames(secondCol);
1452 nameMap[firstCol] = num;
1459 catch(exception& e) {
1460 errorOut(e, "MothurOut", "readNames");
1464 /**********************************************************************************************************************/
1465 int MothurOut::readNames(string namefile, vector<seqPriorityNode>& nameVector, map<string, string>& fastamap) {
1471 openInputFile(namefile, in);
1474 if (control_pressed) { break; }
1476 string firstCol, secondCol;
1477 in >> firstCol >> secondCol; gobble(in);
1479 int num = getNumNames(secondCol);
1481 map<string, string>::iterator it = fastamap.find(firstCol);
1482 if (it == fastamap.end()) {
1484 mothurOut("[ERROR]: " + firstCol + " is not in your fastafile, but is in your namesfile, please correct."); mothurOutEndLine();
1486 seqPriorityNode temp(num, it->second, firstCol);
1487 nameVector.push_back(temp);
1495 catch(exception& e) {
1496 errorOut(e, "MothurOut", "readNames");
1501 /***********************************************************************/
1503 int MothurOut::getNumNames(string names){
1509 for(int i=0;i<names.size();i++){
1510 if(names[i] == ','){
1518 catch(exception& e) {
1519 errorOut(e, "MothurOut", "getNumNames");
1523 /***********************************************************************/
1525 int MothurOut::getNumChar(string line, char c){
1530 for(int i=0;i<line.size();i++){
1539 catch(exception& e) {
1540 errorOut(e, "MothurOut", "getNumChar");
1544 /***********************************************************************/
1545 int MothurOut::mothurRemove(string filename){
1547 filename = getFullPathName(filename);
1548 int error = remove(filename.c_str());
1550 // if (errno != ENOENT) { //ENOENT == file does not exist
1551 // string message = "Error deleting file " + filename;
1552 // perror(message.c_str());
1557 catch(exception& e) {
1558 errorOut(e, "MothurOut", "mothurRemove");
1562 /***********************************************************************/
1563 bool MothurOut::mothurConvert(string item, int& num){
1567 if (isNumeric1(item)) {
1572 mothurOut("[ERROR]: cannot convert " + item + " to an integer."); mothurOutEndLine();
1573 commandInputsConvertError = true;
1578 catch(exception& e) {
1579 errorOut(e, "MothurOut", "mothurConvert");
1583 /***********************************************************************/
1584 bool MothurOut::isNumeric1(string stringToCheck){
1586 bool numeric = false;
1588 if(stringToCheck.find_first_not_of("0123456789.-") == string::npos) { numeric = true; }
1592 catch(exception& e) {
1593 errorOut(e, "MothurOut", "isNumeric1");
1598 /***********************************************************************/
1599 bool MothurOut::mothurConvert(string item, float& num){
1603 if (isNumeric1(item)) {
1608 mothurOut("[ERROR]: cannot convert " + item + " to a float."); mothurOutEndLine();
1609 commandInputsConvertError = true;
1614 catch(exception& e) {
1615 errorOut(e, "MothurOut", "mothurConvert");
1619 /***********************************************************************/
1620 bool MothurOut::mothurConvert(string item, double& num){
1624 if (isNumeric1(item)) {
1629 mothurOut("[ERROR]: cannot convert " + item + " to a double."); mothurOutEndLine();
1630 commandInputsConvertError = true;
1635 catch(exception& e) {
1636 errorOut(e, "MothurOut", "mothurConvert");
1640 /**************************************************************************************************/
1642 vector<vector<double> > MothurOut::binomial(int maxOrder){
1644 vector<vector<double> > binomial(maxOrder+1);
1646 for(int i=0;i<=maxOrder;i++){
1647 binomial[i].resize(maxOrder+1);
1656 for(int i=2;i<=maxOrder;i++){
1660 for(int i=2;i<=maxOrder;i++){
1661 for(int j=1;j<=maxOrder;j++){
1662 if(i==j){ binomial[i][j]=1; }
1663 if(j>i) { binomial[i][j]=0; }
1664 else { binomial[i][j]=binomial[i-1][j-1]+binomial[i-1][j]; }
1671 catch(exception& e) {
1672 errorOut(e, "MothurOut", "binomial");
1676 /**************************************************************************************************/
1677 unsigned int MothurOut::fromBase36(string base36){
1679 unsigned int num = 0;
1681 map<char, int> converts;
1746 while (i < base36.length()) {
1748 num = 36 * num + converts[c];
1755 catch(exception& e) {
1756 errorOut(e, "MothurOut", "fromBase36");
1760 /***********************************************************************/
1762 int MothurOut::factorial(int num){
1766 for (int i = 1; i <= num; i++) {
1772 catch(exception& e) {
1773 errorOut(e, "MothurOut", "factorial");
1777 /***********************************************************************/
1779 int MothurOut::getNumSeqs(ifstream& file){
1781 int numSeqs = count(istreambuf_iterator<char>(file),istreambuf_iterator<char>(), '>');
1785 catch(exception& e) {
1786 errorOut(e, "MothurOut", "getNumSeqs");
1790 /***********************************************************************/
1791 void MothurOut::getNumSeqs(ifstream& file, int& numSeqs){
1796 input = getline(file);
1797 if (input.length() != 0) {
1798 if(input[0] == '>'){ numSeqs++; }
1802 catch(exception& e) {
1803 errorOut(e, "MothurOut", "getNumSeqs");
1807 /***********************************************************************/
1809 //This function parses the estimator options and puts them in a vector
1810 void MothurOut::splitAtChar(string& estim, vector<string>& container, char symbol) {
1812 string individual = "";
1813 int estimLength = estim.size();
1814 for(int i=0;i<estimLength;i++){
1815 if(estim[i] == symbol){
1816 container.push_back(individual);
1820 individual += estim[i];
1823 container.push_back(individual);
1826 catch(exception& e) {
1827 errorOut(e, "MothurOut", "splitAtChar");
1832 /***********************************************************************/
1834 //This function parses the estimator options and puts them in a vector
1835 void MothurOut::splitAtDash(string& estim, vector<string>& container) {
1837 string individual = "";
1838 int estimLength = estim.size();
1839 for(int i=0;i<estimLength;i++){
1840 if(estim[i] == '-'){
1841 container.push_back(individual);
1845 individual += estim[i];
1848 container.push_back(individual);
1851 /* string individual;
1853 while (estim.find_first_of('-') != -1) {
1854 individual = estim.substr(0,estim.find_first_of('-'));
1855 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
1856 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
1857 container.push_back(individual);
1861 container.push_back(estim); */
1863 catch(exception& e) {
1864 errorOut(e, "MothurOut", "splitAtDash");
1869 /***********************************************************************/
1870 //This function parses the label options and puts them in a set
1871 void MothurOut::splitAtDash(string& estim, set<string>& container) {
1873 string individual = "";
1874 int estimLength = estim.size();
1875 for(int i=0;i<estimLength;i++){
1876 if(estim[i] == '-'){
1877 container.insert(individual);
1881 individual += estim[i];
1884 container.insert(individual);
1886 // string individual;
1888 // while (estim.find_first_of('-') != -1) {
1889 // individual = estim.substr(0,estim.find_first_of('-'));
1890 // if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
1891 // estim = estim.substr(estim.find_first_of('-')+1, estim.length());
1892 // container.insert(individual);
1896 // container.insert(estim);
1899 catch(exception& e) {
1900 errorOut(e, "MothurOut", "splitAtDash");
1904 /***********************************************************************/
1905 //This function parses the line options and puts them in a set
1906 void MothurOut::splitAtDash(string& estim, set<int>& container) {
1911 while (estim.find_first_of('-') != -1) {
1912 individual = estim.substr(0,estim.find_first_of('-'));
1913 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
1914 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
1915 convert(individual, lineNum); //convert the string to int
1916 container.insert(lineNum);
1920 convert(estim, lineNum); //convert the string to int
1921 container.insert(lineNum);
1923 catch(exception& e) {
1924 errorOut(e, "MothurOut", "splitAtDash");
1928 /***********************************************************************/
1929 //This function parses the a string and puts peices in a vector
1930 void MothurOut::splitAtComma(string& estim, vector<string>& container) {
1932 string individual = "";
1933 int estimLength = estim.size();
1934 for(int i=0;i<estimLength;i++){
1935 if(estim[i] == ','){
1936 container.push_back(individual);
1940 individual += estim[i];
1943 container.push_back(individual);
1948 // string individual;
1950 // while (estim.find_first_of(',') != -1) {
1951 // individual = estim.substr(0,estim.find_first_of(','));
1952 // if ((estim.find_first_of(',')+1) <= estim.length()) { //checks to make sure you don't have comma at end of string
1953 // estim = estim.substr(estim.find_first_of(',')+1, estim.length());
1954 // container.push_back(individual);
1958 // container.push_back(estim);
1960 catch(exception& e) {
1961 errorOut(e, "MothurOut", "splitAtComma");
1965 /***********************************************************************/
1967 //This function splits up the various option parameters
1968 void MothurOut::splitAtComma(string& prefix, string& suffix){
1970 prefix = suffix.substr(0,suffix.find_first_of(','));
1971 if ((suffix.find_first_of(',')+2) <= suffix.length()) { //checks to make sure you don't have comma at end of string
1972 suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length());
1974 while(suffix.at(0) == ' ')
1975 suffix = suffix.substr(1, suffix.length());
1979 catch(exception& e) {
1980 errorOut(e, "MothurOut", "splitAtComma");
1984 /***********************************************************************/
1986 //This function separates the key value from the option value i.e. dist=96_...
1987 void MothurOut::splitAtEquals(string& key, string& value){
1989 if(value.find_first_of('=') != -1){
1990 key = value.substr(0,value.find_first_of('='));
1991 if ((value.find_first_of('=')+1) <= value.length()) {
1992 value = value.substr(value.find_first_of('=')+1, value.length());
1999 catch(exception& e) {
2000 errorOut(e, "MothurOut", "splitAtEquals");
2005 /**************************************************************************************************/
2007 bool MothurOut::inUsersGroups(string groupname, vector<string> Groups) {
2009 for (int i = 0; i < Groups.size(); i++) {
2010 if (groupname == Groups[i]) { return true; }
2014 catch(exception& e) {
2015 errorOut(e, "MothurOut", "inUsersGroups");
2019 /**************************************************************************************************/
2020 //returns true if any of the strings in first vector are in second vector
2021 bool MothurOut::inUsersGroups(vector<string> groupnames, vector<string> Groups) {
2024 for (int i = 0; i < groupnames.size(); i++) {
2025 if (inUsersGroups(groupnames[i], Groups)) { return true; }
2029 catch(exception& e) {
2030 errorOut(e, "MothurOut", "inUsersGroups");
2034 /***********************************************************************/
2035 //this function determines if the user has given us labels that are smaller than the given label.
2036 //if so then it returns true so that the calling function can run the previous valid distance.
2037 //it's a "smart" distance function. It also checks for invalid labels.
2038 bool MothurOut::anyLabelsToProcess(string label, set<string>& userLabels, string errorOff) {
2041 set<string>::iterator it;
2042 vector<float> orderFloat;
2043 map<string, float> userMap; //the conversion process removes trailing 0's which we need to put back
2044 map<string, float>::iterator it2;
2046 bool smaller = false;
2048 //unique is the smallest line
2049 if (label == "unique") { return false; }
2051 if (convertTestFloat(label, labelFloat)) {
2052 convert(label, labelFloat);
2053 }else { //cant convert
2058 //go through users set and make them floats
2059 for(it = userLabels.begin(); it != userLabels.end();) {
2062 if ((*it != "unique") && (convertTestFloat(*it, temp) == true)){
2064 orderFloat.push_back(temp);
2065 userMap[*it] = temp;
2067 }else if (*it == "unique") {
2068 orderFloat.push_back(-1.0);
2069 userMap["unique"] = -1.0;
2072 if (errorOff == "") { mothurOut(*it + " is not a valid label."); mothurOutEndLine(); }
2073 userLabels.erase(it++);
2078 sort(orderFloat.begin(), orderFloat.end());
2080 /*************************************************/
2081 //is this label bigger than any of the users labels
2082 /*************************************************/
2084 //loop through order until you find a label greater than label
2085 for (int i = 0; i < orderFloat.size(); i++) {
2086 if (orderFloat[i] < labelFloat) {
2088 if (orderFloat[i] == -1) {
2089 if (errorOff == "") { mothurOut("Your file does not include the label unique."); mothurOutEndLine(); }
2090 userLabels.erase("unique");
2093 if (errorOff == "") { mothurOut("Your file does not include the label "); mothurOutEndLine(); }
2095 for (it2 = userMap.begin(); it2!= userMap.end(); it2++) {
2096 if (it2->second == orderFloat[i]) {
2098 //remove small labels
2099 userLabels.erase(s);
2103 if (errorOff == "") {mothurOut( s + ". I will use the next smallest distance. "); mothurOutEndLine(); }
2105 //since they are sorted once you find a bigger one stop looking
2112 catch(exception& e) {
2113 errorOut(e, "MothurOut", "anyLabelsToProcess");
2118 /**************************************************************************************************/
2119 bool MothurOut::checkReleaseVersion(ifstream& file, string version) {
2124 string line = getline(file);
2126 //before we added this check
2127 if (line[0] != '#') { good = false; }
2130 line = line.substr(1);
2132 vector<string> versionVector;
2133 splitAtChar(version, versionVector, '.');
2135 //check file version
2136 vector<string> linesVector;
2137 splitAtChar(line, linesVector, '.');
2139 if (versionVector.size() != linesVector.size()) { good = false; }
2141 for (int j = 0; j < versionVector.size(); j++) {
2143 convert(versionVector[j], num1);
2144 convert(linesVector[j], num2);
2146 //if mothurs version is newer than this files version, then we want to remake it
2147 if (num1 > num2) { good = false; break; }
2153 if (!good) { file.close(); }
2154 else { file.seekg(0); }
2158 catch(exception& e) {
2159 errorOut(e, "MothurOut", "checkReleaseVersion");
2163 /**************************************************************************************************/
2164 bool MothurOut::isContainingOnlyDigits(string input) {
2167 //are you a digit in ascii code
2168 for (int i = 0;i < input.length(); i++){
2169 if( input[i]>47 && input[i]<58){}
2170 else { return false; }
2175 catch(exception& e) {
2176 errorOut(e, "MothurOut", "isContainingOnlyDigits");
2180 /**************************************************************************************************/
2181 int MothurOut::removeConfidences(string& tax) {
2187 while (tax.find_first_of(';') != -1) {
2189 if (control_pressed) { return 0; }
2192 taxon = tax.substr(0,tax.find_first_of(';'));
2194 int pos = taxon.find_last_of('(');
2197 int pos2 = taxon.find_last_of(')');
2199 string confidenceScore = taxon.substr(pos+1, (pos2-(pos+1)));
2200 if (isNumeric1(confidenceScore)) {
2201 taxon = taxon.substr(0, pos); //rip off confidence
2207 tax = tax.substr(tax.find_first_of(';')+1, tax.length());
2215 catch(exception& e) {
2216 errorOut(e, "MothurOut", "removeConfidences");
2220 /**************************************************************************************************/