forked from mothur/mothur
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmothurout.cpp
executable file
·268 lines (247 loc) · 13.3 KB
/
mothurout.cpp
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
* mothurOut.cpp
* Mothur
*
* Created by westcott on 2/25/10.
* Copyright 2010 Schloss Lab. All rights reserved.
*
*/
#include "mothurout.h"
#include "ordervector.hpp"
#include "sharedordervector.h"
#include "counttable.h"
//needed for testing project
//MothurOut* MothurOut::_uniqueInstance;
/******************************************************/
MothurOut* MothurOut::getInstance() {
if( _uniqueInstance == 0) {
_uniqueInstance = new MothurOut();
}
return _uniqueInstance;
}
/*********************************************************************************************/
void MothurOut::appendLogBuffer(string partialLog) {
try {
buffer += partialLog;
}
catch(exception& e) {
errorOut(e, "MothurOut", "appendLogBuffer");
exit(1);
}
}
/*********************************************************************************************/
void MothurOut::setLogFileName(string filename, bool append) {
try {
logFileName = filename;
Utils util;
if ((filename == "silent")) { silenceLog = true; }
else {
if (out.is_open()) { closeLog(); }
silenceLog = false;
if (append) {
util.openOutputFileAppend(filename, out);
out << "\n\n************************************************************\n\n\n";
}else { bool opendLog = util.openOutputFile(filename, out); if (!opendLog) { control_pressed = true; } }
}
}
catch(exception& e) {
errorOut(e, "MothurOut", "setFileName");
exit(1);
}
}
/*********************************************************************************************/
void MothurOut::closeLog() {
try {
if (buffer != "") { mothurOut(buffer); buffer = ""; }
if (numErrors != 0) {
if (!silenceLog) {
out << "\n\n************************************************************\n";
out << "************************************************************\n";
out << "************************************************************\n";
out << "Detected " + toString(numErrors) + " [ERROR] messages, please review.\n";
out << "************************************************************\n";
out << "************************************************************\n";
out << "************************************************************\n";
}
logger() << "\n\n************************************************************\n";
logger() << "************************************************************\n";
logger() << "************************************************************\n";
logger() << "Detected " + toString(numErrors) + " [ERROR] messages, please review.\n";
logger() << "************************************************************\n";
logger() << "************************************************************\n";
logger() << "************************************************************\n";
}
if (numWarnings != 0) {
if (!silenceLog) {
out << "\n\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n";
out << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n";
out << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n";
out << "Detected " + toString(numWarnings) + " [WARNING] messages, please review.\n";
out << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n";
out << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n";
out << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n";
}
logger() << "\n\n<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n";
logger() << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n";
logger() << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n";
logger() << "Detected " + toString(numWarnings) + " [WARNING] messages, please review.\n";
logger() << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n";
logger() << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n";
logger() << "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<^>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n";
}
out.close();
}
catch(exception& e) {
errorOut(e, "MothurOut", "closeLog");
exit(1);
}
}
/*********************************************************************************************/
MothurOut::~MothurOut() {
try {
_uniqueInstance = 0;
}
catch(exception& e) {
errorOut(e, "MothurOut", "MothurOut");
exit(1);
}
}
/*********************************************************************************************/
void MothurOut::mothurOut(string output) {
try {
if (buffer != "") { output = buffer + output; buffer = ""; }
if (output.find("[ERROR]") != string::npos) { numErrors++; }
if (output.find("[WARNING]") != string::npos) { numWarnings++; }
if (!quietMode) {
if (!silenceLog) { out << output; }
logger() << output;
}else {
//check for this being an error
if ((output.find("[ERROR]") != string::npos) || (output.find("mothur >") != string::npos)) {
if (!silenceLog) { out << output; }
logger() << output;
}
}
}
catch(exception& e) {
errorOut(e, "MothurOut", "MothurOut");
exit(1);
}
}
/*********************************************************************************************/
void MothurOut::mothurOutJustToScreen(string output) {
try {
if (buffer != "") { output = buffer + output; buffer = ""; }
if (output.find("[ERROR]") != string::npos) { numErrors++; }
if (output.find("[WARNING]") != string::npos) { numWarnings++; }
if (!quietMode) {
logger() << output;
}else {
//check for this being an error
if ((output.find("[ERROR]") != string::npos) || (output.find("mothur >") != string::npos)) {
logger() << output;
}
}
}
catch(exception& e) {
errorOut(e, "MothurOut", "MothurOut");
exit(1);
}
}
/*********************************************************************************************/
void MothurOut::mothurOutEndLine() {
try {
if (!quietMode) {
if (!silenceLog) { out << buffer << endl; }
logger() << buffer << endl;
}
buffer = "";
}
catch(exception& e) {
errorOut(e, "MothurOut", "MothurOutEndLine");
exit(1);
}
}
/*********************************************************************************************/
void MothurOut::mothurOut(string output, ofstream& outputFile) {
try {
if (buffer != "") { output = buffer + output; buffer = ""; }
if (output.find("[ERROR]") != string::npos) { numErrors++; }
if (output.find("[WARNING]") != string::npos) { numWarnings++; }
if (!quietMode) {
if (!silenceLog) { out << output; }
outputFile << output;
logger() << output;
}else {
//check for this being an error
if ((output.find("[ERROR]") != string::npos) || (output.find("mothur >") != string::npos)) {
if (!silenceLog) { out << output; }
outputFile << output;
logger() << output;
}
}
}
catch(exception& e) {
errorOut(e, "MothurOut", "MothurOut");
exit(1);
}
}
/*********************************************************************************************/
void MothurOut::mothurOutEndLine(ofstream& outputFile) {
try {
if (!quietMode) {
if (!silenceLog) { out << buffer << endl; }
logger() << buffer << endl;
outputFile << buffer << endl;
}
}
catch(exception& e) {
errorOut(e, "MothurOut", "MothurOutEndLine");
exit(1);
}
}
/*********************************************************************************************/
void MothurOut::mothurOutJustToLog(string output) {
try {
if (buffer != "") { output = buffer + output; buffer = ""; }
if (output.find("[ERROR]") != string::npos) { numErrors++; }
if (output.find("[WARNING]") != string::npos) { numWarnings++; }
if (!quietMode) {
if (!silenceLog) { out << output; }
}else {
//check for this being an error
if ((output.find("[ERROR]") != string::npos) || (output.find("mothur >") != string::npos)) {
if (!silenceLog) { out << output; }
}
}
}
catch(exception& e) {
errorOut(e, "MothurOut", "MothurOutJustToLog");
exit(1);
}
}
/*********************************************************************************************/
void MothurOut::errorOut(exception& e, string object, string function) {
numErrors++;
string errorType = toString(e.what());
int pos = errorType.find("bad_alloc");
mothurOut("[ERROR]: ");
mothurOut(errorType);
unsigned long long ramUsed, total;
Utils util;
ramUsed = util.getRAMUsed(); total = util.getTotalRAM();
mothurOut("RAM used: " + toString(ramUsed/(double)GIG) + "Gigabytes . Total Ram: " + toString(total/(double)GIG) + "Gigabytes.\n\n");
if (pos == string::npos) { //not bad_alloc
mothurOut(" has occurred in the " + object + " class function " + function + ". Please contact Pat Schloss at [email protected], and be sure to include the mothur.logFile with your inquiry.");
mothurOutEndLine();
}else { //bad alloc
if (object == "cluster"){
mothurOut(" has occurred in the " + object + " class function " + function + ". This error indicates your computer is running out of memory. There are two common causes for this, file size and format.\n\nFile Size:\nThe cluster command loads your distance matrix into RAM, and your distance file is most likely too large to fit in RAM. There are two options to help with this. The first is to use a cutoff. By using a cutoff mothur will only load distances that are below the cutoff. If that is still not enough, there is a command called cluster.split, http://www.mothur.org/wiki/cluster.split which divides the distance matrix, and clusters the smaller pieces separately. You may also be able to reduce the size of the original distance matrix by using the commands outlined in the Schloss SOP, http://www.mothur.org/wiki/Schloss_SOP. \n\nWrong Format:\nThis error can be caused by trying to read a column formatted distance matrix using the phylip parameter. By default, the dist.seqs command generates a column formatted distance matrix. To make a phylip formatted matrix set the dist.seqs command parameter output to lt. \n\nIf you are unable to resolve the issue, please contact Pat Schloss at [email protected], and be sure to include the mothur.logFile with your inquiry.");
}else if (object == "shhh.flows"){
mothurOut(" has occurred in the " + object + " class function " + function + ". This error indicates your computer is running out of memory. The shhh.flows command is very memory intensive. This error is most commonly caused by trying to process a dataset too large, using multiple processors, or failing to run trim.flows before shhh.flows. If you are running our 32bit version, your memory usage is limited to 4G. If you have more than 4G of RAM and are running a 64bit OS, using our 64bit version may resolve your issue. If you are using multiple processors, try running the command with processors=1, the more processors you use the more memory is required. Running trim.flows with an oligos file, and then shhh.flows with the file option may also resolve the issue. If for some reason you are unable to run shhh.flows with your data, a good alternative is to use the trim.seqs command using a 50-bp sliding window and to trim the sequence when the average quality score over that window drops below 35. Our results suggest that the sequencing error rates by this method are very good, but not quite as good as by shhh.flows and that the resulting sequences tend to be a bit shorter. If you are unable to resolve the issue, please contact Pat Schloss at [email protected], and be sure to include the mothur.logFile with your inquiry. ");
}else {
mothurOut(" has occurred in the " + object + " class function " + function + ". This error indicates your computer is running out of memory. This is most commonly caused by trying to process a dataset too large, using multiple processors, or a file format issue. If you are running our 32bit version, your memory usage is limited to 4G. If you have more than 4G of RAM and are running a 64bit OS, using our 64bit version may resolve your issue. If you are using multiple processors, try running the command with processors=1, the more processors you use the more memory is required. Also, you may be able to reduce the size of your dataset by using the commands outlined in the Schloss SOP, http://www.mothur.org/wiki/Schloss_SOP. If you are unable to resolve the issue, please contact Pat Schloss at [email protected], and be sure to include the mothur.logFile with your inquiry.");
}
}
}
/********************************************************************/