bpp-phyl3  3.0.0
PhyloBranchMapping.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_PHYLOBRANCHMAPPING_H
6 #define BPP_PHYL_MAPPING_PHYLOBRANCHMAPPING_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 ProbabilisticSubstitutionMapping class.
22  *
23  */
24 
26  public PhyloBranch
27 {
28 protected:
29  /*
30  * @brief counts are stored by site / type
31  *
32  */
33 
35 
36 public:
45  PhyloBranch(),
46  counts_()
47  {}
48 
49  PhyloBranchMapping(double length) :
50  PhyloBranch(length),
51  counts_()
52  {}
53 
55  PhyloBranch(branch),
56  counts_()
57  {}
58 
66  PhyloBranch(branch),
67  counts_(branch.counts_)
68  {}
69 
77  {
78  PhyloBranch::operator=(branch);
79  counts_ = branch.counts_;
80  return *this;
81  }
82 
83  PhyloBranchMapping* clone() const { return new PhyloBranchMapping(*this); }
84 
90  {}
91 
96  void setNumberOfSites(size_t nbSites)
97  {
98  VectorTools::resize2(counts_, nbSites, (counts_.size() != 0 ? counts_[0].size() : 0));
99  }
100 
104  void setNumberOfTypes(size_t nbTypes)
105  {
106  VectorTools::resize2(counts_, counts_.size(), nbTypes);
107  }
108 
112  void setNumberOfSitesAndTypes(size_t nbSites, size_t nbTypes)
113  {
114  VectorTools::resize2(counts_, nbSites, nbTypes);
115  }
116 
117 
121  size_t getNumberOfSites() const
122  {
123  return counts_.size();
124  }
125 
129  size_t getNumberOfTypes() const
130  {
131  return counts_.size() ? counts_[0].size() : 0;
132  }
133 
138  Vdouble& getSiteCount(size_t site)
139  {
140  return counts_[site];
141  }
142 
143  const Vdouble& getSiteCount(size_t site) const
144  {
145  return counts_[site];
146  }
147 
157  double getSiteTypeCount(size_t site, size_t type) const
158  {
159  if (site >= getNumberOfSites())
160  throw BadSizeException("PhyloBranchMapping::getSiteTypeCount : bad site number", site, getNumberOfSites());
161  if (type >= getNumberOfTypes())
162  throw BadSizeException("PhyloBranchMapping::getSiteTypeCount : bad site number", type, getNumberOfTypes());
163  return counts_[site][type];
164  }
165 
170  void setSiteTypeCount(size_t site, size_t type, double value)
171  {
172  if (site >= getNumberOfSites())
173  throw BadSizeException("PhyloBranchMapping::setSiteTypeCount : bad site number", site, getNumberOfSites());
174  if (type >= getNumberOfTypes())
175  throw BadSizeException("PhyloBranchMapping::setSiteTypeCount : bad type number", type, getNumberOfTypes());
176  counts_[site][type] = value;
177  }
178 
179 
184  double operator()(size_t site, size_t type) const
185  {
186  return counts_[site][type];
187  }
188 
189  double& operator()(size_t site, size_t type)
190  {
191  return counts_[site][type];
192  }
193 
198  const VVdouble& getCounts() const
199  {
200  return counts_;
201  }
202 
204  {
205  return counts_;
206  }
207 };
208 } // end of namespace bpp.
209 #endif // BPP_PHYL_MAPPING_PHYLOBRANCHMAPPING_H
const Vdouble & getSiteCount(size_t site) const
PhyloBranchMapping(const PhyloBranchMapping &branch)
Copy constructor.
PhyloBranchMapping * clone() const
void setSiteTypeCount(size_t site, size_t type, double value)
Sets the counts at a given site on a given type.
size_t getNumberOfTypes() const
Gets the number of types.
PhyloBranchMapping(const PhyloBranch &branch)
~PhyloBranchMapping()
destructor. In Graph, nothing is changed.
double getSiteTypeCount(size_t site, size_t type) const
Gets the counts at a given site on a given type.
double operator()(size_t site, size_t type) const
Without check.
PhyloBranchMapping()
Constructors.
const VVdouble & getCounts() const
return counts
void setNumberOfTypes(size_t nbTypes)
Define a number of types.
PhyloBranchMapping(double length)
Vdouble & getSiteCount(size_t site)
Gets the counts at a given site.
size_t getNumberOfSites() const
Gets the number of sites.
double & operator()(size_t site, size_t type)
PhyloBranchMapping & operator=(const PhyloBranchMapping &branch)
Assignation operator.
void setNumberOfSites(size_t nbSites)
Sets a number of sites. If the number of types is already defined, it is kept.
void setNumberOfSitesAndTypes(size_t nbSites, size_t nbTypes)
Define a number of types.
PhyloBranch & operator=(const PhyloBranch &branch)
Assignation operator.
Definition: PhyloBranch.cpp:34
static void resize2(VVdouble &vv, size_t n1, size_t n2)
Defines the basic types of data flow nodes.
std::vector< double > Vdouble
std::vector< Vdouble > VVdouble