bpp-phyl  2.4.0
bpp::SubstitutionModelSet Class Reference

Substitution models manager for non-homogeneous / non-reversible models of evolution. More...

#include <Bpp/Phyl/Model/SubstitutionModelSet.h>

+ Inheritance diagram for bpp::SubstitutionModelSet:
+ Collaboration diagram for bpp::SubstitutionModelSet:

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...
 
bool isStationary () const
 
void setRootFrequencies (FrequenciesSet *rootFreqs)
 Sets a given FrequenciesSet for root frequencies. More...
 
 SubstitutionModelSet (const SubstitutionModelSet &set)
 
SubstitutionModelSetoperator= (const SubstitutionModelSet &set)
 
virtual ~SubstitutionModelSet ()
 
SubstitutionModelSetclone () const
 
size_t getNumberOfStates () const
 Get the number of states associated to this model set. More...
 
virtual void fireParameterChanged (const ParameterList &parameters)
 
size_t getNumberOfModels () const
 
bool hasMixedSubstitutionModel () const
 
const TransitionModelgetModel (size_t i) const
 Get one model from the set knowing its index. More...
 
TransitionModelgetModel (size_t i)
 
const SubstitutionModelgetSubstitutionModel (size_t i) const
 Return a markovian substitution model (or null) More...
 
SubstitutionModelgetSubstitutionModel (size_t i)
 
bool hasOnlySubstitutionModels () const
 
size_t getModelIndexForNode (int nodeId) const
 Get the index in the set of the model associated to a particular node id. More...
 
const TransitionModelgetModelForNode (int nodeId) const
 Get the model associated to a particular node id. More...
 
TransitionModelgetModelForNode (int nodeId)
 
const SubstitutionModelgetSubstitutionModelForNode (int nodeId) const
 
SubstitutionModelgetSubstitutionModelForNode (int nodeId)
 
const std::vector< int > & getNodesWithModel (size_t i) const
 Get a list of nodes id for which the given model is associated. More...
 
std::vector< int > getNodesWithParameter (const std::string &name) const
 
void addModel (TransitionModel *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, TransitionModel *model)
 Replace a model in the set, and all corresponding parameters. The replaced model deleted. More...
 
void listModelNames (std::ostream &out=std::cout) const
 
const FrequenciesSetgetRootFrequenciesSet () 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 AlphabetgetAlphabet () const
 
virtual const std::vector< int > & getAlphabetStates () const
 
virtual const StateMapgetStateMap () 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
 Check if the model set is fully specified for a given tree. More...
 
void setNamespace (const std::string &prefix)
 
bool hasIndependentParameter (const std::string &name) const
 
const ParameterListgetIndependentParameters () const
 
size_t getNumberOfIndependentParameters () const
 
void aliasParameters (const std::string &p1, const std::string &p2)
 
void aliasParameters (std::map< std::string, std::string > &unparsedParams, bool verbose)
 
void unaliasParameters (const std::string &p1, const std::string &p2)
 
ParameterList getAliasedParameters (const ParameterList &pl) const
 
ParameterList getFromParameters (const ParameterList &pl) const
 
virtual std::vector< std::string > getAlias (const std::string &name) const
 
virtual std::map< std::string, std::string > getAliases () const
 
std::string getFrom (const std::string &name) const
 
bool hasParameter (const std::string &name) const
 
const ParameterListgetParameters () const
 
const ParametergetParameter (const std::string &name) const
 
const std::shared_ptr< Parameter > & getSharedParameter (const std::string &name) const
 
double getParameterValue (const std::string &name) const
 
void setAllParametersValues (const ParameterList &parameters)
 
void setParameterValue (const std::string &name, double value)
 
void setParametersValues (const ParameterList &parameters)
 
bool matchParametersValues (const ParameterList &parameters)
 
size_t getNumberOfParameters () const
 
std::string getNamespace () const
 
std::string getParameterNameWithoutNamespace (const std::string &name) const
 

Protected Member Functions

void updateRootFrequencies ()
 
const std::shared_ptr< Parameter > & getSharedParameter (size_t i) const
 
std::shared_ptr< Parameter > & getSharedParameter (size_t i)
 
void addParameter_ (Parameter *parameter)
 
void addParameters_ (const ParameterList &parameters)
 
void includeParameters_ (const ParameterList &parameters)
 
void deleteParameter_ (size_t index)
 
void deleteParameter_ (std::string &name)
 
void deleteParameters_ (const std::vector< std::string > &names)
 
void resetParameters_ ()
 
void shareParameter_ (const std::shared_ptr< Parameter > &parameter)
 
void shareParameters_ (const ParameterList &parameters)
 
ParametergetParameter_ (const std::string &name)
 
ParametergetParameter_ (size_t index)
 
const ParametergetParameter_ (size_t index) const
 
ParametergetParameterWithNamespace_ (const std::string &name)
 
const ParametergetParameterWithNamespace_ (const std::string &name) const
 
ParameterListgetParameters_ ()
 
Check function.
bool checkOrphanModels (bool throwEx) const
 
bool checkOrphanNodes (const Tree &tree, bool throwEx) const
 
bool checkUnknownNodes (const Tree &tree, bool throwEx) const
 

Protected Attributes

const Alphabetalphabet_
 A pointer toward the common alphabet to all models in the set. More...
 
size_t nbStates_
 
std::vector< TransitionModel * > modelSet_
 Contains all models used in this tree. More...
 

Private Attributes

std::unique_ptr< FrequenciesSetrootFrequencies_
 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< ParameterListmodelParameters_
 Parameters for each model in the set. More...
 
bool stationarity_
 

Detailed Description

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!

See also
SubstitutionModelSetTools for methods that provide instances of the SubstitutionModelSet for general cases.

Definition at line 105 of file SubstitutionModelSet.h.

Constructor & Destructor Documentation

bpp::SubstitutionModelSet::SubstitutionModelSet ( const Alphabet alpha)
inline

Create a model set according to the specified alphabet. Stationarity is assumed.

Parameters
alphaThe alphabet to use for this set.

Definition at line 151 of file SubstitutionModelSet.h.

Referenced by clone(), and isStationary().

bpp::SubstitutionModelSet::SubstitutionModelSet ( const Alphabet alpha,
FrequenciesSet rootFreqs 
)
inline

Create a model set according to the specified alphabet and root frequencies. Stationarity is not assumed.

Parameters
alphaThe alphabet to use for this set.
rootFreqsThe frequencies at root node. The underlying object will be owned by this instance.

Definition at line 171 of file SubstitutionModelSet.h.

References clear(), and setRootFrequencies().

SubstitutionModelSet::SubstitutionModelSet ( const SubstitutionModelSet set)

Definition at line 49 of file SubstitutionModelSet.cpp.

References modelSet_.

virtual bpp::SubstitutionModelSet::~SubstitutionModelSet ( )
inlinevirtual

Definition at line 207 of file SubstitutionModelSet.h.

Member Function Documentation

void SubstitutionModelSet::addModel ( TransitionModel model,
const std::vector< int > &  nodesId 
)

Add a new model to the set, and set relationships with nodes and params.

Parameters
modelA 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!
nodesIdthe set of nodes in the tree that points toward this model. This will override any previous affectation.
Exceptions
Exceptionin case of error:
  • if the new model does not match the alphabet
  • if the new model does not have the same number of states than existing ones
  • etc.

Definition at line 137 of file SubstitutionModelSet.cpp.

References bpp::AbstractParameterAliasable::addParameter_(), alphabet_, bpp::ParameterList::clone(), bpp::TransitionModel::getAlphabet(), bpp::Alphabet::getAlphabetType(), bpp::TransitionModel::getNumberOfStates(), bpp::ParameterList::getParameter(), bpp::ParameterList::getParameterNames(), bpp::ParameterAliasable::getParameters(), modelParameters_, modelSet_, modelToNodes_, nbStates_, nodeToModel_, bpp::Parameter::setName(), and bpp::TextTools::toString().

Referenced by bpp::SubstitutionModelSetTools::createHomogeneousModelSet(), bpp::SubstitutionModelSetTools::createNonHomogeneousModelSet(), getNodesWithModel(), and bpp::PhylogeneticsApplicationTools::setSubstitutionModelSet().

bool SubstitutionModelSet::checkOrphanModels ( bool  throwEx) const
protected
bool SubstitutionModelSet::checkOrphanNodes ( const Tree tree,
bool  throwEx 
) const
protected
bool SubstitutionModelSet::checkUnknownNodes ( const Tree tree,
bool  throwEx 
) const
protected
SubstitutionModelSet* bpp::SubstitutionModelSet::clone ( ) const
inlinevirtual

Implements bpp::AbstractParameterAliasable.

Definition at line 215 of file SubstitutionModelSet.h.

References SubstitutionModelSet().

void SubstitutionModelSet::fireParameterChanged ( const ParameterList parameters)
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
parametersThe modified parameters.

Reimplemented from bpp::AbstractParameterAliasable.

Reimplemented in bpp::MixedSubstitutionModelSet.

Definition at line 233 of file SubstitutionModelSet.cpp.

References bpp::AbstractParameterAliasable::fireParameterChanged(), bpp::AbstractParameterAliasable::getParameterValue(), modelParameters_, modelSet_, bpp::TextTools::toString(), and updateRootFrequencies().

Referenced by bpp::MixedSubstitutionModelSet::fireParameterChanged(), and getNumberOfStates().

virtual std::string bpp::SubstitutionModelSet::getAlphabetStateAsChar ( size_t  index) const
inlinevirtual
Parameters
indexThe model state.
Returns
The corresponding alphabet state as character code.

Definition at line 499 of file SubstitutionModelSet.h.

References bpp::TransitionModel::getAlphabetStateAsChar(), and getModel().

Referenced by bpp::AbstractNonHomogeneousTreeLikelihood::getAlphabetStateAsChar().

virtual int bpp::SubstitutionModelSet::getAlphabetStateAsInt ( size_t  index) const
inlinevirtual
Parameters
indexThe model state.
Returns
The corresponding alphabet state as character code.

Definition at line 491 of file SubstitutionModelSet.h.

References bpp::TransitionModel::getAlphabetStateAsInt(), and getModel().

Referenced by bpp::AbstractNonHomogeneousTreeLikelihood::getAlphabetStateAsInt().

virtual const std::vector<int>& bpp::SubstitutionModelSet::getAlphabetStates ( ) const
inlinevirtual
Returns
The supported states of the model set, as a vector of int codes.
See also
Alphabet

Definition at line 471 of file SubstitutionModelSet.h.

References bpp::TransitionModel::getAlphabetStates(), and getModel().

Referenced by bpp::AbstractNonHomogeneousTreeLikelihood::getAlphabetStates().

TransitionModel* bpp::SubstitutionModelSet::getModel ( size_t  i)
inline

Definition at line 259 of file SubstitutionModelSet.h.

const TransitionModel* bpp::SubstitutionModelSet::getModelForNode ( int  nodeId) const
inline
TransitionModel* bpp::SubstitutionModelSet::getModelForNode ( int  nodeId)
inline

Definition at line 336 of file SubstitutionModelSet.h.

References bpp::TextTools::toString().

size_t bpp::SubstitutionModelSet::getModelIndexForNode ( int  nodeId) const
inline

Get the index in the set of the model associated to a particular node id.

Parameters
nodeIdThe id of the query node.
Returns
The index of the model associated to the given node.
Exceptions
ExceptionIf no model is found for this node.

Definition at line 314 of file SubstitutionModelSet.h.

References bpp::TextTools::toString().

Referenced by bpp::RNonHomogeneousMixedTreeLikelihood::computeTransitionProbabilitiesForNode().

ParameterList bpp::SubstitutionModelSet::getModelParameters ( size_t  modelIndex) const

Get the parameters attached to a Model.

Parameters
modelIndexthe index of the model in the set
Returns
The parameters attached to the model.

Referenced by getNodeParameters().

virtual std::vector<size_t> bpp::SubstitutionModelSet::getModelStates ( int  code) const
inlinevirtual

Definition at line 479 of file SubstitutionModelSet.h.

References getModel(), and bpp::TransitionModel::getModelStates().

virtual std::vector<size_t> bpp::SubstitutionModelSet::getModelStates ( const std::string &  code) const
inlinevirtual

Definition at line 483 of file SubstitutionModelSet.h.

References getModel(), and bpp::TransitionModel::getModelStates().

ParameterList bpp::SubstitutionModelSet::getNodeParameters ( ) const
inline

Get the parameters corresponding attached to the nodes of the tree.

That is, all the parameters without the root frequencies.

Returns
The parameters attached to the nodes of the tree.

Definition at line 443 of file SubstitutionModelSet.h.

References bpp::ParameterList::addParameter(), getModelParameters(), bpp::AbstractParameterAliasable::getNumberOfParameters(), and bpp::AbstractParameterAliasable::getParameter_().

Referenced by bpp::DRNonHomogeneousTreeLikelihood::fireParameterChanged(), bpp::RNonHomogeneousTreeLikelihood::fireParameterChanged(), bpp::RNonHomogeneousMixedTreeLikelihood::fireParameterChanged(), and replaceModel().

const std::vector<int>& bpp::SubstitutionModelSet::getNodesWithModel ( size_t  i) const
inline
std::vector< int > SubstitutionModelSet::getNodesWithParameter ( const std::string &  name) const
Parameters
nameThe name of the parameter to look for.
Returns
The list of nodes with a model containing the specified parameter.
Exceptions
ParameterNotFoundExceptionIf no parameter with the specified name is found.

Definition at line 115 of file SubstitutionModelSet.cpp.

References bpp::AbstractParameterAliasable::getAlias(), getNodesWithModel(), and bpp::AbstractParameterAliasable::hasParameter().

Referenced by bpp::DRNonHomogeneousTreeLikelihood::fireParameterChanged(), bpp::RNonHomogeneousTreeLikelihood::fireParameterChanged(), bpp::RNonHomogeneousMixedTreeLikelihood::fireParameterChanged(), and getNodesWithModel().

size_t bpp::SubstitutionModelSet::getNumberOfStates ( ) const
inline

Get the number of states associated to this model set.

Returns
The number of states.
Exceptions
Exceptionif no model is associated to the set.

Definition at line 224 of file SubstitutionModelSet.h.

References fireParameterChanged(), and nbStates_.

Referenced by bpp::AbstractNonHomogeneousTreeLikelihood::getNumberOfStates(), and bpp::AbstractNonHomogeneousTreeLikelihood::setSubstitutionModelSet().

ParameterList bpp::SubstitutionModelSet::getRootFrequenciesParameters ( ) const
inline

Get the parameters corresponding to the root frequencies.

Returns
The parameters corresponding to the root frequencies.

Definition at line 428 of file SubstitutionModelSet.h.

Referenced by bpp::AbstractNonHomogeneousTreeLikelihood::getRootFrequenciesParameters().

const FrequenciesSet* bpp::SubstitutionModelSet::getRootFrequenciesSet ( ) const
inline
Returns
The set of root frequencies.

Definition at line 410 of file SubstitutionModelSet.h.

Referenced by bpp::PhylogeneticsApplicationTools::printParameters().

virtual const StateMap& bpp::SubstitutionModelSet::getStateMap ( ) const
inlinevirtual

Definition at line 475 of file SubstitutionModelSet.h.

References getModel(), and bpp::TransitionModel::getStateMap().

SubstitutionModel* bpp::SubstitutionModelSet::getSubstitutionModel ( size_t  i)
inline

Definition at line 281 of file SubstitutionModelSet.h.

References getModel().

const SubstitutionModel* bpp::SubstitutionModelSet::getSubstitutionModelForNode ( int  nodeId) const
inline
SubstitutionModel* bpp::SubstitutionModelSet::getSubstitutionModelForNode ( int  nodeId)
inline

Definition at line 349 of file SubstitutionModelSet.h.

References getModelForNode().

bool SubstitutionModelSet::hasMixedSubstitutionModel ( ) const
bool bpp::SubstitutionModelSet::hasOnlySubstitutionModels ( ) const
inline

Definition at line 298 of file SubstitutionModelSet.h.

bool bpp::SubstitutionModelSet::isFullySetUpFor ( const Tree tree,
bool  throwEx = true 
) const
inline

Check if the model set is fully specified for a given tree.

This include:

  • that each node as a model set up,
  • that each model in the set is attributed to a node,
  • that each parameter in the set actually correspond to a model.
  • all nodes ids in the set refer to an existing node in the tree.
Parameters
treeThe tree to check.
throwExTell if an exception have to be thrown in case of test not passed.

Definition at line 515 of file SubstitutionModelSet.h.

References checkOrphanModels(), checkOrphanNodes(), and checkUnknownNodes().

Referenced by bpp::DRNonHomogeneousTreeLikelihood::DRNonHomogeneousTreeLikelihood(), bpp::NonHomogeneousSequenceSimulator::NonHomogeneousSequenceSimulator(), bpp::RNonHomogeneousMixedTreeLikelihood::RNonHomogeneousMixedTreeLikelihood(), and bpp::RNonHomogeneousTreeLikelihood::RNonHomogeneousTreeLikelihood().

bool bpp::SubstitutionModelSet::isStationary ( ) const
inline
void SubstitutionModelSet::listModelNames ( std::ostream &  out = std::cout) const

Definition at line 220 of file SubstitutionModelSet.cpp.

References modelSet_, and modelToNodes_.

Referenced by getNodesWithModel().

void SubstitutionModelSet::replaceModel ( size_t  modelIndex,
TransitionModel model 
)

Replace a model in the set, and all corresponding parameters. The replaced model deleted.

Parameters
modelIndexThe index of the model in the set.
modelthe new model. This model will be owned by the Set.
Exceptions
Exceptionif a parameter becomes orphan because of the removal.

Definition at line 171 of file SubstitutionModelSet.cpp.

References bpp::AbstractParameterAliasable::addParameter_(), bpp::ParameterList::clone(), bpp::AbstractParameterAliasable::deleteParameter_(), bpp::AbstractParameterAliasable::getAlias(), getNodeParameters(), bpp::ParameterList::getParameter(), bpp::ParameterList::getParameterNames(), bpp::ParameterAliasable::getParameters(), modelParameters_, modelSet_, bpp::Parameter::setName(), bpp::ParameterList::size(), bpp::TextTools::toInt(), bpp::TextTools::toString(), and bpp::AbstractParameterAliasable::unaliasParameters().

Referenced by getNodesWithModel().

void bpp::SubstitutionModelSet::updateRootFrequencies ( )
inlineprotected

Set rootFrequencies_ from parameters.

Definition at line 527 of file SubstitutionModelSet.h.

References checkOrphanModels(), checkOrphanNodes(), checkUnknownNodes(), and bpp::AbstractParameterAliasable::getParameters().

Referenced by fireParameterChanged().

Member Data Documentation

const Alphabet* bpp::SubstitutionModelSet::alphabet_
protected

A pointer toward the common alphabet to all models in the set.

Definition at line 112 of file SubstitutionModelSet.h.

Referenced by addModel(), getAlphabet(), and operator=().

std::vector<ParameterList> bpp::SubstitutionModelSet::modelParameters_
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 140 of file SubstitutionModelSet.h.

Referenced by addModel(), clear(), fireParameterChanged(), operator=(), and replaceModel().

std::vector<TransitionModel*> bpp::SubstitutionModelSet::modelSet_
protected

Contains all models used in this tree.

Definition at line 119 of file SubstitutionModelSet.h.

Referenced by addModel(), checkOrphanModels(), clear(), fireParameterChanged(), listModelNames(), operator=(), replaceModel(), and SubstitutionModelSet().

std::map<size_t, std::vector<int> > bpp::SubstitutionModelSet::modelToNodes_
mutableprivate
size_t bpp::SubstitutionModelSet::nbStates_
protected

Definition at line 114 of file SubstitutionModelSet.h.

Referenced by addModel(), clear(), getNumberOfStates(), and operator=().

std::map<int, size_t> bpp::SubstitutionModelSet::nodeToModel_
mutableprivate

Contains for each node in a tree the index of the corresponding model in modelSet_.

Definition at line 130 of file SubstitutionModelSet.h.

Referenced by addModel(), checkOrphanModels(), checkOrphanNodes(), clear(), and operator=().

std::unique_ptr<FrequenciesSet> bpp::SubstitutionModelSet::rootFrequencies_
private

Root frequencies.

Definition at line 125 of file SubstitutionModelSet.h.

Referenced by clear(), operator=(), and setRootFrequencies().

bool bpp::SubstitutionModelSet::stationarity_
private

Definition at line 142 of file SubstitutionModelSet.h.

Referenced by clear(), isStationary(), operator=(), and setRootFrequencies().


The documentation for this class was generated from the following files: