Skip to content

Commit

Permalink
added some error messages for data input format problems in model/data.d
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephan Schiffels committed Jan 23, 2015
1 parent ca88bd3 commit 26733ca
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ testcoverage : model/*.d unittest.d powell.d brent.d maximization_step.d expecta
build/unittest
mv *.lst code_coverage/

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

Expand Down
4 changes: 2 additions & 2 deletions maximization_step.d
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ unittest {
auto minFunc = new MinFunc(expectationResultVec, expectationResultMat, params, timeSegmentPattern, false, false);
auto rho = 0.001;
auto x = minFunc.getXfromLambdaVec(lambdaVec);
x ~= minFunc.getXfromRecombinationRate(rho);
x ~= log(rho);
auto lambdaFromX = minFunc.getLambdaVecFromX(x);
auto rhoFromX = minFunc.getRecombinationRateFromX(x);
foreach(i; 0 .. lambdaVec.length)
Expand All @@ -250,7 +250,7 @@ unittest {

minFunc = new MinFunc(expectationResultVec, expectationResultMat, params, timeSegmentPattern, true, false);
x = minFunc.getXfromLambdaVec(lambdaVec);
x ~= minFunc.getXfromRecombinationRate(rho);
x ~= log(rho);
lambdaFromX = minFunc.getLambdaVecFromXfixedPop(x);
rhoFromX = minFunc.getRecombinationRateFromX(x);
foreach(i; 0 .. lambdaVec.length)
Expand Down
33 changes: 20 additions & 13 deletions model/data.d
Original file line number Diff line number Diff line change
Expand Up @@ -114,26 +114,27 @@ unittest {
assert(normalizeAlleleString("TC") == "01");
}

void checkDataLine(const char[] line) {
auto r = regex(r"^\w+\s\d+\s\d+(\s[ACTG01\?,]+){0,1}$");
enforce(match(line, r));
}

unittest {
assertThrown(checkDataLine("1 20 5 AACC,AACA 2.44"));
assertNotThrown(checkDataLine("1 20 5 AACC"));
assertNotThrown(checkDataLine("4 5 2"));
assertNotThrown(checkDataLine("1 10 5 ACC"));
assertThrown(checkDataLine("1 20 5 AGGSSXX"));
}
// void checkDataLine(const char[] line) {
// auto r = regex(r"^\w+\s\d+\s\d+(\s[ACTG01\?,]+){0,1}$");
// enforce(match(line, r));
// }
//
// unittest {
// assertThrown(checkDataLine("1 20 5 AACC,AACA 2.44"));
// assertNotThrown(checkDataLine("1 20 5 AACC"));
// assertNotThrown(checkDataLine("4 5 2"));
// assertNotThrown(checkDataLine("1 10 5 ACC"));
// assertThrown(checkDataLine("1 20 5 AGGSSXX"));
// }

size_t getNrHaplotypesFromFile(string filename) {
auto file = File(filename, "r");
scope(exit) file.close();
auto line = file.readln();
line = line.strip();
checkDataLine(line);
// checkDataLine(line);
auto fields = line.strip().split();
enforce(fields.length > 2, "illegal input file");
if(fields.length < 4)
return 2;
else {
Expand Down Expand Up @@ -178,11 +179,17 @@ SegSite_t[] readSegSites(string filename, bool directedEmissions, size_t[] indic

auto f = File(filename, "r");
long lastPos = -1;
auto chrom = "";
foreach(line; f.byLine()) {
// checkDataLine(line.strip());
auto fields = line.strip().split();
if(chrom == "")
chrom = fields[0].idup;
else
enforce(chrom == fields[0], "chromosomes must all be the same within one file (sorry)");
auto pos = to!size_t(fields[1]);
auto nrCalledSites = to!size_t(fields[2]);
enforce(nrCalledSites > 0, "nr of called sites (3rd column in input file) must be always > 0");
if(lastPos == -1) {
lastPos = pos - nrCalledSites;
}
Expand Down
1 change: 0 additions & 1 deletion unittest.d
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ import powell;
import brent;
import maximization_step;
import expectation_step;
import amoeba;
import branchlength;

void main() {
Expand Down

0 comments on commit 26733ca

Please sign in to comment.