5 #ifndef BPP_PHYL_LIKELIHOOD_NONHOMOGENEOUSSUBSTITUTIONPROCESS_H
6 #define BPP_PHYL_LIKELIHOOD_NONHOMOGENEOUSSUBSTITUTIONPROCESS_H
9 #include "../Model/FrequencySet/FrequencySet.h"
86 std::vector<std::shared_ptr<BranchModelInterface>>
modelSet_;
91 std::shared_ptr<DiscreteDistributionInterface>
rDist_;
114 std::shared_ptr<DiscreteDistributionInterface> rdist,
115 std::shared_ptr<const PhyloTree> tree = 0,
116 std::shared_ptr<FrequencySetInterface> rootFreqs = 0) :
138 std::shared_ptr<DiscreteDistributionInterface> rdist,
139 std::shared_ptr<ParametrizablePhyloTree> tree,
140 std::shared_ptr<FrequencySetInterface> rootFreqs = 0) :
183 throw Exception(
"NonHomogeneousSubstitutionProcess::getStateMap : no model associated");
188 std::shared_ptr<const StateMapInterface>
getStateMap()
const override
191 throw Exception(
"NonHomogeneousSubstitutionProcess::getStateMap : no model associated");
213 void setModelScenario(std::shared_ptr<ModelScenario> modelscenario)
override;
218 std::iota(std::begin(v), std::end(v), 1);
228 std::shared_ptr<const BranchModelInterface>
getModel(
size_t n)
const override
234 std::shared_ptr<const BranchModelInterface>
getModel(
size_t n)
252 throw Exception(
"NonHomogeneousSubstitutionProcess::getModelNumberForNode(). No model associated to node with id " +
TextTools::toString(nodeId));
253 return i->second + 1;
263 std::shared_ptr<const BranchModelInterface>
getModelForNode(
unsigned int nodeId)
const override
265 std::map<unsigned int, size_t>::const_iterator i =
nodeToModel_.find(nodeId);
267 throw Exception(
"NonHomogeneousSubstitutionProcess::getModelForNode(). No model associated to node with id " +
TextTools::toString(nodeId));
299 void addModel(std::shared_ptr<BranchModelInterface>
model,
const std::vector<unsigned int>& nodesId);
311 void setModel(std::shared_ptr<BranchModelInterface>
model,
size_t modelIndex);
348 throw NullPointerException(
"NonHomogeneousSubstitutionProcess::rateDistribution. No associated rate distribution.");
355 throw NullPointerException(
"NonHomogeneousSubstitutionProcess::rateDistribution. No associated rate distribution.");
408 if (std::dynamic_pointer_cast<const TransitionModelInterface>(
modelSet_[0]))
409 return std::dynamic_pointer_cast<const TransitionModelInterface>(
modelSet_[0])->getFrequencies();
411 throw Exception(
"NonHomogeneousSubstitutionProcess::getRootFrequencies not callable.");
422 std::shared_ptr<const BranchModelInterface>
getModel(
unsigned int nodeId,
size_t classIndex)
const override
429 if (classIndex >= (
rDist_ ?
rDist_->getNumberOfCategories() : 1))
431 return rDist_ ?
rDist_->getProbability(classIndex) : 1.;
441 for (
size_t i = 0; i <
rDist_->getNumberOfCategories(); i++)
443 vProb.push_back(
rDist_->getProbability(i));
451 if (classIndex >= (
rDist_ ?
rDist_->getNumberOfCategories() : 1))
475 std::shared_ptr<BranchModelInterface>
model,
476 std::shared_ptr<DiscreteDistributionInterface> rdist,
477 std::shared_ptr<PhyloTree> tree,
478 std::shared_ptr<FrequencySetInterface> rootFreqs = 0,
479 std::shared_ptr<ModelScenario> scenario = 0
498 std::shared_ptr<BranchModelInterface>
model,
499 std::shared_ptr<DiscreteDistributionInterface> rdist,
500 std::shared_ptr<PhyloTree> tree,
501 std::shared_ptr<FrequencySetInterface> rootFreqs,
502 const std::vector<std::string>& globalParameterNames,
503 std::shared_ptr<ModelScenario> scenario = 0
A partial implementation of the SubstitutionProcess interface.
const FrequencySetInterface & rootFrequencySet() const
bool hasRootFrequencySet() const
std::shared_ptr< const ParametrizablePhyloTree > getParametrizablePhyloTree() const
void addParameters_(const ParameterList ¶meters)
Interface for all Branch models.
virtual const Vdouble & getFrequencies() const =0
Substitution process manager for non-homogeneous / non-reversible models of evolution.
size_t getModelNumberForNode(unsigned int nodeId) const override
Get the number of the model associated to a particular node id.
double getProbabilityForModel(size_t classIndex) const override
std::vector< std::shared_ptr< BranchModelInterface > > modelSet_
Contains all models used in this tree.
std::map< unsigned int, size_t > nodeToModel_
Contains for each node in a tree the index of the corresponding model in modelSet_.
std::shared_ptr< DiscreteDistributionInterface > rDist_
Rate Distribution.
void setModel(std::shared_ptr< BranchModelInterface > model, size_t modelIndex)
Change a given model.
void fireParameterChanged(const ParameterList ¶meters) override
std::shared_ptr< const BranchModelInterface > getModelForNode(unsigned int nodeId) const override
Get the model associated to a particular node id.
std::shared_ptr< const BranchModelInterface > getModel(size_t n)
void clear()
Resets all the information contained in this object.
const DiscreteDistributionInterface & rateDistribution() const override
Get the rate distribution.
const StateMapInterface & stateMap() const override
const std::vector< double > & getRootFrequencies() const override
const BranchModelInterface & model(size_t n) const override
void setModelScenario(std::shared_ptr< ModelScenario > modelscenario) override
Set the modelPath, after checking it is valid (ie modelpath has only the model of the process).
bool isFullySetUp(bool throwEx=true) const
Check if the model set is fully specified for a given tree.
std::shared_ptr< const StateMapInterface > getStateMap() const override
DiscreteDistributionInterface & rateDistribution() override
Get the rate distribution.
void listModelNames(std::ostream &out=std::cout) const
list all model names.
virtual ~NonHomogeneousSubstitutionProcess()
std::map< size_t, std::vector< unsigned int > > modelToNodes_
bool checkUnknownNodes(bool throwEx) const
ParameterList getSubstitutionModelParameters(bool independent) const override
Get the INDEPENDENT parameters corresponding to the models.
NonHomogeneousSubstitutionProcess(std::shared_ptr< DiscreteDistributionInterface > rdist, std::shared_ptr< const PhyloTree > tree=0, std::shared_ptr< FrequencySetInterface > rootFreqs=0)
Create a model set according to the specified alphabet and root frequencies. Stationarity is not assu...
bool checkOrphanNodes(bool throwEx) const
NonHomogeneousSubstitutionProcess(std::shared_ptr< DiscreteDistributionInterface > rdist, std::shared_ptr< ParametrizablePhyloTree > tree, std::shared_ptr< FrequencySetInterface > rootFreqs=0)
Create a model set according to the specified alphabet and root frequencies. Stationarity is not assu...
void addModel(std::shared_ptr< BranchModelInterface > model, const std::vector< unsigned int > &nodesId)
Add a new model to the set, and set relationships with nodes and params.
std::shared_ptr< DiscreteDistributionInterface > getRateDistribution() override
Get a pointer to the rate distribution (or null if there is no rate distribution).
ParameterList getBranchLengthParameters(bool independent) const override
std::shared_ptr< const BranchModelInterface > getModel(unsigned int nodeId, size_t classIndex) const override
Get the substitution model corresponding to a certain branch, site pattern, and model class.
size_t getNumberOfModels() const override
NonHomogeneousSubstitutionProcess * clone() const override
double getRateForModel(size_t classIndex) const override
std::shared_ptr< const DiscreteDistributionInterface > getRateDistribution() const override
Get a pointer to the rate distribution (or null if there is no rate distribution).
std::vector< size_t > getModelNumbers() const override
static std::unique_ptr< NonHomogeneousSubstitutionProcess > createNonHomogeneousSubstitutionProcess(std::shared_ptr< BranchModelInterface > model, std::shared_ptr< DiscreteDistributionInterface > rdist, std::shared_ptr< PhyloTree > tree, std::shared_ptr< FrequencySetInterface > rootFreqs, const std::vector< std::string > &globalParameterNames, std::shared_ptr< ModelScenario > scenario=0)
Create a NonHomogeneousSubstitutionProcess object, with one model per branch.
static std::unique_ptr< AutonomousSubstitutionProcessInterface > createHomogeneousSubstitutionProcess(std::shared_ptr< BranchModelInterface > model, std::shared_ptr< DiscreteDistributionInterface > rdist, std::shared_ptr< PhyloTree > tree, std::shared_ptr< FrequencySetInterface > rootFreqs=0, std::shared_ptr< ModelScenario > scenario=0)
Create a NonHomogeneousSubstitutionProcess object, corresponding to the homogeneous case.
void setModelToNode(size_t modelIndex, unsigned int nodeNumber)
Associate an existing model with a given node.
Vdouble getClassProbabilities() const override
const BranchModelInterface & model(unsigned int nodeId, size_t classIndex) const override
Get the substitution model corresponding to a certain branch, site pattern, and model class.
std::vector< ParameterList > modelParameters_
Parameters for each model in the set.
ParameterList getRateDistributionParameters(bool independent) const override
Get the parameters attached to the rate distribution.
NonHomogeneousSubstitutionProcess & operator=(const NonHomogeneousSubstitutionProcess &set)
const std::vector< unsigned int > getNodesWithModel(size_t i) const override
Get a list of nodes id for which the given model is associated.
bool hasMixedTransitionModel() const
std::shared_ptr< const BranchModelInterface > getModel(size_t n) const override
Map the states of a given alphabet which have a model state.
std::string toString(T t)
Defines the basic types of data flow nodes.
std::vector< double > Vdouble