X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=mothurout.cpp;h=25e534e43880497955512ce7dc2240adf99157e9;hb=d6c0a11d1cecfac18b323285e7ffadb7f58e848f;hp=90d6f37434d7cb4df231817be6d1759df80b45bb;hpb=4c5e7a20a03ddc6feb49ff9d21fcb4c79bc5508d;p=mothur.git diff --git a/mothurout.cpp b/mothurout.cpp index 90d6f37..25e534e 100644 --- a/mothurout.cpp +++ b/mothurout.cpp @@ -212,8 +212,8 @@ void MothurOut::mothurOut(string output) { if (pid == 0) { //only one process should output to screen #endif - cout << output; out << output; + logger() << output; #ifdef USE_MPI } @@ -234,8 +234,8 @@ void MothurOut::mothurOutEndLine() { if (pid == 0) { //only one process should output to screen #endif - cout << endl; out << endl; + logger() << endl; #ifdef USE_MPI } @@ -257,13 +257,15 @@ void MothurOut::mothurOut(string output, ofstream& outputFile) { if (pid == 0) { //only one process should output to screen #endif - cout << output; + out << output; outputFile << output; + logger() << output; #ifdef USE_MPI } #endif + } catch(exception& e) { errorOut(e, "MothurOut", "MothurOut"); @@ -280,9 +282,9 @@ void MothurOut::mothurOutEndLine(ofstream& outputFile) { if (pid == 0) { //only one process should output to screen #endif - cout << endl; out << endl; outputFile << endl; + logger() << endl; #ifdef USE_MPI } @@ -726,7 +728,7 @@ string MothurOut::getFullPathName(string fileName){ }else if (path[(pos-1)] == '/') { //you want the current working dir ./ path = path.substr(0, pos); }else if (pos == 1) { break; //you are at the end - }else { cout << "cannot resolve path for " << fileName << endl; return fileName; } + }else { mothurOut("cannot resolve path for " + fileName + "\n"); return fileName; } } for (int i = index; i >= 0; i--) { @@ -772,7 +774,7 @@ string MothurOut::getFullPathName(string fileName){ }else if (path[(pos-1)] == '\\') { //you want the current working dir ./ path = path.substr(0, pos); }else if (pos == 1) { break; //you are at the end - }else { cout << "cannot resolve path for " << fileName << endl; return fileName; } + }else { mothurOut("cannot resolve path for " + fileName + "\n"); return fileName; } } for (int i = index; i >= 0; i--) { @@ -1151,7 +1153,7 @@ vector MothurOut::setFilePosEachLine(string filename, int& n while(isspace(d) && (d != in.eof())) { d=in.get(); count++;} } positions.push_back(count-1); - cout << count-1 << endl; + //cout << count-1 << endl; } in.close(); @@ -1182,7 +1184,6 @@ vector MothurOut::setFilePosEachLine(string filename, int& n vector MothurOut::divideFile(string filename, int& proc) { try{ - vector filePos; filePos.push_back(0); @@ -1190,7 +1191,7 @@ vector 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 +1200,9 @@ vector 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 +1222,10 @@ vector 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 +1239,18 @@ vector 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,16 +1479,121 @@ int MothurOut::getNumNames(string names){ } /***********************************************************************/ -void MothurOut::mothurRemove(string filename){ +int MothurOut::getNumChar(string line, char c){ + try { + int count = 0; + + if(line != ""){ + for(int i=0;i > MothurOut::binomial(int maxOrder){ @@ -2020,6 +2135,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 (isNumeric1(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); + } +} +/**************************************************************************************************/