bpp-phyl3  3.0.0
PhyloBranchReward.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_MAPPING_PHYLOBRANCHREWARD_H
6 #define BPP_PHYL_MAPPING_PHYLOBRANCHREWARD_H
7 
8 #include <Bpp/Clonable.h>
9 #include <Bpp/Exceptions.h>
10 #include <Bpp/Numeric/Number.h>
11 
12 #include "../Tree/PhyloBranch.h"
13 
14 namespace bpp
15 {
16 /*
17  * @brief A branch with countings.
18  *
19  * WARNING : this class does not know anything about site
20  * compression, if any. If there are site patterns, they are
21  * available in ProbabilisticSubstitutionReward class.
22  *
23  */
24 
26  public PhyloBranch
27 {
28 protected:
29  /*
30  * @brief rewards are stored by site
31  *
32  */
33 
35 
36 public:
45  PhyloBranch(),
46  rewards_()
47  {}
48 
49  PhyloBranchReward(double length) :
50  PhyloBranch(length),
51  rewards_()
52  {}
53 
54  PhyloBranchReward(const PhyloBranch& branch) :
55  PhyloBranch(branch),
56  rewards_()
57  {}
58 
66  PhyloBranch(branch),
67  rewards_(branch.rewards_)
68  {}
69 
77  {
78  PhyloBranch::operator=(branch);
79  rewards_ = branch.rewards_;
80  return *this;
81  }
82 
83  PhyloBranchReward* clone() const { return new PhyloBranchReward(*this); }
84 
90  {}
91 
95  void setNumberOfSites(size_t nbSites)
96  {
97  rewards_.resize(nbSites);
98  }
99 
103  size_t getNumberOfSites() const
104  {
105  return rewards_.size();
106  }
107 
108 
109  double getSiteReward(size_t site) const
110  {
111  if (site >= getNumberOfSites())
112  throw BadSizeException("PhyloBranchReward::getSiteReward : bad site number", site, getNumberOfSites());
113  return rewards_[site];
114  }
115 
116  void setSiteReward(size_t site, double rew)
117  {
118  if (site >= getNumberOfSites())
119  throw BadSizeException("PhyloBranchReward::setSiteReward : bad site number", site, getNumberOfSites());
120  rewards_[site] = rew;
121  }
122 
132  double operator()(size_t site) const
133  {
134  return rewards_[site];
135  }
136 
137  double& operator()(size_t site)
138  {
139  return rewards_[site];
140  }
141 
146  const Vdouble& getRewards() const
147  {
148  return rewards_;
149  }
150 
152  {
153  return rewards_;
154  }
155 };
156 } // end of namespace bpp.
157 #endif // BPP_PHYL_MAPPING_PHYLOBRANCHREWARD_H
size_t getNumberOfSites() const
Gets the number of sites.
double operator()(size_t site) const
Gets the rewards at a given site on a given type.
const Vdouble & getRewards() const
return rewards
void setSiteReward(size_t site, double rew)
void setNumberOfSites(size_t nbSites)
Sets a number of sites.
double & operator()(size_t site)
double getSiteReward(size_t site) const
PhyloBranchReward(const PhyloBranchReward &branch)
Copy constructor.
PhyloBranchReward & operator=(const PhyloBranchReward &branch)
Assignation operator.
~PhyloBranchReward()
destructor. In Graph, nothing is changed.
PhyloBranchReward * clone() const
PhyloBranchReward()
Constructors.
PhyloBranchReward(double length)
PhyloBranchReward(const PhyloBranch &branch)
PhyloBranch & operator=(const PhyloBranch &branch)
Assignation operator.
Definition: PhyloBranch.cpp:34
Defines the basic types of data flow nodes.
std::vector< double > Vdouble