X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=fileoutput.cpp;h=a4a68a8ef25a66ca52052faf8a1e8e6221bec4af;hp=e6f069dd894e7fe5702b63e5fe6e4c3ce85bc25e;hb=1a20e24ee786195ab0e1cccd4f5aede7a88f3f4e;hpb=c5c7502f435e1413c19e373dab1dfebcaa67588d diff --git a/fileoutput.cpp b/fileoutput.cpp index e6f069d..a4a68a8 100644 --- a/fileoutput.cpp +++ b/fileoutput.cpp @@ -15,24 +15,24 @@ ThreeColumnFile::~ThreeColumnFile(){ inFile.close(); outFile.close(); - remove(outName.c_str()); -}; + m->mothurRemove(outName); +} /***********************************************************************/ void ThreeColumnFile::initFile(string label){ try { if(counter != 0){ - openOutputFile(outName, outFile); - openInputFile(inName, inFile); + m->openOutputFile(outName, outFile); + m->openInputFile(inName, inFile); string inputBuffer; - getline(inFile, inputBuffer); + inputBuffer = m->getline(inFile); outFile << inputBuffer << '\t' << label << "\tlci\thci" << endl; } else{ - openOutputFile(outName, outFile); + m->openOutputFile(outName, outFile); outFile << "numsampled\t" << label << "\tlci\thci" << endl; } @@ -40,11 +40,7 @@ void ThreeColumnFile::initFile(string label){ outFile.setf(ios::showpoint); } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ThreeColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "ThreeColumnFile", "initFile"); exit(1); } } @@ -55,7 +51,7 @@ void ThreeColumnFile::output(int nSeqs, vector data){ try { if(counter != 0){ string inputBuffer; - getline(inFile, inputBuffer); + inputBuffer = m->getline(inFile); outFile << inputBuffer << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl; } @@ -64,14 +60,10 @@ void ThreeColumnFile::output(int nSeqs, vector data){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ThreeColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "ThreeColumnFile", "output"); exit(1); } -}; +} /***********************************************************************/ @@ -86,102 +78,100 @@ void ThreeColumnFile::resetFile(){ } counter = 1; - remove(inName.c_str()); + m->mothurRemove(inName); renameOk = rename(outName.c_str(), inName.c_str()); + //renameFile(outName, inName); + //checks to make sure user was able to rename and remove successfully - if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; } - + if ((renameOk != 0)) { + m->mothurOut("Unable to rename " + outName); m->mothurOutEndLine(); + perror(" : "); + } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "ThreeColumnFile", "resetFile"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the ThreeColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ /***********************************************************************/ -ThreeColumnFile2::~ThreeColumnFile2(){ +ColumnFile::~ColumnFile(){ inFile.close(); outFile.close(); - remove(outName.c_str()); -}; + m->mothurRemove(outName); +} /***********************************************************************/ -void ThreeColumnFile2::initFile(string label, vector tags){ +void ColumnFile::initFile(string label, vector tags){ try { if(counter != 0){ - openOutputFile(outName, outFile); - openInputFile(inName, inFile); + m->openOutputFile(outName, outFile); + m->openInputFile(inName, inFile); string inputBuffer; - getline(inFile, inputBuffer); + inputBuffer = m->getline(inFile); outFile << inputBuffer << '\t'; - for(int i = 1; i < tags.size(); i++) { + for(int i = 0; i < tags.size(); i++) { outFile << label + tags[i] << '\t'; } outFile << endl; } else{ - openOutputFile(outName, outFile); + m->openOutputFile(outName, outFile); for(int i = 0; i < tags.size(); i++) { outFile << label + tags[i] << '\t'; } outFile << endl; - } outFile.setf(ios::fixed, ios::floatfield); outFile.setf(ios::showpoint); } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ThreeColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "ColumnFile", "initFile"); exit(1); } } /***********************************************************************/ -void ThreeColumnFile2::output(vector data){ +void ColumnFile::output(vector data){ try { if(counter != 0){ string inputBuffer; - getline(inFile, inputBuffer); + inputBuffer = m->getline(inFile); - outFile << inputBuffer << '\t' << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << endl; + outFile << inputBuffer << '\t' << setprecision(6) << data[0] << setprecision(iters.length()); + for (int i = 1; i< data.size(); i++) { + outFile << '\t' << data[i]; + } + outFile << endl; } else{ - outFile << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << endl; - + outFile << setprecision(6) << data[0] << setprecision(iters.length()); + for (int i = 1; i< data.size(); i++) { + outFile << '\t' << data[i]; + } + outFile << endl; } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile2 class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ThreeColumnFile2 class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "ColumnFile", "output"); exit(1); } -}; +} /***********************************************************************/ -void ThreeColumnFile2::resetFile(){ +void ColumnFile::resetFile(){ try { if(counter != 0){ outFile.close(); @@ -192,21 +182,21 @@ void ThreeColumnFile2::resetFile(){ } counter = 1; - remove(inName.c_str()); + m->mothurRemove(inName); renameOk = rename(outName.c_str(), inName.c_str()); + //renameFile(outName, inName); + //checks to make sure user was able to rename and remove successfully - if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; } - + if ((renameOk != 0)) { + m->mothurOut("Unable to rename " + outName); m->mothurOutEndLine(); + perror(" : "); + } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile2 class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "ColumnFile", "resetFile"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the ThreeColumnFile2 class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ @@ -216,24 +206,24 @@ SharedThreeColumnFile::~SharedThreeColumnFile(){ inFile.close(); outFile.close(); - remove(outName.c_str()); -}; + m->mothurRemove(outName); +} /***********************************************************************/ void SharedThreeColumnFile::initFile(string label){ try { if(counter != 0){ - openOutputFile(outName, outFile); - openInputFile(inName, inFile); + m->openOutputFile(outName, outFile); + m->openInputFile(inName, inFile); string inputBuffer; - getline(inFile, inputBuffer); + inputBuffer = m->getline(inFile); outFile << inputBuffer << '\t' << label << "\tlci\thci" << endl; } else{ - openOutputFile(outName, outFile); + m->openOutputFile(outName, outFile); outFile << "numsampled\t" << groupLabel << '\t' << label << "\tlci\thci" << endl; } @@ -241,11 +231,7 @@ void SharedThreeColumnFile::initFile(string label){ outFile.setf(ios::showpoint); } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SharedThreeColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the SharedThreeColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "SharedThreeColumnFile", "initFile"); exit(1); } } @@ -256,7 +242,7 @@ void SharedThreeColumnFile::output(int nSeqs, vector data){ try { if(counter != 0){ string inputBuffer; - getline(inFile, inputBuffer); + inputBuffer = m->getline(inFile); outFile << inputBuffer << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl; } @@ -266,14 +252,10 @@ void SharedThreeColumnFile::output(int nSeqs, vector data){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SharedThreeColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "SharedThreeColumnFile", "output"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the SharedThreeColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -}; +} /***********************************************************************/ @@ -287,21 +269,22 @@ void SharedThreeColumnFile::resetFile(){ outFile.close(); } counter = 1; - remove(inName.c_str()); + + m->mothurRemove(inName); renameOk = rename(outName.c_str(), inName.c_str()); + //renameFile(outName, inName); + //checks to make sure user was able to rename and remove successfully - if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; } - + if ((renameOk != 0)) { + m->mothurOut("Unable to rename " + outName); m->mothurOutEndLine(); + perror(" : "); + } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the SharedThreeColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "SharedThreeColumnFile", "resetFile"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the SharedThreeColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ @@ -312,38 +295,34 @@ OneColumnFile::~OneColumnFile(){ inFile.close(); outFile.close(); - remove(outName.c_str()); -}; + m->mothurRemove(outName); +} /***********************************************************************/ void OneColumnFile::initFile(string label){ try { if(counter != 0){ - openOutputFile(outName, outFile); - openInputFile(inName, inFile); + m->openOutputFile(outName, outFile); + m->openInputFile(inName, inFile); string inputBuffer; - getline(inFile, inputBuffer); + inputBuffer = m->getline(inFile); outFile << inputBuffer << '\t' << label << endl; } else{ - openOutputFile(outName, outFile); - outFile << "numsequences\t" << label << endl; + m->openOutputFile(outName, outFile); + outFile << "numsampled\t" << label << endl; } outFile.setf(ios::fixed, ios::floatfield); outFile.setf(ios::showpoint); } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "OneColumnFile", "initFile"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the OneColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ @@ -352,7 +331,7 @@ void OneColumnFile::output(int nSeqs, vector data){ try { if(counter != 0){ string inputBuffer; - getline(inFile, inputBuffer); + inputBuffer = m->getline(inFile); outFile << inputBuffer << setprecision(4) << '\t' << data[0] << endl; } @@ -361,14 +340,10 @@ void OneColumnFile::output(int nSeqs, vector data){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "OneColumnFile", "output"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the OneColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -}; +} /***********************************************************************/ @@ -377,26 +352,27 @@ void OneColumnFile::resetFile(){ if(counter != 0){ outFile.close(); inFile.close(); - } - else{ + }else{ outFile.close(); } counter = 1; - remove(inName.c_str()); + + m->mothurRemove(inName); renameOk = rename(outName.c_str(), inName.c_str()); + //renameFile(outName, inName); + //checks to make sure user was able to rename and remove successfully - if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; } + if ((renameOk != 0)) { + m->mothurOut("Unable to rename " + outName); m->mothurOutEndLine(); + perror(" : "); + } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "OneColumnFile", "resetFile"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the OneColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ @@ -406,25 +382,25 @@ SharedOneColumnFile::~SharedOneColumnFile(){ inFile.close(); outFile.close(); - remove(outName.c_str()); -}; + m->mothurRemove(outName); +} /***********************************************************************/ void SharedOneColumnFile::initFile(string label){ try { if(counter != 0){ - openOutputFile(outName, outFile); - openInputFile(inName, inFile); + m->openOutputFile(outName, outFile); + m->openInputFile(inName, inFile); string inputBuffer; - getline(inFile, inputBuffer); + inputBuffer = m->getline(inFile); outFile << inputBuffer << '\t' << label << endl; } else{ - openOutputFile(outName, outFile); + m->openOutputFile(outName, outFile); outFile << "sampled\t" << label << endl; } @@ -433,13 +409,9 @@ void SharedOneColumnFile::initFile(string label){ outFile.setf(ios::showpoint); } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "SharedOneColumnFile", "initFile"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the OneColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/ @@ -455,7 +427,7 @@ void SharedOneColumnFile::output(int nSeqs, vector data){ } if(counter != 0){ string inputBuffer; - getline(inFile, inputBuffer); + inputBuffer = m->getline(inFile); outFile << inputBuffer << setprecision(2) << '\t' << dataOutput << endl; } @@ -464,14 +436,10 @@ void SharedOneColumnFile::output(int nSeqs, vector data){ } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "SharedOneColumnFile", "output"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the OneColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -}; +} /***********************************************************************/ @@ -485,23 +453,22 @@ void SharedOneColumnFile::resetFile(){ outFile.close(); } counter = 1; - - remove(inName.c_str()); + + m->mothurRemove(inName); renameOk = rename(outName.c_str(), inName.c_str()); - //checks to make sure user was able to rename and remove successfully - if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; } - + //renameFile(outName, inName); + //checks to make sure user was able to rename and remove successfully + if ((renameOk != 0)) { + m->mothurOut("Unable to rename " + outName); m->mothurOutEndLine(); + perror(" : "); + } } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "SharedOneColumnFile", "resetFile"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the OneColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } /***********************************************************************/