7 #include "../../Model/MixedTransitionModel.h"
15 alphabet_ (set.alphabet_),
16 nbStates_ (set.nbStates_),
17 modelSet_(set.modelSet_.size()),
18 rootFrequencies_(set.stationarity_ ? nullptr : set.rootFrequencies_->clone()),
19 nodeToModel_ (set.nodeToModel_),
20 modelToNodes_ (set.modelToNodes_),
21 modelParameters_ (set.modelParameters_),
22 stationarity_ (set.stationarity_)
25 for (
size_t i = 0; i < set.
modelSet_.size(); ++i)
47 for (
size_t i = 0; i < set.
modelSet_.size(); ++i)
80 vector<string> nalias =
getAlias(name);
81 size_t p = name.rfind(
"_");
82 vector<int> inode =
getNodesWithModel(TextTools::to<size_t>(name.substr(p + 1, string::npos)) - 1);
84 for (
size_t i = 0; i < nalias.size(); i++)
86 p = nalias[i].rfind(
"_");
87 size_t pos = TextTools::to<size_t>(nalias[i].substr(p + 1, string::npos));
91 inode.insert(inode.end(), ni.begin(), ni.end());
101 throw Exception(
"SubstitutionModelSet::addModel. A Substitution Model cannot be added to a Model Set if it does not have the same alphabet.");
103 throw Exception(
"SubstitutionModelSet::addModel. A Substitution Model cannot be added to a Model Set if it does not have the same number of states.");
107 size_t thisModelIndex =
modelSet_.size() - 1;
110 for (
size_t i = 0; i < nodesId.size(); i++)
123 for (
size_t i = 0; i < nplm.size(); i++)
157 for (
size_t i = pl.
size(); i > 0; i--)
159 string pn = pl[i - 1].getName();
161 size_t pu = pn.rfind(
"_");
164 if (nm == (
int)modelIndex + 1)
167 for (
unsigned j = 0; j < alpn.size(); j++)
187 for (
size_t i = 0; i < nplm.size(); i++)
203 for (
size_t i = 0; i <
modelSet_.size(); i++)
205 out <<
"Model " << i + 1 <<
": " <<
modelSet_[i]->getName() <<
"\t attached to nodes ";
233 for (
size_t i = 0; i <
modelSet_.size(); i++)
249 for (
size_t i = 0; i < ids.size(); i++)
254 throw Exception(
"SubstitutionModelSet::checkOrphanNodes(). Node '" +
TextTools::toString(ids[i]) +
"' in tree has no model associated.");
274 throw Exception(
"SubstitutionModelSet::checkUnknownNodes(). Node '" +
TextTools::toString(
id) +
"' is not found in tree or is the root node.");
void addParameters_(const ParameterList ¶meters)
virtual std::vector< std::string > getAlias(const std::string &name) const
void unaliasParameters(const std::string &p1, const std::string &p2)
void deleteParameter_(size_t index)
void addParameter_(Parameter *parameter)
AbstractParameterAliasable & operator=(const AbstractParameterAliasable &ap)
bool hasParameter(const std::string &name) const override
double getParameterValue(const std::string &name) const override
virtual std::string getAlphabetType() const=0
virtual size_t getNumberOfStates() const =0
Get the number of states.
virtual const Alphabet & alphabet() const =0
Interface for Transition models, defined as a mixture of "simple" transition models.
virtual std::vector< std::string > getParameterNames() const
ParameterList * clone() const
virtual const Parameter & parameter(const std::string &name) const
virtual void setName(const std::string &name)
virtual const ParameterList & getParameters() const=0
Substitution models manager for non-homogeneous / non-reversible models of evolution.
virtual void fireParameterChanged(const ParameterList ¶meters)
void setNodeToModel(size_t modelIndex, int nodeId)
Sets an assignment of a given model index to a given onde id.
SubstitutionModelSet(std::shared_ptr< const Alphabet > alpha)
Create a model set according to the specified alphabet. Stationarity is assumed.
size_t getNumberOfModels() const
const TransitionModelInterface & model(size_t i) const
std::shared_ptr< FrequencySetInterface > rootFrequencies_
Root frequencies.
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 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.
std::map< int, size_t > nodeToModel_
Contains for each node in a tree the index of the corresponding model in modelSet_.
void updateRootFrequencies()
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
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.
bool checkUnknownNodes(const Tree &tree, bool throwEx) 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.
void clear()
Resets all the information contained in this object.
Interface for phylogenetic tree objects.
virtual std::vector< int > getNodesId() const =0
virtual int getRootId() const =0
int toInt(const std::string &s, char scientificNotation='e')
std::string toString(T t)
Defines the basic types of data flow nodes.