• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DEploid-dev / DEploid / 11997530747

24 Nov 2024 03:51PM UTC coverage: 86.156% (-1.2%) from 87.329%
11997530747

push

github

web-flow
Merge pull request #368 from DEploid-dev/use_vcf_lib

Use vcf lib

5539 of 6429 relevant lines covered (86.16%)

5308376.72 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

73.49
/src/exceptions.hpp
1
/*
2
 * dEploid is used for deconvoluting Plasmodium falciparum genome from
3
 * mix-infected patient sample.
4
 *
5
 * Copyright (C) 2016-2017 University of Oxford
6
 *
7
 * Author: Sha (Joe) Zhu
8
 *
9
 * This file is part of dEploid.
10
 *
11
 * dEploid is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU General Public License as published by
13
 * the Free Software Foundation, either version 3 of the License, or
14
 * (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25

26

27
#include <string>  /* string */
28
#include <exception>
29

30
#ifndef EXCEPTION
31
#define EXCEPTION
32

33
// using namespace std;
34
using std::string;
35
using std::ifstream;
36
using std::stoi;
37

38
struct ShouldNotBeCalled : std::exception{
39
  ShouldNotBeCalled() { }
40
  virtual ~ShouldNotBeCalled() throw() {}
41
  virtual const char* what() const noexcept {
×
42
      static const std::string msg = "Should not reach here";
×
43
      return msg.c_str();
×
44
  }
45
};
46

47

48
struct VirtualFunctionShouldNotBeCalled : public ShouldNotBeCalled{
49
  VirtualFunctionShouldNotBeCalled():ShouldNotBeCalled() {}
50
  ~VirtualFunctionShouldNotBeCalled() throw() {}
51
};
52

53

54
struct InvalidInput : std::exception {
55
  string src;
56
  string reason;
57
  string throwMsg;
58

59
  InvalidInput() {
2✔
60
    this->src      = "";
61
    this->reason   = "";
62
  }
2✔
63

64
  explicit InvalidInput(string str) {
56✔
65
    this->src      = "\033[1;31m" + str + "\033[0m";
112✔
66
    this->reason   = "";
67
  }
56✔
68
  virtual ~InvalidInput() throw() {}
116✔
69
  virtual const char* what() const noexcept {
3✔
70
      return throwMsg.c_str();
3✔
71
  }
72
};
73

74

75
struct OutOfVectorSize : std::exception{
76
  OutOfVectorSize() { }
4✔
77
  virtual ~OutOfVectorSize() throw() {}
4✔
78
  virtual const char* what() const noexcept {
×
79
    static const std::string msg = "Out of vector size!";
×
80
      return msg.c_str();
×
81
  }
82
};
83

84

85
struct InvalidK : public InvalidInput{
86
  InvalidK():InvalidInput() {
2✔
87
    this->reason = "k must be at least 2, when using the flag -ibd.";
2✔
88
    throwMsg = this->reason + this->src;
2✔
89
  }
2✔
90
  ~InvalidK() throw() {}
2✔
91
};
92

93

94
struct PositionUnsorted : public InvalidInput{
95
  explicit PositionUnsorted(string str):InvalidInput(str) {
96
    this->reason = "Position (POS) not sorted in ";
97
    throwMsg = this->reason + this->src;
98
  }
99
  ~PositionUnsorted() throw() {}
100
};
101

102

103
struct NotEnoughArg : public InvalidInput{
104
  explicit NotEnoughArg(string str):InvalidInput(str) {
16✔
105
    this->reason = "Not enough parameters when parsing option: ";
16✔
106
    throwMsg = this->reason + this->src;
16✔
107
  }
16✔
108
  ~NotEnoughArg() throw() {}
16✔
109
};
110

111

112
struct VcfOutUnSpecified : public InvalidInput{
113
  explicit VcfOutUnSpecified(string str):InvalidInput(str) {
1✔
114
    this->reason = "Missing flag \"-vcfOut\".";
1✔
115
    throwMsg = this->reason + this->src;
1✔
116
  }
1✔
117
  ~VcfOutUnSpecified() throw() {}
1✔
118
};
119

120

121
struct WrongType : public InvalidInput{
122
  explicit WrongType(string str):InvalidInput(str) {
5✔
123
    this->reason = "Wrong type for parsing: ";
5✔
124
    throwMsg = this->reason + this->src;
5✔
125
  }
5✔
126
  ~WrongType() throw() {}
5✔
127
};
128

129

130
struct InvalidSampleInVcf : public InvalidInput{
131
  explicit InvalidSampleInVcf(string sample, string vcf):InvalidInput(sample) {
132
    this->reason = "Invalid sample name: ";
133
    throwMsg = this->reason + this->src + " in " + vcf;
134
  }
135
  ~InvalidSampleInVcf() throw() {}
136
};
137

138

139
struct BadScientificNotation : public InvalidInput{
140
  explicit BadScientificNotation(string str1, string str2):InvalidInput(str1) {
141
    this->reason = "Bad scientific notation: ";
142
    throwMsg = this->reason + this->src +
143
      ", int expected. Check input file" + str2;
144
  }
145
  ~BadScientificNotation() throw() {}
146
};
147

148

149
struct BadConversion : public InvalidInput{
150
  explicit BadConversion(string str1, string str2):InvalidInput(str1) {
151
    this->reason = "Bad conversion: ";
152
    throwMsg = this->reason + this->src +
153
      ", int expected. Check input file" + str2;
154
  }
155
  ~BadConversion() throw() {}
156
};
157

158

159
struct InvalidInputFile : public InvalidInput{
160
  explicit InvalidInputFile(string str):InvalidInput(str) {
161
    this->reason = "Invalid input file: ";
162
    throwMsg = this->reason + this->src;
163
  }
164
  ~InvalidInputFile() throw() {}
165
};
166

167

168
struct FileNameMissing : public InvalidInput{
169
  explicit FileNameMissing(string str):InvalidInput(str) {
7✔
170
    this->reason = " file path missing!";
7✔
171
    throwMsg = this->src + this->reason;
7✔
172
  }
7✔
173
  ~FileNameMissing() throw() {}
7✔
174
};
175

176

177
struct UnknowArg : public InvalidInput{
178
  explicit UnknowArg(string str):InvalidInput(str) {
1✔
179
    this->reason = "Unknow option: ";
1✔
180
    throwMsg = this->reason + this->src;
1✔
181
  }
1✔
182
  ~UnknowArg() throw() {}
1✔
183
};
184

185

186
struct FlagsConflict : public InvalidInput{
187
  explicit FlagsConflict(string str1, string str2):InvalidInput(str1) {
16✔
188
    this->reason = "Flag: ";
16✔
189
    throwMsg = this->reason + this->src + string(" conflict with flag ") + str2;
32✔
190
  }
16✔
191
  ~FlagsConflict() throw() {}
16✔
192
};
193

194

195
struct FlagsOrderIncorrect : public InvalidInput{
196
  // -plafFromVcf after -vcf
197
  // -sample after -vcf
198
  explicit FlagsOrderIncorrect(string str1, string str2):InvalidInput(str1) {
×
199
    this->reason = "Flag: ";
×
200
    throwMsg = this->reason + this->src +
×
201
      string(" should be used after flag ") + str2;
×
202
  }
×
203
  ~FlagsOrderIncorrect() throw() {}
×
204
};
205

206

207
struct OutOfRange : public InvalidInput{
208
  explicit OutOfRange(string str1, string str2):InvalidInput(str1) {
3✔
209
    this->reason = "Flag \"";
3✔
210
    throwMsg = this->reason + this->src + string(" ") +
6✔
211
      str2 + string("\" out of range [0, 1].");
9✔
212
  }
3✔
213
  ~OutOfRange() throw() {}
3✔
214
};
215

216

217
struct LociNumberUnequal : public InvalidInput{
218
  explicit LociNumberUnequal(string str):InvalidInput(str) {
×
219
    this->reason = "Number of sites was wrong (compared to ref count) in: ";
×
220
    throwMsg = this->reason + this->src;
×
221
  }
×
222
  ~LociNumberUnequal() throw() {}
×
223
};
224

225

226
struct SumOfPropNotOne : public InvalidInput{
227
  explicit SumOfPropNotOne(string str):InvalidInput(str) {
2✔
228
    this->reason = "Sum of initial proportion is not equal to 1, but equals ";
2✔
229
    throwMsg = this->reason + this->src;
2✔
230
  }
2✔
231
  ~SumOfPropNotOne() throw() {}
2✔
232
};
233

234

235
struct NumOfPropNotMatchNumStrain : public InvalidInput{
236
  explicit NumOfPropNotMatchNumStrain(string str):InvalidInput(str) {
2✔
237
    this->reason =
238
      "Number of initial proportion do not match number of strains!";
2✔
239
    throwMsg = this->reason + this->src;
2✔
240
  }
2✔
241
  ~NumOfPropNotMatchNumStrain() throw() {}
2✔
242
};
243

244

245
struct InitialPropUngiven : public InvalidInput{
246
  explicit InitialPropUngiven(string str):InvalidInput(str) {
×
247
    this->reason = "Initial proportion was not specified.";
×
248
    throwMsg = this->reason + this->src;
×
249
  }
×
250
  ~InitialPropUngiven() throw() {}
×
251
};
252

253
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc