]> git.donarmstrong.com Git - mothur.git/blobdiff - mothurout.cpp
metastats in progress
[mothur.git] / mothurout.cpp
index 1920221fd8c64a0c98e21c8ba71c19e7e49e906b..001e8c48a8932374d7266b4e6097036c5b2ed9ac 100644 (file)
@@ -434,7 +434,7 @@ void MothurOut::gobble(istream& f){
                
                char d;
                while(isspace(d=f.get()))               { ;}
-               f.putback(d);
+               if(!f.eof()) { f.putback(d); }
        }
        catch(exception& e) {
                errorOut(e, "MothurOut", "gobble");
@@ -446,7 +446,7 @@ void MothurOut::gobble(istringstream& f){
        try {
                char d;
                while(isspace(d=f.get()))               {;}
-               f.putback(d);
+               if(!f.eof()) { f.putback(d); }
        }
        catch(exception& e) {
                errorOut(e, "MothurOut", "gobble");
@@ -1182,7 +1182,6 @@ vector<unsigned long long> MothurOut::setFilePosEachLine(string filename, int& n
 
 vector<unsigned long long> MothurOut::divideFile(string filename, int& proc) {
        try{
-       
                vector<unsigned long long> filePos;
                filePos.push_back(0);
                
@@ -1190,7 +1189,7 @@ vector<unsigned long long> MothurOut::divideFile(string filename, int& proc) {
                unsigned long long size;
                
                filename = getFullPathName(filename);
-               
+       
                //get num bytes in file
                pFile = fopen (filename.c_str(),"rb");
                if (pFile==NULL) perror ("Error opening file");
@@ -1199,7 +1198,9 @@ vector<unsigned long long> MothurOut::divideFile(string filename, int& proc) {
                        size=ftell (pFile);
                        fclose (pFile);
                }
-       
+               
+       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                               
                //estimate file breaks
                unsigned long long chunkSize = 0;
                chunkSize = size / proc;
@@ -1219,7 +1220,10 @@ vector<unsigned long long> MothurOut::divideFile(string filename, int& proc) {
                        unsigned long long newSpot = spot;
                        while (!in.eof()) {
                           char c = in.get();
+                               
                           if (c == '>') {   in.putback(c); newSpot = in.tellg(); break;  }
+                          else if (int(c) == -1) { break; }
+                               
                        }
                
                        //there was not another sequence before the end of the file
@@ -1233,14 +1237,18 @@ vector<unsigned long long> MothurOut::divideFile(string filename, int& proc) {
                
                //save end pos
                filePos.push_back(size);
-
+               
                //sanity check filePos
                for (int i = 0; i < (filePos.size()-1); i++) {
                        if (filePos[(i+1)] <= filePos[i]) {  filePos.erase(filePos.begin()+(i+1)); i--; }
                }
 
                proc = (filePos.size() - 1);
-               
+#else
+               mothurOut("[ERROR]: Windows version should not be calling the divideFile function."); mothurOutEndLine();
+               proc=1;
+               filePos.push_back(size);
+#endif
                return filePos;
        }
        catch(exception& e) {
@@ -1469,10 +1477,17 @@ int MothurOut::getNumNames(string names){
 }
 /***********************************************************************/
 
-void MothurOut::mothurRemove(string filename){
+int MothurOut::mothurRemove(string filename){
        try {
                filename = getFullPathName(filename);
-               remove(filename.c_str());
+               int error = remove(filename.c_str());
+               //if (error != 0) { 
+               //      if (errno != ENOENT) { //ENOENT == file does not exist
+               //              string message = "Error deleting file " + filename;
+               //              perror(message.c_str()); 
+               //      }
+               //}
+               return error;
        }
        catch(exception& e) {
                errorOut(e, "MothurOut", "mothurRemove");
@@ -2020,6 +2035,46 @@ bool MothurOut::isContainingOnlyDigits(string input) {
        }
 }
 /**************************************************************************************************/
+int MothurOut::removeConfidences(string& tax) {
+       try {
+               
+               string taxon;
+               string newTax = "";
+               
+               while (tax.find_first_of(';') != -1) {
+                       
+                       if (control_pressed) { return 0; }
+                       
+                       //get taxon
+                       taxon = tax.substr(0,tax.find_first_of(';'));
+       
+                       int pos = taxon.find_last_of('(');
+                       if (pos != -1) {
+                               //is it a number?
+                               int pos2 = taxon.find_last_of(')');
+                               if (pos2 != -1) {
+                                       string confidenceScore = taxon.substr(pos+1, (pos2-(pos+1)));
+                                       if (isContainingOnlyDigits(confidenceScore)) {
+                                               taxon = taxon.substr(0, pos); //rip off confidence 
+                                       }
+                               }
+                       }
+                       taxon += ";";
+                       
+                       tax = tax.substr(tax.find_first_of(';')+1, tax.length());
+                       newTax += taxon;
+               }
+               
+               tax = newTax;
+               
+               return 0;
+       }
+       catch(exception& e) {
+               errorOut(e, "MothurOut", "removeConfidences");
+               exit(1);
+       }
+}
+/**************************************************************************************************/