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 ThreeColumnFile2::~ThreeColumnFile2(){
113 remove(outName.c_str());
116 /***********************************************************************/
118 void ThreeColumnFile2::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 = 1; 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';
142 outFile.setf(ios::fixed, ios::floatfield);
143 outFile.setf(ios::showpoint);
145 catch(exception& e) {
146 cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
150 cout << "An unknown error has occurred in the ThreeColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
155 /***********************************************************************/
157 void ThreeColumnFile2::output(vector<double> data){
162 getline(inFile, inputBuffer);
164 outFile << inputBuffer << '\t' << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << endl;
167 outFile << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << endl;
172 catch(exception& e) {
173 cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile2 class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
177 cout << "An unknown error has occurred in the ThreeColumnFile2 class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
182 /***********************************************************************/
184 void ThreeColumnFile2::resetFile(){
195 remove(inName.c_str());
196 renameOk = rename(outName.c_str(), inName.c_str());
198 //checks to make sure user was able to rename and remove successfully
199 if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
202 catch(exception& e) {
203 cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile2 class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
207 cout << "An unknown error has occurred in the ThreeColumnFile2 class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
212 /***********************************************************************/
213 /***********************************************************************/
215 SharedThreeColumnFile::~SharedThreeColumnFile(){
219 remove(outName.c_str());
222 /***********************************************************************/
224 void SharedThreeColumnFile::initFile(string label){
227 openOutputFile(outName, outFile);
228 openInputFile(inName, inFile);
231 getline(inFile, inputBuffer);
233 outFile << inputBuffer << '\t' << label << "\tlci\thci" << endl;
236 openOutputFile(outName, outFile);
237 outFile << "numsampled\t" << groupLabel << '\t' << label << "\tlci\thci" << endl;
240 outFile.setf(ios::fixed, ios::floatfield);
241 outFile.setf(ios::showpoint);
243 catch(exception& e) {
244 cout << "Standard Error: " << e.what() << " has occurred in the SharedThreeColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
248 cout << "An unknown error has occurred in the SharedThreeColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
253 /***********************************************************************/
255 void SharedThreeColumnFile::output(int nSeqs, vector<double> data){
259 getline(inFile, inputBuffer);
261 outFile << inputBuffer << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
264 outFile << numGroup << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
268 catch(exception& e) {
269 cout << "Standard Error: " << e.what() << " has occurred in the SharedThreeColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
273 cout << "An unknown error has occurred in the SharedThreeColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
278 /***********************************************************************/
280 void SharedThreeColumnFile::resetFile(){
290 remove(inName.c_str());
291 renameOk = rename(outName.c_str(), inName.c_str());
293 //checks to make sure user was able to rename and remove successfully
294 if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
297 catch(exception& e) {
298 cout << "Standard Error: " << e.what() << " has occurred in the SharedThreeColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
302 cout << "An unknown error has occurred in the SharedThreeColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
307 /***********************************************************************/
309 /***********************************************************************/
311 OneColumnFile::~OneColumnFile(){
315 remove(outName.c_str());
318 /***********************************************************************/
320 void OneColumnFile::initFile(string label){
323 openOutputFile(outName, outFile);
324 openInputFile(inName, inFile);
327 getline(inFile, inputBuffer);
329 outFile << inputBuffer << '\t' << label << endl;
332 openOutputFile(outName, outFile);
333 outFile << "numsequences\t" << label << endl;
336 outFile.setf(ios::fixed, ios::floatfield);
337 outFile.setf(ios::showpoint);
339 catch(exception& e) {
340 cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
344 cout << "An unknown error has occurred in the OneColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
349 /***********************************************************************/
351 void OneColumnFile::output(int nSeqs, vector<double> data){
355 getline(inFile, inputBuffer);
357 outFile << inputBuffer << setprecision(4) << '\t' << data[0] << endl;
360 outFile << nSeqs << setprecision(4) << '\t' << data[0] << endl;
363 catch(exception& e) {
364 cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
368 cout << "An unknown error has occurred in the OneColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
373 /***********************************************************************/
375 void OneColumnFile::resetFile(){
385 remove(inName.c_str());
386 renameOk = rename(outName.c_str(), inName.c_str());
388 //checks to make sure user was able to rename and remove successfully
389 if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
392 catch(exception& e) {
393 cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
397 cout << "An unknown error has occurred in the OneColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
402 /***********************************************************************/
403 /***********************************************************************/
405 SharedOneColumnFile::~SharedOneColumnFile(){
409 remove(outName.c_str());
412 /***********************************************************************/
414 void SharedOneColumnFile::initFile(string label){
417 openOutputFile(outName, outFile);
418 openInputFile(inName, inFile);
421 getline(inFile, inputBuffer);
423 outFile << inputBuffer << '\t' << label << endl;
427 openOutputFile(outName, outFile);
428 outFile << "sampled\t" << label << endl;
432 outFile.setf(ios::fixed, ios::floatfield);
433 outFile.setf(ios::showpoint);
435 catch(exception& e) {
436 cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
440 cout << "An unknown error has occurred in the OneColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
445 /***********************************************************************/
447 void SharedOneColumnFile::output(int nSeqs, vector<double> data){
453 for (int i = 0; i < data.size(); i++) {
454 dataOutput = dataOutput + "\t" + toString(data[i]);
458 getline(inFile, inputBuffer);
460 outFile << inputBuffer << setprecision(2) << '\t' << dataOutput << endl;
463 outFile << nSeqs << setprecision(2) << '\t' << dataOutput << endl;
466 catch(exception& e) {
467 cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
471 cout << "An unknown error has occurred in the OneColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
476 /***********************************************************************/
478 void SharedOneColumnFile::resetFile(){
489 remove(inName.c_str());
490 renameOk = rename(outName.c_str(), inName.c_str());
492 //checks to make sure user was able to rename and remove successfully
493 if ((renameOk != 0)) { cout << "Unable to rename necessary files." << endl; }
497 catch(exception& e) {
498 cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
502 cout << "An unknown error has occurred in the OneColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
507 /***********************************************************************/