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(){
88 remove(inName.c_str());
89 rename(outName.c_str(), inName.c_str());
92 cout << "Standard Error: " << e.what() << " has occurred in the ThreeColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
96 cout << "An unknown error has occurred in the ThreeColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
101 /***********************************************************************/
102 /***********************************************************************/
104 SharedThreeColumnFile::~SharedThreeColumnFile(){
108 remove(outName.c_str());
111 /***********************************************************************/
113 void SharedThreeColumnFile::initFile(string label){
116 openOutputFile(outName, outFile);
117 openInputFile(inName, inFile);
120 getline(inFile, inputBuffer);
122 outFile << inputBuffer << '\t' << label << "\tlci\thci" << endl;
125 openOutputFile(outName, outFile);
126 outFile << "numsampled\t" << groupLabel << '\t' << label << "\tlci\thci" << endl;
129 outFile.setf(ios::fixed, ios::floatfield);
130 outFile.setf(ios::showpoint);
132 catch(exception& e) {
133 cout << "Standard Error: " << e.what() << " has occurred in the SharedThreeColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
137 cout << "An unknown error has occurred in the SharedThreeColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
142 /***********************************************************************/
144 void SharedThreeColumnFile::output(int nSeqs, vector<double> data){
148 getline(inFile, inputBuffer);
150 outFile << inputBuffer << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
153 outFile << numGroup << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
157 catch(exception& e) {
158 cout << "Standard Error: " << e.what() << " has occurred in the SharedThreeColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
162 cout << "An unknown error has occurred in the SharedThreeColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
167 /***********************************************************************/
169 void SharedThreeColumnFile::resetFile(){
179 remove(inName.c_str());
180 rename(outName.c_str(), inName.c_str());
182 catch(exception& e) {
183 cout << "Standard Error: " << e.what() << " has occurred in the SharedThreeColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
187 cout << "An unknown error has occurred in the SharedThreeColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
192 /***********************************************************************/
194 /***********************************************************************/
196 OneColumnFile::~OneColumnFile(){
200 remove(outName.c_str());
203 /***********************************************************************/
205 void OneColumnFile::initFile(string label){
208 openOutputFile(outName, outFile);
209 openInputFile(inName, inFile);
212 getline(inFile, inputBuffer);
214 outFile << inputBuffer << '\t' << label << endl;
217 openOutputFile(outName, outFile);
218 outFile << "numsequences\t" << label << endl;
221 outFile.setf(ios::fixed, ios::floatfield);
222 outFile.setf(ios::showpoint);
224 catch(exception& e) {
225 cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
229 cout << "An unknown error has occurred in the OneColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
234 /***********************************************************************/
236 void OneColumnFile::output(int nSeqs, vector<double> data){
240 getline(inFile, inputBuffer);
242 outFile << inputBuffer << setprecision(4) << '\t' << data[0] << endl;
245 outFile << nSeqs << setprecision(4) << '\t' << data[0] << endl;
248 catch(exception& e) {
249 cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
253 cout << "An unknown error has occurred in the OneColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
258 /***********************************************************************/
260 void OneColumnFile::resetFile(){
270 remove(inName.c_str());
271 rename(outName.c_str(), inName.c_str());
273 catch(exception& e) {
274 cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
278 cout << "An unknown error has occurred in the OneColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
283 /***********************************************************************/
284 /***********************************************************************/
286 SharedOneColumnFile::~SharedOneColumnFile(){
290 remove(outName.c_str());
293 /***********************************************************************/
295 void SharedOneColumnFile::initFile(string label){
298 openOutputFile(outName, outFile);
299 openInputFile(inName, inFile);
302 getline(inFile, inputBuffer);
304 outFile << inputBuffer << '\t' << label << endl;
308 openOutputFile(outName, outFile);
309 outFile << "sampled\t" << label << endl;
313 outFile.setf(ios::fixed, ios::floatfield);
314 outFile.setf(ios::showpoint);
316 catch(exception& e) {
317 cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
321 cout << "An unknown error has occurred in the OneColumnFile class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
326 /***********************************************************************/
328 void SharedOneColumnFile::output(int nSeqs, vector<double> data){
334 for (int i = 0; i < data.size(); i++) {
335 dataOutput = dataOutput + "\t" + toString(data[i]);
339 getline(inFile, inputBuffer);
341 outFile << inputBuffer << setprecision(2) << '\t' << dataOutput << endl;
344 outFile << nSeqs << setprecision(2) << '\t' << dataOutput << endl;
347 catch(exception& e) {
348 cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
352 cout << "An unknown error has occurred in the OneColumnFile class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
357 /***********************************************************************/
359 void SharedOneColumnFile::resetFile(){
369 remove(inName.c_str());
370 rename(outName.c_str(), inName.c_str());
372 catch(exception& e) {
373 cout << "Standard Error: " << e.what() << " has occurred in the OneColumnFile class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
377 cout << "An unknown error has occurred in the OneColumnFile class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
382 /***********************************************************************/