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 inputBuffer = getline(inFile);
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 errorOut(e, "ThreeColumnFile", "initFile");
48 /***********************************************************************/
50 void ThreeColumnFile::output(int nSeqs, vector<double> data){
54 inputBuffer = 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 errorOut(e, "ThreeColumnFile", "output");
68 /***********************************************************************/
70 void ThreeColumnFile::resetFile(){
81 remove(inName.c_str());
82 renameOk = rename(outName.c_str(), inName.c_str());
84 //checks to make sure user was able to rename and remove successfully
85 if ((renameOk != 0)) { mothurOut("Unable to rename necessary files."); mothurOutEndLine(); }
89 errorOut(e, "ThreeColumnFile", "resetFile");
94 /***********************************************************************/
95 /***********************************************************************/
97 ColumnFile::~ColumnFile(){
101 remove(outName.c_str());
104 /***********************************************************************/
106 void ColumnFile::initFile(string label, vector<string> tags){
109 openOutputFile(outName, outFile);
110 openInputFile(inName, inFile);
113 inputBuffer = getline(inFile);
115 outFile << inputBuffer << '\t';
116 for(int i = 0; i < tags.size(); i++) {
117 outFile << label + tags[i] << '\t';
122 openOutputFile(outName, outFile);
123 for(int i = 0; i < tags.size(); i++) {
124 outFile << label + tags[i] << '\t';
129 outFile.setf(ios::fixed, ios::floatfield);
130 outFile.setf(ios::showpoint);
132 catch(exception& e) {
133 errorOut(e, "ColumnFile", "initFile");
138 /***********************************************************************/
140 void ColumnFile::output(vector<double> data){
145 inputBuffer = getline(inFile);
147 outFile << inputBuffer << '\t' << setprecision(6) << data[0] << setprecision(iters.length());
148 for (int i = 1; i< data.size(); i++) {
149 outFile << '\t' << data[i];
154 outFile << setprecision(6) << data[0] << setprecision(iters.length());
155 for (int i = 1; i< data.size(); i++) {
156 outFile << '\t' << data[i];
162 catch(exception& e) {
163 errorOut(e, "ColumnFile", "output");
168 /***********************************************************************/
170 void ColumnFile::resetFile(){
181 remove(inName.c_str());
182 renameOk = rename(outName.c_str(), inName.c_str());
184 //checks to make sure user was able to rename and remove successfully
185 if ((renameOk != 0)) { mothurOut("Unable to rename necessary files."); mothurOutEndLine(); }
188 catch(exception& e) {
189 errorOut(e, "ColumnFile", "resetFile");
194 /***********************************************************************/
195 /***********************************************************************/
197 SharedThreeColumnFile::~SharedThreeColumnFile(){
201 remove(outName.c_str());
204 /***********************************************************************/
206 void SharedThreeColumnFile::initFile(string label){
209 openOutputFile(outName, outFile);
210 openInputFile(inName, inFile);
213 inputBuffer = getline(inFile);
215 outFile << inputBuffer << '\t' << label << "\tlci\thci" << endl;
218 openOutputFile(outName, outFile);
219 outFile << "numsampled\t" << groupLabel << '\t' << label << "\tlci\thci" << endl;
222 outFile.setf(ios::fixed, ios::floatfield);
223 outFile.setf(ios::showpoint);
225 catch(exception& e) {
226 errorOut(e, "SharedThreeColumnFile", "initFile");
231 /***********************************************************************/
233 void SharedThreeColumnFile::output(int nSeqs, vector<double> data){
237 inputBuffer = getline(inFile);
239 outFile << inputBuffer << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
242 outFile << numGroup << setprecision(4) << '\t' << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
246 catch(exception& e) {
247 errorOut(e, "SharedThreeColumnFile", "output");
252 /***********************************************************************/
254 void SharedThreeColumnFile::resetFile(){
264 remove(inName.c_str());
265 renameOk = rename(outName.c_str(), inName.c_str());
267 //checks to make sure user was able to rename and remove successfully
268 if ((renameOk != 0)) { mothurOut("Unable to rename necessary files."); mothurOutEndLine(); }
271 catch(exception& e) {
272 errorOut(e, "SharedThreeColumnFile", "resetFile");
277 /***********************************************************************/
279 /***********************************************************************/
281 OneColumnFile::~OneColumnFile(){
285 remove(outName.c_str());
288 /***********************************************************************/
290 void OneColumnFile::initFile(string label){
293 openOutputFile(outName, outFile);
294 openInputFile(inName, inFile);
297 inputBuffer = getline(inFile);
299 outFile << inputBuffer << '\t' << label << endl;
302 openOutputFile(outName, outFile);
303 outFile << "numsequences\t" << label << endl;
306 outFile.setf(ios::fixed, ios::floatfield);
307 outFile.setf(ios::showpoint);
309 catch(exception& e) {
310 errorOut(e, "OneColumnFile", "initFile");
315 /***********************************************************************/
317 void OneColumnFile::output(int nSeqs, vector<double> data){
321 inputBuffer = getline(inFile);
323 outFile << inputBuffer << setprecision(4) << '\t' << data[0] << endl;
326 outFile << nSeqs << setprecision(4) << '\t' << data[0] << endl;
329 catch(exception& e) {
330 errorOut(e, "OneColumnFile", "output");
335 /***********************************************************************/
337 void OneColumnFile::resetFile(){
347 remove(inName.c_str());
348 renameOk = rename(outName.c_str(), inName.c_str());
350 //checks to make sure user was able to rename and remove successfully
351 if ((renameOk != 0)) { mothurOut("Unable to rename necessary files."); mothurOutEndLine(); }
354 catch(exception& e) {
355 errorOut(e, "OneColumnFile", "resetFile");
360 /***********************************************************************/
361 /***********************************************************************/
363 SharedOneColumnFile::~SharedOneColumnFile(){
367 remove(outName.c_str());
370 /***********************************************************************/
372 void SharedOneColumnFile::initFile(string label){
375 openOutputFile(outName, outFile);
376 openInputFile(inName, inFile);
379 inputBuffer = getline(inFile);
381 outFile << inputBuffer << '\t' << label << endl;
385 openOutputFile(outName, outFile);
386 outFile << "sampled\t" << label << endl;
390 outFile.setf(ios::fixed, ios::floatfield);
391 outFile.setf(ios::showpoint);
393 catch(exception& e) {
394 errorOut(e, "SharedOneColumnFile", "initFile");
399 /***********************************************************************/
401 void SharedOneColumnFile::output(int nSeqs, vector<double> data){
407 for (int i = 0; i < data.size(); i++) {
408 dataOutput = dataOutput + "\t" + toString(data[i]);
412 inputBuffer = getline(inFile);
414 outFile << inputBuffer << setprecision(2) << '\t' << dataOutput << endl;
417 outFile << nSeqs << setprecision(2) << '\t' << dataOutput << endl;
420 catch(exception& e) {
421 errorOut(e, "SharedOneColumnFile", "output");
426 /***********************************************************************/
428 void SharedOneColumnFile::resetFile(){
439 remove(inName.c_str());
440 renameOk = rename(outName.c_str(), inName.c_str());
442 //checks to make sure user was able to rename and remove successfully
443 if ((renameOk != 0)) { mothurOut("Unable to rename necessary files."); mothurOutEndLine(); }
447 catch(exception& e) {
448 errorOut(e, "SharedOneColumnFile", "resetFile");
453 /***********************************************************************/