1 #include "Bias.h"
2 #include "convert.h"
3 
open(string & file)4 void Bias::open(string& file) {
5 
6     ifstream input;
7     input.open(file.c_str());
8     if (!input.is_open()) {
9         cerr << "allele reference bias description " << file << " is not open" << endl;
10         exit(1);
11     }
12 
13     string line;
14     bool firstrecord = true;
15     int last;
16     while (std::getline(input, line)) {
17         vector<string> fields = split(line, " \t");
18         if (firstrecord) {
19             convert(fields[0], minLength);
20             last = minLength - 1;
21         }
22         convert(fields[0], maxLength);
23         if (maxLength != last + 1) {
24             cerr << "gap or out-of-order bias list in " << file << endl;
25             cerr << line << endl;
26             exit(1);
27         } else {
28             last = maxLength;
29         }
30         long double dbias;
31         convert(fields[1], dbias);
32         biases.push_back(dbias);
33     }
34     input.close();
35 }
36 
bias(int length)37 long double Bias::bias(int length) {
38     if (biases.empty()) return 1; // no bias
39     if (length < minLength) {
40         return biases.front();
41     } else if (length > maxLength) {
42         return biases.back();
43     } else {
44         return biases.at(length - minLength);
45     }
46 }
47 
empty(void)48 bool Bias::empty(void) {
49     return biases.empty();
50 }
51