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 (biomfile != "") { mothurOut("biom=" + biomfile); mothurOutEndLine(); }
44 if (processors != "1") { mothurOut("processors=" + processors); mothurOutEndLine(); }
48 errorOut(e, "MothurOut", "printCurrentFiles");
52 /*********************************************************************************************/
53 bool MothurOut::hasCurrentFiles() {
55 bool hasCurrent = false;
57 if (accnosfile != "") { return true; }
58 if (columnfile != "") { return true; }
59 if (designfile != "") { return true; }
60 if (fastafile != "") { return true; }
61 if (groupfile != "") { return true; }
62 if (listfile != "") { return true; }
63 if (namefile != "") { return true; }
64 if (oligosfile != "") { return true; }
65 if (orderfile != "") { return true; }
66 if (ordergroupfile != "") { return true; }
67 if (phylipfile != "") { return true; }
68 if (qualfile != "") { return true; }
69 if (rabundfile != "") { return true; }
70 if (relabundfile != "") { return true; }
71 if (sabundfile != "") { return true; }
72 if (sfffile != "") { return true; }
73 if (sharedfile != "") { return true; }
74 if (taxonomyfile != "") { return true; }
75 if (treefile != "") { return true; }
76 if (flowfile != "") { return true; }
77 if (biomfile != "") { return true; }
78 if (processors != "1") { return true; }
84 errorOut(e, "MothurOut", "hasCurrentFiles");
89 /*********************************************************************************************/
90 void MothurOut::clearCurrentFiles() {
115 catch(exception& e) {
116 errorOut(e, "MothurOut", "clearCurrentFiles");
120 /*********************************************************************************************/
121 void MothurOut::setFileName(string filename) {
123 logFileName = filename;
127 MPI_Comm_rank(MPI_COMM_WORLD, &pid);
129 if (pid == 0) { //only one process should output to screen
132 openOutputFile(filename, out);
138 catch(exception& e) {
139 errorOut(e, "MothurOut", "setFileName");
143 /*********************************************************************************************/
144 void MothurOut::setDefaultPath(string pathname) {
147 //add / to name if needed
148 string lastChar = pathname.substr(pathname.length()-1);
149 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
150 if (lastChar != "/") { pathname += "/"; }
152 if (lastChar != "\\") { pathname += "\\"; }
155 defaultPath = pathname;
158 catch(exception& e) {
159 errorOut(e, "MothurOut", "setDefaultPath");
163 /*********************************************************************************************/
164 void MothurOut::setOutputDir(string pathname) {
166 outputDir = pathname;
168 catch(exception& e) {
169 errorOut(e, "MothurOut", "setOutputDir");
173 /*********************************************************************************************/
174 void MothurOut::closeLog() {
179 MPI_Comm_rank(MPI_COMM_WORLD, &pid);
181 if (pid == 0) { //only one process should output to screen
190 catch(exception& e) {
191 errorOut(e, "MothurOut", "closeLog");
196 /*********************************************************************************************/
197 MothurOut::~MothurOut() {
202 catch(exception& e) {
203 errorOut(e, "MothurOut", "MothurOut");
207 /*********************************************************************************************/
208 void MothurOut::mothurOut(string output) {
213 MPI_Comm_rank(MPI_COMM_WORLD, &pid);
215 if (pid == 0) { //only one process should output to screen
225 catch(exception& e) {
226 errorOut(e, "MothurOut", "MothurOut");
230 /*********************************************************************************************/
231 void MothurOut::mothurOutEndLine() {
235 MPI_Comm_rank(MPI_COMM_WORLD, &pid);
237 if (pid == 0) { //only one process should output to screen
247 catch(exception& e) {
248 errorOut(e, "MothurOut", "MothurOutEndLine");
252 /*********************************************************************************************/
253 void MothurOut::mothurOut(string output, ofstream& outputFile) {
258 MPI_Comm_rank(MPI_COMM_WORLD, &pid);
260 if (pid == 0) { //only one process should output to screen
265 outputFile << output;
273 catch(exception& e) {
274 errorOut(e, "MothurOut", "MothurOut");
278 /*********************************************************************************************/
279 void MothurOut::mothurOutEndLine(ofstream& outputFile) {
283 MPI_Comm_rank(MPI_COMM_WORLD, &pid);
285 if (pid == 0) { //only one process should output to screen
296 catch(exception& e) {
297 errorOut(e, "MothurOut", "MothurOutEndLine");
301 /*********************************************************************************************/
302 void MothurOut::mothurOutJustToLog(string output) {
306 MPI_Comm_rank(MPI_COMM_WORLD, &pid);
308 if (pid == 0) { //only one process should output to screen
317 catch(exception& e) {
318 errorOut(e, "MothurOut", "MothurOutJustToLog");
322 /*********************************************************************************************/
323 void MothurOut::errorOut(exception& e, string object, string function) {
325 //mem_usage(vm, rss);
327 mothurOut("[ERROR]: ");
328 mothurOut(toString(e.what()));
329 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.");
332 /*********************************************************************************************/
333 //The following was originally from http://stackoverflow.com/questions/669438/how-to-get-memory-usage-at-run-time-in-c
334 // process_mem_usage(double &, double &) - takes two doubles by reference,
335 // attempts to read the system-dependent data for a process' virtual memory
336 // size and resident set size, and return the results in KB.
338 // On failure, returns 0.0, 0.0
339 int MothurOut::mem_usage(double& vm_usage, double& resident_set) {
340 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
345 // 'file' stat seems to give the most reliable results
347 ifstream stat_stream("/proc/self/stat",ios_base::in);
349 // dummy vars for leading entries in stat that we don't care about
351 string pid, comm, state, ppid, pgrp, session, tty_nr;
352 string tpgid, flags, minflt, cminflt, majflt, cmajflt;
353 string utime, stime, cutime, cstime, priority, nice;
354 string O, itrealvalue, starttime;
356 // the two fields we want
361 stat_stream >> pid >> comm >> state >> ppid >> pgrp >> session >> tty_nr
362 >> tpgid >> flags >> minflt >> cminflt >> majflt >> cmajflt
363 >> utime >> stime >> cutime >> cstime >> priority >> nice
364 >> O >> itrealvalue >> starttime >> vsize >> rss; // don't care about the rest
366 long page_size_kb = sysconf(_SC_PAGE_SIZE) / 1024; // in case x86-64 is configured to use 2MB pages
367 vm_usage = vsize / 1024.0;
368 resident_set = rss * page_size_kb;
370 mothurOut("Memory Usage: vm = " + toString(vm_usage) + " rss = " + toString(resident_set) + "\n");
374 /* //windows memory usage
375 // Get the list of process identifiers.
376 DWORD aProcesses[1024], cbNeeded, cProcesses;
378 if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ){ return 1; }
380 // Calculate how many process identifiers were returned.
381 cProcesses = cbNeeded / sizeof(DWORD);
383 // Print the memory usage for each process
384 for (int i = 0; i < cProcesses; i++ ) {
385 DWORD processID = aProcesses[i];
387 PROCESS_MEMORY_COUNTERS pmc;
389 HANDLE hProcess = OpenProcess((PROCESS_QUERY_INFORMATION | PROCESS_VM_READ), FALSE, processID);
391 // Print the process identifier.
392 printf( "\nProcess ID: %u\n", processID);
394 if (NULL != hProcess) {
396 if ( GetProcessMemoryInfo( hProcess, &pmc, sizeof(pmc)) ) {
397 printf( "\tPageFaultCount: 0x%08X\n", pmc.PageFaultCount );
398 printf( "\tPeakWorkingSetSize: 0x%08X\n", pmc.PeakWorkingSetSize );
399 printf( "\tWorkingSetSize: 0x%08X\n", pmc.WorkingSetSize );
400 printf( "\tQuotaPeakPagedPoolUsage: 0x%08X\n", pmc.QuotaPeakPagedPoolUsage );
401 printf( "\tQuotaPagedPoolUsage: 0x%08X\n", pmc.QuotaPagedPoolUsage );
402 printf( "\tQuotaPeakNonPagedPoolUsage: 0x%08X\n", pmc.QuotaPeakNonPagedPoolUsage );
403 printf( "\tQuotaNonPagedPoolUsage: 0x%08X\n", pmc.QuotaNonPagedPoolUsage );
404 printf( "\tPagefileUsage: 0x%08X\n", pmc.PagefileUsage );
405 printf( "\tPeakPagefileUsage: 0x%08X\n", pmc.PeakPagefileUsage );
407 CloseHandle(hProcess);
417 /***********************************************************************/
418 int MothurOut::openOutputFileAppend(string fileName, ofstream& fileHandle){
420 fileName = getFullPathName(fileName);
422 fileHandle.open(fileName.c_str(), ios::app);
424 mothurOut("[ERROR]: Could not open " + fileName); mothurOutEndLine();
431 catch(exception& e) {
432 errorOut(e, "MothurOut", "openOutputFileAppend");
436 /***********************************************************************/
437 void MothurOut::gobble(istream& f){
441 while(isspace(d=f.get())) { ;}
442 if(!f.eof()) { f.putback(d); }
444 catch(exception& e) {
445 errorOut(e, "MothurOut", "gobble");
449 /***********************************************************************/
450 void MothurOut::gobble(istringstream& f){
453 while(isspace(d=f.get())) {;}
454 if(!f.eof()) { f.putback(d); }
456 catch(exception& e) {
457 errorOut(e, "MothurOut", "gobble");
462 /***********************************************************************/
464 string MothurOut::getline(istringstream& fileHandle) {
469 while (!fileHandle.eof()) {
471 char c = fileHandle.get();
473 //are you at the end of the line
474 if ((c == '\n') || (c == '\r') || (c == '\f')){ break; }
481 catch(exception& e) {
482 errorOut(e, "MothurOut", "getline");
486 /***********************************************************************/
488 string MothurOut::getline(ifstream& fileHandle) {
495 char c = fileHandle.get();
497 //are you at the end of the line
498 if ((c == '\n') || (c == '\r') || (c == '\f') || (c == EOF)){ break; }
505 catch(exception& e) {
506 errorOut(e, "MothurOut", "getline");
510 /***********************************************************************/
512 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
513 #ifdef USE_COMPRESSION
514 inline bool endsWith(string s, const char * suffix){
515 size_t suffixLength = strlen(suffix);
516 return s.size() >= suffixLength && s.substr(s.size() - suffixLength, suffixLength).compare(suffix) == 0;
521 string MothurOut::getRootName(string longName){
524 string rootName = longName;
526 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
527 #ifdef USE_COMPRESSION
528 if (endsWith(rootName, ".gz") || endsWith(rootName, ".bz2")) {
529 int pos = rootName.find_last_of('.');
530 rootName = rootName.substr(0, pos);
531 cerr << "shortening " << longName << " to " << rootName << "\n";
535 if(rootName.find_last_of(".") != rootName.npos){
536 int pos = rootName.find_last_of('.')+1;
537 rootName = rootName.substr(0, pos);
542 catch(exception& e) {
543 errorOut(e, "MothurOut", "getRootName");
547 /***********************************************************************/
549 string MothurOut::getSimpleName(string longName){
551 string simpleName = longName;
554 found=longName.find_last_of("/\\");
556 if(found != longName.npos){
557 simpleName = longName.substr(found+1);
562 catch(exception& e) {
563 errorOut(e, "MothurOut", "getSimpleName");
568 /***********************************************************************/
570 int MothurOut::getRandomIndex(int highest){
573 int random = (int) ((float)(highest+1) * (float)(rand()) / ((float)RAND_MAX+1.0));
577 catch(exception& e) {
578 errorOut(e, "MothurOut", "getRandomIndex");
583 /**********************************************************************/
585 string MothurOut::getPathName(string longName){
587 string rootPathName = longName;
589 if(longName.find_last_of("/\\") != longName.npos){
590 int pos = longName.find_last_of("/\\")+1;
591 rootPathName = longName.substr(0, pos);
596 catch(exception& e) {
597 errorOut(e, "MothurOut", "getPathName");
602 /***********************************************************************/
604 bool MothurOut::dirCheck(string& dirName){
610 MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
615 //add / to name if needed
616 string lastChar = dirName.substr(dirName.length()-1);
617 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
618 if (lastChar != "/") { dirName += "/"; }
620 if (lastChar != "\\") { dirName += "\\"; }
623 //test to make sure directory exists
624 dirName = getFullPathName(dirName);
625 string outTemp = dirName + tag + "temp";
627 out.open(outTemp.c_str(), ios::trunc);
629 mothurOut(dirName + " directory does not exist or is not writable."); mothurOutEndLine();
632 mothurRemove(outTemp);
638 catch(exception& e) {
639 errorOut(e, "MothurOut", "dirCheck");
644 /***********************************************************************/
646 string MothurOut::hasPath(string longName){
651 found=longName.find_last_of("~/\\");
653 if(found != longName.npos){
654 path = longName.substr(0, found+1);
659 catch(exception& e) {
660 errorOut(e, "MothurOut", "hasPath");
665 /***********************************************************************/
667 string MothurOut::getExtension(string longName){
669 string extension = "";
671 if(longName.find_last_of('.') != longName.npos){
672 int pos = longName.find_last_of('.');
673 extension = longName.substr(pos, longName.length());
678 catch(exception& e) {
679 errorOut(e, "MothurOut", "getExtension");
683 /***********************************************************************/
684 bool MothurOut::isBlank(string fileName){
687 fileName = getFullPathName(fileName);
690 fileHandle.open(fileName.c_str());
692 mothurOut("[ERROR]: Could not open " + fileName); mothurOutEndLine();
695 //check for blank file
697 if (fileHandle.eof()) { fileHandle.close(); return true; }
702 catch(exception& e) {
703 errorOut(e, "MothurOut", "isBlank");
707 /***********************************************************************/
709 string MothurOut::getFullPathName(string fileName){
712 string path = hasPath(fileName);
716 if (path == "") { return fileName; } //its a simple name
717 else { //we need to complete the pathname
718 // ex. ../../../filename
719 // cwd = /user/work/desktop
722 //get current working directory
723 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
725 if (path.find("~") != -1) { //go to home directory
728 char *homepath = NULL;
729 homepath = getenv ("HOME");
730 if ( homepath != NULL) { homeDir = homepath; }
731 else { homeDir = ""; }
733 newFileName = homeDir + fileName.substr(fileName.find("~")+1);
736 if (path.rfind("./") == string::npos) { return fileName; } //already complete name
737 else { newFileName = fileName.substr(fileName.rfind("./")+2); } //save the complete part of the name
739 //char* cwdpath = new char[1024];
741 //cwdpath=getcwd(cwdpath,size);
744 char *cwdpath = NULL;
745 cwdpath = getcwd(NULL, 0); // or _getcwd
746 if ( cwdpath != NULL) { cwd = cwdpath; }
752 if (cwd.length() > 0) { simpleCWD = cwd.substr(1); }
754 //break apart the current working directory
756 while (simpleCWD.find_first_of('/') != string::npos) {
757 string dir = simpleCWD.substr(0,simpleCWD.find_first_of('/'));
758 simpleCWD = simpleCWD.substr(simpleCWD.find_first_of('/')+1, simpleCWD.length());
761 //get last one // ex. ../../../filename = /user/work/desktop/filename
762 dirs.push_back(simpleCWD); //ex. dirs[0] = user, dirs[1] = work, dirs[2] = desktop
765 int index = dirs.size()-1;
767 while((pos = path.rfind("./")) != string::npos) { //while you don't have a complete path
768 if (pos == 0) { break; //you are at the end
769 }else if (path[(pos-1)] == '.') { //you want your parent directory ../
770 path = path.substr(0, pos-1);
772 if (index == 0) { break; }
773 }else if (path[(pos-1)] == '/') { //you want the current working dir ./
774 path = path.substr(0, pos);
775 }else if (pos == 1) { break; //you are at the end
776 }else { mothurOut("cannot resolve path for " + fileName + "\n"); return fileName; }
779 for (int i = index; i >= 0; i--) {
780 newFileName = dirs[i] + "/" + newFileName;
783 newFileName = "/" + newFileName;
787 if (path.find("~") != string::npos) { //go to home directory
788 string homeDir = getenv ("HOMEPATH");
789 newFileName = homeDir + fileName.substr(fileName.find("~")+1);
792 if (path.rfind(".\\") == string::npos) { return fileName; } //already complete name
793 else { newFileName = fileName.substr(fileName.rfind(".\\")+2); } //save the complete part of the name
795 char *cwdpath = NULL;
796 cwdpath = getcwd(NULL, 0); // or _getcwd
797 if ( cwdpath != NULL) { cwd = cwdpath; }
800 //break apart the current working directory
802 while (cwd.find_first_of('\\') != -1) {
803 string dir = cwd.substr(0,cwd.find_first_of('\\'));
804 cwd = cwd.substr(cwd.find_first_of('\\')+1, cwd.length());
809 dirs.push_back(cwd); //ex. dirs[0] = user, dirs[1] = work, dirs[2] = desktop
811 int index = dirs.size()-1;
813 while((pos = path.rfind(".\\")) != string::npos) { //while you don't have a complete path
814 if (pos == 0) { break; //you are at the end
815 }else if (path[(pos-1)] == '.') { //you want your parent directory ../
816 path = path.substr(0, pos-1);
818 if (index == 0) { break; }
819 }else if (path[(pos-1)] == '\\') { //you want the current working dir ./
820 path = path.substr(0, pos);
821 }else if (pos == 1) { break; //you are at the end
822 }else { mothurOut("cannot resolve path for " + fileName + "\n"); return fileName; }
825 for (int i = index; i >= 0; i--) {
826 newFileName = dirs[i] + "\\" + newFileName;
835 catch(exception& e) {
836 errorOut(e, "MothurOut", "getFullPathName");
840 /***********************************************************************/
842 int MothurOut::openInputFile(string fileName, ifstream& fileHandle, string m){
845 string completeFileName = getFullPathName(fileName);
846 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
847 #ifdef USE_COMPRESSION
848 // check for gzipped or bzipped file
849 if (endsWith(completeFileName, ".gz") || endsWith(completeFileName, ".bz2")) {
850 string tempName = string(tmpnam(0));
851 mkfifo(tempName.c_str(), 0666);
852 int fork_result = fork();
853 if (fork_result < 0) {
854 cerr << "Error forking.\n";
856 } else if (fork_result == 0) {
857 string command = (endsWith(completeFileName, ".gz") ? "zcat " : "bzcat ") + completeFileName + string(" > ") + tempName;
858 cerr << "Decompressing " << completeFileName << " via temporary named pipe " << tempName << "\n";
859 system(command.c_str());
860 cerr << "Done decompressing " << completeFileName << "\n";
861 mothurRemove(tempName);
864 cerr << "waiting on child process " << fork_result << "\n";
865 completeFileName = tempName;
870 fileHandle.open(completeFileName.c_str());
872 //mothurOut("[ERROR]: Could not open " + completeFileName); mothurOutEndLine();
875 //check for blank file
880 catch(exception& e) {
881 errorOut(e, "MothurOut", "openInputFile - no Error");
885 /***********************************************************************/
887 int MothurOut::openInputFile(string fileName, ifstream& fileHandle){
891 string completeFileName = getFullPathName(fileName);
892 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
893 #ifdef USE_COMPRESSION
894 // check for gzipped or bzipped file
895 if (endsWith(completeFileName, ".gz") || endsWith(completeFileName, ".bz2")) {
896 string tempName = string(tmpnam(0));
897 mkfifo(tempName.c_str(), 0666);
898 int fork_result = fork();
899 if (fork_result < 0) {
900 cerr << "Error forking.\n";
902 } else if (fork_result == 0) {
903 string command = (endsWith(completeFileName, ".gz") ? "zcat " : "bzcat ") + completeFileName + string(" > ") + tempName;
904 cerr << "Decompressing " << completeFileName << " via temporary named pipe " << tempName << "\n";
905 system(command.c_str());
906 cerr << "Done decompressing " << completeFileName << "\n";
907 mothurRemove(tempName);
910 cerr << "waiting on child process " << fork_result << "\n";
911 completeFileName = tempName;
917 fileHandle.open(completeFileName.c_str());
919 mothurOut("[ERROR]: Could not open " + completeFileName); mothurOutEndLine();
923 //check for blank file
925 if (fileHandle.eof()) { mothurOut("[ERROR]: " + completeFileName + " is blank. Please correct."); mothurOutEndLine(); }
930 catch(exception& e) {
931 errorOut(e, "MothurOut", "openInputFile");
935 /***********************************************************************/
937 int MothurOut::renameFile(string oldName, string newName){
940 int exist = openInputFile(newName, inTest, "");
943 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
944 if (exist == 0) { //you could open it so you want to delete it
945 string command = "rm " + newName;
946 system(command.c_str());
949 string command = "mv " + oldName + " " + newName;
950 system(command.c_str());
952 mothurRemove(newName);
953 int renameOk = rename(oldName.c_str(), newName.c_str());
958 catch(exception& e) {
959 errorOut(e, "MothurOut", "renameFile");
964 /***********************************************************************/
966 int MothurOut::openOutputFile(string fileName, ofstream& fileHandle){
969 string completeFileName = getFullPathName(fileName);
970 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
971 #ifdef USE_COMPRESSION
972 // check for gzipped file
973 if (endsWith(completeFileName, ".gz") || endsWith(completeFileName, ".bz2")) {
974 string tempName = string(tmpnam(0));
975 mkfifo(tempName.c_str(), 0666);
976 cerr << "Compressing " << completeFileName << " via temporary named pipe " << tempName << "\n";
977 int fork_result = fork();
978 if (fork_result < 0) {
979 cerr << "Error forking.\n";
981 } else if (fork_result == 0) {
982 string command = string(endsWith(completeFileName, ".gz") ? "gzip" : "bzip2") + " -v > " + completeFileName + string(" < ") + tempName;
983 system(command.c_str());
986 completeFileName = tempName;
991 fileHandle.open(completeFileName.c_str(), ios::trunc);
993 mothurOut("[ERROR]: Could not open " + completeFileName); mothurOutEndLine();
1000 catch(exception& e) {
1001 errorOut(e, "MothurOut", "openOutputFile");
1007 /**************************************************************************************************/
1008 int MothurOut::appendFiles(string temp, string filename) {
1013 //open output file in append mode
1014 openOutputFileAppend(filename, output);
1015 int ableToOpen = openInputFile(temp, input, "no error");
1016 //int ableToOpen = openInputFile(temp, input);
1019 if (ableToOpen == 0) { //you opened it
1020 while(!input.eof()){
1021 char c = input.get();
1022 if(input.eof()) { break; }
1023 else { output << c; if (c == '\n') {numLines++;} }
1032 catch(exception& e) {
1033 errorOut(e, "MothurOut", "appendFiles");
1038 /**************************************************************************************************/
1039 string MothurOut::sortFile(string distFile, string outputDir){
1042 //if (outputDir == "") { outputDir += hasPath(distFile); }
1043 string outfile = getRootName(distFile) + "sorted.dist";
1046 //if you can, use the unix sort since its been optimized for years
1047 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
1048 string command = "sort -n -k +3 " + distFile + " -o " + outfile;
1049 system(command.c_str());
1050 #else //you are stuck with my best attempt...
1051 //windows sort does not have a way to specify a column, only a character in the line
1052 //since we cannot assume that the distance will always be at the the same character location on each line
1053 //due to variable sequence name lengths, I chose to force the distance into first position, then sort and then put it back.
1055 //read in file line by file and put distance first
1056 string tempDistFile = distFile + ".temp";
1059 openInputFile(distFile, input);
1060 openOutputFile(tempDistFile, output);
1062 string firstName, secondName;
1065 input >> firstName >> secondName >> dist;
1066 output << dist << '\t' << firstName << '\t' << secondName << endl;
1073 //sort using windows sort
1074 string tempOutfile = outfile + ".temp";
1075 string command = "sort " + tempDistFile + " /O " + tempOutfile;
1076 system(command.c_str());
1078 //read in sorted file and put distance at end again
1080 openInputFile(tempOutfile, input2);
1081 openOutputFile(outfile, output);
1084 input2 >> dist >> firstName >> secondName;
1085 output << firstName << '\t' << secondName << '\t' << dist << endl;
1092 mothurRemove(tempDistFile);
1093 mothurRemove(tempOutfile);
1098 catch(exception& e) {
1099 errorOut(e, "MothurOut", "sortFile");
1103 /**************************************************************************************************/
1104 vector<unsigned long long> MothurOut::setFilePosFasta(string filename, int& num) {
1106 vector<unsigned long long> positions;
1108 //openInputFile(filename, inFASTA);
1109 inFASTA.open(filename.c_str(), ios::binary);
1112 unsigned long long count = 0;
1113 while(!inFASTA.eof()){
1114 //input = getline(inFASTA);
1115 //cout << input << '\t' << inFASTA.tellg() << endl;
1116 //if (input.length() != 0) {
1117 // if(input[0] == '>'){ unsigned long int pos = inFASTA.tellg(); positions.push_back(pos - input.length() - 1); cout << (pos - input.length() - 1) << endl; }
1119 //gobble(inFASTA); //has to be here since windows line endings are 2 characters and mess up the positions
1120 char c = inFASTA.get(); count++;
1122 positions.push_back(count-1);
1123 //cout << count << endl;
1128 num = positions.size();
1133 //get num bytes in file
1134 pFile = fopen (filename.c_str(),"rb");
1135 if (pFile==NULL) perror ("Error opening file");
1137 fseek (pFile, 0, SEEK_END);
1142 unsigned long long size = positions[(positions.size()-1)];
1144 openInputFile(filename, in);
1149 if(in.eof()) { break; }
1154 positions.push_back(size);
1159 catch(exception& e) {
1160 errorOut(e, "MothurOut", "setFilePosFasta");
1164 /**************************************************************************************************/
1165 vector<unsigned long long> MothurOut::setFilePosEachLine(string filename, int& num) {
1167 filename = getFullPathName(filename);
1169 vector<unsigned long long> positions;
1171 //openInputFile(filename, in);
1172 in.open(filename.c_str(), ios::binary);
1175 unsigned long long count = 0;
1176 positions.push_back(0);
1179 //unsigned long long lastpos = in.tellg();
1180 //input = getline(in);
1181 //if (input.length() != 0) {
1182 //unsigned long long pos = in.tellg();
1183 //if (pos != -1) { positions.push_back(pos - input.length() - 1); }
1184 //else { positions.push_back(lastpos); }
1186 //gobble(in); //has to be here since windows line endings are 2 characters and mess up the positions
1189 //getline counting reads
1190 char d = in.get(); count++;
1191 while ((d != '\n') && (d != '\r') && (d != '\f') && (d != in.eof())) {
1192 //get next character
1198 d=in.get(); count++;
1199 while(isspace(d) && (d != in.eof())) { d=in.get(); count++;}
1201 positions.push_back(count-1);
1202 //cout << count-1 << endl;
1206 num = positions.size()-1;
1209 unsigned long long size;
1211 //get num bytes in file
1212 pFile = fopen (filename.c_str(),"rb");
1213 if (pFile==NULL) perror ("Error opening file");
1215 fseek (pFile, 0, SEEK_END);
1220 positions[(positions.size()-1)] = size;
1224 catch(exception& e) {
1225 errorOut(e, "MothurOut", "setFilePosEachLine");
1229 /**************************************************************************************************/
1231 vector<unsigned long long> MothurOut::divideFile(string filename, int& proc) {
1233 vector<unsigned long long> filePos;
1234 filePos.push_back(0);
1237 unsigned long long size;
1239 filename = getFullPathName(filename);
1241 //get num bytes in file
1242 pFile = fopen (filename.c_str(),"rb");
1243 if (pFile==NULL) perror ("Error opening file");
1245 fseek (pFile, 0, SEEK_END);
1250 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
1252 //estimate file breaks
1253 unsigned long long chunkSize = 0;
1254 chunkSize = size / proc;
1256 //file to small to divide by processors
1257 if (chunkSize == 0) { proc = 1; filePos.push_back(size); return filePos; }
1259 //for each process seekg to closest file break and search for next '>' char. make that the filebreak
1260 for (int i = 0; i < proc; i++) {
1261 unsigned long long spot = (i+1) * chunkSize;
1264 openInputFile(filename, in);
1268 unsigned long long newSpot = spot;
1272 if (c == '>') { in.putback(c); newSpot = in.tellg(); break; }
1273 else if (int(c) == -1) { break; }
1277 //there was not another sequence before the end of the file
1278 unsigned long long sanityPos = in.tellg();
1280 if (sanityPos == -1) { break; }
1281 else { filePos.push_back(newSpot); }
1287 filePos.push_back(size);
1289 //sanity check filePos
1290 for (int i = 0; i < (filePos.size()-1); i++) {
1291 if (filePos[(i+1)] <= filePos[i]) { filePos.erase(filePos.begin()+(i+1)); i--; }
1294 proc = (filePos.size() - 1);
1296 mothurOut("[ERROR]: Windows version should not be calling the divideFile function."); mothurOutEndLine();
1298 filePos.push_back(size);
1302 catch(exception& e) {
1303 errorOut(e, "MothurOut", "divideFile");
1307 /**************************************************************************************************/
1308 int MothurOut::divideFile(string filename, int& proc, vector<string>& files) {
1311 vector<unsigned long long> filePos = divideFile(filename, proc);
1313 for (int i = 0; i < (filePos.size()-1); i++) {
1317 openInputFile(filename, in);
1318 in.seekg(filePos[i]);
1319 unsigned long long size = filePos[(i+1)] - filePos[i];
1320 char* chunk = new char[size];
1321 in.read(chunk, size);
1325 string fileChunkName = filename + "." + toString(i) + ".tmp";
1327 openOutputFile(fileChunkName, out);
1329 out << chunk << endl;
1334 files.push_back(fileChunkName);
1339 catch(exception& e) {
1340 errorOut(e, "MothurOut", "divideFile");
1344 /***********************************************************************/
1346 bool MothurOut::isTrue(string f){
1349 for (int i = 0; i < f.length(); i++) { f[i] = toupper(f[i]); }
1351 if ((f == "TRUE") || (f == "T")) { return true; }
1352 else { return false; }
1354 catch(exception& e) {
1355 errorOut(e, "MothurOut", "isTrue");
1360 /***********************************************************************/
1362 float MothurOut::roundDist(float dist, int precision){
1364 return int(dist * precision + 0.5)/float(precision);
1366 catch(exception& e) {
1367 errorOut(e, "MothurOut", "roundDist");
1371 /***********************************************************************/
1373 float MothurOut::ceilDist(float dist, int precision){
1375 return int(ceil(dist * precision))/float(precision);
1377 catch(exception& e) {
1378 errorOut(e, "MothurOut", "ceilDist");
1382 /**********************************************************************************************************************/
1383 int MothurOut::readNames(string namefile, map<string, string>& nameMap) {
1388 openInputFile(namefile, in);
1391 if (control_pressed) { break; }
1393 string firstCol, secondCol;
1394 in >> firstCol >> secondCol; gobble(in);
1396 nameMap[firstCol] = secondCol;
1400 return nameMap.size();
1403 catch(exception& e) {
1404 errorOut(e, "MothurOut", "readNames");
1408 /**********************************************************************************************************************/
1409 int MothurOut::readNames(string namefile, map<string, vector<string> >& nameMap) {
1414 openInputFile(namefile, in);
1417 if (control_pressed) { break; }
1419 string firstCol, secondCol;
1420 in >> firstCol >> secondCol; gobble(in);
1422 vector<string> temp;
1423 splitAtComma(secondCol, temp);
1425 nameMap[firstCol] = temp;
1429 return nameMap.size();
1432 catch(exception& e) {
1433 errorOut(e, "MothurOut", "readNames");
1437 /**********************************************************************************************************************/
1438 map<string, int> MothurOut::readNames(string namefile) {
1441 map<string, int> nameMap;
1445 openInputFile(namefile, in);
1448 if (control_pressed) { break; }
1450 string firstCol, secondCol;
1451 in >> firstCol; gobble(in);
1452 in >> secondCol; gobble(in);
1454 int num = getNumNames(secondCol);
1456 nameMap[firstCol] = num;
1463 catch(exception& e) {
1464 errorOut(e, "MothurOut", "readNames");
1468 /**********************************************************************************************************************/
1469 int MothurOut::readNames(string namefile, vector<seqPriorityNode>& nameVector, map<string, string>& fastamap) {
1475 openInputFile(namefile, in);
1478 if (control_pressed) { break; }
1480 string firstCol, secondCol;
1481 in >> firstCol >> secondCol; gobble(in);
1483 int num = getNumNames(secondCol);
1485 map<string, string>::iterator it = fastamap.find(firstCol);
1486 if (it == fastamap.end()) {
1488 mothurOut("[ERROR]: " + firstCol + " is not in your fastafile, but is in your namesfile, please correct."); mothurOutEndLine();
1490 seqPriorityNode temp(num, it->second, firstCol);
1491 nameVector.push_back(temp);
1499 catch(exception& e) {
1500 errorOut(e, "MothurOut", "readNames");
1505 /***********************************************************************/
1507 int MothurOut::getNumNames(string names){
1513 for(int i=0;i<names.size();i++){
1514 if(names[i] == ','){
1522 catch(exception& e) {
1523 errorOut(e, "MothurOut", "getNumNames");
1527 /***********************************************************************/
1529 int MothurOut::getNumChar(string line, char c){
1534 for(int i=0;i<line.size();i++){
1543 catch(exception& e) {
1544 errorOut(e, "MothurOut", "getNumChar");
1548 /***********************************************************************/
1549 int MothurOut::mothurRemove(string filename){
1551 filename = getFullPathName(filename);
1552 int error = remove(filename.c_str());
1554 // if (errno != ENOENT) { //ENOENT == file does not exist
1555 // string message = "Error deleting file " + filename;
1556 // perror(message.c_str());
1561 catch(exception& e) {
1562 errorOut(e, "MothurOut", "mothurRemove");
1566 /***********************************************************************/
1567 bool MothurOut::mothurConvert(string item, int& num){
1571 if (isNumeric1(item)) {
1576 mothurOut("[ERROR]: cannot convert " + item + " to an integer."); mothurOutEndLine();
1577 commandInputsConvertError = true;
1582 catch(exception& e) {
1583 errorOut(e, "MothurOut", "mothurConvert");
1587 /***********************************************************************/
1588 bool MothurOut::isNumeric1(string stringToCheck){
1590 bool numeric = false;
1592 if(stringToCheck.find_first_not_of("0123456789.-") == string::npos) { numeric = true; }
1596 catch(exception& e) {
1597 errorOut(e, "MothurOut", "isNumeric1");
1602 /***********************************************************************/
1603 bool MothurOut::mothurConvert(string item, float& num){
1607 if (isNumeric1(item)) {
1612 mothurOut("[ERROR]: cannot convert " + item + " to a float."); mothurOutEndLine();
1613 commandInputsConvertError = true;
1618 catch(exception& e) {
1619 errorOut(e, "MothurOut", "mothurConvert");
1623 /***********************************************************************/
1624 bool MothurOut::mothurConvert(string item, double& num){
1628 if (isNumeric1(item)) {
1633 mothurOut("[ERROR]: cannot convert " + item + " to a double."); mothurOutEndLine();
1634 commandInputsConvertError = true;
1639 catch(exception& e) {
1640 errorOut(e, "MothurOut", "mothurConvert");
1644 /**************************************************************************************************/
1646 vector<vector<double> > MothurOut::binomial(int maxOrder){
1648 vector<vector<double> > binomial(maxOrder+1);
1650 for(int i=0;i<=maxOrder;i++){
1651 binomial[i].resize(maxOrder+1);
1660 for(int i=2;i<=maxOrder;i++){
1664 for(int i=2;i<=maxOrder;i++){
1665 for(int j=1;j<=maxOrder;j++){
1666 if(i==j){ binomial[i][j]=1; }
1667 if(j>i) { binomial[i][j]=0; }
1668 else { binomial[i][j]=binomial[i-1][j-1]+binomial[i-1][j]; }
1675 catch(exception& e) {
1676 errorOut(e, "MothurOut", "binomial");
1680 /**************************************************************************************************/
1681 unsigned int MothurOut::fromBase36(string base36){
1683 unsigned int num = 0;
1685 map<char, int> converts;
1750 while (i < base36.length()) {
1752 num = 36 * num + converts[c];
1759 catch(exception& e) {
1760 errorOut(e, "MothurOut", "fromBase36");
1764 /***********************************************************************/
1766 int MothurOut::factorial(int num){
1770 for (int i = 1; i <= num; i++) {
1776 catch(exception& e) {
1777 errorOut(e, "MothurOut", "factorial");
1781 /***********************************************************************/
1783 int MothurOut::getNumSeqs(ifstream& file){
1785 int numSeqs = count(istreambuf_iterator<char>(file),istreambuf_iterator<char>(), '>');
1789 catch(exception& e) {
1790 errorOut(e, "MothurOut", "getNumSeqs");
1794 /***********************************************************************/
1795 void MothurOut::getNumSeqs(ifstream& file, int& numSeqs){
1800 input = getline(file);
1801 if (input.length() != 0) {
1802 if(input[0] == '>'){ numSeqs++; }
1806 catch(exception& e) {
1807 errorOut(e, "MothurOut", "getNumSeqs");
1811 /***********************************************************************/
1813 //This function parses the estimator options and puts them in a vector
1814 void MothurOut::splitAtChar(string& estim, vector<string>& container, char symbol) {
1816 string individual = "";
1817 int estimLength = estim.size();
1818 for(int i=0;i<estimLength;i++){
1819 if(estim[i] == symbol){
1820 container.push_back(individual);
1824 individual += estim[i];
1827 container.push_back(individual);
1830 catch(exception& e) {
1831 errorOut(e, "MothurOut", "splitAtChar");
1836 /***********************************************************************/
1838 //This function parses the estimator options and puts them in a vector
1839 void MothurOut::splitAtDash(string& estim, vector<string>& container) {
1841 string individual = "";
1842 int estimLength = estim.size();
1843 for(int i=0;i<estimLength;i++){
1844 if(estim[i] == '-'){
1845 container.push_back(individual);
1849 individual += estim[i];
1852 container.push_back(individual);
1855 /* string individual;
1857 while (estim.find_first_of('-') != -1) {
1858 individual = estim.substr(0,estim.find_first_of('-'));
1859 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
1860 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
1861 container.push_back(individual);
1865 container.push_back(estim); */
1867 catch(exception& e) {
1868 errorOut(e, "MothurOut", "splitAtDash");
1873 /***********************************************************************/
1874 //This function parses the label options and puts them in a set
1875 void MothurOut::splitAtDash(string& estim, set<string>& container) {
1877 string individual = "";
1878 int estimLength = estim.size();
1879 for(int i=0;i<estimLength;i++){
1880 if(estim[i] == '-'){
1881 container.insert(individual);
1885 individual += estim[i];
1888 container.insert(individual);
1890 // string individual;
1892 // while (estim.find_first_of('-') != -1) {
1893 // individual = estim.substr(0,estim.find_first_of('-'));
1894 // if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
1895 // estim = estim.substr(estim.find_first_of('-')+1, estim.length());
1896 // container.insert(individual);
1900 // container.insert(estim);
1903 catch(exception& e) {
1904 errorOut(e, "MothurOut", "splitAtDash");
1908 /***********************************************************************/
1909 //This function parses the line options and puts them in a set
1910 void MothurOut::splitAtDash(string& estim, set<int>& container) {
1915 while (estim.find_first_of('-') != -1) {
1916 individual = estim.substr(0,estim.find_first_of('-'));
1917 if ((estim.find_first_of('-')+1) <= estim.length()) { //checks to make sure you don't have dash at end of string
1918 estim = estim.substr(estim.find_first_of('-')+1, estim.length());
1919 convert(individual, lineNum); //convert the string to int
1920 container.insert(lineNum);
1924 convert(estim, lineNum); //convert the string to int
1925 container.insert(lineNum);
1927 catch(exception& e) {
1928 errorOut(e, "MothurOut", "splitAtDash");
1932 /***********************************************************************/
1933 //This function parses the a string and puts peices in a vector
1934 void MothurOut::splitAtComma(string& estim, vector<string>& container) {
1936 string individual = "";
1937 int estimLength = estim.size();
1938 for(int i=0;i<estimLength;i++){
1939 if(estim[i] == ','){
1940 container.push_back(individual);
1944 individual += estim[i];
1947 container.push_back(individual);
1952 // string individual;
1954 // while (estim.find_first_of(',') != -1) {
1955 // individual = estim.substr(0,estim.find_first_of(','));
1956 // if ((estim.find_first_of(',')+1) <= estim.length()) { //checks to make sure you don't have comma at end of string
1957 // estim = estim.substr(estim.find_first_of(',')+1, estim.length());
1958 // container.push_back(individual);
1962 // container.push_back(estim);
1964 catch(exception& e) {
1965 errorOut(e, "MothurOut", "splitAtComma");
1969 /***********************************************************************/
1970 //This function splits up the various option parameters
1971 void MothurOut::splitAtChar(string& prefix, string& suffix, char c){
1973 prefix = suffix.substr(0,suffix.find_first_of(c));
1974 if ((suffix.find_first_of(c)+2) <= suffix.length()) { //checks to make sure you don't have comma at end of string
1975 suffix = suffix.substr(suffix.find_first_of(c)+1, suffix.length());
1977 while(suffix.at(0) == ' ')
1978 suffix = suffix.substr(1, suffix.length());
1982 catch(exception& e) {
1983 errorOut(e, "MothurOut", "splitAtComma");
1988 /***********************************************************************/
1990 //This function splits up the various option parameters
1991 void MothurOut::splitAtComma(string& prefix, string& suffix){
1993 prefix = suffix.substr(0,suffix.find_first_of(','));
1994 if ((suffix.find_first_of(',')+2) <= suffix.length()) { //checks to make sure you don't have comma at end of string
1995 suffix = suffix.substr(suffix.find_first_of(',')+1, suffix.length());
1997 while(suffix.at(0) == ' ')
1998 suffix = suffix.substr(1, suffix.length());
2002 catch(exception& e) {
2003 errorOut(e, "MothurOut", "splitAtComma");
2007 /***********************************************************************/
2009 //This function separates the key value from the option value i.e. dist=96_...
2010 void MothurOut::splitAtEquals(string& key, string& value){
2012 if(value.find_first_of('=') != -1){
2013 key = value.substr(0,value.find_first_of('='));
2014 if ((value.find_first_of('=')+1) <= value.length()) {
2015 value = value.substr(value.find_first_of('=')+1, value.length());
2022 catch(exception& e) {
2023 errorOut(e, "MothurOut", "splitAtEquals");
2028 /**************************************************************************************************/
2030 bool MothurOut::inUsersGroups(string groupname, vector<string> Groups) {
2032 for (int i = 0; i < Groups.size(); i++) {
2033 if (groupname == Groups[i]) { return true; }
2037 catch(exception& e) {
2038 errorOut(e, "MothurOut", "inUsersGroups");
2042 /**************************************************************************************************/
2043 //returns true if any of the strings in first vector are in second vector
2044 bool MothurOut::inUsersGroups(vector<string> groupnames, vector<string> Groups) {
2047 for (int i = 0; i < groupnames.size(); i++) {
2048 if (inUsersGroups(groupnames[i], Groups)) { return true; }
2052 catch(exception& e) {
2053 errorOut(e, "MothurOut", "inUsersGroups");
2057 /***********************************************************************/
2058 //this function determines if the user has given us labels that are smaller than the given label.
2059 //if so then it returns true so that the calling function can run the previous valid distance.
2060 //it's a "smart" distance function. It also checks for invalid labels.
2061 bool MothurOut::anyLabelsToProcess(string label, set<string>& userLabels, string errorOff) {
2064 set<string>::iterator it;
2065 vector<float> orderFloat;
2066 map<string, float> userMap; //the conversion process removes trailing 0's which we need to put back
2067 map<string, float>::iterator it2;
2069 bool smaller = false;
2071 //unique is the smallest line
2072 if (label == "unique") { return false; }
2074 if (convertTestFloat(label, labelFloat)) {
2075 convert(label, labelFloat);
2076 }else { //cant convert
2081 //go through users set and make them floats
2082 for(it = userLabels.begin(); it != userLabels.end();) {
2085 if ((*it != "unique") && (convertTestFloat(*it, temp) == true)){
2087 orderFloat.push_back(temp);
2088 userMap[*it] = temp;
2090 }else if (*it == "unique") {
2091 orderFloat.push_back(-1.0);
2092 userMap["unique"] = -1.0;
2095 if (errorOff == "") { mothurOut(*it + " is not a valid label."); mothurOutEndLine(); }
2096 userLabels.erase(it++);
2101 sort(orderFloat.begin(), orderFloat.end());
2103 /*************************************************/
2104 //is this label bigger than any of the users labels
2105 /*************************************************/
2107 //loop through order until you find a label greater than label
2108 for (int i = 0; i < orderFloat.size(); i++) {
2109 if (orderFloat[i] < labelFloat) {
2111 if (orderFloat[i] == -1) {
2112 if (errorOff == "") { mothurOut("Your file does not include the label unique."); mothurOutEndLine(); }
2113 userLabels.erase("unique");
2116 if (errorOff == "") { mothurOut("Your file does not include the label "); mothurOutEndLine(); }
2118 for (it2 = userMap.begin(); it2!= userMap.end(); it2++) {
2119 if (it2->second == orderFloat[i]) {
2121 //remove small labels
2122 userLabels.erase(s);
2126 if (errorOff == "") {mothurOut( s + ". I will use the next smallest distance. "); mothurOutEndLine(); }
2128 //since they are sorted once you find a bigger one stop looking
2135 catch(exception& e) {
2136 errorOut(e, "MothurOut", "anyLabelsToProcess");
2141 /**************************************************************************************************/
2142 bool MothurOut::checkReleaseVersion(ifstream& file, string version) {
2147 string line = getline(file);
2149 //before we added this check
2150 if (line[0] != '#') { good = false; }
2153 line = line.substr(1);
2155 vector<string> versionVector;
2156 splitAtChar(version, versionVector, '.');
2158 //check file version
2159 vector<string> linesVector;
2160 splitAtChar(line, linesVector, '.');
2162 if (versionVector.size() != linesVector.size()) { good = false; }
2164 for (int j = 0; j < versionVector.size(); j++) {
2166 convert(versionVector[j], num1);
2167 convert(linesVector[j], num2);
2169 //if mothurs version is newer than this files version, then we want to remake it
2170 if (num1 > num2) { good = false; break; }
2176 if (!good) { file.close(); }
2177 else { file.seekg(0); }
2181 catch(exception& e) {
2182 errorOut(e, "MothurOut", "checkReleaseVersion");
2186 /**************************************************************************************************/
2187 bool MothurOut::isContainingOnlyDigits(string input) {
2190 //are you a digit in ascii code
2191 for (int i = 0;i < input.length(); i++){
2192 if( input[i]>47 && input[i]<58){}
2193 else { return false; }
2198 catch(exception& e) {
2199 errorOut(e, "MothurOut", "isContainingOnlyDigits");
2203 /**************************************************************************************************/
2204 int MothurOut::removeConfidences(string& tax) {
2210 while (tax.find_first_of(';') != -1) {
2212 if (control_pressed) { return 0; }
2215 taxon = tax.substr(0,tax.find_first_of(';'));
2217 int pos = taxon.find_last_of('(');
2220 int pos2 = taxon.find_last_of(')');
2222 string confidenceScore = taxon.substr(pos+1, (pos2-(pos+1)));
2223 if (isNumeric1(confidenceScore)) {
2224 taxon = taxon.substr(0, pos); //rip off confidence
2230 tax = tax.substr(tax.find_first_of(';')+1, tax.length());
2238 catch(exception& e) {
2239 errorOut(e, "MothurOut", "removeConfidences");
2243 /**************************************************************************************************/