5 * Created by Sarah Westcott on 11/18/08.
6 * Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "fileoutput.h"
12 /***********************************************************************/
14 ThreeColumnFile::~ThreeColumnFile(){
18 remove(outName.c_str());
21 /***********************************************************************/
23 void ThreeColumnFile::initFile(string label){
26 openOutputFile(outName, outFile);
27 openInputFile(inName, inFile);
30 getline(inFile, inputBuffer);
32 outFile << inputBuffer << '\t' << label << "\tlci\thci" << endl;
35 openOutputFile(outName, outFile);
36 outFile << "numsampled\t" << label << "\tlci\thci" << endl;
39 outFile.setf(ios::fixed, ios::floatfield);
40 outFile.setf(ios::showpoint);
43 cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
47 cout << "An unknown error has occurred in the ThreeColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
52 /***********************************************************************/
54 void ThreeColumnFile::output(int nSeqs, vector<double> data){
58 getline(inFile, inputBuffer);
60 outFile << inputBuffer << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
63 outFile << nSeqs << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
67 cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
71 cout << "An unknown error has occurred in the ThreeColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
76 /***********************************************************************/
78 void ThreeColumnFile::resetFile(){
89 remove(inName.c_str());
90 renameOk = rename(outName.c_str(), inName.c_str());
92 //checks to make sure user was able to rename and remove successfully
93 if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
97 cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
101 cout << "An unknown error has occurred in the ThreeColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
106 /***********************************************************************/
107 /***********************************************************************/
109 ColumnFile::~ColumnFile(){
113 remove(outName.c_str());
116 /***********************************************************************/
118 void ColumnFile::initFile(string label, vector<string> tags){
121 openOutputFile(outName, outFile);
122 openInputFile(inName, inFile);
125 getline(inFile, inputBuffer);
127 outFile << inputBuffer << '\t';
128 for(int i = 0; i < tags.size(); i++) {
129 outFile << label + tags[i] << '\t';
134 openOutputFile(outName, outFile);
135 for(int i = 0; i < tags.size(); i++) {
136 outFile << label + tags[i] << '\t';
141 outFile.setf(ios::fixed, ios::floatfield);
142 outFile.setf(ios::showpoint);
144 catch(exception& e) {
145 cout << "Standard Error: " << e.what() << " has occurred in the ColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
149 cout << "An unknown error has occurred in the ColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
154 /***********************************************************************/
156 void ColumnFile::output(vector<double> data){
161 getline(inFile, inputBuffer);
163 outFile << inputBuffer << '\t' << setprecision(6) << data[0] << setprecision(globaldata->getIters().length());
164 for (int i = 1; i< data.size(); i++) {
165 outFile << '\t' << data[i];
170 outFile << setprecision(6) << data[0] << setprecision(globaldata->getIters().length());
171 for (int i = 1; i< data.size(); i++) {
172 outFile << '\t' << data[i];
178 catch(exception& e) {
179 cout << "Standard Error: " << e.what() << " has occurred in the ColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
183 cout << "An unknown error has occurred in the ColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
188 /***********************************************************************/
190 void ColumnFile::resetFile(){
201 remove(inName.c_str());
202 renameOk = rename(outName.c_str(), inName.c_str());
204 //checks to make sure user was able to rename and remove successfully
205 if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
208 catch(exception& e) {
209 cout << "Standard Error: " << e.what() << " has occurred in the ColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
213 cout << "An unknown error has occurred in the ColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
218 /***********************************************************************/
219 /***********************************************************************/
221 SharedThreeColumnFile::~SharedThreeColumnFile(){
225 remove(outName.c_str());
228 /***********************************************************************/
230 void SharedThreeColumnFile::initFile(string label){
233 openOutputFile(outName, outFile);
234 openInputFile(inName, inFile);
237 getline(inFile, inputBuffer);
239 outFile << inputBuffer << '\t' << label << "\tlci\thci" << endl;
242 openOutputFile(outName, outFile);
243 outFile << "numsampled\t" << groupLabel << '\t' << label << "\tlci\thci" << endl;
246 outFile.setf(ios::fixed, ios::floatfield);
247 outFile.setf(ios::showpoint);
249 catch(exception& e) {
250 cout << "Standard Error: " << e.what() << " has occurred in the SharedThreeColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
254 cout << "An unknown error has occurred in the SharedThreeColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
259 /***********************************************************************/
261 void SharedThreeColumnFile::output(int nSeqs, vector<double> data){
265 getline(inFile, inputBuffer);
267 outFile << inputBuffer << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
270 outFile << numGroup << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
274 catch(exception& e) {
275 cout << "Standard Error: " << e.what() << " has occurred in the SharedThreeColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
279 cout << "An unknown error has occurred in the SharedThreeColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
284 /***********************************************************************/
286 void SharedThreeColumnFile::resetFile(){
296 remove(inName.c_str());
297 renameOk = rename(outName.c_str(), inName.c_str());
299 //checks to make sure user was able to rename and remove successfully
300 if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
303 catch(exception& e) {
304 cout << "Standard Error: " << e.what() << " has occurred in the SharedThreeColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
308 cout << "An unknown error has occurred in the SharedThreeColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
313 /***********************************************************************/
315 /***********************************************************************/
317 OneColumnFile::~OneColumnFile(){
321 remove(outName.c_str());
324 /***********************************************************************/
326 void OneColumnFile::initFile(string label){
329 openOutputFile(outName, outFile);
330 openInputFile(inName, inFile);
333 getline(inFile, inputBuffer);
335 outFile << inputBuffer << '\t' << label << endl;
338 openOutputFile(outName, outFile);
339 outFile << "numsequences\t" << label << endl;
342 outFile.setf(ios::fixed, ios::floatfield);
343 outFile.setf(ios::showpoint);
345 catch(exception& e) {
346 cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
350 cout << "An unknown error has occurred in the OneColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
355 /***********************************************************************/
357 void OneColumnFile::output(int nSeqs, vector<double> data){
361 getline(inFile, inputBuffer);
363 outFile << inputBuffer << setprecision(4) << '\t' << data[0] << endl;
366 outFile << nSeqs << setprecision(4) << '\t' << data[0] << endl;
369 catch(exception& e) {
370 cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
374 cout << "An unknown error has occurred in the OneColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
379 /***********************************************************************/
381 void OneColumnFile::resetFile(){
391 remove(inName.c_str());
392 renameOk = rename(outName.c_str(), inName.c_str());
394 //checks to make sure user was able to rename and remove successfully
395 if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
398 catch(exception& e) {
399 cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
403 cout << "An unknown error has occurred in the OneColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
408 /***********************************************************************/
409 /***********************************************************************/
411 SharedOneColumnFile::~SharedOneColumnFile(){
415 remove(outName.c_str());
418 /***********************************************************************/
420 void SharedOneColumnFile::initFile(string label){
423 openOutputFile(outName, outFile);
424 openInputFile(inName, inFile);
427 getline(inFile, inputBuffer);
429 outFile << inputBuffer << '\t' << label << endl;
433 openOutputFile(outName, outFile);
434 outFile << "sampled\t" << label << endl;
438 outFile.setf(ios::fixed, ios::floatfield);
439 outFile.setf(ios::showpoint);
441 catch(exception& e) {
442 cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
446 cout << "An unknown error has occurred in the OneColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
451 /***********************************************************************/
453 void SharedOneColumnFile::output(int nSeqs, vector<double> data){
459 for (int i = 0; i < data.size(); i++) {
460 dataOutput = dataOutput + "\t" + toString(data[i]);
464 getline(inFile, inputBuffer);
466 outFile << inputBuffer << setprecision(2) << '\t' << dataOutput << endl;
469 outFile << nSeqs << setprecision(2) << '\t' << dataOutput << endl;
472 catch(exception& e) {
473 cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
477 cout << "An unknown error has occurred in the OneColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
482 /***********************************************************************/
484 void SharedOneColumnFile::resetFile(){
495 remove(inName.c_str());
496 renameOk = rename(outName.c_str(), inName.c_str());
498 //checks to make sure user was able to rename and remove successfully
499 if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
503 catch(exception& e) {
504 cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
508 cout << "An unknown error has occurred in the OneColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
513 /***********************************************************************/