File: fileoutput.cpp

package info (click to toggle)
mothur 1.48.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,692 kB
  • sloc: cpp: 161,866; makefile: 122; sh: 31
file content (204 lines) | stat: -rwxr-xr-x 6,994 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
 *  fileoutput.cpp
 *  Dotur
 *
 *  Created by Sarah Westcott on 11/18/08.
 *  Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
 *
 */

#include "fileoutput.h"

/***********************************************************************/
void ThreeColumnFile::setLabelName(string label){
	try {
		if(!firstLabel)     { fileHeader += "\t" + label + "\tlci\thci";             }
        else                { fileHeader = "numsampled\t" + label + "\tlci\thci";    }
    }
	catch(exception& e) {
		m->errorOut(e, "ThreeColumnFile", "setLabelName");
		exit(1);
	}
}
/***********************************************************************/
void ThreeColumnFile::updateOutput(int nSeqs, vector<double> data){
	try {
        
        map<int, int>::iterator it = nseqsToRow.find(nSeqs);
        if (it != nseqsToRow.end()) { //new column in row for next label
            int resultsIndex = it->second;
            results[resultsIndex].push_back(data[0]);
            results[resultsIndex].push_back(data[1]);
            results[resultsIndex].push_back(data[2]);
        }else{
            //new row
            nseqsToRow[nSeqs] = results.size();
            vector<double> theseResults;
            theseResults.push_back(nSeqs);
            theseResults.push_back(data[0]);
            theseResults.push_back(data[1]);
            theseResults.push_back(data[2]);
            results.push_back(theseResults);
        }
	}
	catch(exception& e) {
		m->errorOut(e, "ThreeColumnFile", "updateOutput");
		exit(1);
	}
}
/***********************************************************************/
void ColumnFile::setLabelName(string label, vector<string> tags){
	try {
		if(firstLabel){ fileHeader = ""; }
        
        for(int i = 0; i < tags.size(); i++) { fileHeader += label + tags[i] + '\t'; }
	}
	catch(exception& e) {
		m->errorOut(e, "ColumnFile", "setLabelName");
		exit(1);
	}
}
/***********************************************************************/
void ColumnFile::updateOutput(vector<double> data){
	try {
        vector<double> theseResults;
        for (size_t i = 0; i < data.size(); i++) { theseResults.push_back(data[i]);  }
        results.push_back(theseResults);
	}
	catch(exception& e) {
		m->errorOut(e, "ColumnFile", "updateOutput");
		exit(1);
	}
}
/***********************************************************************/
void FileOutput::printFile(){
	try {
        ofstream outFile;
        util.openOutputFile(filename, outFile);
        
        outFile.setf(ios::fixed, ios::floatfield); outFile.setf(ios::showpoint);
        cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint);
    
        outFile << fileHeader << endl;
        for (size_t i = 0; i < results.size(); i++) {
            for (size_t j = 0; j < results[i].size(); j++) {
                outFile << setprecision(6) << results[i][j] << '\t';
            }
            outFile << endl;
        }
        outFile << endl; 
        
        outFile.close();
    }
	catch(exception& e) {
		m->errorOut(e, "FileOutput", "printFile");
		exit(1);
	}
}
/***********************************************************************/
void SharedThreeColumnFile::setLabelName(string label){
	try {
        if (groupLabel != "") { groupLabel = "_" + groupLabel; }
        
        if(!firstLabel)     { fileHeader += "\t" + label + groupLabel + "\tlci" + groupLabel + "\thci"+ groupLabel; }
        else                { fileHeader = "numsampled\t" + label + groupLabel + "\tlci" + groupLabel + "\thci"+ groupLabel;  }
	}
	catch(exception& e) {
		m->errorOut(e, "SharedThreeColumnFile", "setLabelName");
		exit(1);
	}
}
/***********************************************************************/
void SharedThreeColumnFile::updateOutput(int nSeqs, vector<double> data){
	try {
        
        map<int, int>::iterator it = nseqsToRow.find(nSeqs);
        if (it != nseqsToRow.end()) { //new column in row for next label
            int resultsIndex = it->second;
            results[resultsIndex].push_back(data[0]);
            results[resultsIndex].push_back(data[1]);
            results[resultsIndex].push_back(data[2]);
        }else{ //new row
            nseqsToRow[nSeqs] = results.size();
            vector<double> theseResults;
            theseResults.push_back(numGroup); numGroup++;
            theseResults.push_back(data[0]);
            theseResults.push_back(data[1]);
            theseResults.push_back(data[2]);
            results.push_back(theseResults);
        }
    }
	catch(exception& e) {
		m->errorOut(e, "SharedThreeColumnFile", "output");
		exit(1);
	}
}
/***********************************************************************/
void OneColumnFile::setLabelName(string label){
	try {
        if(!firstLabel)     { fileHeader += "\t" + label;            }
        else                { fileHeader = "numsampled\t" + label;   }
    }
	catch(exception& e) {
		m->errorOut(e, "OneColumnFile", "setLabelName");
		exit(1);
	}
}
/***********************************************************************/
void OneColumnFile::updateOutput(int nSeqs, vector<double> data){
	try {
        map<int, int>::iterator it = nseqsToRow.find(nSeqs);
        if (it != nseqsToRow.end()) { //new column in row for next label
            int resultsIndex = it->second;
            results[resultsIndex].push_back(data[0]);
        }else{
            //new row
            nseqsToRow[nSeqs] = results.size();
            vector<double> theseResults;
            theseResults.push_back(nSeqs);
            theseResults.push_back(data[0]);
            results.push_back(theseResults);
        }
	}
	catch(exception& e) {
		m->errorOut(e, "OneColumnFile", "updateOutput");
		exit(1);
	}
}
/***********************************************************************/

void SharedOneColumnFile::setLabelName(string label){
	try {
        if(!firstLabel)     { fileHeader += "\t" + label;            }
        else                { fileHeader = "sampled\t" + label;   }
    }
	catch(exception& e) {
		m->errorOut(e, "SharedOneColumnFile", "setLabelName");
		exit(1);
	}
}
/***********************************************************************/
void SharedOneColumnFile::updateOutput(int nSeqs, vector<double> data){
	try {
        
        map<int, int>::iterator it = nseqsToRow.find(nSeqs);
        if (it != nseqsToRow.end()) { //new column in row for next label
            int resultsIndex = it->second;
            for (int i = 0; i < data.size(); i++) { results[resultsIndex].push_back(data[i]); }
        }else{
            //new row
            nseqsToRow[nSeqs] = results.size();
            vector<double> theseResults;
            theseResults.push_back(nSeqs);
            for (int i = 0; i < data.size(); i++) { theseResults.push_back(data[i]); }
            results.push_back(theseResults);
        }
    }
	catch(exception& e) {
		m->errorOut(e, "SharedOneColumnFile", "updateOutput");
		exit(1);
	}
}
/***********************************************************************/