11 #include "../Likelihood/PairedSiteLikelihoods.h"
26 istringstream iss (line);
27 size_t nmodels, nsites;
33 vector<vector<double>> loglikelihoods;
34 loglikelihoods.reserve(nmodels);
39 streampos pos (is.tellg());
41 if (line.find(
"\t") != string::npos)
43 else if (line.find(
" ") != string::npos)
50 while (getline(is, line))
52 size_t delim_pos (line.find(delim));
53 if (delim_pos == string::npos)
56 msg <<
"IOTreepuzzlePairedSiteLikelihoods::read: Couldn't find delimiter. The beginning of the line was : "
57 << endl << line.substr(0, 100);
62 names.push_back( TextTools::removeSurroundingWhiteSpaces(line.substr(0, delim_pos)) );
65 loglikelihoods.push_back(vector<double>());
66 loglikelihoods.back().reserve(nsites);
68 istringstream liks_stream ( line.substr(delim_pos) );
70 while (liks_stream >> currllik)
71 loglikelihoods.back().push_back(currllik);
74 if (loglikelihoods.back().size() != nsites)
77 oss <<
"IOTreepuzzlePairedSiteLikelihoods::read: Model '" << names.back()
78 <<
"' does not have the correct number of sites. ("
79 << loglikelihoods.back().size() <<
", expected: " << nsites <<
")";
85 if (loglikelihoods.size() != nmodels)
86 throw Exception(
"IOTreepuzzlePairedSiteLikelihoods::read: Wrong number of models.");
98 ifstream iF (path.c_str());
109 throw Exception(
"Writing an empty PairedSiteLikelihoods object to file.");
122 for (vector<double>::const_iterator sitelik = psl.
getLikelihoods().at(i).begin();
129 os << *sitelik <<
" ";
135 else if (delim ==
" ")
139 vector<size_t> name_sizes;
140 for (vector<string>::const_iterator name = psl.
getModelNames().begin();
144 name_sizes.push_back(name->size());
146 size_t names_field_size = *max_element(name_sizes.begin(), name_sizes.end()) + 2;
153 while (name.size() != names_field_size)
158 for (vector<double>::const_iterator sitelik = psl.
getLikelihoods().at(i).begin();
165 os << *sitelik <<
" ";
174 msg <<
"IOTreepuzzlePairedSiteLikelihoods::write: Unknown field delimiter "
175 <<
"\"" << delim <<
"\".";
176 os << msg.str() << endl;
185 void IOTreepuzzlePairedSiteLikelihoods::writePairedSiteLikelihoods(
const bpp::PairedSiteLikelihoods& psl,
const std::string& path,
const string& delim)
187 ofstream oF (path.c_str());
188 IOTreepuzzlePairedSiteLikelihoods::writePairedSiteLikelihoods(psl, oF, delim);
195 vector<double> IOPhymlPairedSiteLikelihoods::readPairedSiteLikelihoods(std::istream& is)
197 vector<double> loglikelihoods;
202 string expected (
"Note : P(D|M) is the probability of site D given the model M (i.e., the site likelihood)");
203 if (str.find(expected) == string::npos)
206 msg <<
"IOPhymlPairedSiteLikelihoods::read: The first line was expected to be :"
208 <<
"and was :" << endl
214 for (
int i = 0; i < 6; ++i)
219 while (getline(is, str))
222 istringstream ss (str);
226 loglikelihoods.push_back(
log(lik));
229 return loglikelihoods;
235 vector<double> IOPhymlPairedSiteLikelihoods::readPairedSiteLikelihoods(
const std::string& path)
237 ifstream iF (path.c_str());
238 vector<double> loglikelihoods(IOPhymlPairedSiteLikelihoods::readPairedSiteLikelihoods(iF));
239 return loglikelihoods;
A container for paired-site likelihoods (likelihoods over the same sites for different models,...
size_t getNumberOfModels() const
Get the number of models in the container.
const std::vector< std::string > & getModelNames() const
std::size_t getNumberOfSites() const
const std::vector< std::vector< double > > & getLikelihoods() const
Defines the basic types of data flow nodes.