char d;
while(isspace(d=f.get())) { ;}
- f.putback(d);
+ if(!f.eof()) { f.putback(d); }
}
catch(exception& e) {
errorOut(e, "MothurOut", "gobble");
try {
char d;
while(isspace(d=f.get())) {;}
- f.putback(d);
+ if(!f.eof()) { f.putback(d); }
}
catch(exception& e) {
errorOut(e, "MothurOut", "gobble");
try {
ifstream inTest;
int exist = openInputFile(newName, inTest, "");
+ inTest.close();
#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
if (exist == 0) { //you could open it so you want to delete it
- inTest.close();
string command = "rm " + newName;
system(command.c_str());
}
vector<unsigned long long> MothurOut::divideFile(string filename, int& proc) {
try{
-
vector<unsigned long long> filePos;
filePos.push_back(0);
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");
size=ftell (pFile);
fclose (pFile);
}
-
+
+ #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+
//estimate file breaks
unsigned long long chunkSize = 0;
chunkSize = size / 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
//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) {
}
/***********************************************************************/
-void MothurOut::mothurRemove(string filename){
+int MothurOut::getNumChar(string line, char c){
+ try {
+ int count = 0;
+
+ if(line != ""){
+ for(int i=0;i<line.size();i++){
+ if(line[i] == c){
+ count++;
+ }
+ }
+ }
+
+ return count;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "getNumChar");
+ exit(1);
+ }
+}
+/***********************************************************************/
+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");
exit(1);
}
}
+/***********************************************************************/
+bool MothurOut::mothurConvert(string item, int& num){
+ try {
+ bool error = false;
+
+ if (isNumeric1(item)) {
+ convert(item, num);
+ }else {
+ num = 0;
+ error = true;
+ mothurOut("[ERROR]: cannot convert " + item + " to an integer."); mothurOutEndLine();
+ commandInputsConvertError = true;
+ }
+
+ return error;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "mothurConvert");
+ exit(1);
+ }
+}
+/***********************************************************************/
+bool MothurOut::isNumeric1(string stringToCheck){
+ try {
+ bool numeric = false;
+
+ if(stringToCheck.find_first_not_of("0123456789.-") == string::npos) { numeric = true; }
+
+ return numeric;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "isNumeric1");
+ exit(1);
+ }
+
+}
+/***********************************************************************/
+bool MothurOut::mothurConvert(string item, float& num){
+ try {
+ bool error = false;
+
+ if (isNumeric1(item)) {
+ convert(item, num);
+ }else {
+ num = 0;
+ error = true;
+ mothurOut("[ERROR]: cannot convert " + item + " to a float."); mothurOutEndLine();
+ commandInputsConvertError = true;
+ }
+
+ return error;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "mothurConvert");
+ exit(1);
+ }
+}
+/***********************************************************************/
+bool MothurOut::mothurConvert(string item, double& num){
+ try {
+ bool error = false;
+
+ if (isNumeric1(item)) {
+ convert(item, num);
+ }else {
+ num = 0;
+ error = true;
+ mothurOut("[ERROR]: cannot convert " + item + " to a double."); mothurOutEndLine();
+ commandInputsConvertError = true;
+ }
+
+ return error;
+ }
+ catch(exception& e) {
+ errorOut(e, "MothurOut", "mothurConvert");
+ exit(1);
+ }
+}
/**************************************************************************************************/
vector<vector<double> > MothurOut::binomial(int maxOrder){
}
}
/**************************************************************************************************/
+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);
+ }
+}
+/**************************************************************************************************/