59 for (
size_t i = 0; i < site.
size(); i++)
72 for (
size_t i = 0; i < site.
size(); i++)
85 for (
size_t i = 0; i < site.
size(); i++)
98 for (
size_t i = 0; i < site.
size(); i++)
114 for (
size_t i = 0; i < site.
size(); i++)
127 for (
size_t i = 0; i < site.
size(); i++)
146 for (
size_t i = 0; i < site1.
size(); i++)
148 if (site1[i] != site2[i])
160 if (site.size() == 0)
161 throw EmptySiteException(
"SiteTools::isConstant: Incorrect specified site, size must be > 0", &site);
164 int gap = site.getAlphabet()->getGapCharacterCode();
168 int unknown = site.getAlphabet()->getUnknownCharacterCode();
170 while (i < site.size() && (s == gap || s == unknown))
175 if (s == unknown || s == gap)
177 if (unresolvedRaisesException)
178 throw EmptySiteException(
"SiteTools::isConstant: Site is only made of gaps or generic characters.");
182 while (i < site.size())
184 if (site[i] != s && site[i] != gap && site[i] != unknown)
193 while (i < site.size() && s == gap)
200 if (unresolvedRaisesException)
205 while (i < site.size())
207 if (site[i] != s && site[i] != gap)
221 if (site.size() == 0)
222 throw EmptySiteException(
"SiteTools::variabilityShannon: Incorrect specified site, size must be > 0", &site);
224 getFrequencies(site, p, resolveUnknown);
227 for (
int i = 0; i < static_cast<int>(site.getAlphabet()->getSize()); i++)
241 if (site1.size() == 0)
242 throw EmptySiteException(
"SiteTools::mutualInformation: Incorrect specified site, size must be > 0", &site1);
243 if (site2.size() == 0)
244 throw EmptySiteException(
"SiteTools::mutualInformation: Incorrect specified site, size must be > 0", &site2);
245 if (site1.size() != site2.size())
246 throw DimensionException(
"SiteTools::mutualInformation: sites must have the same size!", site1.size(), site2.size());
247 vector<double> p1(site1.getAlphabet()->getSize());
248 vector<double> p2(site2.getAlphabet()->getSize());
249 map<int, map<int, double> > p12;
250 getCounts(site1, site2, p12, resolveUnknown);
251 double mi = 0, tot = 0, pxy;
253 for (
size_t i = 0; i < site1.getAlphabet()->getSize(); i++)
255 for (
size_t j = 0; j < site2.getAlphabet()->getSize(); j++)
257 pxy = p12[
static_cast<int>(i)][static_cast<int>(j)];
263 for (
size_t i = 0; i < site1.getAlphabet()->getSize(); i++)
267 for (
size_t j = 0; j < site2.getAlphabet()->getSize(); j++)
271 for (
size_t i = 0; i < site1.getAlphabet()->getSize(); i++)
273 for (
size_t j = 0; j < site2.getAlphabet()->getSize(); j++)
275 pxy = p12[
static_cast<int>(i)][static_cast<int>(j)] / tot;
277 mi += pxy * log(pxy / (p1[i] * p2[j]));
288 if (site1.size() == 0)
289 throw EmptySiteException(
"SiteTools::jointEntropy: Incorrect specified site, size must be > 0", &site1);
290 if (site2.size() == 0)
291 throw EmptySiteException(
"SiteTools::jointEntropy: Incorrect specified site, size must be > 0", &site2);
292 if (site1.size() != site2.size())
293 throw DimensionException(
"SiteTools::jointEntropy: sites must have the same size!", site1.size(), site2.size());
294 map<int, map<int, double> > p12;
295 getCounts(site1, site2, p12, resolveUnknown);
296 double tot = 0, pxy, h = 0;
298 for (
size_t i = 0; i < site1.getAlphabet()->getSize(); i++)
300 for (
size_t j = 0; j < site2.getAlphabet()->getSize(); j++)
302 pxy = p12[
static_cast<int>(i)][static_cast<int>(j)];
306 for (
size_t i = 0; i < site1.getAlphabet()->getSize(); i++)
308 for (
size_t j = 0; j < site2.getAlphabet()->getSize(); j++)
310 pxy = p12[
static_cast<int>(i)][static_cast<int>(j)] / tot;
323 if (site.size() == 0)
324 throw EmptySiteException(
"SiteTools::variabilityFactorial: Incorrect specified site, size must be > 0", &site);
330 return (static_cast<double>(std::log(l)));
338 if (site.size() == 0)
339 throw EmptySiteException(
"SiteTools::heterozygosity: Incorrect specified site, size must be > 0", &site);
341 getFrequencies(site, p);
352 if (site.size() == 0)
353 throw EmptySiteException(
"SiteTools::getNumberOfDistinctCharacters(): Incorrect specified site, size must be > 0", &site);
357 map<int, size_t> counts;
360 for (map<int, size_t>::iterator it = counts.begin(); it != counts.end(); it++)
373 if (site.size() == 0)
374 throw EmptySiteException(
"SiteTools::hasSingleton: Incorrect specified site, size must be > 0", &site);
378 map<int, size_t> counts;
379 getCounts(site, counts);
380 for (map<int, size_t>::iterator it = counts.begin(); it != counts.end(); it++)
393 if (site.size() == 0)
394 throw EmptySiteException(
"SiteTools::isParsimonyInformativeSite: Incorrect specified site, size must be > 0", &site);
398 map<int, size_t> counts;
401 for (map<int, size_t>::iterator it = counts.begin(); it != counts.end(); it++)
416 if (site.size() == 0)
417 throw EmptySiteException(
"SiteTools::isTriplet: Incorrect specified site, size must be > 0", &site);