-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathreportsystem.h
553 lines (405 loc) · 18.4 KB
/
reportsystem.h
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
/* *****************************************************************************
trimAl v2.0: a tool for automated alignment trimming in large-scale
phylogenetics analyses.
readAl v2.0: a tool for automated alignment conversion among different
formats.
2009-2019
Fernandez-Rodriguez V. ([email protected])
Capella-Gutierrez S. ([email protected])
Gabaldon, T. ([email protected])
This file is part of trimAl/readAl.
trimAl/readAl are free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, the last available version.
trimAl/readAl are distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with trimAl/readAl. If not, see <http://www.gnu.org/licenses/>.
***************************************************************************** */
#ifndef VERBOSEMANAGER_H
#define VERBOSEMANAGER_H
#include <iostream>
#include <cstring>
#include <iomanip>
#include <vector>
#include <array>
#include <map>
/**
* \brief VerboseLevel used to report messages.
*/
enum VerboseLevel {
/// 1 = Info, warning and error messages
INFO = 1,
/// 2 = Error and warning messages
WARNING = 2,
/// 3 = Only error messages
ERROR = 3,
/// 4 = No output messages
NONE = 4,
};
enum ErrorCode {
SomethingWentWrong_reportToDeveloper = 0,
AlignmentNotLoaded = 1,
NoFormatsSpecified = 2,
AlternativeMatrixNotRecognized = 3,
ReferenceFileNotLoaded = 4,
GapThresholdOutOfRange = 5,
GapThresholdNotRecognized = 6,
SimilarityThresholdOutOfRange = 7,
SimilarityThresholdNotRecognized = 8,
ConsistencyThresholdOutOfRange = 9,
ConsistencyThresholdNotRecognized = 10,
ConservationThresholdOutOfRange = 11,
ConservationThresholdNotRecognized = 12,
ResidueOverlapOutOfRange = 13,
ResidueOverlapNotRecognized = 14,
SequencesOverlapOutOfRange = 15,
SequencesOverlapNotRecognized = 16,
MaxIdentityOutOfRange = 17,
MaxIdentityNotRecognized = 18,
ClustersValueOutOfRange = 19,
ClustersValueNotRecognized = 20,
WindowValueOutOfRange = 21,
WindowValueNotRecognized = 22,
SelectSeqsNotRecognized = 23,
SelectColsNotRecognized = 24,
GapWindowValueOutOfRange = 25,
GapWindowValueNotRecognized = 26,
SimilarityWindowValueOutOfRange = 27,
SimilarityWindowValueNotRecognized = 28,
ConsistencyWindowValueOutOfRange = 27,
ConsistencyWindowValueNotRecognized = 28,
BlockSizeOutOfRange = 29,
BlockSizeNotRecognized = 30,
InFileComparisonStatistics = 31,
IncompatibleArguments = 32,
SelectSeqsResAndThresholdIncompatibilities = 33,
SelectSeqsResAndAutomathedMethodsIncompatibilities = 34,
SelectSeqsResAndWindowIncompatibilities = 35,
SelectSeqsResAndOverlapIncompatibilites = 36,
OnlyOneSequencesSelectionMethodAllowed = 37,
CombinationAmongTrimmingMethods = 38,
AutomathicMethodAndBlock = 39,
WindowAndArgumentIncompatibilities = 40,
CombinationAmongThresholdsMethods = 41,
GeneralAndSpecificWindows = 42,
StatisticsArgumentIncompatibilities = 43,
TrimmingMethodNeeded = 44,
ForceFileWithoutCompareDataset = 45,
BacktranslationWithoutMainAlignment = 46,
NotAligned = 47,
MatrixGivenWithNoMethodToUseIt = 48,
SameNameOutput = 49,
SequenceAndResiduesOverlapMutuallyNeeded = 50,
OutFileNeededWhenPrintingStatistics = 51,
AlignmentTypesNotMatching = 52,
BlocksizeTooBig = 53,
ParemeterOnlyOnBacktranslation = 54,
ProteinAlignmentMustBeAligned = 55,
BacktransAlignIsDNA = 56,
ImpossibleToGenerate = 57,
ImpossibleToProcessMatrix = 58,
SelectOnlyAccepts = 59,
MoreClustersThanSequences = 60,
LeftBoundaryBiggerThanRightBoundary = 61,
DifferentNumberOfSequencesInCompareset = 62,
DifferentSeqsNamesInCompareset = 63,
CDScontainsProteinSequences = 64,
SequenceContainsGap = 65,
SequenceNotMultipleOfThree = 66,
SequenceHasStopCodon = 67,
SequenceNotPresentInCDS = 68,
UnknownCharacter = 69,
SequencesNotSameSize = 70,
IncorrectSymbol = 71,
UndefinedSymbol = 72,
ParameterNotFoundOrRepeated = 73,
SimilarityMatrixNotCompatibleWindow = 74,
PossibleMissmatch = 75,
BracketsMissmatchFound = 76,
UnalignedAlignmentToAlignedFormat = 77,
CantOpenFile = 78,
FileIsEmpty = 79,
AlignmentFormatNotRecognized = 80,
OutputFormatNotRecognized = 81,
OnlyOneFormatOnConsoleOutput = 82,
AlignmentNotSaved = 83,
VerboseLevelNotRecognized = 84,
NeedToSpecifyVerboseLevel = 85,
NoReferenceSequenceForContig = 86,
SNPoutOfBounds = 87,
NoInputFile = 88,
ComparesetFailedAlignmentMissing = 89,
GapWindowTooBig = 90,
SimilarityWindowTooBig = 91,
ConsistencyWindowTooBig = 92,
WindowTooBig = 93,
AlignmentIsEmpty = 94,
AlignmentTypeIsUnknown = 95,
MultipleOutputFormatsSameName = 96,
MultipleInputs = 97, // Not in use
ReferenceNucleotideNotCorresponding = 98,
OverwrittingSNP = 99,
MoreDonorsOnLineThanPresented = 100,
MinQualityLesserThan0 = 101,
MinQualityNotRecognized = 102,
MinCoverageLesserThan0 = 103,
MinCoverageNotRecognized = 104,
OnlyValidWithVCF = 105,
TriedRenamingOutputPreventOverride = 106,
AbsoluteAndRelativeGapThreshold = 107,
AbsoluteGapThresholdLessThanZero = 108,
AbsoluteGapThresholdBiggerThanNumberOfSequences = 109,
AbsoluteGapThresholdNotRecognized = 110,
MoreThanOneAutomatedMethod = 111,
ForceSelectAndInArgumentsProvided = 108,
ComparesetAndInArgumentsProvided = 109,
__MAXERROR,
};
enum WarningCode {
RemovingOnlyGapsSequence = 1,
KeepingOnlyGapsSequence = 2,
SequenceWillBeCut = 3,
IncludingIndeterminationSymbols = 4,
LessNucleotidesThanExpected = 5,
HeaderWillBeCut = 6,
DonorAlreadyAdded = 7,
SNPAlreadApplied = 8,
OverwrittingFile = 9,
RenamingOutputPreventOverride = 10,
IndeterminateAlignmentType = 11,
DegenerateNucleotides = 12,
AmbiguousResidues = 13,
AlternativeAminoAcids = 14,
__MAXWARNING
};
enum InfoCode {
CuttingSequence = 1,
WindowSizeCompareset = 2,
AddingSNP = 3,
RemovingDuplicateSequences = 4,
UsingPlatform = 5,
__MAXINFO
};
/// \brief Internal classes to handle reporting to user in several ways.\n
/// The reporting system is made so a developer that wants to use the system
/// doesn't need to enter to the namespace, but use the global variable #debug
namespace reporting {
/**
\brief Internal class used by reporting::reportManager \n
This class serves as a proxy for message reporting. \n
It will only output to std::cout if
reporting::reportWrapper::CanReport it's true
*/
class reportWrapper {
/// \brief Variable that specifies if the object is able to output to cout or not.
bool CanReport;
public:
/// \brief Constructor
explicit reportWrapper(bool CanReport) : CanReport{CanReport} { }
/// \brief Overloaded operator that allows to use this object as
/// it was an iostream, as cout.
template <typename T>
reportWrapper &operator<<(const T &a) {
if (CanReport)
std::cout<<a;
return *this;
}
/// \brief Overloaded operator that allows to use this object as
/// it was an iostream, as cout.
reportWrapper &operator<<(std::ostream& (*pf) (std::ostream&)) {
if (CanReport)
std::cout<<pf;
return *this;
}
};
/**
\brief Class that allows us to centralize all the reporting messages that
should be used to inform the user of Errors, Warnings and Info.\n
The object can also be used as a substitute to cout for temporal messages using
the << overloaded operator or the \link reportManager::log log \endlink method,
and the messages will be behind the IsDebug variable,
which should be set to false in Release.\n
This allows us to protect the user from receiving Debug/Developing messages
that shouldn't bother them, in case any of them is not removed by error.
\warning <b> THIS CLASS SHOULDN'T BE USED DIRECTLY </b> \n
Use instanced global variable \link debug debug \endlink instead.
*/
class reportManager
{
private:
/** \brief Object that will be returned by
\link reporting::reportManager::log log \endlink
if it allows to output the message
*/
reportWrapper canReport = reportWrapper(true);
/** \brief Object that will be returned by
* \link reporting::reportManager::log log \endlink
* if it doesn't allow to output the message
* */
reportWrapper cantReport = reportWrapper(false);
static const std::map<InfoCode, const char *> InfoMessages ;
static const std::map<WarningCode, const char *> WarningMessages ;
static const std::map<ErrorCode, const char *> ErrorMessages ;
public:
/** \brief Level of Verbosity.\n
* The report system won't output messages
* that are lower than the current level */
VerboseLevel Level = VerboseLevel::INFO;
/** \brief Protection variable.
This variable should be set to true while in development,
and false on Release. */
bool IsDebug = false;
/**
\brief Method to print all Info, Warning and Error codes
and their respective message.\n
This method is useful to check whether all codes
have a message linked to them.
It will use the current VerboseLevel of the object,
which defaults to ERROR level.
*/
void PrintCodesAndMessages();
/**
\brief Method to report an Error. \n
It will be displayed if
\link reporting::reportManager::Level Level \endlink
is equal or higher to VerboseLevel::ERROR
\param message
Code to report.
\param vars
Array of strings that will replace the '[tags]' in the message.\n
The number of elements in the array must be the same as
[tag] occurrences on the message.\n
<b> The method will take care of destroying the array </b>
*/
void report(ErrorCode message, std::string * vars = nullptr);
/**
\brief Method to report an Error.\n
It will be displayed if
\link reporting::reportManager::Level Level \endlink
is equal or higher to VerboseLevel::ERROR
\param message
Code to report.
\param vars
Array of chars that will replace the first occurrence of
'[tags]' in the message. \n
<b> The method wont take care of destroying the array </b>\n
This allows to reuse the parameter passed.
*/
void report(ErrorCode message, const char *vars);
/**
\brief Method to report a Warning. \n
It will be displayed if
\link reporting::reportManager::Level Level \endlink
is equal or higher to VerboseLevel::WARNING
\param message
Code to report.
\param vars
Array of strings that will replace the '[tags]' in the message.\n
The number of elements in the array must be the same as
[tag] occurrences on the message.\n
<b> The method will take care of destroying the array </b>
*/
void report(WarningCode message, std::string * vars = nullptr);
/**
\brief Method to report a Warning.\n
It will be displayed if
\link reporting::reportManager::Level Level \endlink
is equal or higher to VerboseLevel::WARNING
\param message
Code to report.
\param vars
Array of chars that will replace the first occurrence of
'[tags]' in the message. \n
<b> The method wont take care of destroying the array </b>\n
This allows to reuse the parameter passed.
*/
void report(WarningCode message, const char *vars);
/**
\brief Method to report an Info message. \n
It will be displayed if
\link reporting::reportManager::Level Level \endlink
is equal or higher to VerboseLevel::INFO
\param message
Code to report.
\param vars
Array of strings that will replace the '[tags]' in the message.\n
The number of elements in the array must be the same as
[tag] occurrences on the message.\n
<b> The method will take care of destroying the array </b>
*/
void report(InfoCode message, std::string * vars = nullptr);
/**
\brief Method to report an Info message.\n
It will be displayed if
\link reporting::reportManager::Level Level \endlink
is equal or higher to VerboseLevel::WARNING
\param message
Code to report.
\param vars
Array of chars that will replace the first occurrence of
'[tags]' in the message. \n
<b> The method wont take care of destroying the array </b>\n
This allows to reuse the parameter passed.
*/
void report(InfoCode message, const char *vars);
/**
\brief Method to output a message behind two checks:
\link reporting::reportManager::IsDebug IsDebug \endlink
and VerboseLevel passed.\n
If \link reporting::reportManager::IsDebug IsDebug \endlink is false,
it will ignore the message returning the
\link reporting::reportManager::cantReport cantReport \endlink,
otherwise, VerboseLevel level will be checked.
\param level
Level to use for this message.\n
If \link reporting::reportManager::Level Level \endlink is higher
than this argument, message will be ignored,
otherwise, message will be outputted to cout.
*/
reportWrapper log(VerboseLevel level)
{
if (!IsDebug) return cantReport;
if (level >= Level)
return canReport;
else
return cantReport;
}
/**
\brief Overloaded operator that allows us to debug some messages behind
\link reporting::reportManager::IsDebug IsDebug \endlink
\param a
Message to be outputed if
\link reporting::reportManager::IsDebug IsDebug \endlink
*/
template <typename T>
reportManager &operator<<(const T &a) {
if (IsDebug)
std::cout<<a;
return *this;
}
/**
\brief Overloaded operator that allows us to debug some messages behind
\link reporting::reportManager::IsDebug IsDebug \endlink
\param pf
Object that overloads the '<<' operator
*/
reportManager &operator<<(std::ostream& (*pf) (std::ostream&)) {
if (IsDebug)
std::cout<<pf;
return *this;
}
};
}
/** \brief <b> This instance is the one that should be used</b> \n
* It's use is similar to a singleton, without the need to obtain
* the instance every time it's needed.\n
* Instead, it's a global instance of the reporting::reportManager \n
* This allows us to have the '<<' operator overloaded,
* as it can't be statically overloaded.
\relates reporting::reportManager
*/
extern reporting::reportManager debug;
#endif // VERBOSEMANAGER_H