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 std::vector< size_t > getModelStates(int code) const =0
Get the state in the model corresponding to a particular state in the alphabet.
virtual const std::vector< int > & getAlphabetStates() const =0
virtual std::string getAlphabetStateAsChar(size_t index) const =0
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.
std::vector< size_t > getModelStates(const std::string &code) const
virtual void fireParameterChanged(const ParameterList ¶meters)
std::shared_ptr< SubstitutionModelInterface > getSubstitutionModel(size_t i)
std::vector< double > getRootFrequencies() const
const TransitionModelInterface & model(size_t i) const
void setNodeToModel(size_t modelIndex, int nodeId)
Sets an assignment of a given model index to a given onde id.
const FrequencySetInterface & rootFrequencySet() const
SubstitutionModelSet(std::shared_ptr< const Alphabet > alpha)
Create a model set according to the specified alphabet. Stationarity is assumed.
size_t getNumberOfModels() const
std::shared_ptr< FrequencySetInterface > rootFrequencies_
Root frequencies.
TransitionModelInterface & model(size_t i)
std::vector< int > getNodesWithParameter(const std::string &name) const
bool isFullySetUpFor(const Tree &tree, bool throwEx=true) const
Check if the model set is fully specified for a given tree.
std::shared_ptr< TransitionModelInterface > getModel(size_t i)
const std::vector< int > & getAlphabetStates() const
bool checkOrphanModels(bool throwEx) const
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::shared_ptr< SubstitutionModelInterface > getSubstitutionModelForNode(int nodeId)
std::map< int, size_t > nodeToModel_
Contains for each node in a tree the index of the corresponding model in modelSet_.
std::shared_ptr< const TransitionModelInterface > getModelForNode(int nodeId) const
Get the model associated to a particular node id.
const std::shared_ptr< FrequencySetInterface > getRootFrequencySet() const
const SubstitutionModelInterface & substitutionModel(size_t i) const
virtual ~SubstitutionModelSet()
ParameterList getRootFrequenciesParameters() const
Get the parameters corresponding to the root frequencies.
void updateRootFrequencies()
SubstitutionModelSet * clone() const
std::shared_ptr< const StateMapInterface > getStateMap() const
size_t getNumberOfStates() const
Get the number of states associated to this model set.
std::shared_ptr< const Alphabet > getAlphabet() const
std::shared_ptr< const SubstitutionModelInterface > getSubstitutionModelForNode(int nodeId) 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
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.
void listModelNames(std::ostream &out=std::cout) const
void resetModelToNodeIds()
Reset model indices to node ids assignment.
bool hasMixedTransitionModel() const
std::vector< size_t > getModelStates(int code) const
SubstitutionModelSet & operator=(const SubstitutionModelSet &set)
const std::vector< int > & getNodesWithModel(size_t i) const
Get a list of nodes id for which the given model is associated.
std::shared_ptr< const SubstitutionModelInterface > getSubstitutionModel(size_t i) const
Return a markovian substitution model (or null)
const StateMapInterface & stateMap() const
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
std::shared_ptr< TransitionModelInterface > getModelForNode(int nodeId)
bool checkUnknownNodes(const Tree &tree, bool throwEx) const
const Alphabet & alphabet() 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.
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.
std::shared_ptr< const TransitionModelInterface > getModel(size_t i) const
Get one model from the set knowing its index.
Interface for all transition models.
Interface for phylogenetic tree objects.
std::string toString(T t)
Defines the basic types of data flow nodes.