Skip to content

Commit 26733ca

Browse files
author
Stephan Schiffels
committed
added some error messages for data input format problems in model/data.d
1 parent ca88bd3 commit 26733ca

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ testcoverage : model/*.d unittest.d powell.d brent.d maximization_step.d expecta
2828
build/unittest
2929
mv *.lst code_coverage/
3030

31-
unittest : model/*.d unittest.d powell.d brent.d maximization_step.d expectation_step.d amoeba.d logger.d branchlength.d
31+
unittest : model/*.d unittest.d powell.d brent.d maximization_step.d expectation_step.d logger.d branchlength.d
3232
dmd -unittest ${GSL} -odbuild -ofbuild/unittest $^
3333
build/unittest
3434

maximization_step.d

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ unittest {
241241
auto minFunc = new MinFunc(expectationResultVec, expectationResultMat, params, timeSegmentPattern, false, false);
242242
auto rho = 0.001;
243243
auto x = minFunc.getXfromLambdaVec(lambdaVec);
244-
x ~= minFunc.getXfromRecombinationRate(rho);
244+
x ~= log(rho);
245245
auto lambdaFromX = minFunc.getLambdaVecFromX(x);
246246
auto rhoFromX = minFunc.getRecombinationRateFromX(x);
247247
foreach(i; 0 .. lambdaVec.length)
@@ -250,7 +250,7 @@ unittest {
250250

251251
minFunc = new MinFunc(expectationResultVec, expectationResultMat, params, timeSegmentPattern, true, false);
252252
x = minFunc.getXfromLambdaVec(lambdaVec);
253-
x ~= minFunc.getXfromRecombinationRate(rho);
253+
x ~= log(rho);
254254
lambdaFromX = minFunc.getLambdaVecFromXfixedPop(x);
255255
rhoFromX = minFunc.getRecombinationRateFromX(x);
256256
foreach(i; 0 .. lambdaVec.length)

model/data.d

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,26 +114,27 @@ unittest {
114114
assert(normalizeAlleleString("TC") == "01");
115115
}
116116

117-
void checkDataLine(const char[] line) {
118-
auto r = regex(r"^\w+\s\d+\s\d+(\s[ACTG01\?,]+){0,1}$");
119-
enforce(match(line, r));
120-
}
121-
122-
unittest {
123-
assertThrown(checkDataLine("1 20 5 AACC,AACA 2.44"));
124-
assertNotThrown(checkDataLine("1 20 5 AACC"));
125-
assertNotThrown(checkDataLine("4 5 2"));
126-
assertNotThrown(checkDataLine("1 10 5 ACC"));
127-
assertThrown(checkDataLine("1 20 5 AGGSSXX"));
128-
}
117+
// void checkDataLine(const char[] line) {
118+
// auto r = regex(r"^\w+\s\d+\s\d+(\s[ACTG01\?,]+){0,1}$");
119+
// enforce(match(line, r));
120+
// }
121+
//
122+
// unittest {
123+
// assertThrown(checkDataLine("1 20 5 AACC,AACA 2.44"));
124+
// assertNotThrown(checkDataLine("1 20 5 AACC"));
125+
// assertNotThrown(checkDataLine("4 5 2"));
126+
// assertNotThrown(checkDataLine("1 10 5 ACC"));
127+
// assertThrown(checkDataLine("1 20 5 AGGSSXX"));
128+
// }
129129

130130
size_t getNrHaplotypesFromFile(string filename) {
131131
auto file = File(filename, "r");
132132
scope(exit) file.close();
133133
auto line = file.readln();
134134
line = line.strip();
135-
checkDataLine(line);
135+
// checkDataLine(line);
136136
auto fields = line.strip().split();
137+
enforce(fields.length > 2, "illegal input file");
137138
if(fields.length < 4)
138139
return 2;
139140
else {
@@ -178,11 +179,17 @@ SegSite_t[] readSegSites(string filename, bool directedEmissions, size_t[] indic
178179

179180
auto f = File(filename, "r");
180181
long lastPos = -1;
182+
auto chrom = "";
181183
foreach(line; f.byLine()) {
182184
// checkDataLine(line.strip());
183185
auto fields = line.strip().split();
186+
if(chrom == "")
187+
chrom = fields[0].idup;
188+
else
189+
enforce(chrom == fields[0], "chromosomes must all be the same within one file (sorry)");
184190
auto pos = to!size_t(fields[1]);
185191
auto nrCalledSites = to!size_t(fields[2]);
192+
enforce(nrCalledSites > 0, "nr of called sites (3rd column in input file) must be always > 0");
186193
if(lastPos == -1) {
187194
lastPos = pos - nrCalledSites;
188195
}

unittest.d

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import powell;
3838
import brent;
3939
import maximization_step;
4040
import expectation_step;
41-
import amoeba;
4241
import branchlength;
4342

4443
void main() {

0 commit comments

Comments
 (0)