bpp-phyl
2.2.0
|
Substitution models manager for non-homogeneous / non-reversible models of evolution. More...
#include <Bpp/Phyl/Model/SubstitutionModelSet.h>
Public Member Functions | |
SubstitutionModelSet (const Alphabet *alpha) | |
Create a model set according to the specified alphabet. Stationarity is assumed. More... | |
SubstitutionModelSet (const Alphabet *alpha, FrequenciesSet *rootFreqs) | |
Create a model set according to the specified alphabet and root frequencies. Stationarity is not assumed. More... | |
void | clear () |
Resets all the information contained in this object. More... | |
void | setRootFrequencies (FrequenciesSet *rootFreqs) |
Sets a given FrequenciesSet for root frequencies. More... | |
SubstitutionModelSet (const SubstitutionModelSet &set) | |
SubstitutionModelSet & | operator= (const SubstitutionModelSet &set) |
virtual | ~SubstitutionModelSet () |
SubstitutionModelSet * | clone () const |
size_t | getNumberOfStates () const throw (Exception) |
Get the number of states associated to this model set. More... | |
virtual void | fireParameterChanged (const ParameterList ¶meters) |
size_t | getNumberOfModels () const |
bool | hasMixedSubstitutionModel () const |
const SubstitutionModel * | getModel (size_t i) const throw (IndexOutOfBoundsException) |
Get one model from the set knowing its index. More... | |
SubstitutionModel * | getModel (size_t i) throw (IndexOutOfBoundsException) |
size_t | getModelIndexForNode (int nodeId) const throw (Exception) |
Get the index in the set of the model associated to a particular node id. More... | |
const SubstitutionModel * | getModelForNode (int nodeId) const throw (Exception) |
Get the model associated to a particular node id. More... | |
SubstitutionModel * | getModelForNode (int nodeId) throw (Exception) |
const std::vector< int > & | getNodesWithModel (size_t i) const throw (IndexOutOfBoundsException) |
Get a list of nodes id for which the given model is associated. More... | |
std::vector< int > | getNodesWithParameter (const std::string &name) const throw (ParameterNotFoundException) |
void | addModel (SubstitutionModel *model, const std::vector< int > &nodesId) |
Add a new model to the set, and set relationships with nodes and params. More... | |
void | replaceModel (size_t modelIndex, SubstitutionModel *model) throw (Exception) |
Replace a model in the set, and all corresponding parameters. The replaced model deleted. More... | |
void | listModelNames (std::ostream &out=std::cout) const |
const FrequenciesSet * | getRootFrequenciesSet () const |
std::vector< double > | getRootFrequencies () const |
ParameterList | getRootFrequenciesParameters () const |
Get the parameters corresponding to the root frequencies. More... | |
ParameterList | getNodeParameters () const |
Get the parameters corresponding attached to the nodes of the tree. More... | |
ParameterList | getModelParameters (size_t modelIndex) const |
Get the parameters attached to a Model. More... | |
const Alphabet * | getAlphabet () const |
virtual const std::vector< int > & | getAlphabetStates () const |
virtual const StateMap & | getStateMap () const |
virtual std::vector< size_t > | getModelStates (int code) const |
virtual std::vector< size_t > | getModelStates (const std::string &code) const |
virtual int | getAlphabetStateAsInt (size_t index) const |
virtual std::string | getAlphabetStateAsChar (size_t index) const |
bool | isFullySetUpFor (const Tree &tree, bool throwEx=true) const throw (Exception) |
Check if the model set is fully specified for a given tree. More... | |
Protected Member Functions | |
void | updateRootFrequencies () |
Check function. | |
bool | checkOrphanModels (bool throwEx) const throw (Exception) |
bool | checkOrphanNodes (const Tree &tree, bool throwEx) const throw (Exception) |
bool | checkUnknownNodes (const Tree &tree, bool throwEx) const throw (Exception) |
Protected Attributes | |
const Alphabet * | alphabet_ |
A pointer toward the common alphabet to all models in the set. More... | |
size_t | nbStates_ |
std::vector< SubstitutionModel * > | modelSet_ |
Contains all models used in this tree. More... | |
Private Attributes | |
std::auto_ptr< FrequenciesSet > | rootFrequencies_ |
Root frequencies. More... | |
std::map< int, size_t > | nodeToModel_ |
Contains for each node in a tree the index of the corresponding model in modelSet_. More... | |
std::map< size_t, std::vector< int > > | modelToNodes_ |
std::vector< ParameterList > | modelParameters_ |
Parameters for each model in the set. More... | |
bool | stationarity_ |
Substitution models manager for non-homogeneous / non-reversible models of evolution.
This class contains a set of substitution models, and their assigment toward the branches of a phylogenetic tree. Each branch in the tree corresponds to a model in the set, but a susbstitution model may correspond to several branches. The particular case where all branches point toward a unique model is the homogeneous case.
This class also deals with the parameters associated to the models. In the homogeneous case, the parameter list is the same as the list in susbstitution model. When two models at least are specified, these models may have their own parameters or share some of them. To deal with this issue, the SubstitutionModelSet class contains its own parameter list, where parameters are numbered according to the model they belong to.
The user only act on parameters_, the fireParameterChanged function, automatically called, will update the modelParameters_ field.
In the non-homogeneous and homogeneous non-reversible cases, the likelihood depends on the position of the root. The states frequencies at the root of the tree are hence distinct parameters. Theses are accounted by a FrequenciesSet objet, managed by the SubstitutionModelSet class. The corresponding parameters, if any, are added at the begining of the global parameter list.
If the heterogenity of the model does not affect the equilibrium frequencies, the model can be considered as stationary. In such a model, the process is supposed to be at equilibrium all along the trees, including at the root. Whether a model should be considered as stationary or not is left to the user. If the "asumme stationarity" option is set when building the set, then no FrequenciesSet object is used, but the frequencies are taken to be the same as the one at the first model in the set. Nothing hence prevents you to build a "supposingly stationary model which actually is not", so be careful!!
This class provides several methods to specify which model and/or which parameter is associated to which branch/clade. Several check points are provided, but some are probably missing due to the large set of possible models that this class allows to build, so be carefull!
Definition at line 104 of file SubstitutionModelSet.h.
|
inline |
Create a model set according to the specified alphabet. Stationarity is assumed.
alpha | The alphabet to use for this set. |
Definition at line 150 of file SubstitutionModelSet.h.
Referenced by clone().
|
inline |
Create a model set according to the specified alphabet and root frequencies. Stationarity is not assumed.
alpha | The alphabet to use for this set. |
rootFreqs | The frequencies at root node. The underlying object will be owned by this instance. |
Definition at line 170 of file SubstitutionModelSet.h.
References setRootFrequencies().
SubstitutionModelSet::SubstitutionModelSet | ( | const SubstitutionModelSet & | set | ) |
Definition at line 49 of file SubstitutionModelSet.cpp.
References modelSet_.
|
inlinevirtual |
Definition at line 203 of file SubstitutionModelSet.h.
References modelSet_.
void SubstitutionModelSet::addModel | ( | SubstitutionModel * | model, |
const std::vector< int > & | nodesId | ||
) |
Add a new model to the set, and set relationships with nodes and params.
model | A pointer toward a susbstitution model, that will added to the set. Warning! The set will now be the owner of the pointer, and will destroy it if needed! Copy the model first if you don't want it to be lost! |
nodesId | the set of nodes in the tree that points toward this model. This will override any previous affectation. |
Exception | in case of error:
|
Definition at line 135 of file SubstitutionModelSet.cpp.
References alphabet_, bpp::SubstitutionModel::clone(), bpp::SubstitutionModel::getAlphabet(), bpp::SubstitutionModel::getNumberOfStates(), modelParameters_, modelSet_, modelToNodes_, nbStates_, and nodeToModel_.
Referenced by bpp::SubstitutionModelSetTools::createHomogeneousModelSet(), bpp::SubstitutionModelSetTools::createNonHomogeneousModelSet(), and bpp::PhylogeneticsApplicationTools::setSubstitutionModelSet().
|
protected |
Definition at line 249 of file SubstitutionModelSet.cpp.
Referenced by isFullySetUpFor().
|
protected |
Definition at line 264 of file SubstitutionModelSet.cpp.
Referenced by isFullySetUpFor().
|
protected |
Definition at line 280 of file SubstitutionModelSet.cpp.
Referenced by isFullySetUpFor().
void SubstitutionModelSet::clear | ( | ) |
Resets all the information contained in this object.
Definition at line 90 of file SubstitutionModelSet.cpp.
References modelParameters_, modelSet_, nbStates_, nodeToModel_, rootFrequencies_, and stationarity_.
Referenced by bpp::MixedSubstitutionModelSet::clear(), and bpp::PhylogeneticsApplicationTools::setSubstitutionModelSet().
|
inline |
Definition at line 213 of file SubstitutionModelSet.h.
References SubstitutionModelSet().
|
virtual |
To be called when a parameter has changed. Depending on parameters, this will actualize the _initialFrequencies vector or the corresponding models in the set.
parameters | The modified parameters. |
Reimplemented in bpp::MixedSubstitutionModelSet.
Definition at line 231 of file SubstitutionModelSet.cpp.
References modelParameters_, modelSet_, and updateRootFrequencies().
Referenced by bpp::MixedSubstitutionModelSet::fireParameterChanged().
|
inline |
Definition at line 410 of file SubstitutionModelSet.h.
References alphabet_.
Referenced by bpp::NonHomogeneousSequenceSimulator::dSimulateSite(), and bpp::SubstitutionMappingTools::getNormalizationsPerBranch().
|
inlinevirtual |
index | The model state. |
Definition at line 445 of file SubstitutionModelSet.h.
References bpp::SubstitutionModel::getAlphabetStateAsChar(), and getModel().
Referenced by bpp::AbstractNonHomogeneousTreeLikelihood::getAlphabetStateAsChar().
|
inlinevirtual |
index | The model state. |
Definition at line 437 of file SubstitutionModelSet.h.
References bpp::SubstitutionModel::getAlphabetStateAsInt(), and getModel().
Referenced by bpp::AbstractNonHomogeneousTreeLikelihood::getAlphabetStateAsInt().
|
inlinevirtual |
Definition at line 417 of file SubstitutionModelSet.h.
References bpp::SubstitutionModel::getAlphabetStates(), and getModel().
Referenced by bpp::AbstractNonHomogeneousTreeLikelihood::getAlphabetStates().
|
inline |
Get one model from the set knowing its index.
i | Index of the model in the set. |
Definition at line 251 of file SubstitutionModelSet.h.
References modelSet_.
Referenced by bpp::MixedSubstitutionModelSet::complete(), bpp::PhylogeneticsApplicationTools::completeMixedSubstitutionModelSet(), bpp::MixedSubstitutionModelSet::computeHyperNodesProbabilities(), bpp::AbstractNonHomogeneousTreeLikelihood::ConstNonHomogeneousSiteModelIterator::ConstNonHomogeneousSiteModelIterator(), getAlphabetStateAsChar(), getAlphabetStateAsInt(), getAlphabetStates(), bpp::SubstitutionMappingTools::getCountsPerBranch(), bpp::MixedSubstitutionModelSet::getHyperNodeProbability(), getModelStates(), bpp::SubstitutionMappingTools::getNormalizationsPerBranch(), bpp::SubstitutionMappingTools::getNormalizedCountsPerBranch(), getStateMap(), bpp::HomogeneousSequenceSimulator::getSubstitutionModel(), hasMixedSubstitutionModel(), bpp::MixedSubstitutionModelSet::HyperNode::HyperNode(), and bpp::PhylogeneticsApplicationTools::printParameters().
|
inline |
Definition at line 257 of file SubstitutionModelSet.h.
References modelSet_.
|
inline |
Get the model associated to a particular node id.
nodeId | The id of the query node. |
Exception | If no model is found for this node. |
Definition at line 285 of file SubstitutionModelSet.h.
References modelSet_, and nodeToModel_.
Referenced by bpp::RNonHomogeneousMixedTreeLikelihood::computeTransitionProbabilitiesForNode(), bpp::AbstractNonHomogeneousTreeLikelihood::computeTransitionProbabilitiesForNode(), bpp::AbstractNonHomogeneousTreeLikelihood::getNewBranchModelIterator(), bpp::AbstractNonHomogeneousTreeLikelihood::getSubstitutionModelForNode(), and bpp::NonHomogeneousSequenceSimulator::init().
|
inline |
Definition at line 292 of file SubstitutionModelSet.h.
References modelSet_, and nodeToModel_.
|
inline |
Get the index in the set of the model associated to a particular node id.
nodeId | The id of the query node. |
Exception | If no model is found for this node. |
Definition at line 270 of file SubstitutionModelSet.h.
References nodeToModel_.
Referenced by bpp::RNonHomogeneousMixedTreeLikelihood::computeTransitionProbabilitiesForNode().
ParameterList bpp::SubstitutionModelSet::getModelParameters | ( | size_t | modelIndex | ) | const |
Get the parameters attached to a Model.
modelIndex | the index of the model in the set |
|
inlinevirtual |
Definition at line 425 of file SubstitutionModelSet.h.
References getModel(), and bpp::SubstitutionModel::getModelStates().
|
inlinevirtual |
Definition at line 429 of file SubstitutionModelSet.h.
References getModel(), and bpp::SubstitutionModel::getModelStates().
|
inline |
Get the parameters corresponding attached to the nodes of the tree.
That is, all the parameters without the root frequencies.
Definition at line 389 of file SubstitutionModelSet.h.
References rootFrequencies_, and stationarity_.
Referenced by bpp::DRNonHomogeneousTreeLikelihood::fireParameterChanged(), bpp::RNonHomogeneousTreeLikelihood::fireParameterChanged(), and bpp::RNonHomogeneousMixedTreeLikelihood::fireParameterChanged().
|
inline |
Get a list of nodes id for which the given model is associated.
i | The index of the model in the set. |
IndexOutOfBoundsException | If the index is not valid. |
Definition at line 307 of file SubstitutionModelSet.h.
References modelSet_, and modelToNodes_.
Referenced by bpp::AbstractNonHomogeneousTreeLikelihood::ConstNonHomogeneousSiteModelIterator::ConstNonHomogeneousSiteModelIterator(), bpp::SubstitutionMappingTools::getNormalizationsPerBranch(), bpp::RNonHomogeneousMixedTreeLikelihood::init(), and bpp::PhylogeneticsApplicationTools::printParameters().
std::vector< int > SubstitutionModelSet::getNodesWithParameter | ( | const std::string & | name | ) | const |
throw | ( | ParameterNotFoundException | |||
) |
name | The name of the parameter to look for. |
ParameterNotFoundException | If no parameter with the specified name is found. |
Definition at line 115 of file SubstitutionModelSet.cpp.
Referenced by bpp::DRNonHomogeneousTreeLikelihood::fireParameterChanged(), bpp::RNonHomogeneousTreeLikelihood::fireParameterChanged(), and bpp::RNonHomogeneousMixedTreeLikelihood::fireParameterChanged().
|
inline |
Definition at line 237 of file SubstitutionModelSet.h.
References modelSet_.
Referenced by bpp::MixedSubstitutionModelSet::addToHyperNode(), bpp::MixedSubstitutionModelSet::complete(), bpp::MixedSubstitutionModelSet::computeHyperNodesProbabilities(), bpp::MixedSubstitutionModelSet::getHyperNodeProbability(), bpp::SubstitutionMappingTools::getNormalizationsPerBranch(), hasMixedSubstitutionModel(), bpp::MixedSubstitutionModelSet::HyperNode::HyperNode(), bpp::RNonHomogeneousMixedTreeLikelihood::init(), and bpp::PhylogeneticsApplicationTools::printParameters().
|
inline |
Get the number of states associated to this model set.
Exception | if no model is associated to the set. |
Definition at line 222 of file SubstitutionModelSet.h.
References nbStates_.
Referenced by bpp::AbstractNonHomogeneousTreeLikelihood::getNumberOfStates().
|
inline |
Definition at line 361 of file SubstitutionModelSet.h.
References modelSet_, rootFrequencies_, and stationarity_.
Referenced by bpp::AbstractNonHomogeneousTreeLikelihood::computeAllTransitionProbabilities(), bpp::NonHomogeneousSequenceSimulator::dSimulateSite(), bpp::DRNonHomogeneousTreeLikelihood::fireParameterChanged(), bpp::RNonHomogeneousTreeLikelihood::fireParameterChanged(), bpp::RNonHomogeneousMixedTreeLikelihood::fireParameterChanged(), bpp::NonHomogeneousSequenceSimulator::simulate(), and bpp::NonHomogeneousSequenceSimulator::simulateSite().
|
inline |
Get the parameters corresponding to the root frequencies.
Definition at line 374 of file SubstitutionModelSet.h.
References rootFrequencies_, and stationarity_.
Referenced by bpp::AbstractNonHomogeneousTreeLikelihood::getRootFrequenciesParameters().
|
inline |
Definition at line 356 of file SubstitutionModelSet.h.
References rootFrequencies_.
Referenced by bpp::PhylogeneticsApplicationTools::printParameters().
|
inlinevirtual |
Definition at line 421 of file SubstitutionModelSet.h.
References getModel(), and bpp::SubstitutionModel::getStateMap().
bool SubstitutionModelSet::hasMixedSubstitutionModel | ( | ) | const |
Definition at line 301 of file SubstitutionModelSet.cpp.
References getModel(), and getNumberOfModels().
Referenced by bpp::PhylogeneticsApplicationTools::getSubstitutionModelSet().
|
inline |
Check if the model set is fully specified for a given tree.
This include:
tree | The tree to check. |
throwEx | Tell if an exception have to be thrown in case of test not passed. |
Definition at line 461 of file SubstitutionModelSet.h.
References checkOrphanModels(), checkOrphanNodes(), and checkUnknownNodes().
Referenced by bpp::RNonHomogeneousMixedTreeLikelihood::RNonHomogeneousMixedTreeLikelihood().
void SubstitutionModelSet::listModelNames | ( | std::ostream & | out = std::cout | ) | const |
Definition at line 218 of file SubstitutionModelSet.cpp.
References modelSet_, and modelToNodes_.
SubstitutionModelSet & SubstitutionModelSet::operator= | ( | const SubstitutionModelSet & | set | ) |
Definition at line 67 of file SubstitutionModelSet.cpp.
References alphabet_, modelParameters_, modelSet_, modelToNodes_, nbStates_, nodeToModel_, rootFrequencies_, and stationarity_.
Referenced by bpp::MixedSubstitutionModelSet::operator=().
void SubstitutionModelSet::replaceModel | ( | size_t | modelIndex, |
SubstitutionModel * | model | ||
) | |||
throw | ( | Exception | |
) |
Replace a model in the set, and all corresponding parameters. The replaced model deleted.
modelIndex | The index of the model in the set. |
model | the new model. This model will be owned by the Set. |
Exception | if a parameter becomes orphan because of the removal. |
Definition at line 169 of file SubstitutionModelSet.cpp.
void SubstitutionModelSet::setRootFrequencies | ( | FrequenciesSet * | rootFreqs | ) |
Sets a given FrequenciesSet for root frequencies.
rootFreqs | The FrequenciesSet for root frequencies. |
Definition at line 106 of file SubstitutionModelSet.cpp.
References rootFrequencies_, and stationarity_.
Referenced by bpp::SubstitutionModelSetTools::createHomogeneousModelSet(), bpp::SubstitutionModelSetTools::createNonHomogeneousModelSet(), bpp::PhylogeneticsApplicationTools::setSubstitutionModelSet(), and SubstitutionModelSet().
|
inlineprotected |
Set rootFrequencies_ from parameters.
Definition at line 473 of file SubstitutionModelSet.h.
References rootFrequencies_, and stationarity_.
Referenced by fireParameterChanged().
|
protected |
A pointer toward the common alphabet to all models in the set.
Definition at line 111 of file SubstitutionModelSet.h.
Referenced by addModel(), getAlphabet(), and operator=().
|
private |
Parameters for each model in the set.
The parameters_ field, inherited from AbstractSubstitutionModel contains all parameters, with unique names. To make the correspondance with parameters for each model in the set, we duplicate them in this array. In most cases, this is something like 'theta_1 <=> theta', 'theta_2 <=> theta', etc.
Definition at line 139 of file SubstitutionModelSet.h.
Referenced by addModel(), clear(), fireParameterChanged(), and operator=().
|
protected |
Contains all models used in this tree.
Definition at line 118 of file SubstitutionModelSet.h.
Referenced by addModel(), clear(), fireParameterChanged(), getModel(), getModelForNode(), getNodesWithModel(), getNumberOfModels(), getRootFrequencies(), listModelNames(), operator=(), SubstitutionModelSet(), and ~SubstitutionModelSet().
|
mutableprivate |
Definition at line 130 of file SubstitutionModelSet.h.
Referenced by addModel(), getNodesWithModel(), listModelNames(), and operator=().
|
protected |
Definition at line 113 of file SubstitutionModelSet.h.
Referenced by addModel(), clear(), getNumberOfStates(), and operator=().
|
mutableprivate |
Contains for each node in a tree the index of the corresponding model in modelSet_.
Definition at line 129 of file SubstitutionModelSet.h.
Referenced by addModel(), clear(), getModelForNode(), getModelIndexForNode(), and operator=().
|
private |
Root frequencies.
Definition at line 124 of file SubstitutionModelSet.h.
Referenced by clear(), getNodeParameters(), getRootFrequencies(), getRootFrequenciesParameters(), getRootFrequenciesSet(), operator=(), setRootFrequencies(), and updateRootFrequencies().
|
private |
Definition at line 141 of file SubstitutionModelSet.h.
Referenced by clear(), getNodeParameters(), getRootFrequencies(), getRootFrequenciesParameters(), operator=(), setRootFrequencies(), and updateRootFrequencies().