5 #ifndef BPP_PHYL_LEGACY_MODEL_SUBSTITUTIONMODELSET_H
6 #define BPP_PHYL_LEGACY_MODEL_SUBSTITUTIONMODELSET_H
12 #include "../../Model/AbstractSubstitutionModel.h"
13 #include "../../Model/FrequencySet/FrequencySet.h"
14 #include "../../Tree/Tree.h"
81 std::vector< std::shared_ptr<TransitionModelInterface>>
modelSet_;
133 std::shared_ptr<const Alphabet> alpha,
134 std::shared_ptr<FrequencySetInterface> rootFreqs) :
210 std::shared_ptr<const TransitionModelInterface>
getModel(
size_t i)
const
222 std::shared_ptr<TransitionModelInterface>
getModel(
size_t i)
238 auto m = std::dynamic_pointer_cast<const SubstitutionModelInterface>(
getModel(i));
241 throw Exception(
"SubstitutionModelSet::getSubstitutionModel : " +
model(i).getName() +
" is not a substitution model.");
247 auto m = std::dynamic_pointer_cast<SubstitutionModelInterface>(
getModel(i));
250 throw Exception(
"SubstitutionModelSet::getSubstitutionModel : " +
model(i).getName() +
" is not a substitution model.");
262 throw Exception(
"SubstitutionModelSet::substitutionModel : " +
model(i).getName() +
" is not a substitution model.");
273 auto model = std::dynamic_pointer_cast<const SubstitutionModelInterface>(mod);
274 if (!
model)
return false;
318 return std::dynamic_pointer_cast<const SubstitutionModelInterface>(
getModelForNode(nodeId));
323 return std::dynamic_pointer_cast<SubstitutionModelInterface>(
getModelForNode(nodeId));
363 void addModel(std::shared_ptr<TransitionModelInterface>
model,
const std::vector<int>& nodesId);
389 void replaceModel(
size_t modelIndex, std::shared_ptr<TransitionModelInterface>
model);
409 throw NullPointerException(
"SubstitutionModelSet::rootFrequencySet. No associated root frequencies.");
size_t getNumberOfParameters() const override
const ParameterList & getParameters() const override
Parameter & getParameter_(const std::string &name)
virtual int getAlphabetStateAsInt(size_t index) const =0
virtual const std::vector< int > & getAlphabetStates() const =0
virtual std::string getAlphabetStateAsChar(size_t index) const =0
virtual std::vector< size_t > getModelStates(int code) const =0
Get the state in the model corresponding to a particular state in the alphabet.
virtual std::shared_ptr< const StateMapInterface > getStateMap() const =0
virtual const StateMapInterface & stateMap() const =0
Parametrize a set of state frequencies.
virtual void addParameter(const Parameter ¶m)
Map the states of a given alphabet which have a model state.
Interface for all substitution models.
Substitution models manager for non-homogeneous / non-reversible models of evolution.
virtual void fireParameterChanged(const ParameterList ¶meters)
std::shared_ptr< const SubstitutionModelInterface > getSubstitutionModelForNode(int nodeId) const
void setNodeToModel(size_t modelIndex, int nodeId)
Sets an assignment of a given model index to a given onde id.
const std::shared_ptr< FrequencySetInterface > getRootFrequencySet() const
SubstitutionModelSet(std::shared_ptr< const Alphabet > alpha)
Create a model set according to the specified alphabet. Stationarity is assumed.
std::vector< size_t > getModelStates(int code) const
size_t getNumberOfModels() const
const TransitionModelInterface & model(size_t i) const
std::shared_ptr< FrequencySetInterface > rootFrequencies_
Root frequencies.
const std::vector< int > & getAlphabetStates() const
std::shared_ptr< TransitionModelInterface > getModelForNode(int nodeId)
std::vector< int > getNodesWithParameter(const std::string &name) const
const std::vector< int > & getNodesWithModel(size_t i) const
Get a list of nodes id for which the given model is associated.
bool isFullySetUpFor(const Tree &tree, bool throwEx=true) const
Check if the model set is fully specified for a given tree.
bool checkOrphanModels(bool throwEx) const
std::shared_ptr< const TransitionModelInterface > getModel(size_t i) const
Get one model from the set knowing its index.
std::shared_ptr< const Alphabet > alphabet_
A pointer toward the common alphabet to all models in the set.
bool checkOrphanNodes(const Tree &tree, bool throwEx) const
void setRootFrequencies(std::shared_ptr< FrequencySetInterface > rootFreqs)
Sets a given FrequencySet for root frequencies.
ParameterList getModelParameters(size_t modelIndex) const
Get the parameters attached to a Model.
int getAlphabetStateAsInt(size_t index) const
std::map< int, size_t > nodeToModel_
Contains for each node in a tree the index of the corresponding model in modelSet_.
std::shared_ptr< SubstitutionModelInterface > getSubstitutionModel(size_t i)
std::shared_ptr< const SubstitutionModelInterface > getSubstitutionModel(size_t i) const
Return a markovian substitution model (or null)
std::shared_ptr< TransitionModelInterface > getModel(size_t i)
std::shared_ptr< SubstitutionModelInterface > getSubstitutionModelForNode(int nodeId)
virtual ~SubstitutionModelSet()
std::shared_ptr< const TransitionModelInterface > getModelForNode(int nodeId) const
Get the model associated to a particular node id.
ParameterList getRootFrequenciesParameters() const
Get the parameters corresponding to the root frequencies.
void updateRootFrequencies()
size_t getNumberOfStates() const
Get the number of states associated to this model set.
std::shared_ptr< const StateMapInterface > getStateMap() const
std::vector< double > getRootFrequencies() const
const SubstitutionModelInterface & substitutionModel(size_t i) const
size_t getModelIndexForNode(int nodeId) const
Get the index in the set of the model associated to a particular node id.
bool hasOnlySubstitutionModels() const
check if has only markovian substitution models
const Alphabet & alphabet() const
void addModel(std::shared_ptr< TransitionModelInterface > model, const std::vector< int > &nodesId)
Add a new model to the set, and set relationships with nodes and params.
SubstitutionModelSet * clone() const
std::vector< size_t > getModelStates(const std::string &code) const
void listModelNames(std::ostream &out=std::cout) const
void resetModelToNodeIds()
Reset model indices to node ids assignment.
bool hasMixedTransitionModel() const
SubstitutionModelSet & operator=(const SubstitutionModelSet &set)
std::map< size_t, std::vector< int > > modelToNodes_
ParameterList getNodeParameters() const
Get the parameters corresponding attached to the nodes of the tree.
std::string getAlphabetStateAsChar(size_t index) const
bool checkUnknownNodes(const Tree &tree, bool throwEx) const
bool isStationary() const
void replaceModel(size_t modelIndex, std::shared_ptr< TransitionModelInterface > model)
Replace a model in the set, and all corresponding parameters. The replaced model deleted.
std::vector< std::shared_ptr< TransitionModelInterface > > modelSet_
Contains all models used in this tree.
std::vector< ParameterList > modelParameters_
Parameters for each model in the set.
TransitionModelInterface & model(size_t i)
const StateMapInterface & stateMap() const
std::shared_ptr< const Alphabet > getAlphabet() const
const FrequencySetInterface & rootFrequencySet() const
SubstitutionModelSet(std::shared_ptr< const Alphabet > alpha, std::shared_ptr< FrequencySetInterface > rootFreqs)
Create a model set according to the specified alphabet and root frequencies. Stationarity is not assu...
void clear()
Resets all the information contained in this object.
Interface for all transition models.
Interface for phylogenetic tree objects.
std::string toString(T t)
Defines the basic types of data flow nodes.