-
Notifications
You must be signed in to change notification settings - Fork 2
/
configfile.cc
84 lines (67 loc) · 2.07 KB
/
configfile.cc
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
#include <iostream>
#include <fstream>
#include <boost/algorithm/string.hpp>
#include <boost/lexical_cast.hpp>
#include "sputil.h"
#include "configfile.h"
using namespace std;
typedef SPIOException SPIOE;
void ConfigFile::read(istream & inp)
{
size_t n_loci, npops;
if (!get_value(inp, n_loci))
throw SPIOE(ERR_LOC
" Error in reading initial conditions: cannot read nloci");
if (!get_value(inp, npops))
throw SPIOE(ERR_LOC
" Error in reading initial conditions: cannot read npops");
for(size_t p=0; p<npops; p++)
{
_n_sequences.push_back(vector<size_t>());
_n_sequences.back().resize(n_loci);
}
_n_sites.resize(n_loci);
for (size_t l=0; l<n_loci; l++)
{
for (size_t p=0; p<npops; p++)
{
int v;
if (!get_value<int>(inp, v))
{
throw SPIOE(ERR_LOC
" Error in reading initial conditions: cannot read nSeq at locus "
+ lexical_cast<string>(l));
}
_n_sequences[p][l] = v;
}
if (!get_value(inp, _n_sites[l]))
{
throw SPIOE(ERR_LOC
" Error in reading initial conditions: cannot read nSites at locus "
+ lexical_cast<string>(l));
}
}
if (!get_value(inp, _n_datasets))
throw SPIOE(ERR_LOC
" Error in reading inital conditions: cannot read ndatasets");
if (!get_value(inp, _datafilename))
throw SPIOE(ERR_LOC
" Error in reading initial conditions: cannot read data file name");
}
/* print initial values of parameters read from input file as a check*/
void ConfigFile::dump(ostream & out)
{
const size_t nLoci = _n_sites.size();
out << "\n\tnumber of populations: " << _n_sequences.size();
out << "\n\tnumber of loci: " << nLoci;
for(size_t l=0;l<nLoci;l++) /*loop over loci*/
{
for (size_t p=0; p<_n_sequences.size(); p++)
out << "\n\tnumber of sequences in population " << p <<
" at locus " << l << ":" << _n_sequences[p][l];
out << "\n\t\tnumber of sites at locus " << l << ": " << _n_sites[l];
}
out << "\n\tnumber of replicate datasets: " << _n_datasets;
out << "\n\tname of the dataset file: " << _datafilename;
out << "\n\n";
} /*end of print_initial_conditions*/