bpp-phyl3  3.0.0
ModelPath.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
5 #ifndef BPP_PHYL_LIKELIHOOD_MODELPATH_H
6 #define BPP_PHYL_LIKELIHOOD_MODELPATH_H
7 
8 #include <Bpp/Exceptions.h>
10 
11 #include "../Model/MixedTransitionModel.h"
12 
13 namespace bpp
14 {
21 class ModelPath
22 {
23 public:
29  class PathNode : public Vuint
30  {
31 public:
32  PathNode() {}
33  PathNode(const PathNode& n) : Vuint(n){}
34 
36 
42  void insertN(const Vuint& vn);
43 
49  void removeN(const Vuint& vn);
50 
51 
52  PathNode& operator=(const Vuint& vn)
53  {
54  clear();
55  insertN(vn);
56  return *this;
57  }
58 
64  {
65  insertN(n);
66  return *this;
67  }
68 
73  {
74  removeN(n);
75  return *this;
76  }
77 
81  bool operator<=(const PathNode&) const;
82 
86  bool operator>=(const PathNode&) const;
87 
91  bool intersects(const PathNode&) const;
92 
96  std::string to_string() const;
97  };
98 
99 private:
103  std::map<std::shared_ptr<MixedTransitionModelInterface>, PathNode> mModPath_;
104 
108  std::shared_ptr<MixedTransitionModelInterface> leadMod_;
109 
113  double proba_;
114 
115 public:
117  ModelPath(const ModelPath&);
118  ModelPath& operator=(const ModelPath&);
120 
121  size_t size() const
122  {
123  return mModPath_.size();
124  }
125 
129  std::shared_ptr<MixedTransitionModelInterface> getLeadModel()
130  {
131  return leadMod_;
132  }
133 
134  const std::shared_ptr<MixedTransitionModelInterface> getLeadModel() const
135  {
136  return leadMod_;
137  }
138 
144  void setLeadModel(std::shared_ptr<MixedTransitionModelInterface> model)
145  {
146  if (mModPath_.find(model) == mModPath_.end())
147  throw Exception("ModelPath::setLeadModel: Unknown model " + model->getName());
148  leadMod_ = model;
149  }
150 
158  void setModel(std::shared_ptr<MixedTransitionModelInterface> mMod, const Vuint& vnS);
159 
168  void changeModel(std::shared_ptr<MixedTransitionModelInterface> mMod1,
169  std::shared_ptr<MixedTransitionModelInterface> mMod2);
170 
176  void removeModel(std::shared_ptr<MixedTransitionModelInterface> mMod)
177  {
178  if (mMod == leadMod_)
179  leadMod_ = 0;
180 
181  if (mModPath_.find(mMod) != mModPath_.end())
182  mModPath_.erase(mMod);
183  }
184 
192  void addToModel(std::shared_ptr<MixedTransitionModelInterface> mMod, const Vuint& vnS);
193 
197  ModelPath& operator+=(const ModelPath&);
198 
202  ModelPath& operator-=(const ModelPath&);
203 
208  bool operator<=(const ModelPath&) const;
209 
213  bool operator>=(const ModelPath&) const;
214 
220  bool intersects(const ModelPath&) const;
221 
225  double getProbability() const {return proba_; }
226 
230  void setProbability(double x) { proba_ = x; }
231 
235  bool hasModel(std::shared_ptr<MixedTransitionModelInterface> mMod) const
236  { return mModPath_.find(mMod) != mModPath_.end(); }
237 
238  bool hasModel(std::shared_ptr<const MixedTransitionModelInterface> mMod) const
239  {
240  for (const auto& mn:mModPath_)
241  {
242  if (mn.first == mMod)
243  return true;
244  }
245  return false;
246  }
247 
251  const PathNode& getPathNode(std::shared_ptr<MixedTransitionModelInterface> mMod) const
252  { return mModPath_.at(mMod); }
253 
254  const PathNode& getPathNode(std::shared_ptr<const MixedTransitionModelInterface> mMod) const
255  {
256  for (const auto& mn:mModPath_)
257  {
258  if (mn.first == mMod)
259  return mn.second;
260  }
261  throw Exception("ModelPath::getPathNode : unknown model " + mMod->getName());
262  }
263 
267  std::vector<std::shared_ptr<MixedTransitionModelInterface>> getModels() const;
268 
272  std::string toString() const;
273 };
274 } // end of namespace bpp.
275 #endif // BPP_PHYL_LIKELIHOOD_MODELPATH_H
A vector<int> where all elements are different and in INCREASING ORDER. So inclusion should be done t...
Definition: ModelPath.h:30
void insertN(const Vuint &vn)
Insert elements.
Definition: ModelPath.cpp:195
PathNode & operator+=(const PathNode &n)
Cumulates the elements of the given PathNode into this one.
Definition: ModelPath.h:63
bool operator>=(const PathNode &) const
checks if this PathNode includes another one.
Definition: ModelPath.cpp:235
PathNode & operator=(const Vuint &vn)
Definition: ModelPath.h:52
bool intersects(const PathNode &) const
checks if this PathNode intersects another one.
Definition: ModelPath.cpp:240
void removeN(const Vuint &vn)
Remove elements.
Definition: ModelPath.cpp:213
bool operator<=(const PathNode &) const
checks if this PathNode is included in another one.
Definition: ModelPath.cpp:221
PathNode & operator-=(const PathNode &n)
Remove the elements of the given PathNode from this one.
Definition: ModelPath.h:72
PathNode(const PathNode &n)
Definition: ModelPath.h:33
std::string to_string() const
Output.
Definition: ModelPath.cpp:257
Organization of submodels in mixed substitution models in a path. See class ModelScenario for a thoro...
Definition: ModelPath.h:22
ModelPath & operator-=(const ModelPath &)
Remove from the PathNodes of this object the matching ones of the ModelPath.
Definition: ModelPath.cpp:115
std::shared_ptr< MixedTransitionModelInterface > getLeadModel()
gets the leader model.
Definition: ModelPath.h:129
std::shared_ptr< MixedTransitionModelInterface > leadMod_
Definition: ModelPath.h:108
bool intersects(const ModelPath &) const
checks if this ModelPath intersects another one. Which means that one submodel explicitly declared in...
Definition: ModelPath.cpp:83
void removeModel(std::shared_ptr< MixedTransitionModelInterface > mMod)
Remove a model.
Definition: ModelPath.h:176
const std::shared_ptr< MixedTransitionModelInterface > getLeadModel() const
Definition: ModelPath.h:134
std::string toString() const
string description
Definition: ModelPath.cpp:147
std::map< std::shared_ptr< MixedTransitionModelInterface >, PathNode > mModPath_
Definition: ModelPath.h:103
const PathNode & getPathNode(std::shared_ptr< MixedTransitionModelInterface > mMod) const
gets the pathnode associated with a model
Definition: ModelPath.h:251
double getProbability() const
returns the probability
Definition: ModelPath.h:225
void setProbability(double x)
sets the probability
Definition: ModelPath.h:230
void changeModel(std::shared_ptr< MixedTransitionModelInterface > mMod1, std::shared_ptr< MixedTransitionModelInterface > mMod2)
change from a model to another
Definition: ModelPath.cpp:39
ModelPath & operator=(const ModelPath &)
Definition: ModelPath.cpp:20
std::vector< std::shared_ptr< MixedTransitionModelInterface > > getModels() const
gets the MixedTransitionModel used in the ModelPath
Definition: ModelPath.cpp:132
void setModel(std::shared_ptr< MixedTransitionModelInterface > mMod, const Vuint &vnS)
sets submodel numbers in the mixed model. Checks if all the numbers are valid.
Definition: ModelPath.cpp:28
bool hasModel(std::shared_ptr< MixedTransitionModelInterface > mMod) const
checks if there is a pathnode associated with a model
Definition: ModelPath.h:235
ModelPath & operator+=(const ModelPath &)
Cumulates the PathNodes of the given ModelPath into this one.
Definition: ModelPath.cpp:103
void addToModel(std::shared_ptr< MixedTransitionModelInterface > mMod, const Vuint &vnS)
adds submodel numbers to the mixed model. Checks if all the numbers are valid.
Definition: ModelPath.cpp:53
size_t size() const
Definition: ModelPath.h:121
void setLeadModel(std::shared_ptr< MixedTransitionModelInterface > model)
sets the leader model.
Definition: ModelPath.h:144
bool operator<=(const ModelPath &) const
checks if this ModelPath is included in another one. Which means that all submodels of this path are ...
Definition: ModelPath.cpp:64
double proba_
probability of this ModelPath.
Definition: ModelPath.h:113
bool hasModel(std::shared_ptr< const MixedTransitionModelInterface > mMod) const
Definition: ModelPath.h:238
const PathNode & getPathNode(std::shared_ptr< const MixedTransitionModelInterface > mMod) const
Definition: ModelPath.h:254
bool operator>=(const ModelPath &) const
checks if this ModelPath includes another one.
Definition: ModelPath.cpp:78
Defines the basic types of data flow nodes.
std::vector< unsigned int > Vuint