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 m->mothurRemove(outName);
21 /***********************************************************************/
23 void ThreeColumnFile::initFile(string label){
26 m->openOutputFile(outName, outFile);
27 m->openInputFile(inName, inFile);
30 inputBuffer = m->getline(inFile);
32 outFile << inputBuffer << '\t' << label << "\tlci\thci" << endl;
35 m->openOutputFile(outName, outFile);
36 outFile << "numsampled\t" << label << "\tlci\thci" << endl;
39 outFile.setf(ios::fixed, ios::floatfield);
40 outFile.setf(ios::showpoint);
43 m->errorOut(e, "ThreeColumnFile", "initFile");
48 /***********************************************************************/
50 void ThreeColumnFile::output(int nSeqs, vector<double> data){
54 inputBuffer = m->getline(inFile);
56 outFile << inputBuffer << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
59 outFile << nSeqs << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
63 m->errorOut(e, "ThreeColumnFile", "output");
68 /***********************************************************************/
70 void ThreeColumnFile::resetFile(){
81 m->mothurRemove(inName);
82 renameOk = rename(outName.c_str(), inName.c_str());
84 //renameFile(outName, inName);
86 //checks to make sure user was able to rename and remove successfully
87 if ((renameOk != 0)) {
88 m->mothurOut("Unable to rename " + outName); m->mothurOutEndLine();
93 m->errorOut(e, "ThreeColumnFile", "resetFile");
98 /***********************************************************************/
99 /***********************************************************************/
101 ColumnFile::~ColumnFile(){
105 m->mothurRemove(outName);
108 /***********************************************************************/
110 void ColumnFile::initFile(string label, vector<string> tags){
113 m->openOutputFile(outName, outFile);
114 m->openInputFile(inName, inFile);
117 inputBuffer = m->getline(inFile);
119 outFile << inputBuffer << '\t';
120 for(int i = 0; i < tags.size(); i++) {
121 outFile << label + tags[i] << '\t';
126 m->openOutputFile(outName, outFile);
127 for(int i = 0; i < tags.size(); i++) {
128 outFile << label + tags[i] << '\t';
133 outFile.setf(ios::fixed, ios::floatfield);
134 outFile.setf(ios::showpoint);
136 catch(exception& e) {
137 m->errorOut(e, "ColumnFile", "initFile");
142 /***********************************************************************/
144 void ColumnFile::output(vector<double> data){
149 inputBuffer = m->getline(inFile);
151 outFile << inputBuffer << '\t' << setprecision(6) << data[0] << setprecision(iters.length());
152 for (int i = 1; i< data.size(); i++) {
153 outFile << '\t' << data[i];
158 outFile << setprecision(6) << data[0] << setprecision(iters.length());
159 for (int i = 1; i< data.size(); i++) {
160 outFile << '\t' << data[i];
166 catch(exception& e) {
167 m->errorOut(e, "ColumnFile", "output");
172 /***********************************************************************/
174 void ColumnFile::resetFile(){
185 m->mothurRemove(inName);
186 renameOk = rename(outName.c_str(), inName.c_str());
188 //renameFile(outName, inName);
190 //checks to make sure user was able to rename and remove successfully
191 if ((renameOk != 0)) {
192 m->mothurOut("Unable to rename " + outName); m->mothurOutEndLine();
196 catch(exception& e) {
197 m->errorOut(e, "ColumnFile", "resetFile");
202 /***********************************************************************/
203 /***********************************************************************/
205 SharedThreeColumnFile::~SharedThreeColumnFile(){
209 m->mothurRemove(outName);
212 /***********************************************************************/
214 void SharedThreeColumnFile::initFile(string label){
217 m->openOutputFile(outName, outFile);
218 m->openInputFile(inName, inFile);
221 inputBuffer = m->getline(inFile);
223 outFile << inputBuffer << '\t' << label << "\tlci\thci" << endl;
226 m->openOutputFile(outName, outFile);
227 outFile << "numsampled\t" << groupLabel << '\t' << label << "\tlci\thci" << endl;
230 outFile.setf(ios::fixed, ios::floatfield);
231 outFile.setf(ios::showpoint);
233 catch(exception& e) {
234 m->errorOut(e, "SharedThreeColumnFile", "initFile");
239 /***********************************************************************/
241 void SharedThreeColumnFile::output(int nSeqs, vector<double> data){
245 inputBuffer = m->getline(inFile);
247 outFile << inputBuffer << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
250 outFile << numGroup << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
254 catch(exception& e) {
255 m->errorOut(e, "SharedThreeColumnFile", "output");
260 /***********************************************************************/
262 void SharedThreeColumnFile::resetFile(){
273 m->mothurRemove(inName);
274 renameOk = rename(outName.c_str(), inName.c_str());
276 //renameFile(outName, inName);
278 //checks to make sure user was able to rename and remove successfully
279 if ((renameOk != 0)) {
280 m->mothurOut("Unable to rename " + outName); m->mothurOutEndLine();
284 catch(exception& e) {
285 m->errorOut(e, "SharedThreeColumnFile", "resetFile");
290 /***********************************************************************/
292 /***********************************************************************/
294 OneColumnFile::~OneColumnFile(){
298 m->mothurRemove(outName);
301 /***********************************************************************/
303 void OneColumnFile::initFile(string label){
306 m->openOutputFile(outName, outFile);
307 m->openInputFile(inName, inFile);
310 inputBuffer = m->getline(inFile);
312 outFile << inputBuffer << '\t' << label << endl;
315 m->openOutputFile(outName, outFile);
316 outFile << "numsampled\t" << label << endl;
319 outFile.setf(ios::fixed, ios::floatfield);
320 outFile.setf(ios::showpoint);
322 catch(exception& e) {
323 m->errorOut(e, "OneColumnFile", "initFile");
328 /***********************************************************************/
330 void OneColumnFile::output(int nSeqs, vector<double> data){
334 inputBuffer = m->getline(inFile);
336 outFile << inputBuffer << setprecision(4) << '\t' << data[0] << endl;
339 outFile << nSeqs << setprecision(4) << '\t' << data[0] << endl;
342 catch(exception& e) {
343 m->errorOut(e, "OneColumnFile", "output");
348 /***********************************************************************/
350 void OneColumnFile::resetFile(){
360 m->mothurRemove(inName);
361 renameOk = rename(outName.c_str(), inName.c_str());
363 //renameFile(outName, inName);
365 //checks to make sure user was able to rename and remove successfully
366 if ((renameOk != 0)) {
367 m->mothurOut("Unable to rename " + outName); m->mothurOutEndLine();
372 catch(exception& e) {
373 m->errorOut(e, "OneColumnFile", "resetFile");
378 /***********************************************************************/
379 /***********************************************************************/
381 SharedOneColumnFile::~SharedOneColumnFile(){
385 m->mothurRemove(outName);
388 /***********************************************************************/
390 void SharedOneColumnFile::initFile(string label){
393 m->openOutputFile(outName, outFile);
394 m->openInputFile(inName, inFile);
397 inputBuffer = m->getline(inFile);
399 outFile << inputBuffer << '\t' << label << endl;
403 m->openOutputFile(outName, outFile);
404 outFile << "sampled\t" << label << endl;
408 outFile.setf(ios::fixed, ios::floatfield);
409 outFile.setf(ios::showpoint);
411 catch(exception& e) {
412 m->errorOut(e, "SharedOneColumnFile", "initFile");
417 /***********************************************************************/
419 void SharedOneColumnFile::output(int nSeqs, vector<double> data){
425 for (int i = 0; i < data.size(); i++) {
426 dataOutput = dataOutput + "\t" + toString(data[i]);
430 inputBuffer = m->getline(inFile);
432 outFile << inputBuffer << setprecision(2) << '\t' << dataOutput << endl;
435 outFile << nSeqs << setprecision(2) << '\t' << dataOutput << endl;
438 catch(exception& e) {
439 m->errorOut(e, "SharedOneColumnFile", "output");
444 /***********************************************************************/
446 void SharedOneColumnFile::resetFile(){
457 m->mothurRemove(inName);
458 renameOk = rename(outName.c_str(), inName.c_str());
460 //renameFile(outName, inName);
462 //checks to make sure user was able to rename and remove successfully
463 if ((renameOk != 0)) {
464 m->mothurOut("Unable to rename " + outName); m->mothurOutEndLine();
468 catch(exception& e) {
469 m->errorOut(e, "SharedOneColumnFile", "resetFile");
474 /***********************************************************************/