-
Notifications
You must be signed in to change notification settings - Fork 10
/
exceptions.hpp
251 lines (201 loc) · 6.58 KB
/
exceptions.hpp
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
/*
* dEploid is used for deconvoluting Plasmodium falciparum genome from
* mix-infected patient sample.
*
* Copyright (C) 2016-2017 University of Oxford
*
* Author: Sha (Joe) Zhu
*
* This file is part of dEploid.
*
* dEploid is 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, either version 3 of the License, or
* (at your option) any later version.
*
* This program is 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include <string> /* string */
#include <exception>
#ifndef EXCEPTION
#define EXCEPTION
// using namespace std;
using std::string;
using std::ifstream;
using std::stoi;
struct ShouldNotBeCalled : std::exception{
ShouldNotBeCalled() { }
virtual ~ShouldNotBeCalled() throw() {}
virtual const char* what() const noexcept {
return "Should not reach here";
}
};
struct VirtualFunctionShouldNotBeCalled : public ShouldNotBeCalled{
VirtualFunctionShouldNotBeCalled():ShouldNotBeCalled() {}
~VirtualFunctionShouldNotBeCalled() throw() {}
};
struct InvalidInput : std::exception {
string src;
string reason;
string throwMsg;
InvalidInput() {
this->src = "";
this->reason = "";
}
explicit InvalidInput(string str) {
this->src = "\033[1;31m" + str + "\033[0m";
this->reason = "";
}
virtual ~InvalidInput() throw() {}
virtual const char* what() const noexcept {
return throwMsg.c_str();
}
};
struct OutOfVectorSize : std::exception{
OutOfVectorSize() { }
virtual ~OutOfVectorSize() throw() {}
virtual const char* what() const noexcept {
return "Out of vector size!";
}
};
struct InvalidK : public InvalidInput{
InvalidK():InvalidInput() {
this->reason = "k must be at least 2, when using the flag -ibd.";
throwMsg = this->reason + this->src;
}
~InvalidK() throw() {}
};
struct PositionUnsorted : public InvalidInput{
explicit PositionUnsorted(string str):InvalidInput(str) {
this->reason = "Position (POS) not sorted in ";
throwMsg = this->reason + this->src;
}
~PositionUnsorted() throw() {}
};
struct NotEnoughArg : public InvalidInput{
explicit NotEnoughArg(string str):InvalidInput(str) {
this->reason = "Not enough parameters when parsing option: ";
throwMsg = this->reason + this->src;
}
~NotEnoughArg() throw() {}
};
struct VcfOutUnSpecified : public InvalidInput{
explicit VcfOutUnSpecified(string str):InvalidInput(str) {
this->reason = "Missing flag \"-vcfOut\".";
throwMsg = this->reason + this->src;
}
~VcfOutUnSpecified() throw() {}
};
struct WrongType : public InvalidInput{
explicit WrongType(string str):InvalidInput(str) {
this->reason = "Wrong type for parsing: ";
throwMsg = this->reason + this->src;
}
~WrongType() throw() {}
};
struct InvalidSampleInVcf : public InvalidInput{
explicit InvalidSampleInVcf(string sample, string vcf):InvalidInput(sample) {
this->reason = "Invalid sample name: ";
throwMsg = this->reason + this->src + " in " + vcf;
}
~InvalidSampleInVcf() throw() {}
};
struct BadScientificNotation : public InvalidInput{
explicit BadScientificNotation(string str1, string str2):InvalidInput(str1) {
this->reason = "Bad scientific notation: ";
throwMsg = this->reason + this->src +
", int expected. Check input file" + str2;
}
~BadScientificNotation() throw() {}
};
struct BadConversion : public InvalidInput{
explicit BadConversion(string str1, string str2):InvalidInput(str1) {
this->reason = "Bad conversion: ";
throwMsg = this->reason + this->src +
", int expected. Check input file" + str2;
}
~BadConversion() throw() {}
};
struct InvalidInputFile : public InvalidInput{
explicit InvalidInputFile(string str):InvalidInput(str) {
this->reason = "Invalid input file: ";
throwMsg = this->reason + this->src;
}
~InvalidInputFile() throw() {}
};
struct FileNameMissing : public InvalidInput{
explicit FileNameMissing(string str):InvalidInput(str) {
this->reason = " file path missing!";
throwMsg = this->src + this->reason;
}
~FileNameMissing() throw() {}
};
struct UnknowArg : public InvalidInput{
explicit UnknowArg(string str):InvalidInput(str) {
this->reason = "Unknow option: ";
throwMsg = this->reason + this->src;
}
~UnknowArg() throw() {}
};
struct FlagsConflict : public InvalidInput{
explicit FlagsConflict(string str1, string str2):InvalidInput(str1) {
this->reason = "Flag: ";
throwMsg = this->reason + this->src + string(" conflict with flag ") + str2;
}
~FlagsConflict() throw() {}
};
struct FlagsOrderIncorrect : public InvalidInput{
// -plafFromVcf after -vcf
// -sample after -vcf
explicit FlagsOrderIncorrect(string str1, string str2):InvalidInput(str1) {
this->reason = "Flag: ";
throwMsg = this->reason + this->src +
string(" should be used after flag ") + str2;
}
~FlagsOrderIncorrect() throw() {}
};
struct OutOfRange : public InvalidInput{
explicit OutOfRange(string str1, string str2):InvalidInput(str1) {
this->reason = "Flag \"";
throwMsg = this->reason + this->src + string(" ") +
str2 + string("\" out of range [0, 1].");
}
~OutOfRange() throw() {}
};
struct LociNumberUnequal : public InvalidInput{
explicit LociNumberUnequal(string str):InvalidInput(str) {
this->reason = "Number of sites was wrong (compared to ref count) in: ";
throwMsg = this->reason + this->src;
}
~LociNumberUnequal() throw() {}
};
struct SumOfPropNotOne : public InvalidInput{
explicit SumOfPropNotOne(string str):InvalidInput(str) {
this->reason = "Sum of initial proportion is not equal to 1, but equals ";
throwMsg = this->reason + this->src;
}
~SumOfPropNotOne() throw() {}
};
struct NumOfPropNotMatchNumStrain : public InvalidInput{
explicit NumOfPropNotMatchNumStrain(string str):InvalidInput(str) {
this->reason =
"Number of initial proportion do not match number of strains!";
throwMsg = this->reason + this->src;
}
~NumOfPropNotMatchNumStrain() throw() {}
};
struct InitialPropUngiven : public InvalidInput{
explicit InitialPropUngiven(string str):InvalidInput(str) {
this->reason = "Initial proportion was not specified.";
throwMsg = this->reason + this->src;
}
~InitialPropUngiven() throw() {}
};
#endif