bpp-phyl3  3.0.0
RASTools.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
6 
7 #include "RASTools.h"
8 
9 using namespace bpp;
10 
11 // From the STL
12 #include <map>
13 
14 using namespace std;
15 
16 unique_ptr<DiscreteDistributionInterface> RASTools::getPosteriorRateDistribution(
18 {
19  // Get all posterior rate classes for each sites:
20  vector<size_t> classes = treeLikelihood.getRateClassWithMaxPostProbPerSite();
21  map<size_t, size_t> counts;
22  for (size_t i = 0; i < classes.size(); i++)
23  {
24  counts[classes[i]]++;
25  }
26 
27  // Now compute the distribution:
28  auto rDist = treeLikelihood.getRateDistribution();
29  map<double, double> distribution;
30  for (auto& i : counts)
31  {
32  distribution[rDist->getCategory(i.first)] = static_cast<double>(i.second) / static_cast<double>(classes.size());
33  }
34 
35  // Build a new distribution and return it:
36  return make_unique<SimpleDiscreteDistribution>(distribution);
37 }
Interface for rate across sites (RAS) implementation.
virtual std::shared_ptr< const DiscreteDistributionInterface > getRateDistribution() const =0
Get the rate distribution used for the computation.
virtual std::vector< size_t > getRateClassWithMaxPostProbPerSite() const =0
Get the posterior rate class (the one with maximum posterior probability) for each site.
static std::unique_ptr< DiscreteDistributionInterface > getPosteriorRateDistribution(const DiscreteRatesAcrossSitesTreeLikelihoodInterface &treeLikelihood)
Get the rate distribution estimated from a dataset.
Definition: RASTools.cpp:16
Defines the basic types of data flow nodes.