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(char c = input.get()){
1018 if(input.eof()) { break; }
1019 else { output << c; if (c == '\n') {numLines++;} }
1028 catch(exception& e) {
1029 errorOut(e, "MothurOut", "appendFiles");
1034 /**************************************************************************************************/
1035 string MothurOut::sortFile(string distFile, string outputDir){
1038 //if (outputDir == "") { outputDir += hasPath(distFile); }
1039 string outfile = getRootName(distFile) + "sorted.dist";
1042 //if you can, use the unix sort since its been optimized for years
1043 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
1044 string command = "sort -n -k +3 " + distFile + " -o " + outfile;
1045 system(command.c_str());
1046 #else //you are stuck with my best attempt...
1047 //windows sort does not have a way to specify a column, only a character in the line
1048 //since we cannot assume that the distance will always be at the the same character location on each line
1049 //due to variable sequence name lengths, I chose to force the distance into first position, then sort and then put it back.
1051 //read in file line by file and put distance first
1052 string tempDistFile = distFile + ".temp";
1055 openInputFile(distFile, input);
1056 openOutputFile(tempDistFile, output);
1058 string firstName, secondName;
1061 input >> firstName >> secondName >> dist;
1062 output << dist << '\t' << firstName << '\t' << secondName << endl;
1069 //sort using windows sort
1070 string tempOutfile = outfile + ".temp";
1071 string command = "sort " + tempDistFile + " /O " + tempOutfile;
1072 system(command.c_str());
1074 //read in sorted file and put distance at end again
1076 openInputFile(tempOutfile, input2);
1077 openOutputFile(outfile, output);
1080 input2 >> dist >> firstName >> secondName;
1081 output << firstName << '\t' << secondName << '\t' << dist << endl;
1088 mothurRemove(tempDistFile);
1089 mothurRemove(tempOutfile);
1094 catch(exception& e) {
1095 errorOut(e, "MothurOut", "sortFile");
1099 /**************************************************************************************************/
1100 vector<unsigned long long> MothurOut::setFilePosFasta(string filename, int& num) {
1102 vector<unsigned long long> positions;
1104 //openInputFile(filename, inFASTA);
1105 inFASTA.open(filename.c_str(), ios::binary);
1108 unsigned long long count = 0;
1109 while(!inFASTA.eof()){
1110 //input = getline(inFASTA);
1111 //cout << input << '\t' << inFASTA.tellg() << endl;
1112 //if (input.length() != 0) {
1113 // if(input[0] == '>'){ unsigned long int pos = inFASTA.tellg(); positions.push_back(pos - input.length() - 1); cout << (pos - input.length() - 1) << endl; }
1115 //gobble(inFASTA); //has to be here since windows line endings are 2 characters and mess up the positions
1116 char c = inFASTA.get(); count++;
1118 positions.push_back(count-1);
1119 //cout << count << endl;
1124 num = positions.size();
1129 //get num bytes in file
1130 pFile = fopen (filename.c_str(),"rb");
1131 if (pFile==NULL) perror ("Error opening file");
1133 fseek (pFile, 0, SEEK_END);
1138 unsigned long long size = positions[(positions.size()-1)];
1140 openInputFile(filename, in);
1145 if(in.eof()) { break; }
1150 positions.push_back(size);
1155 catch(exception& e) {
1156 errorOut(e, "MothurOut", "setFilePosFasta");
1160 /**************************************************************************************************/
1161 vector<unsigned long long> MothurOut::setFilePosEachLine(string filename, int& num) {
1163 filename = getFullPathName(filename);
1165 vector<unsigned long long> positions;
1167 //openInputFile(filename, in);
1168 in.open(filename.c_str(), ios::binary);
1171 unsigned long long count = 0;
1172 positions.push_back(0);
1175 //unsigned long long lastpos = in.tellg();
1176 //input = getline(in);
1177 //if (input.length() != 0) {
1178 //unsigned long long pos = in.tellg();
1179 //if (pos != -1) { positions.push_back(pos - input.length() - 1); }
1180 //else { positions.push_back(lastpos); }
1182 //gobble(in); //has to be here since windows line endings are 2 characters and mess up the positions
1185 //getline counting reads
1186 char d = in.get(); count++;
1187 while ((d != '\n') && (d != '\r') && (d != '\f') && (d != in.eof())) {
1188 //get next character
1194 d=in.get(); count++;
1195 while(isspace(d) && (d != in.eof())) { d=in.get(); count++;}
1197 positions.push_back(count-1);
1198 //cout << count-1 << endl;
1202 num = positions.size()-1;
1205 unsigned long long size;
1207 //get num bytes in file
1208 pFile = fopen (filename.c_str(),"rb");
1209 if (pFile==NULL) perror ("Error opening file");
1211 fseek (pFile, 0, SEEK_END);
1216 positions[(positions.size()-1)] = size;
1220 catch(exception& e) {
1221 errorOut(e, "MothurOut", "setFilePosEachLine");
1225 /**************************************************************************************************/
1227 vector<unsigned long long> MothurOut::divideFile(string filename, int& proc) {
1229 vector<unsigned long long> filePos;
1230 filePos.push_back(0);
1233 unsigned long long size;
1235 filename = getFullPathName(filename);
1237 //get num bytes in file
1238 pFile = fopen (filename.c_str(),"rb");
1239 if (pFile==NULL) perror ("Error opening file");
1241 fseek (pFile, 0, SEEK_END);
1246 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
1248 //estimate file breaks
1249 unsigned long long chunkSize = 0;
1250 chunkSize = size / proc;
1252 //file to small to divide by processors
1253 if (chunkSize == 0) { proc = 1; filePos.push_back(size); return filePos; }
1255 //for each process seekg to closest file break and search for next '>' char. make that the filebreak
1256 for (int i = 0; i < proc; i++) {
1257 unsigned long long spot = (i+1) * chunkSize;
1260 openInputFile(filename, in);
1264 unsigned long long newSpot = spot;
1268 if (c == '>') { in.putback(c); newSpot = in.tellg(); break; }
1269 else if (int(c) == -1) { break; }
1273 //there was not another sequence before the end of the file
1274 unsigned long long sanityPos = in.tellg();
1276 if (sanityPos == -1) { break; }
1277 else { filePos.push_back(newSpot); }
1283 filePos.push_back(size);
1285 //sanity check filePos
1286 for (int i = 0; i < (filePos.size()-1); i++) {
1287 if (filePos[(i+1)] <= filePos[i]) { filePos.erase(filePos.begin()+(i+1)); i--; }
1290 proc = (filePos.size() - 1);
1292 mothurOut("[ERROR]: Windows version should not be calling the divideFile function."); mothurOutEndLine();
1294 filePos.push_back(size);
1298 catch(exception& e) {
1299 errorOut(e, "MothurOut", "divideFile");
1303 /**************************************************************************************************/
1304 int MothurOut::divideFile(string filename, int& proc, vector<string>& files) {
1307 vector<unsigned long long> filePos = divideFile(filename, proc);
1309 for (int i = 0; i < (filePos.size()-1); i++) {
1313 openInputFile(filename, in);
1314 in.seekg(filePos[i]);
1315 unsigned long long size = filePos[(i+1)] - filePos[i];
1316 char* chunk = new char[size];
1317 in.read(chunk, size);
1321 string fileChunkName = filename + "." + toString(i) + ".tmp";
1323 openOutputFile(fileChunkName, out);
1325 out << chunk << endl;
1330 files.push_back(fileChunkName);
1335 catch(exception& e) {
1336 errorOut(e, "MothurOut", "divideFile");
1340 /***********************************************************************/
1342 bool MothurOut::isTrue(string f){
1345 for (int i = 0; i < f.length(); i++) { f[i] = toupper(f[i]); }
1347 if ((f == "TRUE") || (f == "T")) { return true; }
1348 else { return false; }
1350 catch(exception& e) {
1351 errorOut(e, "MothurOut", "isTrue");
1356 /***********************************************************************/
1358 float MothurOut::roundDist(float dist, int precision){
1360 return int(dist * precision + 0.5)/float(precision);
1362 catch(exception& e) {
1363 errorOut(e, "MothurOut", "roundDist");
1367 /***********************************************************************/
1369 float MothurOut::ceilDist(float dist, int precision){
1371 return int(ceil(dist * precision))/float(precision);
1373 catch(exception& e) {
1374 errorOut(e, "MothurOut", "ceilDist");
1378 /**********************************************************************************************************************/
1379 int MothurOut::readNames(string namefile, map<string, string>& nameMap) {
1384 openInputFile(namefile, in);
1387 if (control_pressed) { break; }
1389 string firstCol, secondCol;
1390 in >> firstCol >> secondCol; gobble(in);
1392 nameMap[firstCol] = secondCol;
1396 return nameMap.size();
1399 catch(exception& e) {
1400 errorOut(e, "MothurOut", "readNames");
1404 /**********************************************************************************************************************/
1405 int MothurOut::readNames(string namefile, map<string, vector<string> >& nameMap) {
1410 openInputFile(namefile, in);
1413 if (control_pressed) { break; }
1415 string firstCol, secondCol;
1416 in >> firstCol >> secondCol; gobble(in);
1418 vector<string> temp;
1419 splitAtComma(secondCol, temp);
1421 nameMap[firstCol] = temp;
1425 return nameMap.size();
1428 catch(exception& e) {
1429 errorOut(e, "MothurOut", "readNames");
1433 /**********************************************************************************************************************/
1434 map<string, int> MothurOut::readNames(string namefile) {
1437 map<string, int> nameMap;
1441 openInputFile(namefile, in);
1444 if (control_pressed) { break; }
1446 string firstCol, secondCol;
1447 in >> firstCol >> secondCol; gobble(in);
1449 int num = getNumNames(secondCol);
1451 nameMap[firstCol] = num;
1458 catch(exception& e) {
1459 errorOut(e, "MothurOut", "readNames");
1463 /**********************************************************************************************************************/
1464 int MothurOut::readNames(string namefile, vector<seqPriorityNode>& nameVector, map<string, string>& fastamap) {
1470 openInputFile(namefile, in);
1473 if (control_pressed) { break; }
1475 string firstCol, secondCol;
1476 in >> firstCol >> secondCol; gobble(in);
1478 int num = getNumNames(secondCol);
1480 map<string, string>::iterator it = fastamap.find(firstCol);
1481 if (it == fastamap.end()) {
1483 mothurOut("[ERROR]: " + firstCol + " is not in your fastafile, but is in your namesfile, please correct."); mothurOutEndLine();
1485 seqPriorityNode temp(num, it->second, firstCol);
1486 nameVector.push_back(temp);
1494 catch(exception& e) {
1495 errorOut(e, "MothurOut", "readNames");
1500 /***********************************************************************/
1502 int MothurOut::getNumNames(string names){
1508 for(int i=0;i<names.size();i++){
1509 if(names[i] == ','){
1517 catch(exception& e) {
1518 errorOut(e, "MothurOut", "getNumNames");
1522 /***********************************************************************/
1524 int MothurOut::getNumChar(string line, char c){
1529 for(int i=0;i<line.size();i++){
1538 catch(exception& e) {
1539 errorOut(e, "MothurOut", "getNumChar");
1543 /***********************************************************************/
1544 int MothurOut::mothurRemove(string filename){
1546 filename = getFullPathName(filename);
1547 int error = remove(filename.c_str());
1549 // if (errno != ENOENT) { //ENOENT == file does not exist
1550 // string message = "Error deleting file " + filename;
1551 // perror(message.c_str());
1556 catch(exception& e) {
1557 errorOut(e, "MothurOut", "mothurRemove");
1561 /***********************************************************************/
1562 bool MothurOut::mothurConvert(string item, int& num){
1566 if (isNumeric1(item)) {
1571 mothurOut("[ERROR]: cannot convert " + item + " to an integer."); mothurOutEndLine();
1572 commandInputsConvertError = true;
1577 catch(exception& e) {
1578 errorOut(e, "MothurOut", "mothurConvert");
1582 /***********************************************************************/
1583 bool MothurOut::isNumeric1(string stringToCheck){
1585 bool numeric = false;
1587 if(stringToCheck.find_first_not_of("0123456789.-") == string::npos) { numeric = true; }
1591 catch(exception& e) {
1592 errorOut(e, "MothurOut", "isNumeric1");
1597 /***********************************************************************/
1598 bool MothurOut::mothurConvert(string item, float& num){
1602 if (isNumeric1(item)) {
1607 mothurOut("[ERROR]: cannot convert " + item + " to a float."); mothurOutEndLine();
1608 commandInputsConvertError = true;
1613 catch(exception& e) {
1614 errorOut(e, "MothurOut", "mothurConvert");
1618 /***********************************************************************/
1619 bool MothurOut::mothurConvert(string item, double& num){
1623 if (isNumeric1(item)) {
1628 mothurOut("[ERROR]: cannot convert " + item + " to a double."); mothurOutEndLine();
1629 commandInputsConvertError = true;
1634 catch(exception& e) {
1635 errorOut(e, "MothurOut", "mothurConvert");
1639 /**************************************************************************************************/
1641 vector<vector<double> > MothurOut::binomial(int maxOrder){
1643 vector<vector<double> > binomial(maxOrder+1);
1645 for(int i=0;i<=maxOrder;i++){
1646 binomial[i].resize(maxOrder+1);
1655 for(int i=2;i<=maxOrder;i++){
1659 for(int i=2;i<=maxOrder;i++){
1660 for(int j=1;j<=maxOrder;j++){
1661 if(i==j){ binomial[i][j]=1; }
1662 if(j>i) { binomial[i][j]=0; }
1663 else { binomial[i][j]=binomial[i-1][j-1]+binomial[i-1][j]; }
1670 catch(exception& e) {
1671 errorOut(e, "MothurOut", "binomial");
1675 /**************************************************************************************************/
1676 unsigned int MothurOut::fromBase36(string base36){
1678 unsigned int num = 0;
1680 map<char, int> converts;
1745 while (i < base36.length()) {
1747 num = 36 * num + converts[c];
1754 catch(exception& e) {
1755 errorOut(e, "MothurOut", "fromBase36");
1759 /***********************************************************************/
1761 int MothurOut::factorial(int num){
1765 for (int i = 1; i <= num; i++) {
1771 catch(exception& e) {
1772 errorOut(e, "MothurOut", "factorial");
1776 /***********************************************************************/
1778 int MothurOut::getNumSeqs(ifstream& file){
1780 int numSeqs = count(istreambuf_iterator<char>(file),istreambuf_iterator<char>(), '>');
1784 catch(exception& e) {
1785 errorOut(e, "MothurOut", "getNumSeqs");
1789 /***********************************************************************/
1790 void MothurOut::getNumSeqs(ifstream& file, int& numSeqs){
1795 input = getline(file);
1796 if (input.length() != 0) {
1797 if(input[0] == '>'){ numSeqs++; }
1801 catch(exception& e) {
1802 errorOut(e, "MothurOut", "getNumSeqs");
1806 /***********************************************************************/
1808 //This function parses the estimator options and puts them in a vector
1809 void MothurOut::splitAtChar(string& estim, vector<string>& container, char symbol) {
1811 string individual = "";
1812 int estimLength = estim.size();
1813 for(int i=0;i<estimLength;i++){
1814 if(estim[i] == symbol){
1815 container.push_back(individual);
1819 individual += estim[i];
1822 container.push_back(individual);
1825 catch(exception& e) {
1826 errorOut(e, "MothurOut", "splitAtChar");
1831 /***********************************************************************/
1833 //This function parses the estimator options and puts them in a vector
1834 void MothurOut::splitAtDash(string& estim, vector<string>& container) {
1836 string individual = "";
1837 int estimLength = estim.size();
1838 for(int i=0;i<estimLength;i++){
1839 if(estim[i] == '-'){
1840 container.push_back(individual);
1844 individual += estim[i];
1847 container.push_back(individual);
1850 /* string individual;
1852 while (estim.find_first_of('-') != -1) {
1853 individual = estim.substr(0,estim.find_first_of('-'));
1854 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
1855 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
1856 container.push_back(individual);
1860 container.push_back(estim); */
1862 catch(exception& e) {
1863 errorOut(e, "MothurOut", "splitAtDash");
1868 /***********************************************************************/
1869 //This function parses the label options and puts them in a set
1870 void MothurOut::splitAtDash(string& estim, set<string>& container) {
1872 string individual = "";
1873 int estimLength = estim.size();
1874 for(int i=0;i<estimLength;i++){
1875 if(estim[i] == '-'){
1876 container.insert(individual);
1880 individual += estim[i];
1883 container.insert(individual);
1885 // string individual;
1887 // while (estim.find_first_of('-') != -1) {
1888 // individual = estim.substr(0,estim.find_first_of('-'));
1889 // if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
1890 // estim = estim.substr(estim.find_first_of('-')+1, estim.length());
1891 // container.insert(individual);
1895 // container.insert(estim);
1898 catch(exception& e) {
1899 errorOut(e, "MothurOut", "splitAtDash");
1903 /***********************************************************************/
1904 //This function parses the line options and puts them in a set
1905 void MothurOut::splitAtDash(string& estim, set<int>& container) {
1910 while (estim.find_first_of('-') != -1) {
1911 individual = estim.substr(0,estim.find_first_of('-'));
1912 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
1913 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
1914 convert(individual, lineNum); //convert the string to int
1915 container.insert(lineNum);
1919 convert(estim, lineNum); //convert the string to int
1920 container.insert(lineNum);
1922 catch(exception& e) {
1923 errorOut(e, "MothurOut", "splitAtDash");
1927 /***********************************************************************/
1928 //This function parses the a string and puts peices in a vector
1929 void MothurOut::splitAtComma(string& estim, vector<string>& container) {
1931 string individual = "";
1932 int estimLength = estim.size();
1933 for(int i=0;i<estimLength;i++){
1934 if(estim[i] == ','){
1935 container.push_back(individual);
1939 individual += estim[i];
1942 container.push_back(individual);
1947 // string individual;
1949 // while (estim.find_first_of(',') != -1) {
1950 // individual = estim.substr(0,estim.find_first_of(','));
1951 // if ((estim.find_first_of(',')+1) <= estim.length()) { //checks to make sure you don't have comma at end of string
1952 // estim = estim.substr(estim.find_first_of(',')+1, estim.length());
1953 // container.push_back(individual);
1957 // container.push_back(estim);
1959 catch(exception& e) {
1960 errorOut(e, "MothurOut", "splitAtComma");
1964 /***********************************************************************/
1966 //This function splits up the various option parameters
1967 void MothurOut::splitAtComma(string& prefix, string& suffix){
1969 prefix = suffix.substr(0,suffix.find_first_of(','));
1970 if ((suffix.find_first_of(',')+2) <= suffix.length()) { //checks to make sure you don't have comma at end of string
1971 suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length());
1973 while(suffix.at(0) == ' ')
1974 suffix = suffix.substr(1, suffix.length());
1978 catch(exception& e) {
1979 errorOut(e, "MothurOut", "splitAtComma");
1983 /***********************************************************************/
1985 //This function separates the key value from the option value i.e. dist=96_...
1986 void MothurOut::splitAtEquals(string& key, string& value){
1988 if(value.find_first_of('=') != -1){
1989 key = value.substr(0,value.find_first_of('='));
1990 if ((value.find_first_of('=')+1) <= value.length()) {
1991 value = value.substr(value.find_first_of('=')+1, value.length());
1998 catch(exception& e) {
1999 errorOut(e, "MothurOut", "splitAtEquals");
2004 /**************************************************************************************************/
2006 bool MothurOut::inUsersGroups(string groupname, vector<string> Groups) {
2008 for (int i = 0; i < Groups.size(); i++) {
2009 if (groupname == Groups[i]) { return true; }
2013 catch(exception& e) {
2014 errorOut(e, "MothurOut", "inUsersGroups");
2018 /**************************************************************************************************/
2019 //returns true if any of the strings in first vector are in second vector
2020 bool MothurOut::inUsersGroups(vector<string> groupnames, vector<string> Groups) {
2023 for (int i = 0; i < groupnames.size(); i++) {
2024 if (inUsersGroups(groupnames[i], Groups)) { return true; }
2028 catch(exception& e) {
2029 errorOut(e, "MothurOut", "inUsersGroups");
2033 /***********************************************************************/
2034 //this function determines if the user has given us labels that are smaller than the given label.
2035 //if so then it returns true so that the calling function can run the previous valid distance.
2036 //it's a "smart" distance function. It also checks for invalid labels.
2037 bool MothurOut::anyLabelsToProcess(string label, set<string>& userLabels, string errorOff) {
2040 set<string>::iterator it;
2041 vector<float> orderFloat;
2042 map<string, float> userMap; //the conversion process removes trailing 0's which we need to put back
2043 map<string, float>::iterator it2;
2045 bool smaller = false;
2047 //unique is the smallest line
2048 if (label == "unique") { return false; }
2050 if (convertTestFloat(label, labelFloat)) {
2051 convert(label, labelFloat);
2052 }else { //cant convert
2057 //go through users set and make them floats
2058 for(it = userLabels.begin(); it != userLabels.end();) {
2061 if ((*it != "unique") && (convertTestFloat(*it, temp) == true)){
2063 orderFloat.push_back(temp);
2064 userMap[*it] = temp;
2066 }else if (*it == "unique") {
2067 orderFloat.push_back(-1.0);
2068 userMap["unique"] = -1.0;
2071 if (errorOff == "") { mothurOut(*it + " is not a valid label."); mothurOutEndLine(); }
2072 userLabels.erase(it++);
2077 sort(orderFloat.begin(), orderFloat.end());
2079 /*************************************************/
2080 //is this label bigger than any of the users labels
2081 /*************************************************/
2083 //loop through order until you find a label greater than label
2084 for (int i = 0; i < orderFloat.size(); i++) {
2085 if (orderFloat[i] < labelFloat) {
2087 if (orderFloat[i] == -1) {
2088 if (errorOff == "") { mothurOut("Your file does not include the label unique."); mothurOutEndLine(); }
2089 userLabels.erase("unique");
2092 if (errorOff == "") { mothurOut("Your file does not include the label "); mothurOutEndLine(); }
2094 for (it2 = userMap.begin(); it2!= userMap.end(); it2++) {
2095 if (it2->second == orderFloat[i]) {
2097 //remove small labels
2098 userLabels.erase(s);
2102 if (errorOff == "") {mothurOut( s + ". I will use the next smallest distance. "); mothurOutEndLine(); }
2104 //since they are sorted once you find a bigger one stop looking
2111 catch(exception& e) {
2112 errorOut(e, "MothurOut", "anyLabelsToProcess");
2117 /**************************************************************************************************/
2118 bool MothurOut::checkReleaseVersion(ifstream& file, string version) {
2123 string line = getline(file);
2125 //before we added this check
2126 if (line[0] != '#') { good = false; }
2129 line = line.substr(1);
2131 vector<string> versionVector;
2132 splitAtChar(version, versionVector, '.');
2134 //check file version
2135 vector<string> linesVector;
2136 splitAtChar(line, linesVector, '.');
2138 if (versionVector.size() != linesVector.size()) { good = false; }
2140 for (int j = 0; j < versionVector.size(); j++) {
2142 convert(versionVector[j], num1);
2143 convert(linesVector[j], num2);
2145 //if mothurs version is newer than this files version, then we want to remake it
2146 if (num1 > num2) { good = false; break; }
2152 if (!good) { file.close(); }
2153 else { file.seekg(0); }
2157 catch(exception& e) {
2158 errorOut(e, "MothurOut", "checkReleaseVersion");
2162 /**************************************************************************************************/
2163 bool MothurOut::isContainingOnlyDigits(string input) {
2166 //are you a digit in ascii code
2167 for (int i = 0;i < input.length(); i++){
2168 if( input[i]>47 && input[i]<58){}
2169 else { return false; }
2174 catch(exception& e) {
2175 errorOut(e, "MothurOut", "isContainingOnlyDigits");
2179 /**************************************************************************************************/
2180 int MothurOut::removeConfidences(string& tax) {
2186 while (tax.find_first_of(';') != -1) {
2188 if (control_pressed) { return 0; }
2191 taxon = tax.substr(0,tax.find_first_of(';'));
2193 int pos = taxon.find_last_of('(');
2196 int pos2 = taxon.find_last_of(')');
2198 string confidenceScore = taxon.substr(pos+1, (pos2-(pos+1)));
2199 if (isNumeric1(confidenceScore)) {
2200 taxon = taxon.substr(0, pos); //rip off confidence
2206 tax = tax.substr(tax.find_first_of(';')+1, tax.length());
2214 catch(exception& e) {
2215 errorOut(e, "MothurOut", "removeConfidences");
2219 /**************************************************************************************************/